10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 220Sstevel@tonic-gate /* 230Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 280Sstevel@tonic-gate 290Sstevel@tonic-gate /* 300Sstevel@tonic-gate * PCI nexus interrupt handling: 310Sstevel@tonic-gate * PCI device interrupt handler wrapper 320Sstevel@tonic-gate * pil lookup routine 330Sstevel@tonic-gate * PCI device interrupt related initchild code 340Sstevel@tonic-gate */ 350Sstevel@tonic-gate 360Sstevel@tonic-gate #include <sys/types.h> 370Sstevel@tonic-gate #include <sys/kmem.h> 380Sstevel@tonic-gate #include <sys/async.h> 390Sstevel@tonic-gate #include <sys/spl.h> 400Sstevel@tonic-gate #include <sys/sunddi.h> 410Sstevel@tonic-gate #include <sys/machsystm.h> /* e_ddi_nodeid_to_dip() */ 420Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 430Sstevel@tonic-gate #include <sys/pci/pci_obj.h> 440Sstevel@tonic-gate #include <sys/sdt.h> 4566Sesolom #include <sys/clock.h> 460Sstevel@tonic-gate 470Sstevel@tonic-gate #ifdef _STARFIRE 480Sstevel@tonic-gate #include <sys/starfire.h> 490Sstevel@tonic-gate #endif /* _STARFIRE */ 500Sstevel@tonic-gate 510Sstevel@tonic-gate /* 520Sstevel@tonic-gate * interrupt jabber: 530Sstevel@tonic-gate * 540Sstevel@tonic-gate * When an interrupt line is jabbering, every time the state machine for the 550Sstevel@tonic-gate * associated ino is idled, a new mondo will be sent and the ino will go into 560Sstevel@tonic-gate * the pending state again. The mondo will cause a new call to 570Sstevel@tonic-gate * pci_intr_wrapper() which normally idles the ino's state machine which would 580Sstevel@tonic-gate * precipitate another trip round the loop. 590Sstevel@tonic-gate * The loop can be broken by preventing the ino's state machine from being 600Sstevel@tonic-gate * idled when an interrupt line is jabbering. See the comment at the 610Sstevel@tonic-gate * beginning of pci_intr_wrapper() explaining how the 'interrupt jabber 620Sstevel@tonic-gate * protection' code does this. 630Sstevel@tonic-gate */ 640Sstevel@tonic-gate 650Sstevel@tonic-gate /*LINTLIBRARY*/ 660Sstevel@tonic-gate 670Sstevel@tonic-gate #ifdef NOT_DEFINED 680Sstevel@tonic-gate /* 690Sstevel@tonic-gate * This array is used to determine the sparc PIL at the which the 700Sstevel@tonic-gate * handler for a given INO will execute. This table is for onboard 710Sstevel@tonic-gate * devices only. A different scheme will be used for plug-in cards. 720Sstevel@tonic-gate */ 730Sstevel@tonic-gate 740Sstevel@tonic-gate uint_t ino_to_pil[] = { 750Sstevel@tonic-gate 760Sstevel@tonic-gate /* pil */ /* ino */ 770Sstevel@tonic-gate 780Sstevel@tonic-gate 0, 0, 0, 0, /* 0x00 - 0x03: bus A slot 0 int#A, B, C, D */ 790Sstevel@tonic-gate 0, 0, 0, 0, /* 0x04 - 0x07: bus A slot 1 int#A, B, C, D */ 800Sstevel@tonic-gate 0, 0, 0, 0, /* 0x08 - 0x0B: unused */ 810Sstevel@tonic-gate 0, 0, 0, 0, /* 0x0C - 0x0F: unused */ 820Sstevel@tonic-gate 830Sstevel@tonic-gate 0, 0, 0, 0, /* 0x10 - 0x13: bus B slot 0 int#A, B, C, D */ 840Sstevel@tonic-gate 0, 0, 0, 0, /* 0x14 - 0x17: bus B slot 1 int#A, B, C, D */ 850Sstevel@tonic-gate 0, 0, 0, 0, /* 0x18 - 0x1B: bus B slot 2 int#A, B, C, D */ 860Sstevel@tonic-gate 4, 0, 0, 0, /* 0x1C - 0x1F: bus B slot 3 int#A, B, C, D */ 870Sstevel@tonic-gate 880Sstevel@tonic-gate 4, /* 0x20: SCSI */ 890Sstevel@tonic-gate 6, /* 0x21: ethernet */ 900Sstevel@tonic-gate 3, /* 0x22: parallel port */ 910Sstevel@tonic-gate 9, /* 0x23: audio record */ 920Sstevel@tonic-gate 9, /* 0x24: audio playback */ 930Sstevel@tonic-gate 14, /* 0x25: power fail */ 940Sstevel@tonic-gate 4, /* 0x26: 2nd SCSI */ 950Sstevel@tonic-gate 8, /* 0x27: floppy */ 960Sstevel@tonic-gate 14, /* 0x28: thermal warning */ 970Sstevel@tonic-gate 12, /* 0x29: keyboard */ 980Sstevel@tonic-gate 12, /* 0x2A: mouse */ 990Sstevel@tonic-gate 12, /* 0x2B: serial */ 1000Sstevel@tonic-gate 0, /* 0x2C: timer/counter 0 */ 1010Sstevel@tonic-gate 0, /* 0x2D: timer/counter 1 */ 1020Sstevel@tonic-gate 14, /* 0x2E: uncorrectable ECC errors */ 1030Sstevel@tonic-gate 14, /* 0x2F: correctable ECC errors */ 1040Sstevel@tonic-gate 14, /* 0x30: PCI bus A error */ 1050Sstevel@tonic-gate 14, /* 0x31: PCI bus B error */ 1060Sstevel@tonic-gate 14, /* 0x32: power management wakeup */ 1070Sstevel@tonic-gate 14, /* 0x33 */ 1080Sstevel@tonic-gate 14, /* 0x34 */ 1090Sstevel@tonic-gate 14, /* 0x35 */ 1100Sstevel@tonic-gate 14, /* 0x36 */ 1110Sstevel@tonic-gate 14, /* 0x37 */ 1120Sstevel@tonic-gate 14, /* 0x38 */ 1130Sstevel@tonic-gate 14, /* 0x39 */ 1140Sstevel@tonic-gate 14, /* 0x3a */ 1150Sstevel@tonic-gate 14, /* 0x3b */ 1160Sstevel@tonic-gate 14, /* 0x3c */ 1170Sstevel@tonic-gate 14, /* 0x3d */ 1180Sstevel@tonic-gate 14, /* 0x3e */ 1190Sstevel@tonic-gate 14, /* 0x3f */ 1200Sstevel@tonic-gate 14 /* 0x40 */ 1210Sstevel@tonic-gate }; 1220Sstevel@tonic-gate #endif /* NOT_DEFINED */ 1230Sstevel@tonic-gate 1240Sstevel@tonic-gate 1250Sstevel@tonic-gate #define PCI_SIMBA_VENID 0x108e /* vendor id for simba */ 1260Sstevel@tonic-gate #define PCI_SIMBA_DEVID 0x5000 /* device id for simba */ 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate /* 1290Sstevel@tonic-gate * map_pcidev_cfg_reg - create mapping to pci device configuration registers 1300Sstevel@tonic-gate * if we have a simba AND a pci to pci bridge along the 1310Sstevel@tonic-gate * device path. 1320Sstevel@tonic-gate * Called with corresponding mutexes held!! 1330Sstevel@tonic-gate * 1340Sstevel@tonic-gate * XXX XXX XXX The purpose of this routine is to overcome a hardware 1350Sstevel@tonic-gate * defect in Sabre CPU and Simba bridge configuration 1360Sstevel@tonic-gate * which does not drain DMA write data stalled in 1370Sstevel@tonic-gate * PCI to PCI bridges (such as the DEC bridge) beyond 1380Sstevel@tonic-gate * Simba. This routine will setup the data structures 1390Sstevel@tonic-gate * to allow the pci_intr_wrapper to perform a manual 1400Sstevel@tonic-gate * drain data operation before passing the control to 1410Sstevel@tonic-gate * interrupt handlers of device drivers. 1420Sstevel@tonic-gate * return value: 1430Sstevel@tonic-gate * DDI_SUCCESS 1440Sstevel@tonic-gate * DDI_FAILURE if unable to create mapping 1450Sstevel@tonic-gate */ 1460Sstevel@tonic-gate static int 1470Sstevel@tonic-gate map_pcidev_cfg_reg(dev_info_t *dip, dev_info_t *rdip, ddi_acc_handle_t *hdl_p) 1480Sstevel@tonic-gate { 1490Sstevel@tonic-gate dev_info_t *cdip; 1500Sstevel@tonic-gate dev_info_t *pci_dip = NULL; 1510Sstevel@tonic-gate pci_t *pci_p = get_pci_soft_state(ddi_get_instance(dip)); 1520Sstevel@tonic-gate int simba_found = 0, pci_bridge_found = 0; 1530Sstevel@tonic-gate 1540Sstevel@tonic-gate for (cdip = rdip; cdip && cdip != dip; cdip = ddi_get_parent(cdip)) { 1550Sstevel@tonic-gate ddi_acc_handle_t config_handle; 1560Sstevel@tonic-gate uint32_t vendor_id = ddi_getprop(DDI_DEV_T_ANY, cdip, 1570Sstevel@tonic-gate DDI_PROP_DONTPASS, "vendor-id", 0xffff); 1580Sstevel@tonic-gate 1590Sstevel@tonic-gate DEBUG4(DBG_A_INTX, pci_p->pci_dip, 1600Sstevel@tonic-gate "map dev cfg reg for %s%d: @%s%d\n", 1610Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip), 1620Sstevel@tonic-gate ddi_driver_name(cdip), ddi_get_instance(cdip)); 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate if (ddi_prop_exists(DDI_DEV_T_ANY, cdip, DDI_PROP_DONTPASS, 1650Sstevel@tonic-gate "no-dma-interrupt-sync")) 1660Sstevel@tonic-gate continue; 1670Sstevel@tonic-gate 1680Sstevel@tonic-gate /* continue to search up-stream if not a PCI device */ 1690Sstevel@tonic-gate if (vendor_id == 0xffff) 1700Sstevel@tonic-gate continue; 1710Sstevel@tonic-gate 1720Sstevel@tonic-gate /* record the deepest pci device */ 1730Sstevel@tonic-gate if (!pci_dip) 1740Sstevel@tonic-gate pci_dip = cdip; 1750Sstevel@tonic-gate 1760Sstevel@tonic-gate /* look for simba */ 1770Sstevel@tonic-gate if (vendor_id == PCI_SIMBA_VENID) { 1780Sstevel@tonic-gate uint32_t device_id = ddi_getprop(DDI_DEV_T_ANY, 1790Sstevel@tonic-gate cdip, DDI_PROP_DONTPASS, "device-id", -1); 1800Sstevel@tonic-gate if (device_id == PCI_SIMBA_DEVID) { 1810Sstevel@tonic-gate simba_found = 1; 1820Sstevel@tonic-gate DEBUG0(DBG_A_INTX, pci_p->pci_dip, 1830Sstevel@tonic-gate "\tFound simba\n"); 1840Sstevel@tonic-gate continue; /* do not check bridge if simba */ 1850Sstevel@tonic-gate } 1860Sstevel@tonic-gate } 1870Sstevel@tonic-gate 1880Sstevel@tonic-gate /* look for pci to pci bridge */ 1890Sstevel@tonic-gate if (pci_config_setup(cdip, &config_handle) != DDI_SUCCESS) { 1900Sstevel@tonic-gate cmn_err(CE_WARN, 1910Sstevel@tonic-gate "%s%d: can't get brdg cfg space for %s%d\n", 1920Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip), 1930Sstevel@tonic-gate ddi_driver_name(cdip), ddi_get_instance(cdip)); 1940Sstevel@tonic-gate return (DDI_FAILURE); 1950Sstevel@tonic-gate } 1960Sstevel@tonic-gate if (pci_config_get8(config_handle, PCI_CONF_BASCLASS) 1970Sstevel@tonic-gate == PCI_CLASS_BRIDGE) { 1980Sstevel@tonic-gate DEBUG0(DBG_A_INTX, pci_p->pci_dip, 1990Sstevel@tonic-gate "\tFound PCI to xBus bridge\n"); 2000Sstevel@tonic-gate pci_bridge_found = 1; 2010Sstevel@tonic-gate } 2020Sstevel@tonic-gate pci_config_teardown(&config_handle); 2030Sstevel@tonic-gate } 2040Sstevel@tonic-gate 2050Sstevel@tonic-gate if (!pci_bridge_found) 2060Sstevel@tonic-gate return (DDI_SUCCESS); 2070Sstevel@tonic-gate if (!simba_found && (CHIP_TYPE(pci_p) < PCI_CHIP_SCHIZO)) 2080Sstevel@tonic-gate return (DDI_SUCCESS); 2090Sstevel@tonic-gate if (pci_config_setup(pci_dip, hdl_p) != DDI_SUCCESS) { 2100Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: can not get config space for %s%d\n", 2110Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip), 2120Sstevel@tonic-gate ddi_driver_name(cdip), ddi_get_instance(cdip)); 2130Sstevel@tonic-gate return (DDI_FAILURE); 2140Sstevel@tonic-gate } 2150Sstevel@tonic-gate return (DDI_SUCCESS); 2160Sstevel@tonic-gate } 2170Sstevel@tonic-gate 2180Sstevel@tonic-gate /* 2190Sstevel@tonic-gate * If the unclaimed interrupt count has reached the limit set by 2200Sstevel@tonic-gate * pci_unclaimed_intr_max within the time limit, then all interrupts 2210Sstevel@tonic-gate * on this ino is blocked by not idling the interrupt state machine. 2220Sstevel@tonic-gate */ 2230Sstevel@tonic-gate static int 2240Sstevel@tonic-gate pci_spurintr(ib_ino_info_t *ino_p) { 2250Sstevel@tonic-gate int i; 2260Sstevel@tonic-gate ih_t *ih_p = ino_p->ino_ih_start; 2270Sstevel@tonic-gate pci_t *pci_p = ino_p->ino_ib_p->ib_pci_p; 2280Sstevel@tonic-gate char *err_fmt_str; 2290Sstevel@tonic-gate 2300Sstevel@tonic-gate if (ino_p->ino_unclaimed > pci_unclaimed_intr_max) 2310Sstevel@tonic-gate return (DDI_INTR_CLAIMED); 2320Sstevel@tonic-gate 2330Sstevel@tonic-gate if (!ino_p->ino_unclaimed) 2340Sstevel@tonic-gate ino_p->ino_spurintr_begin = ddi_get_lbolt(); 2350Sstevel@tonic-gate 2360Sstevel@tonic-gate ino_p->ino_unclaimed++; 2370Sstevel@tonic-gate 2380Sstevel@tonic-gate if (ino_p->ino_unclaimed <= pci_unclaimed_intr_max) 2390Sstevel@tonic-gate goto clear; 2400Sstevel@tonic-gate 2410Sstevel@tonic-gate if (drv_hztousec(ddi_get_lbolt() - ino_p->ino_spurintr_begin) 2420Sstevel@tonic-gate > pci_spurintr_duration) { 2430Sstevel@tonic-gate ino_p->ino_unclaimed = 0; 2440Sstevel@tonic-gate goto clear; 2450Sstevel@tonic-gate } 2460Sstevel@tonic-gate err_fmt_str = "%s%d: ino 0x%x blocked"; 2470Sstevel@tonic-gate goto warn; 2480Sstevel@tonic-gate clear: 2490Sstevel@tonic-gate IB_INO_INTR_CLEAR(ino_p->ino_clr_reg); /* clear the pending state */ 2500Sstevel@tonic-gate if (!pci_spurintr_msgs) /* tomatillo errata #71 spurious mondo */ 2510Sstevel@tonic-gate return (DDI_INTR_CLAIMED); 2520Sstevel@tonic-gate 2530Sstevel@tonic-gate err_fmt_str = "!%s%d: spurious interrupt from ino 0x%x"; 2540Sstevel@tonic-gate warn: 2550Sstevel@tonic-gate cmn_err(CE_WARN, err_fmt_str, NAMEINST(pci_p->pci_dip), ino_p->ino_ino); 2560Sstevel@tonic-gate for (i = 0; i < ino_p->ino_ih_size; i++, ih_p = ih_p->ih_next) 2570Sstevel@tonic-gate cmn_err(CE_CONT, "!%s-%d#%x ", NAMEINST(ih_p->ih_dip), 2580Sstevel@tonic-gate ih_p->ih_inum); 2590Sstevel@tonic-gate cmn_err(CE_CONT, "!\n"); 2600Sstevel@tonic-gate return (DDI_INTR_CLAIMED); 2610Sstevel@tonic-gate } 2620Sstevel@tonic-gate 2630Sstevel@tonic-gate /* 2640Sstevel@tonic-gate * pci_intr_wrapper 2650Sstevel@tonic-gate * 2660Sstevel@tonic-gate * This routine is used as wrapper around interrupt handlers installed by child 2670Sstevel@tonic-gate * device drivers. This routine invokes the driver interrupt handlers and 2680Sstevel@tonic-gate * examines the return codes. 2690Sstevel@tonic-gate * There is a count of unclaimed interrupts kept on a per-ino basis. If at 2700Sstevel@tonic-gate * least one handler claims the interrupt then the counter is halved and the 2710Sstevel@tonic-gate * interrupt state machine is idled. If no handler claims the interrupt then 2720Sstevel@tonic-gate * the counter is incremented by one and the state machine is idled. 2730Sstevel@tonic-gate * If the count ever reaches the limit value set by pci_unclaimed_intr_max 2740Sstevel@tonic-gate * then the interrupt state machine is not idled thus preventing any further 2750Sstevel@tonic-gate * interrupts on that ino. The state machine will only be idled again if a 2760Sstevel@tonic-gate * handler is subsequently added or removed. 2770Sstevel@tonic-gate * 2780Sstevel@tonic-gate * return value: DDI_INTR_CLAIMED if any handlers claimed the interrupt, 2790Sstevel@tonic-gate * DDI_INTR_UNCLAIMED otherwise. 2800Sstevel@tonic-gate */ 2810Sstevel@tonic-gate 2820Sstevel@tonic-gate extern uint64_t intr_get_time(void); 2830Sstevel@tonic-gate 2840Sstevel@tonic-gate uint_t 2850Sstevel@tonic-gate pci_intr_wrapper(caddr_t arg) 2860Sstevel@tonic-gate { 2870Sstevel@tonic-gate ib_ino_info_t *ino_p = (ib_ino_info_t *)arg; 2880Sstevel@tonic-gate uint_t result = 0, r; 2890Sstevel@tonic-gate pci_t *pci_p = ino_p->ino_ib_p->ib_pci_p; 2900Sstevel@tonic-gate pbm_t *pbm_p = pci_p->pci_pbm_p; 2910Sstevel@tonic-gate ih_t *ih_p = ino_p->ino_ih_start; 2920Sstevel@tonic-gate int i; 2930Sstevel@tonic-gate 2940Sstevel@tonic-gate for (i = 0; i < ino_p->ino_ih_size; i++, ih_p = ih_p->ih_next) { 2950Sstevel@tonic-gate dev_info_t *dip = ih_p->ih_dip; 2960Sstevel@tonic-gate uint_t (*handler)() = ih_p->ih_handler; 2970Sstevel@tonic-gate caddr_t arg1 = ih_p->ih_handler_arg1; 2980Sstevel@tonic-gate caddr_t arg2 = ih_p->ih_handler_arg2; 2990Sstevel@tonic-gate ddi_acc_handle_t cfg_hdl = ih_p->ih_config_handle; 3000Sstevel@tonic-gate 3010Sstevel@tonic-gate if (pci_intr_dma_sync && cfg_hdl && pbm_p->pbm_sync_reg_pa) { 3020Sstevel@tonic-gate (void) pci_config_get16(cfg_hdl, PCI_CONF_VENID); 3030Sstevel@tonic-gate pci_pbm_dma_sync(pbm_p, ino_p->ino_ino); 3040Sstevel@tonic-gate } 3050Sstevel@tonic-gate 3060Sstevel@tonic-gate if (ih_p->ih_intr_state == PCI_INTR_STATE_DISABLE) { 3070Sstevel@tonic-gate DEBUG3(DBG_INTR, pci_p->pci_dip, 3080Sstevel@tonic-gate "pci_intr_wrapper: %s%d interrupt %d is disabled\n", 3090Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip), 3100Sstevel@tonic-gate ino_p->ino_ino); 3110Sstevel@tonic-gate 3120Sstevel@tonic-gate continue; 3130Sstevel@tonic-gate } 3140Sstevel@tonic-gate 3150Sstevel@tonic-gate DTRACE_PROBE4(interrupt__start, dev_info_t, dip, 3160Sstevel@tonic-gate void *, handler, caddr_t, arg1, caddr_t, arg2); 3170Sstevel@tonic-gate 3180Sstevel@tonic-gate r = (*handler)(arg1, arg2); 3190Sstevel@tonic-gate 3200Sstevel@tonic-gate /* 3210Sstevel@tonic-gate * Account for time used by this interrupt. Protect against 3220Sstevel@tonic-gate * conflicting writes to ih_ticks from ib_intr_dist_all() by 3230Sstevel@tonic-gate * using atomic ops. 3240Sstevel@tonic-gate */ 3250Sstevel@tonic-gate 3260Sstevel@tonic-gate if (ino_p->ino_pil <= LOCK_LEVEL) 3270Sstevel@tonic-gate atomic_add_64(&ih_p->ih_ticks, intr_get_time()); 3280Sstevel@tonic-gate 3290Sstevel@tonic-gate DTRACE_PROBE4(interrupt__complete, dev_info_t, dip, 3300Sstevel@tonic-gate void *, handler, caddr_t, arg1, int, r); 3310Sstevel@tonic-gate 3320Sstevel@tonic-gate result += r; 3330Sstevel@tonic-gate 3340Sstevel@tonic-gate if (pci_check_all_handlers) 3350Sstevel@tonic-gate continue; 3360Sstevel@tonic-gate if (result) 3370Sstevel@tonic-gate break; 3380Sstevel@tonic-gate } 3390Sstevel@tonic-gate 3400Sstevel@tonic-gate if (!result) 3410Sstevel@tonic-gate return (pci_spurintr(ino_p)); 3420Sstevel@tonic-gate 3430Sstevel@tonic-gate ino_p->ino_unclaimed = 0; 3440Sstevel@tonic-gate IB_INO_INTR_CLEAR(ino_p->ino_clr_reg); /* clear the pending state */ 3450Sstevel@tonic-gate 3460Sstevel@tonic-gate return (DDI_INTR_CLAIMED); 3470Sstevel@tonic-gate } 3480Sstevel@tonic-gate 3490Sstevel@tonic-gate dev_info_t * 3500Sstevel@tonic-gate get_my_childs_dip(dev_info_t *dip, dev_info_t *rdip) 3510Sstevel@tonic-gate { 3520Sstevel@tonic-gate dev_info_t *cdip = rdip; 3530Sstevel@tonic-gate 3540Sstevel@tonic-gate for (; ddi_get_parent(cdip) != dip; cdip = ddi_get_parent(cdip)) 3550Sstevel@tonic-gate ; 3560Sstevel@tonic-gate 3570Sstevel@tonic-gate return (cdip); 3580Sstevel@tonic-gate } 3590Sstevel@tonic-gate 3600Sstevel@tonic-gate /* default class to pil value mapping */ 3610Sstevel@tonic-gate pci_class_val_t pci_default_pil [] = { 3620Sstevel@tonic-gate {0x000000, 0xff0000, 0x1}, /* Class code for pre-2.0 devices */ 3630Sstevel@tonic-gate {0x010000, 0xff0000, 0x4}, /* Mass Storage Controller */ 3640Sstevel@tonic-gate {0x020000, 0xff0000, 0x6}, /* Network Controller */ 3650Sstevel@tonic-gate {0x030000, 0xff0000, 0x9}, /* Display Controller */ 3660Sstevel@tonic-gate {0x040000, 0xff0000, 0x9}, /* Multimedia Controller */ 3670Sstevel@tonic-gate {0x050000, 0xff0000, 0xb}, /* Memory Controller */ 3680Sstevel@tonic-gate {0x060000, 0xff0000, 0xb}, /* Bridge Controller */ 3690Sstevel@tonic-gate {0x0c0000, 0xffff00, 0x9}, /* Serial Bus, FireWire (IEEE 1394) */ 3700Sstevel@tonic-gate {0x0c0100, 0xffff00, 0x4}, /* Serial Bus, ACCESS.bus */ 3710Sstevel@tonic-gate {0x0c0200, 0xffff00, 0x4}, /* Serial Bus, SSA */ 3720Sstevel@tonic-gate {0x0c0300, 0xffff00, 0x9}, /* Serial Bus Universal Serial Bus */ 3730Sstevel@tonic-gate {0x0c0400, 0xffff00, 0x6}, /* Serial Bus, Fibre Channel */ 3740Sstevel@tonic-gate {0x0c0600, 0xffff00, 0x6} /* Serial Bus, Infiniband */ 3750Sstevel@tonic-gate }; 3760Sstevel@tonic-gate 3770Sstevel@tonic-gate /* 3780Sstevel@tonic-gate * Default class to intr_weight value mapping (% of CPU). A driver.conf 3790Sstevel@tonic-gate * entry on or above the pci node like 3800Sstevel@tonic-gate * 3810Sstevel@tonic-gate * pci-class-intr-weights= 0x020000, 0xff0000, 30; 3820Sstevel@tonic-gate * 3830Sstevel@tonic-gate * can be used to augment or override entries in the default table below. 3840Sstevel@tonic-gate * 3850Sstevel@tonic-gate * NB: The values below give NICs preference on redistribution, and provide 3860Sstevel@tonic-gate * NICs some isolation from other interrupt sources. We need better interfaces 3870Sstevel@tonic-gate * that allow the NIC driver to identify a specific NIC instance as high 3880Sstevel@tonic-gate * bandwidth, and thus deserving of separation from other low bandwidth 3890Sstevel@tonic-gate * NICs additional isolation from other interrupt sources. 3900Sstevel@tonic-gate * 3910Sstevel@tonic-gate * NB: We treat Infiniband like a NIC. 3920Sstevel@tonic-gate */ 3930Sstevel@tonic-gate pci_class_val_t pci_default_intr_weight [] = { 3940Sstevel@tonic-gate {0x020000, 0xff0000, 35}, /* Network Controller */ 3950Sstevel@tonic-gate {0x010000, 0xff0000, 10}, /* Mass Storage Controller */ 3960Sstevel@tonic-gate {0x0c0400, 0xffff00, 10}, /* Serial Bus, Fibre Channel */ 3970Sstevel@tonic-gate {0x0c0600, 0xffff00, 50} /* Serial Bus, Infiniband */ 3980Sstevel@tonic-gate }; 3990Sstevel@tonic-gate 4000Sstevel@tonic-gate static uint32_t 4010Sstevel@tonic-gate pci_match_class_val(uint32_t key, pci_class_val_t *rec_p, int nrec, 4020Sstevel@tonic-gate uint32_t default_val) 4030Sstevel@tonic-gate { 4040Sstevel@tonic-gate int i; 4050Sstevel@tonic-gate 4060Sstevel@tonic-gate for (i = 0; i < nrec; rec_p++, i++) { 4070Sstevel@tonic-gate if ((rec_p->class_code & rec_p->class_mask) == 4080Sstevel@tonic-gate (key & rec_p->class_mask)) 4090Sstevel@tonic-gate return (rec_p->class_val); 4100Sstevel@tonic-gate } 4110Sstevel@tonic-gate 4120Sstevel@tonic-gate return (default_val); 4130Sstevel@tonic-gate } 4140Sstevel@tonic-gate 4150Sstevel@tonic-gate /* 4160Sstevel@tonic-gate * Return the configuration value, based on class code and sub class code, 4170Sstevel@tonic-gate * from the specified property based or default pci_class_val_t table. 4180Sstevel@tonic-gate */ 4190Sstevel@tonic-gate uint32_t 4200Sstevel@tonic-gate pci_class_to_val(dev_info_t *rdip, char *property_name, pci_class_val_t *rec_p, 4210Sstevel@tonic-gate int nrec, uint32_t default_val) 4220Sstevel@tonic-gate { 4230Sstevel@tonic-gate int property_len; 4240Sstevel@tonic-gate uint32_t class_code; 4250Sstevel@tonic-gate pci_class_val_t *conf; 4260Sstevel@tonic-gate uint32_t val = default_val; 4270Sstevel@tonic-gate 4280Sstevel@tonic-gate /* 4290Sstevel@tonic-gate * Use the "class-code" property to get the base and sub class 4300Sstevel@tonic-gate * codes for the requesting device. 4310Sstevel@tonic-gate */ 4320Sstevel@tonic-gate class_code = (uint32_t)ddi_prop_get_int(DDI_DEV_T_ANY, rdip, 4330Sstevel@tonic-gate DDI_PROP_DONTPASS, "class-code", -1); 4340Sstevel@tonic-gate 4350Sstevel@tonic-gate if (class_code == -1) 4360Sstevel@tonic-gate return (val); 4370Sstevel@tonic-gate 4380Sstevel@tonic-gate /* look up the val from the default table */ 4390Sstevel@tonic-gate val = pci_match_class_val(class_code, rec_p, nrec, val); 4400Sstevel@tonic-gate 4410Sstevel@tonic-gate 4420Sstevel@tonic-gate /* see if there is a more specific property specified value */ 4430Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_ANY, rdip, DDI_PROP_NOTPROM, 4440Sstevel@tonic-gate property_name, (caddr_t)&conf, &property_len)) 4450Sstevel@tonic-gate return (val); 4460Sstevel@tonic-gate 4470Sstevel@tonic-gate if ((property_len % sizeof (pci_class_val_t)) == 0) 4480Sstevel@tonic-gate val = pci_match_class_val(class_code, conf, 4490Sstevel@tonic-gate property_len / sizeof (pci_class_val_t), val); 4500Sstevel@tonic-gate kmem_free(conf, property_len); 4510Sstevel@tonic-gate return (val); 4520Sstevel@tonic-gate } 4530Sstevel@tonic-gate 4540Sstevel@tonic-gate /* pci_class_to_pil: return the pil for a given PCI device. */ 4550Sstevel@tonic-gate uint32_t 4560Sstevel@tonic-gate pci_class_to_pil(dev_info_t *rdip) 4570Sstevel@tonic-gate { 4580Sstevel@tonic-gate uint32_t pil; 4590Sstevel@tonic-gate 4600Sstevel@tonic-gate /* default pil is 0 (uninitialized) */ 4610Sstevel@tonic-gate pil = pci_class_to_val(rdip, 4620Sstevel@tonic-gate "pci-class-priorities", pci_default_pil, 4630Sstevel@tonic-gate sizeof (pci_default_pil) / sizeof (pci_class_val_t), 0); 4640Sstevel@tonic-gate 4650Sstevel@tonic-gate /* range check the result */ 4660Sstevel@tonic-gate if (pil >= 0xf) 4670Sstevel@tonic-gate pil = 0; 4680Sstevel@tonic-gate 4690Sstevel@tonic-gate return (pil); 4700Sstevel@tonic-gate } 4710Sstevel@tonic-gate 4720Sstevel@tonic-gate /* pci_class_to_intr_weight: return the intr_weight for a given PCI device. */ 4730Sstevel@tonic-gate int32_t 4740Sstevel@tonic-gate pci_class_to_intr_weight(dev_info_t *rdip) 4750Sstevel@tonic-gate { 4760Sstevel@tonic-gate int32_t intr_weight; 4770Sstevel@tonic-gate 4780Sstevel@tonic-gate /* default weight is 0% */ 4790Sstevel@tonic-gate intr_weight = pci_class_to_val(rdip, 4800Sstevel@tonic-gate "pci-class-intr-weights", pci_default_intr_weight, 4810Sstevel@tonic-gate sizeof (pci_default_intr_weight) / sizeof (pci_class_val_t), 0); 4820Sstevel@tonic-gate 4830Sstevel@tonic-gate /* range check the result */ 4840Sstevel@tonic-gate if (intr_weight < 0) 4850Sstevel@tonic-gate intr_weight = 0; 4860Sstevel@tonic-gate if (intr_weight > 1000) 4870Sstevel@tonic-gate intr_weight = 1000; 4880Sstevel@tonic-gate 4890Sstevel@tonic-gate return (intr_weight); 4900Sstevel@tonic-gate } 4910Sstevel@tonic-gate 49266Sesolom static struct { 49366Sesolom kstat_named_t pciintr_ks_name; 49466Sesolom kstat_named_t pciintr_ks_type; 49566Sesolom kstat_named_t pciintr_ks_cpu; 49666Sesolom kstat_named_t pciintr_ks_pil; 49766Sesolom kstat_named_t pciintr_ks_time; 49866Sesolom kstat_named_t pciintr_ks_ino; 49966Sesolom kstat_named_t pciintr_ks_cookie; 50066Sesolom kstat_named_t pciintr_ks_devpath; 50166Sesolom kstat_named_t pciintr_ks_buspath; 50266Sesolom } pciintr_ks_template = { 50366Sesolom { "name", KSTAT_DATA_CHAR }, 50466Sesolom { "type", KSTAT_DATA_CHAR }, 50566Sesolom { "cpu", KSTAT_DATA_UINT64 }, 50666Sesolom { "pil", KSTAT_DATA_UINT64 }, 50766Sesolom { "time", KSTAT_DATA_UINT64 }, 50866Sesolom { "ino", KSTAT_DATA_UINT64 }, 50966Sesolom { "cookie", KSTAT_DATA_UINT64 }, 51066Sesolom { "devpath", KSTAT_DATA_STRING }, 51166Sesolom { "buspath", KSTAT_DATA_STRING }, 51266Sesolom }; 51366Sesolom static uint32_t pciintr_ks_instance; 51466Sesolom 51566Sesolom kmutex_t pciintr_ks_template_lock; 51666Sesolom 51766Sesolom int 51866Sesolom pci_ks_update(kstat_t *ksp, int rw) 51966Sesolom { 52066Sesolom ih_t *ih_p = ksp->ks_private; 52166Sesolom int maxlen = sizeof (pciintr_ks_template.pciintr_ks_name.value.c); 52266Sesolom ib_t *ib_p = ih_p->ih_ino_p->ino_ib_p; 52366Sesolom pci_t *pci_p = ib_p->ib_pci_p; 52466Sesolom ib_ino_t ino; 52566Sesolom char ih_devpath[MAXPATHLEN]; 52666Sesolom char ih_buspath[MAXPATHLEN]; 52766Sesolom 52866Sesolom ino = ih_p->ih_ino_p->ino_ino; 52966Sesolom 53066Sesolom (void) snprintf(pciintr_ks_template.pciintr_ks_name.value.c, maxlen, 53166Sesolom "%s%d", ddi_driver_name(ih_p->ih_dip), 53266Sesolom ddi_get_instance(ih_p->ih_dip)); 53366Sesolom (void) strcpy(pciintr_ks_template.pciintr_ks_type.value.c, "fixed"); 53466Sesolom pciintr_ks_template.pciintr_ks_cpu.value.ui64 = 53566Sesolom ih_p->ih_ino_p->ino_cpuid; 53666Sesolom pciintr_ks_template.pciintr_ks_pil.value.ui64 = 53766Sesolom ih_p->ih_ino_p->ino_pil; 53866Sesolom pciintr_ks_template.pciintr_ks_time.value.ui64 = 53966Sesolom ih_p->ih_nsec + (uint64_t) 54066Sesolom tick2ns((hrtime_t)ih_p->ih_ticks, ih_p->ih_ino_p->ino_cpuid); 54166Sesolom pciintr_ks_template.pciintr_ks_ino.value.ui64 = ino; 54266Sesolom pciintr_ks_template.pciintr_ks_cookie.value.ui64 = 54366Sesolom IB_INO_TO_MONDO(ib_p, ino); 54466Sesolom 54566Sesolom (void) ddi_pathname(ih_p->ih_dip, ih_devpath); 54666Sesolom (void) ddi_pathname(pci_p->pci_dip, ih_buspath); 54766Sesolom kstat_named_setstr(&pciintr_ks_template.pciintr_ks_devpath, ih_devpath); 54866Sesolom kstat_named_setstr(&pciintr_ks_template.pciintr_ks_buspath, ih_buspath); 54966Sesolom 55066Sesolom return (0); 55166Sesolom } 55266Sesolom 5530Sstevel@tonic-gate int 5540Sstevel@tonic-gate pci_add_intr(dev_info_t *dip, dev_info_t *rdip, ddi_intr_handle_impl_t *hdlp) 5550Sstevel@tonic-gate { 5560Sstevel@tonic-gate pci_t *pci_p = get_pci_soft_state(ddi_get_instance(dip)); 5570Sstevel@tonic-gate ib_t *ib_p = pci_p->pci_ib_p; 5580Sstevel@tonic-gate cb_t *cb_p = pci_p->pci_cb_p; 5590Sstevel@tonic-gate ih_t *ih_p; 5600Sstevel@tonic-gate ib_ino_t ino; 5610Sstevel@tonic-gate ib_ino_info_t *ino_p; /* pulse interrupts have no ino */ 5620Sstevel@tonic-gate ib_mondo_t mondo; 5630Sstevel@tonic-gate uint32_t cpu_id; 5640Sstevel@tonic-gate int ret; 5650Sstevel@tonic-gate int32_t weight; 5660Sstevel@tonic-gate 5670Sstevel@tonic-gate ino = IB_MONDO_TO_INO(hdlp->ih_vector); 5680Sstevel@tonic-gate 5690Sstevel@tonic-gate DEBUG3(DBG_A_INTX, dip, "pci_add_intr: rdip=%s%d ino=%x\n", 5700Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip), ino); 5710Sstevel@tonic-gate 5720Sstevel@tonic-gate if (ino > ib_p->ib_max_ino) { 5730Sstevel@tonic-gate DEBUG1(DBG_A_INTX, dip, "ino %x is invalid\n", ino); 5740Sstevel@tonic-gate return (DDI_INTR_NOTFOUND); 5750Sstevel@tonic-gate } 5760Sstevel@tonic-gate 5770Sstevel@tonic-gate if (hdlp->ih_vector & PCI_PULSE_INO) { 5780Sstevel@tonic-gate volatile uint64_t *map_reg_addr; 5790Sstevel@tonic-gate map_reg_addr = ib_intr_map_reg_addr(ib_p, ino); 5800Sstevel@tonic-gate 5810Sstevel@tonic-gate mondo = pci_xlate_intr(dip, rdip, ib_p, ino); 5820Sstevel@tonic-gate if (mondo == 0) 5830Sstevel@tonic-gate goto fail1; 5840Sstevel@tonic-gate 5850Sstevel@tonic-gate hdlp->ih_vector = CB_MONDO_TO_XMONDO(cb_p, mondo); 5860Sstevel@tonic-gate 5870Sstevel@tonic-gate if (i_ddi_add_ivintr(hdlp) != DDI_SUCCESS) 5880Sstevel@tonic-gate goto fail1; 5890Sstevel@tonic-gate 5900Sstevel@tonic-gate /* 5910Sstevel@tonic-gate * Select cpu and program. 5920Sstevel@tonic-gate * 5930Sstevel@tonic-gate * Since there is no good way to always derive cpuid in 5940Sstevel@tonic-gate * pci_remove_intr for PCI_PULSE_INO (esp. for STARFIRE), we 5950Sstevel@tonic-gate * don't add (or remove) device weight for pulsed interrupt 5960Sstevel@tonic-gate * sources. 5970Sstevel@tonic-gate */ 5980Sstevel@tonic-gate mutex_enter(&ib_p->ib_intr_lock); 5990Sstevel@tonic-gate cpu_id = intr_dist_cpuid(); 6000Sstevel@tonic-gate *map_reg_addr = ib_get_map_reg(mondo, cpu_id); 6010Sstevel@tonic-gate mutex_exit(&ib_p->ib_intr_lock); 6020Sstevel@tonic-gate *map_reg_addr; /* flush previous write */ 6030Sstevel@tonic-gate goto done; 6040Sstevel@tonic-gate } 6050Sstevel@tonic-gate 6060Sstevel@tonic-gate if ((mondo = pci_xlate_intr(dip, rdip, pci_p->pci_ib_p, ino)) == 0) 6070Sstevel@tonic-gate goto fail1; 6080Sstevel@tonic-gate 6090Sstevel@tonic-gate ino = IB_MONDO_TO_INO(mondo); 6100Sstevel@tonic-gate 6110Sstevel@tonic-gate mutex_enter(&ib_p->ib_ino_lst_mutex); 6120Sstevel@tonic-gate ih_p = ib_alloc_ih(rdip, hdlp->ih_inum, 6130Sstevel@tonic-gate hdlp->ih_cb_func, hdlp->ih_cb_arg1, hdlp->ih_cb_arg2); 6140Sstevel@tonic-gate if (map_pcidev_cfg_reg(dip, rdip, &ih_p->ih_config_handle)) 6150Sstevel@tonic-gate goto fail2; 6160Sstevel@tonic-gate 6170Sstevel@tonic-gate if (ino_p = ib_locate_ino(ib_p, ino)) { /* sharing ino */ 6180Sstevel@tonic-gate uint32_t intr_index = hdlp->ih_inum; 6190Sstevel@tonic-gate if (ib_ino_locate_intr(ino_p, rdip, intr_index)) { 6200Sstevel@tonic-gate DEBUG1(DBG_A_INTX, dip, "dup intr #%d\n", intr_index); 6210Sstevel@tonic-gate goto fail3; 6220Sstevel@tonic-gate } 6230Sstevel@tonic-gate 6240Sstevel@tonic-gate /* add weight to the cpu that we are already targeting */ 6250Sstevel@tonic-gate cpu_id = ino_p->ino_cpuid; 6260Sstevel@tonic-gate weight = pci_class_to_intr_weight(rdip); 6270Sstevel@tonic-gate intr_dist_cpuid_add_device_weight(cpu_id, rdip, weight); 6280Sstevel@tonic-gate 6290Sstevel@tonic-gate ib_ino_add_intr(pci_p, ino_p, ih_p); 6300Sstevel@tonic-gate goto ino_done; 6310Sstevel@tonic-gate } 6320Sstevel@tonic-gate 6330Sstevel@tonic-gate ino_p = ib_new_ino(ib_p, ino, ih_p); 6340Sstevel@tonic-gate 6350Sstevel@tonic-gate if (hdlp->ih_pri == 0) 6360Sstevel@tonic-gate hdlp->ih_pri = pci_class_to_pil(rdip); 6370Sstevel@tonic-gate 6380Sstevel@tonic-gate hdlp->ih_vector = CB_MONDO_TO_XMONDO(cb_p, mondo); 6390Sstevel@tonic-gate 640*909Segillett /* Store this global mondo */ 641*909Segillett ino_p->ino_mondo = hdlp->ih_vector; 642*909Segillett 6430Sstevel@tonic-gate DEBUG2(DBG_A_INTX, dip, "pci_add_intr: pil=0x%x mondo=0x%x\n", 6440Sstevel@tonic-gate hdlp->ih_pri, hdlp->ih_vector); 6450Sstevel@tonic-gate 6460Sstevel@tonic-gate DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp, 6470Sstevel@tonic-gate (ddi_intr_handler_t *)pci_intr_wrapper, (caddr_t)ino_p, NULL); 6480Sstevel@tonic-gate 6490Sstevel@tonic-gate ret = i_ddi_add_ivintr(hdlp); 6500Sstevel@tonic-gate 6510Sstevel@tonic-gate /* 6520Sstevel@tonic-gate * Restore original interrupt handler 6530Sstevel@tonic-gate * and arguments in interrupt handle. 6540Sstevel@tonic-gate */ 6550Sstevel@tonic-gate DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp, ih_p->ih_handler, 6560Sstevel@tonic-gate ih_p->ih_handler_arg1, ih_p->ih_handler_arg2); 6570Sstevel@tonic-gate 6580Sstevel@tonic-gate if (ret != DDI_SUCCESS) 6590Sstevel@tonic-gate goto fail4; 6600Sstevel@tonic-gate 6610Sstevel@tonic-gate /* Save the pil for this ino */ 6620Sstevel@tonic-gate ino_p->ino_pil = hdlp->ih_pri; 6630Sstevel@tonic-gate 6640Sstevel@tonic-gate /* clear and enable interrupt */ 6650Sstevel@tonic-gate IB_INO_INTR_CLEAR(ino_p->ino_clr_reg); 6660Sstevel@tonic-gate 6670Sstevel@tonic-gate /* select cpu and compute weight, saving both for sharing and removal */ 6680Sstevel@tonic-gate cpu_id = pci_intr_dist_cpuid(ib_p, ino_p); 6690Sstevel@tonic-gate ino_p->ino_cpuid = cpu_id; 6700Sstevel@tonic-gate ino_p->ino_established = 1; 6710Sstevel@tonic-gate weight = pci_class_to_intr_weight(rdip); 6720Sstevel@tonic-gate intr_dist_cpuid_add_device_weight(cpu_id, rdip, weight); 6730Sstevel@tonic-gate 6740Sstevel@tonic-gate #ifdef _STARFIRE 6750Sstevel@tonic-gate cpu_id = pc_translate_tgtid(cb_p->cb_ittrans_cookie, cpu_id, 6760Sstevel@tonic-gate IB_GET_MAPREG_INO(ino)); 6770Sstevel@tonic-gate #endif /* _STARFIRE */ 6780Sstevel@tonic-gate *ino_p->ino_map_reg = ib_get_map_reg(mondo, cpu_id); 6790Sstevel@tonic-gate *ino_p->ino_map_reg; 6800Sstevel@tonic-gate ino_done: 6810Sstevel@tonic-gate ih_p->ih_ino_p = ino_p; 68266Sesolom ih_p->ih_ksp = kstat_create("pci_intrs", 68366Sesolom atomic_inc_32_nv(&pciintr_ks_instance), "config", "interrupts", 68466Sesolom KSTAT_TYPE_NAMED, 68566Sesolom sizeof (pciintr_ks_template) / sizeof (kstat_named_t), 68666Sesolom KSTAT_FLAG_VIRTUAL); 68766Sesolom if (ih_p->ih_ksp != NULL) { 68866Sesolom ih_p->ih_ksp->ks_data_size += MAXPATHLEN * 2; 68966Sesolom ih_p->ih_ksp->ks_lock = &pciintr_ks_template_lock; 69066Sesolom ih_p->ih_ksp->ks_data = &pciintr_ks_template; 69166Sesolom ih_p->ih_ksp->ks_private = ih_p; 69266Sesolom ih_p->ih_ksp->ks_update = pci_ks_update; 6930Sstevel@tonic-gate kstat_install(ih_p->ih_ksp); 69466Sesolom } 6950Sstevel@tonic-gate ib_ino_map_reg_share(ib_p, ino, ino_p); 6960Sstevel@tonic-gate mutex_exit(&ib_p->ib_ino_lst_mutex); 6970Sstevel@tonic-gate done: 6980Sstevel@tonic-gate DEBUG2(DBG_A_INTX, dip, "done! Interrupt 0x%x pil=%x\n", 6990Sstevel@tonic-gate hdlp->ih_vector, hdlp->ih_pri); 7000Sstevel@tonic-gate return (DDI_SUCCESS); 7010Sstevel@tonic-gate fail4: 7020Sstevel@tonic-gate ib_delete_ino(ib_p, ino_p); 7030Sstevel@tonic-gate fail3: 7040Sstevel@tonic-gate if (ih_p->ih_config_handle) 7050Sstevel@tonic-gate pci_config_teardown(&ih_p->ih_config_handle); 7060Sstevel@tonic-gate fail2: 7070Sstevel@tonic-gate mutex_exit(&ib_p->ib_ino_lst_mutex); 7080Sstevel@tonic-gate kmem_free(ih_p, sizeof (ih_t)); 7090Sstevel@tonic-gate fail1: 7100Sstevel@tonic-gate DEBUG2(DBG_A_INTX, dip, "Failed! Interrupt 0x%x pil=%x\n", 7110Sstevel@tonic-gate hdlp->ih_vector, hdlp->ih_pri); 7120Sstevel@tonic-gate return (DDI_FAILURE); 7130Sstevel@tonic-gate } 7140Sstevel@tonic-gate 7150Sstevel@tonic-gate int 7160Sstevel@tonic-gate pci_remove_intr(dev_info_t *dip, dev_info_t *rdip, ddi_intr_handle_impl_t *hdlp) 7170Sstevel@tonic-gate { 7180Sstevel@tonic-gate pci_t *pci_p = get_pci_soft_state(ddi_get_instance(dip)); 7190Sstevel@tonic-gate ib_t *ib_p = pci_p->pci_ib_p; 7200Sstevel@tonic-gate cb_t *cb_p = pci_p->pci_cb_p; 7210Sstevel@tonic-gate ib_ino_t ino; 7220Sstevel@tonic-gate ib_mondo_t mondo; 7230Sstevel@tonic-gate ib_ino_info_t *ino_p; /* non-pulse only */ 7240Sstevel@tonic-gate ih_t *ih_p; /* non-pulse only */ 7250Sstevel@tonic-gate 7260Sstevel@tonic-gate ino = IB_MONDO_TO_INO(hdlp->ih_vector); 7270Sstevel@tonic-gate 7280Sstevel@tonic-gate DEBUG3(DBG_R_INTX, dip, "pci_rem_intr: rdip=%s%d ino=%x\n", 7290Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip), ino); 7300Sstevel@tonic-gate 7310Sstevel@tonic-gate if (hdlp->ih_vector & PCI_PULSE_INO) { /* pulse interrupt */ 7320Sstevel@tonic-gate volatile uint64_t *map_reg_addr; 7330Sstevel@tonic-gate 7340Sstevel@tonic-gate /* 7350Sstevel@tonic-gate * No weight was added by pci_add_intr for PCI_PULSE_INO 7360Sstevel@tonic-gate * because it is difficult to determine cpuid here. 7370Sstevel@tonic-gate */ 7380Sstevel@tonic-gate map_reg_addr = ib_intr_map_reg_addr(ib_p, ino); 7390Sstevel@tonic-gate IB_INO_INTR_RESET(map_reg_addr); /* disable intr */ 7400Sstevel@tonic-gate *map_reg_addr; 7410Sstevel@tonic-gate 7420Sstevel@tonic-gate mondo = pci_xlate_intr(dip, rdip, ib_p, ino); 7430Sstevel@tonic-gate if (mondo == 0) { 7440Sstevel@tonic-gate DEBUG1(DBG_R_INTX, dip, 7450Sstevel@tonic-gate "can't get mondo for ino %x\n", ino); 7460Sstevel@tonic-gate return (DDI_FAILURE); 7470Sstevel@tonic-gate } 7480Sstevel@tonic-gate 7490Sstevel@tonic-gate if (hdlp->ih_pri == 0) 7500Sstevel@tonic-gate hdlp->ih_pri = pci_class_to_pil(rdip); 7510Sstevel@tonic-gate 7520Sstevel@tonic-gate hdlp->ih_vector = CB_MONDO_TO_XMONDO(cb_p, mondo); 7530Sstevel@tonic-gate 7540Sstevel@tonic-gate DEBUG2(DBG_R_INTX, dip, "pci_rem_intr: pil=0x%x mondo=0x%x\n", 7550Sstevel@tonic-gate hdlp->ih_pri, hdlp->ih_vector); 7560Sstevel@tonic-gate 7570Sstevel@tonic-gate i_ddi_rem_ivintr(hdlp); 7580Sstevel@tonic-gate 7590Sstevel@tonic-gate DEBUG2(DBG_R_INTX, dip, "pulse success mondo=%x reg=%p\n", 7600Sstevel@tonic-gate mondo, map_reg_addr); 7610Sstevel@tonic-gate return (DDI_SUCCESS); 7620Sstevel@tonic-gate } 7630Sstevel@tonic-gate 7640Sstevel@tonic-gate /* Translate the interrupt property */ 7650Sstevel@tonic-gate mondo = pci_xlate_intr(dip, rdip, pci_p->pci_ib_p, ino); 7660Sstevel@tonic-gate if (mondo == 0) { 7670Sstevel@tonic-gate DEBUG1(DBG_R_INTX, dip, "can't get mondo for ino %x\n", ino); 7680Sstevel@tonic-gate return (DDI_FAILURE); 7690Sstevel@tonic-gate } 7700Sstevel@tonic-gate ino = IB_MONDO_TO_INO(mondo); 7710Sstevel@tonic-gate 7720Sstevel@tonic-gate mutex_enter(&ib_p->ib_ino_lst_mutex); 7730Sstevel@tonic-gate ino_p = ib_locate_ino(ib_p, ino); 7740Sstevel@tonic-gate if (!ino_p) { 7750Sstevel@tonic-gate int r = cb_remove_xintr(pci_p, dip, rdip, ino, mondo); 7760Sstevel@tonic-gate if (r != DDI_SUCCESS) 7770Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d-xintr: ino %x is invalid", 7780Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip), ino); 7790Sstevel@tonic-gate mutex_exit(&ib_p->ib_ino_lst_mutex); 7800Sstevel@tonic-gate return (r); 7810Sstevel@tonic-gate } 7820Sstevel@tonic-gate 7830Sstevel@tonic-gate ih_p = ib_ino_locate_intr(ino_p, rdip, hdlp->ih_inum); 7840Sstevel@tonic-gate ib_ino_rem_intr(pci_p, ino_p, ih_p); 7850Sstevel@tonic-gate intr_dist_cpuid_rem_device_weight(ino_p->ino_cpuid, rdip); 7860Sstevel@tonic-gate if (ino_p->ino_ih_size == 0) { 7870Sstevel@tonic-gate IB_INO_INTR_PEND(ib_clear_intr_reg_addr(ib_p, ino)); 7880Sstevel@tonic-gate hdlp->ih_vector = CB_MONDO_TO_XMONDO(cb_p, mondo); 7890Sstevel@tonic-gate if (hdlp->ih_pri == 0) 7900Sstevel@tonic-gate hdlp->ih_pri = pci_class_to_pil(rdip); 7910Sstevel@tonic-gate 7920Sstevel@tonic-gate i_ddi_rem_ivintr(hdlp); 7930Sstevel@tonic-gate ib_delete_ino(ib_p, ino_p); 7940Sstevel@tonic-gate } 7950Sstevel@tonic-gate 7960Sstevel@tonic-gate /* re-enable interrupt only if mapping register still shared */ 7970Sstevel@tonic-gate if (ib_ino_map_reg_unshare(ib_p, ino, ino_p)) { 7980Sstevel@tonic-gate IB_INO_INTR_ON(ino_p->ino_map_reg); 7990Sstevel@tonic-gate *ino_p->ino_map_reg; 8000Sstevel@tonic-gate } 8010Sstevel@tonic-gate mutex_exit(&ib_p->ib_ino_lst_mutex); 8020Sstevel@tonic-gate 8030Sstevel@tonic-gate if (ino_p->ino_ih_size == 0) 8040Sstevel@tonic-gate kmem_free(ino_p, sizeof (ib_ino_info_t)); 8050Sstevel@tonic-gate 8060Sstevel@tonic-gate DEBUG1(DBG_R_INTX, dip, "success! mondo=%x\n", mondo); 8070Sstevel@tonic-gate return (DDI_SUCCESS); 8080Sstevel@tonic-gate } 8090Sstevel@tonic-gate 8100Sstevel@tonic-gate /* 8110Sstevel@tonic-gate * free the pci_inos array allocated during pci_intr_setup. the actual 8120Sstevel@tonic-gate * interrupts are torn down by their respective block destroy routines: 8130Sstevel@tonic-gate * cb_destroy, pbm_destroy, and ib_destroy. 8140Sstevel@tonic-gate */ 8150Sstevel@tonic-gate void 8160Sstevel@tonic-gate pci_intr_teardown(pci_t *pci_p) 8170Sstevel@tonic-gate { 8180Sstevel@tonic-gate kmem_free(pci_p->pci_inos, pci_p->pci_inos_len); 8190Sstevel@tonic-gate pci_p->pci_inos = NULL; 8200Sstevel@tonic-gate pci_p->pci_inos_len = 0; 8210Sstevel@tonic-gate } 822