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 51542Sjohnny * Common Development and Distribution License (the "License"). 61542Sjohnny * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 228535Sevan.yan@sun.com * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate /* 270Sstevel@tonic-gate * PX nexus interrupt handling: 280Sstevel@tonic-gate * PX device interrupt handler wrapper 290Sstevel@tonic-gate * PIL lookup routine 300Sstevel@tonic-gate * PX device interrupt related initchild code 310Sstevel@tonic-gate */ 320Sstevel@tonic-gate 330Sstevel@tonic-gate #include <sys/types.h> 340Sstevel@tonic-gate #include <sys/kmem.h> 350Sstevel@tonic-gate #include <sys/async.h> 360Sstevel@tonic-gate #include <sys/spl.h> 370Sstevel@tonic-gate #include <sys/sunddi.h> 3827Sjchu #include <sys/fm/protocol.h> 3927Sjchu #include <sys/fm/util.h> 400Sstevel@tonic-gate #include <sys/machsystm.h> /* e_ddi_nodeid_to_dip() */ 410Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 420Sstevel@tonic-gate #include <sys/sdt.h> 430Sstevel@tonic-gate #include <sys/atomic.h> 440Sstevel@tonic-gate #include "px_obj.h" 4527Sjchu #include <sys/ontrap.h> 4627Sjchu #include <sys/membar.h> 4766Sesolom #include <sys/clock.h> 480Sstevel@tonic-gate 490Sstevel@tonic-gate /* 500Sstevel@tonic-gate * interrupt jabber: 510Sstevel@tonic-gate * 520Sstevel@tonic-gate * When an interrupt line is jabbering, every time the state machine for the 530Sstevel@tonic-gate * associated ino is idled, a new mondo will be sent and the ino will go into 540Sstevel@tonic-gate * the pending state again. The mondo will cause a new call to 550Sstevel@tonic-gate * px_intr_wrapper() which normally idles the ino's state machine which would 560Sstevel@tonic-gate * precipitate another trip round the loop. 570Sstevel@tonic-gate * 580Sstevel@tonic-gate * The loop can be broken by preventing the ino's state machine from being 590Sstevel@tonic-gate * idled when an interrupt line is jabbering. See the comment at the 600Sstevel@tonic-gate * beginning of px_intr_wrapper() explaining how the 'interrupt jabber 610Sstevel@tonic-gate * protection' code does this. 620Sstevel@tonic-gate */ 630Sstevel@tonic-gate 640Sstevel@tonic-gate /*LINTLIBRARY*/ 650Sstevel@tonic-gate 660Sstevel@tonic-gate /* 670Sstevel@tonic-gate * If the unclaimed interrupt count has reached the limit set by 680Sstevel@tonic-gate * pci_unclaimed_intr_max within the time limit, then all interrupts 690Sstevel@tonic-gate * on this ino is blocked by not idling the interrupt state machine. 700Sstevel@tonic-gate */ 710Sstevel@tonic-gate static int 722973Sgovinda px_spurintr(px_ino_pil_t *ipil_p) 730Sstevel@tonic-gate { 742973Sgovinda px_ino_t *ino_p = ipil_p->ipil_ino_p; 75*10596SDaniel.Ice@Sun.COM px_ih_t *ih_p; 762973Sgovinda px_t *px_p = ino_p->ino_ib_p->ib_px_p; 772973Sgovinda char *err_fmt_str; 782973Sgovinda boolean_t blocked = B_FALSE; 792973Sgovinda int i; 800Sstevel@tonic-gate 812973Sgovinda if (ino_p->ino_unclaimed_intrs > px_unclaimed_intr_max) 820Sstevel@tonic-gate return (DDI_INTR_CLAIMED); 830Sstevel@tonic-gate 842973Sgovinda if (!ino_p->ino_unclaimed_intrs) 850Sstevel@tonic-gate ino_p->ino_spurintr_begin = ddi_get_lbolt(); 860Sstevel@tonic-gate 872973Sgovinda ino_p->ino_unclaimed_intrs++; 880Sstevel@tonic-gate 892973Sgovinda if (ino_p->ino_unclaimed_intrs <= px_unclaimed_intr_max) 900Sstevel@tonic-gate goto clear; 910Sstevel@tonic-gate 920Sstevel@tonic-gate if (drv_hztousec(ddi_get_lbolt() - ino_p->ino_spurintr_begin) 930Sstevel@tonic-gate > px_spurintr_duration) { 942973Sgovinda ino_p->ino_unclaimed_intrs = 0; 950Sstevel@tonic-gate goto clear; 960Sstevel@tonic-gate } 970Sstevel@tonic-gate err_fmt_str = "%s%d: ino 0x%x blocked"; 982973Sgovinda blocked = B_TRUE; 990Sstevel@tonic-gate goto warn; 1000Sstevel@tonic-gate clear: 1010Sstevel@tonic-gate err_fmt_str = "!%s%d: spurious interrupt from ino 0x%x"; 1020Sstevel@tonic-gate warn: 1030Sstevel@tonic-gate cmn_err(CE_WARN, err_fmt_str, NAMEINST(px_p->px_dip), ino_p->ino_ino); 104*10596SDaniel.Ice@Sun.COM for (ipil_p = ino_p->ino_ipil_p; ipil_p; 105*10596SDaniel.Ice@Sun.COM ipil_p = ipil_p->ipil_next_p) { 106*10596SDaniel.Ice@Sun.COM for (i = 0, ih_p = ipil_p->ipil_ih_start; 107*10596SDaniel.Ice@Sun.COM i < ipil_p->ipil_ih_size; i++, ih_p = ih_p->ih_next) 108*10596SDaniel.Ice@Sun.COM cmn_err(CE_CONT, "!%s-%d#%x ", NAMEINST(ih_p->ih_dip), 109*10596SDaniel.Ice@Sun.COM ih_p->ih_inum); 110*10596SDaniel.Ice@Sun.COM } 1110Sstevel@tonic-gate cmn_err(CE_CONT, "!\n"); 1122973Sgovinda 1132973Sgovinda /* Clear the pending state */ 1142973Sgovinda if (blocked == B_FALSE) { 1152973Sgovinda if (px_lib_intr_setstate(px_p->px_dip, ino_p->ino_sysino, 1162973Sgovinda INTR_IDLE_STATE) != DDI_SUCCESS) 1172973Sgovinda return (DDI_INTR_UNCLAIMED); 1182973Sgovinda } 1192973Sgovinda 1200Sstevel@tonic-gate return (DDI_INTR_CLAIMED); 1210Sstevel@tonic-gate } 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate extern uint64_t intr_get_time(void); 1240Sstevel@tonic-gate 1250Sstevel@tonic-gate /* 126693Sgovinda * px_intx_intr (INTx or legacy interrupt handler) 1270Sstevel@tonic-gate * 1280Sstevel@tonic-gate * This routine is used as wrapper around interrupt handlers installed by child 1290Sstevel@tonic-gate * device drivers. This routine invokes the driver interrupt handlers and 1300Sstevel@tonic-gate * examines the return codes. 1310Sstevel@tonic-gate * 1320Sstevel@tonic-gate * There is a count of unclaimed interrupts kept on a per-ino basis. If at 1330Sstevel@tonic-gate * least one handler claims the interrupt then the counter is halved and the 1340Sstevel@tonic-gate * interrupt state machine is idled. If no handler claims the interrupt then 1350Sstevel@tonic-gate * the counter is incremented by one and the state machine is idled. 1360Sstevel@tonic-gate * If the count ever reaches the limit value set by pci_unclaimed_intr_max 1370Sstevel@tonic-gate * then the interrupt state machine is not idled thus preventing any further 1380Sstevel@tonic-gate * interrupts on that ino. The state machine will only be idled again if a 1390Sstevel@tonic-gate * handler is subsequently added or removed. 1400Sstevel@tonic-gate * 1410Sstevel@tonic-gate * return value: DDI_INTR_CLAIMED if any handlers claimed the interrupt, 1420Sstevel@tonic-gate * DDI_INTR_UNCLAIMED otherwise. 1430Sstevel@tonic-gate */ 1440Sstevel@tonic-gate uint_t 1450Sstevel@tonic-gate px_intx_intr(caddr_t arg) 1460Sstevel@tonic-gate { 1472973Sgovinda px_ino_pil_t *ipil_p = (px_ino_pil_t *)arg; 1482973Sgovinda px_ino_t *ino_p = ipil_p->ipil_ino_p; 1490Sstevel@tonic-gate px_t *px_p = ino_p->ino_ib_p->ib_px_p; 1502973Sgovinda px_ih_t *ih_p = ipil_p->ipil_ih_start; 1512973Sgovinda ushort_t pil = ipil_p->ipil_pil; 1522973Sgovinda uint_t result = 0, r = DDI_INTR_UNCLAIMED; 1530Sstevel@tonic-gate int i; 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate DBG(DBG_INTX_INTR, px_p->px_dip, "px_intx_intr:" 1560Sstevel@tonic-gate "ino=%x sysino=%llx pil=%x ih_size=%x ih_lst=%x\n", 1572973Sgovinda ino_p->ino_ino, ino_p->ino_sysino, ipil_p->ipil_pil, 1582973Sgovinda ipil_p->ipil_ih_size, ipil_p->ipil_ih_head); 1590Sstevel@tonic-gate 1602973Sgovinda for (i = 0; i < ipil_p->ipil_ih_size; i++, ih_p = ih_p->ih_next) { 1610Sstevel@tonic-gate dev_info_t *dip = ih_p->ih_dip; 1620Sstevel@tonic-gate uint_t (*handler)() = ih_p->ih_handler; 1630Sstevel@tonic-gate caddr_t arg1 = ih_p->ih_handler_arg1; 1640Sstevel@tonic-gate caddr_t arg2 = ih_p->ih_handler_arg2; 1650Sstevel@tonic-gate 1660Sstevel@tonic-gate if (ih_p->ih_intr_state == PX_INTR_STATE_DISABLE) { 1670Sstevel@tonic-gate DBG(DBG_INTX_INTR, px_p->px_dip, 1680Sstevel@tonic-gate "px_intx_intr: %s%d interrupt %d is disabled\n", 1690Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip), 1700Sstevel@tonic-gate ino_p->ino_ino); 1710Sstevel@tonic-gate 1720Sstevel@tonic-gate continue; 1730Sstevel@tonic-gate } 1740Sstevel@tonic-gate 1750Sstevel@tonic-gate DBG(DBG_INTX_INTR, px_p->px_dip, "px_intx_intr:" 1760Sstevel@tonic-gate "ino=%x handler=%p arg1 =%p arg2 = %p\n", 1770Sstevel@tonic-gate ino_p->ino_ino, handler, arg1, arg2); 1780Sstevel@tonic-gate 1790Sstevel@tonic-gate DTRACE_PROBE4(interrupt__start, dev_info_t, dip, 1800Sstevel@tonic-gate void *, handler, caddr_t, arg1, caddr_t, arg2); 1810Sstevel@tonic-gate 1820Sstevel@tonic-gate r = (*handler)(arg1, arg2); 1830Sstevel@tonic-gate 1840Sstevel@tonic-gate /* 1850Sstevel@tonic-gate * Account for time used by this interrupt. Protect against 1860Sstevel@tonic-gate * conflicting writes to ih_ticks from ib_intr_dist_all() by 1870Sstevel@tonic-gate * using atomic ops. 1880Sstevel@tonic-gate */ 1890Sstevel@tonic-gate 1902973Sgovinda if (pil <= LOCK_LEVEL) 1910Sstevel@tonic-gate atomic_add_64(&ih_p->ih_ticks, intr_get_time()); 1920Sstevel@tonic-gate 1930Sstevel@tonic-gate DTRACE_PROBE4(interrupt__complete, dev_info_t, dip, 1940Sstevel@tonic-gate void *, handler, caddr_t, arg1, int, r); 1950Sstevel@tonic-gate 1960Sstevel@tonic-gate result += r; 1970Sstevel@tonic-gate 1980Sstevel@tonic-gate if (px_check_all_handlers) 1990Sstevel@tonic-gate continue; 2000Sstevel@tonic-gate if (result) 2010Sstevel@tonic-gate break; 2020Sstevel@tonic-gate } 2030Sstevel@tonic-gate 2042973Sgovinda if (result) 2052973Sgovinda ino_p->ino_claimed |= (1 << pil); 2062973Sgovinda 2072973Sgovinda /* Interrupt can only be cleared after all pil levels are handled */ 2082973Sgovinda if (pil != ino_p->ino_lopil) 2092973Sgovinda return (DDI_INTR_CLAIMED); 2100Sstevel@tonic-gate 2112973Sgovinda if (!ino_p->ino_claimed) { 2122973Sgovinda if (px_unclaimed_intr_block) 2132973Sgovinda return (px_spurintr(ipil_p)); 2142973Sgovinda } 2152973Sgovinda 2162973Sgovinda ino_p->ino_unclaimed_intrs = 0; 2172973Sgovinda ino_p->ino_claimed = 0; 2180Sstevel@tonic-gate 2190Sstevel@tonic-gate /* Clear the pending state */ 2202973Sgovinda if (px_lib_intr_setstate(px_p->px_dip, 2210Sstevel@tonic-gate ino_p->ino_sysino, INTR_IDLE_STATE) != DDI_SUCCESS) 2220Sstevel@tonic-gate return (DDI_INTR_UNCLAIMED); 2230Sstevel@tonic-gate 2240Sstevel@tonic-gate return (DDI_INTR_CLAIMED); 2250Sstevel@tonic-gate } 2260Sstevel@tonic-gate 2270Sstevel@tonic-gate /* 228693Sgovinda * px_msiq_intr (MSI/X or PCIe MSG interrupt handler) 2290Sstevel@tonic-gate * 2300Sstevel@tonic-gate * This routine is used as wrapper around interrupt handlers installed by child 2310Sstevel@tonic-gate * device drivers. This routine invokes the driver interrupt handlers and 2320Sstevel@tonic-gate * examines the return codes. 2330Sstevel@tonic-gate * 2340Sstevel@tonic-gate * There is a count of unclaimed interrupts kept on a per-ino basis. If at 2350Sstevel@tonic-gate * least one handler claims the interrupt then the counter is halved and the 2360Sstevel@tonic-gate * interrupt state machine is idled. If no handler claims the interrupt then 2370Sstevel@tonic-gate * the counter is incremented by one and the state machine is idled. 2380Sstevel@tonic-gate * If the count ever reaches the limit value set by pci_unclaimed_intr_max 2390Sstevel@tonic-gate * then the interrupt state machine is not idled thus preventing any further 2400Sstevel@tonic-gate * interrupts on that ino. The state machine will only be idled again if a 2410Sstevel@tonic-gate * handler is subsequently added or removed. 2420Sstevel@tonic-gate * 2430Sstevel@tonic-gate * return value: DDI_INTR_CLAIMED if any handlers claimed the interrupt, 2440Sstevel@tonic-gate * DDI_INTR_UNCLAIMED otherwise. 2450Sstevel@tonic-gate */ 2460Sstevel@tonic-gate uint_t 2470Sstevel@tonic-gate px_msiq_intr(caddr_t arg) 2480Sstevel@tonic-gate { 2492973Sgovinda px_ino_pil_t *ipil_p = (px_ino_pil_t *)arg; 2502973Sgovinda px_ino_t *ino_p = ipil_p->ipil_ino_p; 2510Sstevel@tonic-gate px_t *px_p = ino_p->ino_ib_p->ib_px_p; 2520Sstevel@tonic-gate px_msiq_state_t *msiq_state_p = &px_p->px_ib_p->ib_msiq_state; 2530Sstevel@tonic-gate px_msiq_t *msiq_p = ino_p->ino_msiq_p; 2540Sstevel@tonic-gate dev_info_t *dip = px_p->px_dip; 2552973Sgovinda ushort_t pil = ipil_p->ipil_pil; 2560Sstevel@tonic-gate msiq_rec_t msiq_rec, *msiq_rec_p = &msiq_rec; 2572588Segillett msiqhead_t *curr_head_p; 2582588Segillett msiqtail_t curr_tail_index; 2590Sstevel@tonic-gate msgcode_t msg_code; 2600Sstevel@tonic-gate px_ih_t *ih_p; 2612973Sgovinda uint_t ret = DDI_INTR_UNCLAIMED; 2622973Sgovinda int i, j; 2630Sstevel@tonic-gate 2640Sstevel@tonic-gate DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: msiq_id =%x ino=%x pil=%x " 2650Sstevel@tonic-gate "ih_size=%x ih_lst=%x\n", msiq_p->msiq_id, ino_p->ino_ino, 2662973Sgovinda ipil_p->ipil_pil, ipil_p->ipil_ih_size, ipil_p->ipil_ih_head); 2672973Sgovinda 2682973Sgovinda /* 2692973Sgovinda * The px_msiq_intr() handles multiple interrupt priorities and it 2702973Sgovinda * will set msiq->msiq_rec2process to the number of MSIQ records to 2712973Sgovinda * process while handling the highest priority interrupt. Subsequent 2722973Sgovinda * lower priority interrupts will just process any unprocessed MSIQ 2732973Sgovinda * records or will just return immediately. 2742973Sgovinda */ 2752973Sgovinda if (msiq_p->msiq_recs2process == 0) { 276*10596SDaniel.Ice@Sun.COM ASSERT(ino_p->ino_ipil_cntr == 0); 277*10596SDaniel.Ice@Sun.COM ino_p->ino_ipil_cntr = ino_p->ino_ipil_size; 278*10596SDaniel.Ice@Sun.COM 2792973Sgovinda /* Read current MSIQ tail index */ 2802973Sgovinda px_lib_msiq_gettail(dip, msiq_p->msiq_id, &curr_tail_index); 2812973Sgovinda msiq_p->msiq_new_head_index = msiq_p->msiq_curr_head_index; 2820Sstevel@tonic-gate 2832973Sgovinda if (curr_tail_index < msiq_p->msiq_curr_head_index) 2842973Sgovinda curr_tail_index += msiq_state_p->msiq_rec_cnt; 2852973Sgovinda 2862973Sgovinda msiq_p->msiq_recs2process = curr_tail_index - 2872973Sgovinda msiq_p->msiq_curr_head_index; 2882973Sgovinda } 2890Sstevel@tonic-gate 2902973Sgovinda DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: curr_head %x new_head %x " 2912973Sgovinda "rec2process %x\n", msiq_p->msiq_curr_head_index, 2922973Sgovinda msiq_p->msiq_new_head_index, msiq_p->msiq_recs2process); 2932973Sgovinda 2942973Sgovinda /* If all MSIQ records are already processed, just return immediately */ 2952973Sgovinda if ((msiq_p->msiq_new_head_index - msiq_p->msiq_curr_head_index) 2962973Sgovinda == msiq_p->msiq_recs2process) 2972973Sgovinda goto intr_done; 2982973Sgovinda 2992973Sgovinda curr_head_p = (msiqhead_t *)((caddr_t)msiq_p->msiq_base_p + 3002973Sgovinda (msiq_p->msiq_curr_head_index * sizeof (msiq_rec_t))); 3010Sstevel@tonic-gate 3020Sstevel@tonic-gate /* 3032588Segillett * Calculate the number of recs to process by taking the difference 3042588Segillett * between the head and tail pointers. For all records we always 3052588Segillett * verify that we have a valid record type before we do any processing. 3062973Sgovinda * If triggered, we should always have at least one valid record. 3070Sstevel@tonic-gate */ 3082973Sgovinda for (i = 0; i < msiq_p->msiq_recs2process; i++) { 3099686SAlan.Adamson@Sun.COM msiq_rec_type_t rec_type; 3109686SAlan.Adamson@Sun.COM 3112973Sgovinda /* Read next MSIQ record */ 3122588Segillett px_lib_get_msiq_rec(dip, curr_head_p, msiq_rec_p); 3132588Segillett 3149686SAlan.Adamson@Sun.COM rec_type = msiq_rec_p->msiq_rec_type; 3159686SAlan.Adamson@Sun.COM 3160Sstevel@tonic-gate DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: MSIQ RECORD, " 3170Sstevel@tonic-gate "msiq_rec_type 0x%llx msiq_rec_rid 0x%llx\n", 3189686SAlan.Adamson@Sun.COM rec_type, msiq_rec_p->msiq_rec_rid); 3190Sstevel@tonic-gate 3209686SAlan.Adamson@Sun.COM if (!rec_type) 3212973Sgovinda goto next_rec; 3220Sstevel@tonic-gate 3230Sstevel@tonic-gate /* Check MSIQ record type */ 3249686SAlan.Adamson@Sun.COM switch (rec_type) { 3250Sstevel@tonic-gate case MSG_REC: 3260Sstevel@tonic-gate msg_code = msiq_rec_p->msiq_rec_data.msg.msg_code; 3270Sstevel@tonic-gate DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: PCIE MSG " 3280Sstevel@tonic-gate "record, msg type 0x%x\n", msg_code); 3290Sstevel@tonic-gate break; 3300Sstevel@tonic-gate case MSI32_REC: 3310Sstevel@tonic-gate case MSI64_REC: 3320Sstevel@tonic-gate msg_code = msiq_rec_p->msiq_rec_data.msi.msi_data; 3330Sstevel@tonic-gate DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: MSI record, " 3340Sstevel@tonic-gate "msi 0x%x\n", msg_code); 3350Sstevel@tonic-gate 3360Sstevel@tonic-gate /* Clear MSI state */ 3370Sstevel@tonic-gate px_lib_msi_setstate(dip, (msinum_t)msg_code, 3380Sstevel@tonic-gate PCI_MSI_STATE_IDLE); 3390Sstevel@tonic-gate break; 3400Sstevel@tonic-gate default: 3410Sstevel@tonic-gate msg_code = 0; 3420Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: px_msiq_intr: 0x%x MSIQ " 3430Sstevel@tonic-gate "record type is not supported", 3440Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip), 3459686SAlan.Adamson@Sun.COM rec_type); 3462973Sgovinda 3470Sstevel@tonic-gate goto next_rec; 3480Sstevel@tonic-gate } 3490Sstevel@tonic-gate 3500Sstevel@tonic-gate /* 3510Sstevel@tonic-gate * Scan through px_ih_t linked list, searching for the 3520Sstevel@tonic-gate * right px_ih_t, matching MSIQ record data. 3530Sstevel@tonic-gate */ 3542973Sgovinda for (j = 0, ih_p = ipil_p->ipil_ih_start; 3552973Sgovinda ih_p && (j < ipil_p->ipil_ih_size) && 3561653Sgovinda ((ih_p->ih_msg_code != msg_code) || 3579686SAlan.Adamson@Sun.COM (ih_p->ih_rec_type != rec_type)); 3584397Sschwartz ih_p = ih_p->ih_next, j++) 3594397Sschwartz ; 3600Sstevel@tonic-gate 3610Sstevel@tonic-gate if ((ih_p->ih_msg_code == msg_code) && 3629686SAlan.Adamson@Sun.COM (ih_p->ih_rec_type == rec_type)) { 3630Sstevel@tonic-gate dev_info_t *dip = ih_p->ih_dip; 3640Sstevel@tonic-gate uint_t (*handler)() = ih_p->ih_handler; 3650Sstevel@tonic-gate caddr_t arg1 = ih_p->ih_handler_arg1; 3660Sstevel@tonic-gate caddr_t arg2 = ih_p->ih_handler_arg2; 3670Sstevel@tonic-gate 3680Sstevel@tonic-gate DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: ino=%x data=%x " 3690Sstevel@tonic-gate "handler=%p arg1 =%p arg2=%p\n", ino_p->ino_ino, 3700Sstevel@tonic-gate msg_code, handler, arg1, arg2); 3710Sstevel@tonic-gate 3720Sstevel@tonic-gate DTRACE_PROBE4(interrupt__start, dev_info_t, dip, 3730Sstevel@tonic-gate void *, handler, caddr_t, arg1, caddr_t, arg2); 3740Sstevel@tonic-gate 37510053SEvan.Yan@Sun.COM ih_p->ih_retarget_flag = B_FALSE; 37610053SEvan.Yan@Sun.COM 37727Sjchu /* 37827Sjchu * Special case for PCIE Error Messages. 37927Sjchu * The current frame work doesn't fit PCIE Err Msgs 38027Sjchu * This should be fixed when PCIE MESSAGES as a whole 38127Sjchu * is architected correctly. 38227Sjchu */ 3839686SAlan.Adamson@Sun.COM if ((rec_type == MSG_REC) && 3849686SAlan.Adamson@Sun.COM ((msg_code == PCIE_MSG_CODE_ERR_COR) || 38527Sjchu (msg_code == PCIE_MSG_CODE_ERR_NONFATAL) || 3869686SAlan.Adamson@Sun.COM (msg_code == PCIE_MSG_CODE_ERR_FATAL))) { 38727Sjchu ret = px_err_fabric_intr(px_p, msg_code, 38827Sjchu msiq_rec_p->msiq_rec_rid); 38927Sjchu } else 39027Sjchu ret = (*handler)(arg1, arg2); 3910Sstevel@tonic-gate 3920Sstevel@tonic-gate /* 3930Sstevel@tonic-gate * Account for time used by this interrupt. Protect 3940Sstevel@tonic-gate * against conflicting writes to ih_ticks from 3950Sstevel@tonic-gate * ib_intr_dist_all() by using atomic ops. 3960Sstevel@tonic-gate */ 3970Sstevel@tonic-gate 3982973Sgovinda if (pil <= LOCK_LEVEL) 3990Sstevel@tonic-gate atomic_add_64(&ih_p->ih_ticks, intr_get_time()); 4000Sstevel@tonic-gate 4010Sstevel@tonic-gate DTRACE_PROBE4(interrupt__complete, dev_info_t, dip, 4020Sstevel@tonic-gate void *, handler, caddr_t, arg1, int, ret); 4032588Segillett 4042973Sgovinda msiq_p->msiq_new_head_index++; 4052973Sgovinda px_lib_clr_msiq_rec(dip, curr_head_p); 4060Sstevel@tonic-gate } else { 4070Sstevel@tonic-gate DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr:" 4082588Segillett "No matching MSIQ record found\n"); 4092588Segillett } 4102588Segillett next_rec: 4112588Segillett /* Get the pointer next EQ record */ 4122588Segillett curr_head_p = (msiqhead_t *) 4132588Segillett ((caddr_t)curr_head_p + sizeof (msiq_rec_t)); 4140Sstevel@tonic-gate 4152588Segillett /* Check for overflow condition */ 4162588Segillett if (curr_head_p >= (msiqhead_t *)((caddr_t)msiq_p->msiq_base_p 4172973Sgovinda + (msiq_state_p->msiq_rec_cnt * sizeof (msiq_rec_t)))) 4182588Segillett curr_head_p = (msiqhead_t *)msiq_p->msiq_base_p; 4190Sstevel@tonic-gate } 4200Sstevel@tonic-gate 4212973Sgovinda DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: No of MSIQ recs processed %x\n", 4222973Sgovinda (msiq_p->msiq_new_head_index - msiq_p->msiq_curr_head_index)); 4232973Sgovinda 4242973Sgovinda DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: curr_head %x new_head %x " 4252973Sgovinda "rec2process %x\n", msiq_p->msiq_curr_head_index, 4262973Sgovinda msiq_p->msiq_new_head_index, msiq_p->msiq_recs2process); 4272588Segillett 4282973Sgovinda /* ino_claimed used just for debugging purpose */ 4292973Sgovinda if (ret) 4302973Sgovinda ino_p->ino_claimed |= (1 << pil); 4312973Sgovinda 4322973Sgovinda intr_done: 4332973Sgovinda /* Interrupt can only be cleared after all pil levels are handled */ 434*10596SDaniel.Ice@Sun.COM if (--ino_p->ino_ipil_cntr != 0) 4352973Sgovinda return (DDI_INTR_CLAIMED); 4362973Sgovinda 4372973Sgovinda if (msiq_p->msiq_new_head_index <= msiq_p->msiq_curr_head_index) { 4382973Sgovinda if (px_unclaimed_intr_block) 4392973Sgovinda return (px_spurintr(ipil_p)); 4402588Segillett } 4410Sstevel@tonic-gate 4420Sstevel@tonic-gate /* Update MSIQ head index with no of MSIQ records processed */ 4432973Sgovinda if (msiq_p->msiq_new_head_index >= msiq_state_p->msiq_rec_cnt) 4442973Sgovinda msiq_p->msiq_new_head_index -= msiq_state_p->msiq_rec_cnt; 4450Sstevel@tonic-gate 4462973Sgovinda msiq_p->msiq_curr_head_index = msiq_p->msiq_new_head_index; 4472973Sgovinda px_lib_msiq_sethead(dip, msiq_p->msiq_id, msiq_p->msiq_new_head_index); 4482973Sgovinda 4492973Sgovinda msiq_p->msiq_new_head_index = 0; 4502973Sgovinda msiq_p->msiq_recs2process = 0; 4512973Sgovinda ino_p->ino_claimed = 0; 4520Sstevel@tonic-gate 4530Sstevel@tonic-gate /* Clear the pending state */ 4540Sstevel@tonic-gate if (px_lib_intr_setstate(dip, ino_p->ino_sysino, 4550Sstevel@tonic-gate INTR_IDLE_STATE) != DDI_SUCCESS) 4560Sstevel@tonic-gate return (DDI_INTR_UNCLAIMED); 4570Sstevel@tonic-gate 4580Sstevel@tonic-gate return (DDI_INTR_CLAIMED); 4590Sstevel@tonic-gate } 4600Sstevel@tonic-gate 4610Sstevel@tonic-gate dev_info_t * 4620Sstevel@tonic-gate px_get_my_childs_dip(dev_info_t *dip, dev_info_t *rdip) 4630Sstevel@tonic-gate { 4640Sstevel@tonic-gate dev_info_t *cdip = rdip; 4650Sstevel@tonic-gate 4660Sstevel@tonic-gate for (; ddi_get_parent(cdip) != dip; cdip = ddi_get_parent(cdip)) 4670Sstevel@tonic-gate ; 4680Sstevel@tonic-gate 4690Sstevel@tonic-gate return (cdip); 4700Sstevel@tonic-gate } 4710Sstevel@tonic-gate 4720Sstevel@tonic-gate /* ARGSUSED */ 4730Sstevel@tonic-gate int 4740Sstevel@tonic-gate px_intx_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op, 4750Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, void *result) 4760Sstevel@tonic-gate { 477693Sgovinda px_t *px_p = DIP_TO_STATE(dip); 478693Sgovinda int ret = DDI_SUCCESS; 4790Sstevel@tonic-gate 4800Sstevel@tonic-gate DBG(DBG_INTROPS, dip, "px_intx_ops: dip=%x rdip=%x intr_op=%x " 4810Sstevel@tonic-gate "handle=%p\n", dip, rdip, intr_op, hdlp); 4820Sstevel@tonic-gate 4830Sstevel@tonic-gate switch (intr_op) { 4840Sstevel@tonic-gate case DDI_INTROP_GETCAP: 4850Sstevel@tonic-gate ret = pci_intx_get_cap(rdip, (int *)result); 4860Sstevel@tonic-gate break; 4870Sstevel@tonic-gate case DDI_INTROP_SETCAP: 4880Sstevel@tonic-gate DBG(DBG_INTROPS, dip, "px_intx_ops: SetCap is not supported\n"); 4890Sstevel@tonic-gate ret = DDI_ENOTSUP; 4900Sstevel@tonic-gate break; 4910Sstevel@tonic-gate case DDI_INTROP_ALLOC: 4920Sstevel@tonic-gate *(int *)result = hdlp->ih_scratch1; 4930Sstevel@tonic-gate break; 4940Sstevel@tonic-gate case DDI_INTROP_FREE: 4950Sstevel@tonic-gate break; 4960Sstevel@tonic-gate case DDI_INTROP_GETPRI: 497693Sgovinda *(int *)result = hdlp->ih_pri ? 4988535Sevan.yan@sun.com hdlp->ih_pri : pci_class_to_pil(rdip); 4990Sstevel@tonic-gate break; 5000Sstevel@tonic-gate case DDI_INTROP_SETPRI: 5010Sstevel@tonic-gate break; 5020Sstevel@tonic-gate case DDI_INTROP_ADDISR: 5030Sstevel@tonic-gate ret = px_add_intx_intr(dip, rdip, hdlp); 5040Sstevel@tonic-gate break; 5050Sstevel@tonic-gate case DDI_INTROP_REMISR: 5060Sstevel@tonic-gate ret = px_rem_intx_intr(dip, rdip, hdlp); 5070Sstevel@tonic-gate break; 50810053SEvan.Yan@Sun.COM case DDI_INTROP_GETTARGET: 50910053SEvan.Yan@Sun.COM ret = px_ib_get_intr_target(px_p, hdlp->ih_vector, 51010053SEvan.Yan@Sun.COM (cpuid_t *)result); 51110053SEvan.Yan@Sun.COM break; 51210053SEvan.Yan@Sun.COM case DDI_INTROP_SETTARGET: 51310053SEvan.Yan@Sun.COM ret = DDI_ENOTSUP; 51410053SEvan.Yan@Sun.COM break; 5150Sstevel@tonic-gate case DDI_INTROP_ENABLE: 5160Sstevel@tonic-gate ret = px_ib_update_intr_state(px_p, rdip, hdlp->ih_inum, 5172973Sgovinda hdlp->ih_vector, hdlp->ih_pri, PX_INTR_STATE_ENABLE, 0, 0); 5180Sstevel@tonic-gate break; 5190Sstevel@tonic-gate case DDI_INTROP_DISABLE: 5200Sstevel@tonic-gate ret = px_ib_update_intr_state(px_p, rdip, hdlp->ih_inum, 5212973Sgovinda hdlp->ih_vector, hdlp->ih_pri, PX_INTR_STATE_DISABLE, 0, 0); 5220Sstevel@tonic-gate break; 5230Sstevel@tonic-gate case DDI_INTROP_SETMASK: 5240Sstevel@tonic-gate ret = pci_intx_set_mask(rdip); 5250Sstevel@tonic-gate break; 5260Sstevel@tonic-gate case DDI_INTROP_CLRMASK: 5270Sstevel@tonic-gate ret = pci_intx_clr_mask(rdip); 5280Sstevel@tonic-gate break; 5290Sstevel@tonic-gate case DDI_INTROP_GETPENDING: 5300Sstevel@tonic-gate ret = pci_intx_get_pending(rdip, (int *)result); 5310Sstevel@tonic-gate break; 5320Sstevel@tonic-gate case DDI_INTROP_NINTRS: 5330Sstevel@tonic-gate case DDI_INTROP_NAVAIL: 5342580Sanish *(int *)result = i_ddi_get_intx_nintrs(rdip); 5350Sstevel@tonic-gate break; 5360Sstevel@tonic-gate default: 5370Sstevel@tonic-gate ret = DDI_ENOTSUP; 5380Sstevel@tonic-gate break; 5390Sstevel@tonic-gate } 5400Sstevel@tonic-gate 5410Sstevel@tonic-gate return (ret); 5420Sstevel@tonic-gate } 5430Sstevel@tonic-gate 5440Sstevel@tonic-gate /* ARGSUSED */ 5450Sstevel@tonic-gate int 5460Sstevel@tonic-gate px_msix_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op, 5470Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, void *result) 5480Sstevel@tonic-gate { 5490Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip); 5500Sstevel@tonic-gate px_msi_state_t *msi_state_p = &px_p->px_ib_p->ib_msi_state; 551965Sgovinda msiq_rec_type_t msiq_rec_type; 552965Sgovinda msi_type_t msi_type; 553965Sgovinda uint64_t msi_addr; 5540Sstevel@tonic-gate msinum_t msi_num; 5550Sstevel@tonic-gate msiqid_t msiq_id; 5560Sstevel@tonic-gate uint_t nintrs; 55710053SEvan.Yan@Sun.COM int ret = DDI_SUCCESS; 5580Sstevel@tonic-gate 5590Sstevel@tonic-gate DBG(DBG_INTROPS, dip, "px_msix_ops: dip=%x rdip=%x intr_op=%x " 5600Sstevel@tonic-gate "handle=%p\n", dip, rdip, intr_op, hdlp); 5610Sstevel@tonic-gate 562965Sgovinda /* Check for MSI64 support */ 5631653Sgovinda if ((hdlp->ih_cap & DDI_INTR_FLAG_MSI64) && msi_state_p->msi_addr64) { 564965Sgovinda msiq_rec_type = MSI64_REC; 565965Sgovinda msi_type = MSI64_TYPE; 5661653Sgovinda msi_addr = msi_state_p->msi_addr64; 567965Sgovinda } else { 568965Sgovinda msiq_rec_type = MSI32_REC; 569965Sgovinda msi_type = MSI32_TYPE; 570965Sgovinda msi_addr = msi_state_p->msi_addr32; 571965Sgovinda } 572965Sgovinda 57310053SEvan.Yan@Sun.COM (void) px_msi_get_msinum(px_p, hdlp->ih_dip, 57410053SEvan.Yan@Sun.COM (hdlp->ih_flags & DDI_INTR_MSIX_DUP) ? hdlp->ih_main->ih_inum : 57510053SEvan.Yan@Sun.COM hdlp->ih_inum, &msi_num); 57610053SEvan.Yan@Sun.COM 5770Sstevel@tonic-gate switch (intr_op) { 5780Sstevel@tonic-gate case DDI_INTROP_GETCAP: 5790Sstevel@tonic-gate ret = pci_msi_get_cap(rdip, hdlp->ih_type, (int *)result); 58010053SEvan.Yan@Sun.COM if (ret == DDI_SUCCESS) 58110053SEvan.Yan@Sun.COM *(int *)result |= DDI_INTR_FLAG_RETARGETABLE; 5820Sstevel@tonic-gate break; 5830Sstevel@tonic-gate case DDI_INTROP_SETCAP: 5840Sstevel@tonic-gate DBG(DBG_INTROPS, dip, "px_msix_ops: SetCap is not supported\n"); 5850Sstevel@tonic-gate ret = DDI_ENOTSUP; 5860Sstevel@tonic-gate break; 5870Sstevel@tonic-gate case DDI_INTROP_ALLOC: 5880Sstevel@tonic-gate /* 5890Sstevel@tonic-gate * We need to restrict this allocation in future 5900Sstevel@tonic-gate * based on Resource Management policies. 5910Sstevel@tonic-gate */ 5928561SScott.Carter@Sun.COM if ((ret = px_msi_alloc(px_p, rdip, hdlp->ih_type, 5938561SScott.Carter@Sun.COM hdlp->ih_inum, hdlp->ih_scratch1, 5948561SScott.Carter@Sun.COM (uintptr_t)hdlp->ih_scratch2, 5951725Segillett (int *)result)) != DDI_SUCCESS) { 5961725Segillett DBG(DBG_INTROPS, dip, "px_msix_ops: allocation " 5971725Segillett "failed, rdip 0x%p type 0x%d inum 0x%x " 5981725Segillett "count 0x%x\n", rdip, hdlp->ih_type, hdlp->ih_inum, 5991725Segillett hdlp->ih_scratch1); 6000Sstevel@tonic-gate 6010Sstevel@tonic-gate return (ret); 6020Sstevel@tonic-gate } 6030Sstevel@tonic-gate 6041725Segillett if ((hdlp->ih_type == DDI_INTR_TYPE_MSIX) && 6051725Segillett (i_ddi_get_msix(rdip) == NULL)) { 6061725Segillett ddi_intr_msix_t *msix_p; 6071725Segillett 6081725Segillett if (msix_p = pci_msix_init(rdip)) { 6091725Segillett i_ddi_set_msix(rdip, msix_p); 6101725Segillett break; 6111725Segillett } 6121725Segillett 6131725Segillett DBG(DBG_INTROPS, dip, "px_msix_ops: MSI-X allocation " 6141725Segillett "failed, rdip 0x%p inum 0x%x\n", rdip, 6151725Segillett hdlp->ih_inum); 6161725Segillett 6171725Segillett (void) px_msi_free(px_p, rdip, hdlp->ih_inum, 6181725Segillett hdlp->ih_scratch1); 6191725Segillett 6201725Segillett return (DDI_FAILURE); 6211725Segillett } 6221725Segillett 6230Sstevel@tonic-gate break; 6240Sstevel@tonic-gate case DDI_INTROP_FREE: 6250Sstevel@tonic-gate (void) pci_msi_unconfigure(rdip, hdlp->ih_type, hdlp->ih_inum); 6261725Segillett 6271725Segillett if (hdlp->ih_type == DDI_INTR_TYPE_MSI) 6281725Segillett goto msi_free; 6291725Segillett 6301725Segillett if (hdlp->ih_flags & DDI_INTR_MSIX_DUP) 6311725Segillett break; 6321725Segillett 6331725Segillett if (((i_ddi_intr_get_current_nintrs(hdlp->ih_dip) - 1) == 0) && 6341725Segillett (i_ddi_get_msix(rdip))) { 6351725Segillett pci_msix_fini(i_ddi_get_msix(rdip)); 6361725Segillett i_ddi_set_msix(rdip, NULL); 6371725Segillett } 6381725Segillett msi_free: 6390Sstevel@tonic-gate (void) px_msi_free(px_p, rdip, hdlp->ih_inum, 6400Sstevel@tonic-gate hdlp->ih_scratch1); 6410Sstevel@tonic-gate break; 6420Sstevel@tonic-gate case DDI_INTROP_GETPRI: 6430Sstevel@tonic-gate *(int *)result = hdlp->ih_pri ? 6448535Sevan.yan@sun.com hdlp->ih_pri : pci_class_to_pil(rdip); 6450Sstevel@tonic-gate break; 6460Sstevel@tonic-gate case DDI_INTROP_SETPRI: 6470Sstevel@tonic-gate break; 6480Sstevel@tonic-gate case DDI_INTROP_ADDISR: 6490Sstevel@tonic-gate if ((ret = px_add_msiq_intr(dip, rdip, hdlp, 65010053SEvan.Yan@Sun.COM msiq_rec_type, msi_num, -1, &msiq_id)) != DDI_SUCCESS) { 6510Sstevel@tonic-gate DBG(DBG_INTROPS, dip, "px_msix_ops: Add MSI handler " 6520Sstevel@tonic-gate "failed, rdip 0x%p msi 0x%x\n", rdip, msi_num); 6530Sstevel@tonic-gate return (ret); 6540Sstevel@tonic-gate } 6550Sstevel@tonic-gate 6560Sstevel@tonic-gate DBG(DBG_INTROPS, dip, "px_msix_ops: msiq used 0x%x\n", msiq_id); 6570Sstevel@tonic-gate 6580Sstevel@tonic-gate if ((ret = px_lib_msi_setmsiq(dip, msi_num, 659965Sgovinda msiq_id, msi_type)) != DDI_SUCCESS) { 6600Sstevel@tonic-gate (void) px_rem_msiq_intr(dip, rdip, 661965Sgovinda hdlp, msiq_rec_type, msi_num, msiq_id); 6620Sstevel@tonic-gate return (ret); 6630Sstevel@tonic-gate } 6640Sstevel@tonic-gate 6650Sstevel@tonic-gate if ((ret = px_lib_msi_setstate(dip, msi_num, 6660Sstevel@tonic-gate PCI_MSI_STATE_IDLE)) != DDI_SUCCESS) { 6670Sstevel@tonic-gate (void) px_rem_msiq_intr(dip, rdip, 668965Sgovinda hdlp, msiq_rec_type, msi_num, msiq_id); 6690Sstevel@tonic-gate return (ret); 6700Sstevel@tonic-gate } 6710Sstevel@tonic-gate 67210053SEvan.Yan@Sun.COM if ((ret = px_lib_msi_setvalid(dip, msi_num, 67310053SEvan.Yan@Sun.COM PCI_MSI_VALID)) != DDI_SUCCESS) 67410053SEvan.Yan@Sun.COM return (ret); 67510053SEvan.Yan@Sun.COM 67610053SEvan.Yan@Sun.COM ret = px_ib_update_intr_state(px_p, rdip, hdlp->ih_inum, 67710053SEvan.Yan@Sun.COM px_msiqid_to_devino(px_p, msiq_id), hdlp->ih_pri, 67810053SEvan.Yan@Sun.COM PX_INTR_STATE_ENABLE, msiq_rec_type, msi_num); 67910053SEvan.Yan@Sun.COM 6800Sstevel@tonic-gate break; 6810Sstevel@tonic-gate case DDI_INTROP_DUPVEC: 6821725Segillett DBG(DBG_INTROPS, dip, "px_msix_ops: dupisr - inum: %x, " 6831725Segillett "new_vector: %x\n", hdlp->ih_inum, hdlp->ih_scratch1); 6841725Segillett 6851725Segillett ret = pci_msix_dup(hdlp->ih_dip, hdlp->ih_inum, 6861725Segillett hdlp->ih_scratch1); 6870Sstevel@tonic-gate break; 6880Sstevel@tonic-gate case DDI_INTROP_REMISR: 6890Sstevel@tonic-gate if ((ret = px_lib_msi_getmsiq(dip, msi_num, 6900Sstevel@tonic-gate &msiq_id)) != DDI_SUCCESS) 6910Sstevel@tonic-gate return (ret); 6920Sstevel@tonic-gate 69310053SEvan.Yan@Sun.COM if ((ret = px_ib_update_intr_state(px_p, rdip, 69410053SEvan.Yan@Sun.COM hdlp->ih_inum, px_msiqid_to_devino(px_p, msiq_id), 69510053SEvan.Yan@Sun.COM hdlp->ih_pri, PX_INTR_STATE_DISABLE, msiq_rec_type, 69610053SEvan.Yan@Sun.COM msi_num)) != DDI_SUCCESS) 69710053SEvan.Yan@Sun.COM return (ret); 69810053SEvan.Yan@Sun.COM 69910053SEvan.Yan@Sun.COM if ((ret = px_lib_msi_setvalid(dip, msi_num, 70010053SEvan.Yan@Sun.COM PCI_MSI_INVALID)) != DDI_SUCCESS) 70110053SEvan.Yan@Sun.COM return (ret); 70210053SEvan.Yan@Sun.COM 7030Sstevel@tonic-gate if ((ret = px_lib_msi_setstate(dip, msi_num, 704965Sgovinda PCI_MSI_STATE_IDLE)) != DDI_SUCCESS) 7050Sstevel@tonic-gate return (ret); 7060Sstevel@tonic-gate 7070Sstevel@tonic-gate ret = px_rem_msiq_intr(dip, rdip, 708965Sgovinda hdlp, msiq_rec_type, msi_num, msiq_id); 7090Sstevel@tonic-gate 7100Sstevel@tonic-gate break; 71110053SEvan.Yan@Sun.COM case DDI_INTROP_GETTARGET: 71210053SEvan.Yan@Sun.COM if ((ret = px_lib_msi_getmsiq(dip, msi_num, 71310053SEvan.Yan@Sun.COM &msiq_id)) != DDI_SUCCESS) 7140Sstevel@tonic-gate return (ret); 7150Sstevel@tonic-gate 71610053SEvan.Yan@Sun.COM ret = px_ib_get_intr_target(px_p, 71710053SEvan.Yan@Sun.COM px_msiqid_to_devino(px_p, msiq_id), (cpuid_t *)result); 71810053SEvan.Yan@Sun.COM break; 71910053SEvan.Yan@Sun.COM case DDI_INTROP_SETTARGET: 72010053SEvan.Yan@Sun.COM ret = px_ib_set_msix_target(px_p, hdlp, msi_num, 72110053SEvan.Yan@Sun.COM *(cpuid_t *)result); 72210053SEvan.Yan@Sun.COM break; 72310053SEvan.Yan@Sun.COM case DDI_INTROP_ENABLE: 72410053SEvan.Yan@Sun.COM /* 72510115SGovinda.Tatti@Sun.COM * For MSI, just clear the mask bit and return if curr_nenables 72610115SGovinda.Tatti@Sun.COM * is > 1. For MSI-X, program MSI address and data for every 72710115SGovinda.Tatti@Sun.COM * MSI-X vector including dup vectors irrespective of current 72810115SGovinda.Tatti@Sun.COM * curr_nenables value. 72910053SEvan.Yan@Sun.COM */ 73010115SGovinda.Tatti@Sun.COM if ((pci_is_msi_enabled(rdip, hdlp->ih_type) != DDI_SUCCESS) || 73110115SGovinda.Tatti@Sun.COM (hdlp->ih_type == DDI_INTR_TYPE_MSIX)) { 73210115SGovinda.Tatti@Sun.COM nintrs = i_ddi_intr_get_current_nintrs(hdlp->ih_dip); 7330Sstevel@tonic-gate 73410115SGovinda.Tatti@Sun.COM if ((ret = pci_msi_configure(rdip, hdlp->ih_type, 73510115SGovinda.Tatti@Sun.COM nintrs, hdlp->ih_inum, msi_addr, 73610115SGovinda.Tatti@Sun.COM hdlp->ih_type == DDI_INTR_TYPE_MSIX ? 73710115SGovinda.Tatti@Sun.COM msi_num : msi_num & ~(nintrs - 1))) != DDI_SUCCESS) 73810115SGovinda.Tatti@Sun.COM return (ret); 7390Sstevel@tonic-gate 74010115SGovinda.Tatti@Sun.COM if (i_ddi_intr_get_current_nenables(rdip) < 1) { 74110115SGovinda.Tatti@Sun.COM if ((ret = pci_msi_enable_mode(rdip, 74210115SGovinda.Tatti@Sun.COM hdlp->ih_type)) != DDI_SUCCESS) 74310115SGovinda.Tatti@Sun.COM return (ret); 74410115SGovinda.Tatti@Sun.COM } 74510115SGovinda.Tatti@Sun.COM } 7460Sstevel@tonic-gate 747909Segillett if ((ret = pci_msi_clr_mask(rdip, hdlp->ih_type, 748909Segillett hdlp->ih_inum)) != DDI_SUCCESS) 749909Segillett return (ret); 750909Segillett 7510Sstevel@tonic-gate break; 7520Sstevel@tonic-gate case DDI_INTROP_DISABLE: 7530Sstevel@tonic-gate if ((ret = pci_msi_set_mask(rdip, hdlp->ih_type, 7540Sstevel@tonic-gate hdlp->ih_inum)) != DDI_SUCCESS) 7550Sstevel@tonic-gate return (ret); 7560Sstevel@tonic-gate 75710053SEvan.Yan@Sun.COM /* 75810053SEvan.Yan@Sun.COM * curr_nenables will be greater than 1 if rdip is using 75910053SEvan.Yan@Sun.COM * MSI-X and also, if it is using DUP interface. If this 76010053SEvan.Yan@Sun.COM * curr_enables is > 1, return after setting the mask bit. 76110053SEvan.Yan@Sun.COM */ 76210053SEvan.Yan@Sun.COM if (i_ddi_intr_get_current_nenables(rdip) > 1) 76310053SEvan.Yan@Sun.COM return (DDI_SUCCESS); 7641725Segillett 76510053SEvan.Yan@Sun.COM if ((ret = pci_msi_disable_mode(rdip, hdlp->ih_type)) 76610053SEvan.Yan@Sun.COM != DDI_SUCCESS) 767909Segillett return (ret); 768909Segillett 7690Sstevel@tonic-gate break; 7700Sstevel@tonic-gate case DDI_INTROP_BLOCKENABLE: 7710Sstevel@tonic-gate nintrs = i_ddi_intr_get_current_nintrs(hdlp->ih_dip); 7720Sstevel@tonic-gate 7730Sstevel@tonic-gate if ((ret = pci_msi_configure(rdip, hdlp->ih_type, 774965Sgovinda nintrs, hdlp->ih_inum, msi_addr, 7750Sstevel@tonic-gate msi_num & ~(nintrs - 1))) != DDI_SUCCESS) 7760Sstevel@tonic-gate return (ret); 7770Sstevel@tonic-gate 7782755Segillett ret = pci_msi_enable_mode(rdip, hdlp->ih_type); 7790Sstevel@tonic-gate break; 7800Sstevel@tonic-gate case DDI_INTROP_BLOCKDISABLE: 78110053SEvan.Yan@Sun.COM ret = pci_msi_disable_mode(rdip, hdlp->ih_type); 7820Sstevel@tonic-gate break; 7830Sstevel@tonic-gate case DDI_INTROP_SETMASK: 7840Sstevel@tonic-gate ret = pci_msi_set_mask(rdip, hdlp->ih_type, hdlp->ih_inum); 7850Sstevel@tonic-gate break; 7860Sstevel@tonic-gate case DDI_INTROP_CLRMASK: 7870Sstevel@tonic-gate ret = pci_msi_clr_mask(rdip, hdlp->ih_type, hdlp->ih_inum); 7880Sstevel@tonic-gate break; 7890Sstevel@tonic-gate case DDI_INTROP_GETPENDING: 7900Sstevel@tonic-gate ret = pci_msi_get_pending(rdip, hdlp->ih_type, 7910Sstevel@tonic-gate hdlp->ih_inum, (int *)result); 7920Sstevel@tonic-gate break; 7930Sstevel@tonic-gate case DDI_INTROP_NINTRS: 7940Sstevel@tonic-gate ret = pci_msi_get_nintrs(rdip, hdlp->ih_type, (int *)result); 7950Sstevel@tonic-gate break; 7960Sstevel@tonic-gate case DDI_INTROP_NAVAIL: 7970Sstevel@tonic-gate /* XXX - a new interface may be needed */ 7980Sstevel@tonic-gate ret = pci_msi_get_nintrs(rdip, hdlp->ih_type, (int *)result); 7990Sstevel@tonic-gate break; 8008561SScott.Carter@Sun.COM case DDI_INTROP_GETPOOL: 8018561SScott.Carter@Sun.COM if (msi_state_p->msi_pool_p == NULL) { 8028561SScott.Carter@Sun.COM *(ddi_irm_pool_t **)result = NULL; 8038561SScott.Carter@Sun.COM return (DDI_ENOTSUP); 8048561SScott.Carter@Sun.COM } 8058561SScott.Carter@Sun.COM *(ddi_irm_pool_t **)result = msi_state_p->msi_pool_p; 8068561SScott.Carter@Sun.COM ret = DDI_SUCCESS; 8078561SScott.Carter@Sun.COM break; 8080Sstevel@tonic-gate default: 8090Sstevel@tonic-gate ret = DDI_ENOTSUP; 8100Sstevel@tonic-gate break; 8110Sstevel@tonic-gate } 8120Sstevel@tonic-gate 8130Sstevel@tonic-gate return (ret); 8140Sstevel@tonic-gate } 8150Sstevel@tonic-gate 81666Sesolom static struct { 81766Sesolom kstat_named_t pxintr_ks_name; 81866Sesolom kstat_named_t pxintr_ks_type; 81966Sesolom kstat_named_t pxintr_ks_cpu; 82066Sesolom kstat_named_t pxintr_ks_pil; 82166Sesolom kstat_named_t pxintr_ks_time; 82266Sesolom kstat_named_t pxintr_ks_ino; 82366Sesolom kstat_named_t pxintr_ks_cookie; 82466Sesolom kstat_named_t pxintr_ks_devpath; 82566Sesolom kstat_named_t pxintr_ks_buspath; 82666Sesolom } pxintr_ks_template = { 82766Sesolom { "name", KSTAT_DATA_CHAR }, 82866Sesolom { "type", KSTAT_DATA_CHAR }, 82966Sesolom { "cpu", KSTAT_DATA_UINT64 }, 83066Sesolom { "pil", KSTAT_DATA_UINT64 }, 83166Sesolom { "time", KSTAT_DATA_UINT64 }, 83266Sesolom { "ino", KSTAT_DATA_UINT64 }, 83366Sesolom { "cookie", KSTAT_DATA_UINT64 }, 83466Sesolom { "devpath", KSTAT_DATA_STRING }, 83566Sesolom { "buspath", KSTAT_DATA_STRING }, 83666Sesolom }; 83766Sesolom 83866Sesolom static uint32_t pxintr_ks_instance; 8391811Sesolom static char ih_devpath[MAXPATHLEN]; 8401811Sesolom static char ih_buspath[MAXPATHLEN]; 84166Sesolom kmutex_t pxintr_ks_template_lock; 84266Sesolom 84366Sesolom int 84466Sesolom px_ks_update(kstat_t *ksp, int rw) 84566Sesolom { 84666Sesolom px_ih_t *ih_p = ksp->ks_private; 84766Sesolom int maxlen = sizeof (pxintr_ks_template.pxintr_ks_name.value.c); 8482973Sgovinda px_ino_pil_t *ipil_p = ih_p->ih_ipil_p; 8492973Sgovinda px_ino_t *ino_p = ipil_p->ipil_ino_p; 8502973Sgovinda px_t *px_p = ino_p->ino_ib_p->ib_px_p; 85166Sesolom devino_t ino; 85266Sesolom sysino_t sysino; 85366Sesolom 8542973Sgovinda ino = ino_p->ino_ino; 8557124Sanbui if (px_lib_intr_devino_to_sysino(px_p->px_dip, ino, &sysino) != 8567124Sanbui DDI_SUCCESS) { 8577124Sanbui cmn_err(CE_WARN, "px_ks_update: px_lib_intr_devino_to_sysino " 8587124Sanbui "failed"); 8597124Sanbui } 86066Sesolom 86166Sesolom (void) snprintf(pxintr_ks_template.pxintr_ks_name.value.c, maxlen, 86266Sesolom "%s%d", ddi_driver_name(ih_p->ih_dip), 86366Sesolom ddi_get_instance(ih_p->ih_dip)); 86466Sesolom 86566Sesolom (void) ddi_pathname(ih_p->ih_dip, ih_devpath); 86666Sesolom (void) ddi_pathname(px_p->px_dip, ih_buspath); 86766Sesolom kstat_named_setstr(&pxintr_ks_template.pxintr_ks_devpath, ih_devpath); 86866Sesolom kstat_named_setstr(&pxintr_ks_template.pxintr_ks_buspath, ih_buspath); 86966Sesolom 8701087Sschwartz if (ih_p->ih_intr_state == PX_INTR_STATE_ENABLE) { 8711087Sschwartz 8724397Sschwartz switch (i_ddi_intr_get_current_type(ih_p->ih_dip)) { 8734397Sschwartz case DDI_INTR_TYPE_MSI: 8744397Sschwartz (void) strcpy(pxintr_ks_template.pxintr_ks_type.value.c, 8754397Sschwartz "msi"); 8764397Sschwartz break; 8774397Sschwartz case DDI_INTR_TYPE_MSIX: 8784397Sschwartz (void) strcpy(pxintr_ks_template.pxintr_ks_type.value.c, 8794397Sschwartz "msix"); 8804397Sschwartz break; 8814397Sschwartz default: 8824397Sschwartz (void) strcpy(pxintr_ks_template.pxintr_ks_type.value.c, 8834397Sschwartz "fixed"); 8844397Sschwartz break; 8854397Sschwartz } 8864397Sschwartz 8872973Sgovinda pxintr_ks_template.pxintr_ks_cpu.value.ui64 = ino_p->ino_cpuid; 8882973Sgovinda pxintr_ks_template.pxintr_ks_pil.value.ui64 = ipil_p->ipil_pil; 8891087Sschwartz pxintr_ks_template.pxintr_ks_time.value.ui64 = ih_p->ih_nsec + 8901087Sschwartz (uint64_t)tick2ns((hrtime_t)ih_p->ih_ticks, 8912973Sgovinda ino_p->ino_cpuid); 8921087Sschwartz pxintr_ks_template.pxintr_ks_ino.value.ui64 = ino; 8931087Sschwartz pxintr_ks_template.pxintr_ks_cookie.value.ui64 = sysino; 8941087Sschwartz } else { 8951087Sschwartz (void) strcpy(pxintr_ks_template.pxintr_ks_type.value.c, 8961087Sschwartz "disabled"); 8971087Sschwartz pxintr_ks_template.pxintr_ks_cpu.value.ui64 = 0; 8981087Sschwartz pxintr_ks_template.pxintr_ks_pil.value.ui64 = 0; 8991087Sschwartz pxintr_ks_template.pxintr_ks_time.value.ui64 = 0; 9001087Sschwartz pxintr_ks_template.pxintr_ks_ino.value.ui64 = 0; 9011087Sschwartz pxintr_ks_template.pxintr_ks_cookie.value.ui64 = 0; 9021087Sschwartz } 90366Sesolom return (0); 90466Sesolom } 90566Sesolom 90666Sesolom void 90766Sesolom px_create_intr_kstats(px_ih_t *ih_p) 90866Sesolom { 90966Sesolom msiq_rec_type_t rec_type = ih_p->ih_rec_type; 91066Sesolom 91166Sesolom ASSERT(ih_p->ih_ksp == NULL); 91266Sesolom 91366Sesolom /* 91466Sesolom * Create pci_intrs::: kstats for all ih types except messages, 91566Sesolom * which represent unusual conditions and don't need to be tracked. 91666Sesolom */ 91766Sesolom if (rec_type == 0 || rec_type == MSI32_REC || rec_type == MSI64_REC) { 91866Sesolom ih_p->ih_ksp = kstat_create("pci_intrs", 91966Sesolom atomic_inc_32_nv(&pxintr_ks_instance), "config", 92066Sesolom "interrupts", KSTAT_TYPE_NAMED, 92166Sesolom sizeof (pxintr_ks_template) / sizeof (kstat_named_t), 92266Sesolom KSTAT_FLAG_VIRTUAL); 92366Sesolom } 92466Sesolom if (ih_p->ih_ksp != NULL) { 92566Sesolom ih_p->ih_ksp->ks_data_size += MAXPATHLEN * 2; 92666Sesolom ih_p->ih_ksp->ks_lock = &pxintr_ks_template_lock; 92766Sesolom ih_p->ih_ksp->ks_data = &pxintr_ks_template; 92866Sesolom ih_p->ih_ksp->ks_private = ih_p; 92966Sesolom ih_p->ih_ksp->ks_update = px_ks_update; 93066Sesolom } 93166Sesolom } 93266Sesolom 933693Sgovinda /* 934693Sgovinda * px_add_intx_intr: 935693Sgovinda * 936693Sgovinda * This function is called to register INTx and legacy hardware 937693Sgovinda * interrupt pins interrupts. 938693Sgovinda */ 9390Sstevel@tonic-gate int 9400Sstevel@tonic-gate px_add_intx_intr(dev_info_t *dip, dev_info_t *rdip, 9410Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp) 9420Sstevel@tonic-gate { 9430Sstevel@tonic-gate px_t *px_p = INST_TO_STATE(ddi_get_instance(dip)); 9440Sstevel@tonic-gate px_ib_t *ib_p = px_p->px_ib_p; 9450Sstevel@tonic-gate devino_t ino; 9460Sstevel@tonic-gate px_ih_t *ih_p; 9472973Sgovinda px_ino_t *ino_p; 9482973Sgovinda px_ino_pil_t *ipil_p, *ipil_list; 9490Sstevel@tonic-gate int32_t weight; 9500Sstevel@tonic-gate int ret = DDI_SUCCESS; 9510Sstevel@tonic-gate 9520Sstevel@tonic-gate ino = hdlp->ih_vector; 9530Sstevel@tonic-gate 9540Sstevel@tonic-gate DBG(DBG_A_INTX, dip, "px_add_intx_intr: rdip=%s%d ino=%x " 9550Sstevel@tonic-gate "handler=%x arg1=%x arg2=%x\n", ddi_driver_name(rdip), 9560Sstevel@tonic-gate ddi_get_instance(rdip), ino, hdlp->ih_cb_func, 9570Sstevel@tonic-gate hdlp->ih_cb_arg1, hdlp->ih_cb_arg2); 9580Sstevel@tonic-gate 9590Sstevel@tonic-gate ih_p = px_ib_alloc_ih(rdip, hdlp->ih_inum, 9600Sstevel@tonic-gate hdlp->ih_cb_func, hdlp->ih_cb_arg1, hdlp->ih_cb_arg2, 0, 0); 9610Sstevel@tonic-gate 9620Sstevel@tonic-gate mutex_enter(&ib_p->ib_ino_lst_mutex); 9630Sstevel@tonic-gate 9642973Sgovinda ino_p = px_ib_locate_ino(ib_p, ino); 9652973Sgovinda ipil_list = ino_p ? ino_p->ino_ipil_p : NULL; 9662973Sgovinda 9672973Sgovinda /* Sharing ino */ 9682973Sgovinda if (ino_p && (ipil_p = px_ib_ino_locate_ipil(ino_p, hdlp->ih_pri))) { 9692973Sgovinda if (px_ib_intr_locate_ih(ipil_p, rdip, hdlp->ih_inum, 0, 0)) { 9700Sstevel@tonic-gate DBG(DBG_A_INTX, dip, "px_add_intx_intr: " 9712973Sgovinda "dup intr #%d\n", hdlp->ih_inum); 9720Sstevel@tonic-gate 9730Sstevel@tonic-gate ret = DDI_FAILURE; 9740Sstevel@tonic-gate goto fail1; 9750Sstevel@tonic-gate } 9760Sstevel@tonic-gate 9770Sstevel@tonic-gate /* Save mondo value in hdlp */ 9780Sstevel@tonic-gate hdlp->ih_vector = ino_p->ino_sysino; 9790Sstevel@tonic-gate 9802973Sgovinda if ((ret = px_ib_ino_add_intr(px_p, ipil_p, 9812973Sgovinda ih_p)) != DDI_SUCCESS) 9820Sstevel@tonic-gate goto fail1; 9832973Sgovinda 9842973Sgovinda goto ino_done; 9852973Sgovinda } 9860Sstevel@tonic-gate 9872973Sgovinda if (hdlp->ih_pri == 0) 9888535Sevan.yan@sun.com hdlp->ih_pri = pci_class_to_pil(rdip); 9892973Sgovinda 9902973Sgovinda ipil_p = px_ib_new_ino_pil(ib_p, ino, hdlp->ih_pri, ih_p); 9912973Sgovinda ino_p = ipil_p->ipil_ino_p; 9920Sstevel@tonic-gate 9932973Sgovinda /* Save mondo value in hdlp */ 9942973Sgovinda hdlp->ih_vector = ino_p->ino_sysino; 9950Sstevel@tonic-gate 9962973Sgovinda DBG(DBG_A_INTX, dip, "px_add_intx_intr: pil=0x%x mondo=0x%x\n", 9972973Sgovinda hdlp->ih_pri, hdlp->ih_vector); 9980Sstevel@tonic-gate 9992973Sgovinda DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp, 10002973Sgovinda (ddi_intr_handler_t *)px_intx_intr, (caddr_t)ipil_p, NULL); 10010Sstevel@tonic-gate 10022973Sgovinda ret = i_ddi_add_ivintr(hdlp); 10030Sstevel@tonic-gate 10042973Sgovinda /* 10052973Sgovinda * Restore original interrupt handler 10062973Sgovinda * and arguments in interrupt handle. 10072973Sgovinda */ 10082973Sgovinda DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp, ih_p->ih_handler, 10092973Sgovinda ih_p->ih_handler_arg1, ih_p->ih_handler_arg2); 10100Sstevel@tonic-gate 10112973Sgovinda if (ret != DDI_SUCCESS) 10122973Sgovinda goto fail2; 10130Sstevel@tonic-gate 10142973Sgovinda /* Save the pil for this ino */ 10152973Sgovinda ipil_p->ipil_pil = hdlp->ih_pri; 10160Sstevel@tonic-gate 10172973Sgovinda /* Select cpu, saving it for sharing and removal */ 10182973Sgovinda if (ipil_list == NULL) { 101910053SEvan.Yan@Sun.COM if (ino_p->ino_cpuid == -1) 102010053SEvan.Yan@Sun.COM ino_p->ino_cpuid = intr_dist_cpuid(); 10210Sstevel@tonic-gate 10220Sstevel@tonic-gate /* Enable interrupt */ 10230Sstevel@tonic-gate px_ib_intr_enable(px_p, ino_p->ino_cpuid, ino); 10240Sstevel@tonic-gate } 10250Sstevel@tonic-gate 10262973Sgovinda ino_done: 102710053SEvan.Yan@Sun.COM hdlp->ih_target = ino_p->ino_cpuid; 102810053SEvan.Yan@Sun.COM 10292973Sgovinda /* Add weight to the cpu that we are already targeting */ 10308535Sevan.yan@sun.com weight = pci_class_to_intr_weight(rdip); 10310Sstevel@tonic-gate intr_dist_cpuid_add_device_weight(ino_p->ino_cpuid, rdip, weight); 10320Sstevel@tonic-gate 10332973Sgovinda ih_p->ih_ipil_p = ipil_p; 103466Sesolom px_create_intr_kstats(ih_p); 10350Sstevel@tonic-gate if (ih_p->ih_ksp) 10360Sstevel@tonic-gate kstat_install(ih_p->ih_ksp); 10370Sstevel@tonic-gate mutex_exit(&ib_p->ib_ino_lst_mutex); 10380Sstevel@tonic-gate 10390Sstevel@tonic-gate DBG(DBG_A_INTX, dip, "px_add_intx_intr: done! Interrupt 0x%x pil=%x\n", 10400Sstevel@tonic-gate ino_p->ino_sysino, hdlp->ih_pri); 10410Sstevel@tonic-gate 10420Sstevel@tonic-gate return (ret); 10430Sstevel@tonic-gate fail2: 10442973Sgovinda px_ib_delete_ino_pil(ib_p, ipil_p); 10450Sstevel@tonic-gate fail1: 10460Sstevel@tonic-gate if (ih_p->ih_config_handle) 10470Sstevel@tonic-gate pci_config_teardown(&ih_p->ih_config_handle); 10480Sstevel@tonic-gate 10490Sstevel@tonic-gate mutex_exit(&ib_p->ib_ino_lst_mutex); 10500Sstevel@tonic-gate kmem_free(ih_p, sizeof (px_ih_t)); 10510Sstevel@tonic-gate 10520Sstevel@tonic-gate DBG(DBG_A_INTX, dip, "px_add_intx_intr: Failed! Interrupt 0x%x " 10530Sstevel@tonic-gate "pil=%x\n", ino_p->ino_sysino, hdlp->ih_pri); 10540Sstevel@tonic-gate 10550Sstevel@tonic-gate return (ret); 10560Sstevel@tonic-gate } 10570Sstevel@tonic-gate 1058693Sgovinda /* 1059693Sgovinda * px_rem_intx_intr: 1060693Sgovinda * 1061693Sgovinda * This function is called to unregister INTx and legacy hardware 1062693Sgovinda * interrupt pins interrupts. 1063693Sgovinda */ 10640Sstevel@tonic-gate int 10650Sstevel@tonic-gate px_rem_intx_intr(dev_info_t *dip, dev_info_t *rdip, 10660Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp) 10670Sstevel@tonic-gate { 10680Sstevel@tonic-gate px_t *px_p = INST_TO_STATE(ddi_get_instance(dip)); 10690Sstevel@tonic-gate px_ib_t *ib_p = px_p->px_ib_p; 10700Sstevel@tonic-gate devino_t ino; 10710Sstevel@tonic-gate cpuid_t curr_cpu; 10722973Sgovinda px_ino_t *ino_p; 10732973Sgovinda px_ino_pil_t *ipil_p; 10740Sstevel@tonic-gate px_ih_t *ih_p; 10750Sstevel@tonic-gate int ret = DDI_SUCCESS; 10760Sstevel@tonic-gate 10770Sstevel@tonic-gate ino = hdlp->ih_vector; 10780Sstevel@tonic-gate 10790Sstevel@tonic-gate DBG(DBG_R_INTX, dip, "px_rem_intx_intr: rdip=%s%d ino=%x\n", 10800Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip), ino); 10810Sstevel@tonic-gate 10820Sstevel@tonic-gate mutex_enter(&ib_p->ib_ino_lst_mutex); 10830Sstevel@tonic-gate 10840Sstevel@tonic-gate ino_p = px_ib_locate_ino(ib_p, ino); 10852973Sgovinda ipil_p = px_ib_ino_locate_ipil(ino_p, hdlp->ih_pri); 10862973Sgovinda ih_p = px_ib_intr_locate_ih(ipil_p, rdip, hdlp->ih_inum, 0, 0); 10870Sstevel@tonic-gate 10880Sstevel@tonic-gate /* Get the current cpu */ 10890Sstevel@tonic-gate if ((ret = px_lib_intr_gettarget(px_p->px_dip, ino_p->ino_sysino, 10900Sstevel@tonic-gate &curr_cpu)) != DDI_SUCCESS) 10910Sstevel@tonic-gate goto fail; 10920Sstevel@tonic-gate 10932973Sgovinda if ((ret = px_ib_ino_rem_intr(px_p, ipil_p, ih_p)) != DDI_SUCCESS) 10940Sstevel@tonic-gate goto fail; 10950Sstevel@tonic-gate 10960Sstevel@tonic-gate intr_dist_cpuid_rem_device_weight(ino_p->ino_cpuid, rdip); 10970Sstevel@tonic-gate 10982973Sgovinda if (ipil_p->ipil_ih_size == 0) { 10990Sstevel@tonic-gate hdlp->ih_vector = ino_p->ino_sysino; 11000Sstevel@tonic-gate i_ddi_rem_ivintr(hdlp); 11010Sstevel@tonic-gate 11022973Sgovinda px_ib_delete_ino_pil(ib_p, ipil_p); 11032973Sgovinda } 11042973Sgovinda 11052973Sgovinda if (ino_p->ino_ipil_size == 0) { 11062973Sgovinda kmem_free(ino_p, sizeof (px_ino_t)); 11070Sstevel@tonic-gate } else { 11083780Segillett /* Re-enable interrupt only if mapping register still shared */ 11093780Segillett PX_INTR_ENABLE(px_p->px_dip, ino_p->ino_sysino, curr_cpu); 11100Sstevel@tonic-gate } 11110Sstevel@tonic-gate 11120Sstevel@tonic-gate fail: 11130Sstevel@tonic-gate mutex_exit(&ib_p->ib_ino_lst_mutex); 11140Sstevel@tonic-gate return (ret); 11150Sstevel@tonic-gate } 11160Sstevel@tonic-gate 1117693Sgovinda /* 1118693Sgovinda * px_add_msiq_intr: 1119693Sgovinda * 1120693Sgovinda * This function is called to register MSI/Xs and PCIe message interrupts. 1121693Sgovinda */ 11220Sstevel@tonic-gate int 11230Sstevel@tonic-gate px_add_msiq_intr(dev_info_t *dip, dev_info_t *rdip, 11240Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, msiq_rec_type_t rec_type, 112510053SEvan.Yan@Sun.COM msgcode_t msg_code, cpuid_t cpu_id, msiqid_t *msiq_id_p) 11260Sstevel@tonic-gate { 11270Sstevel@tonic-gate px_t *px_p = INST_TO_STATE(ddi_get_instance(dip)); 11280Sstevel@tonic-gate px_ib_t *ib_p = px_p->px_ib_p; 11290Sstevel@tonic-gate px_msiq_state_t *msiq_state_p = &ib_p->ib_msiq_state; 11300Sstevel@tonic-gate devino_t ino; 11310Sstevel@tonic-gate px_ih_t *ih_p; 11322973Sgovinda px_ino_t *ino_p; 11332973Sgovinda px_ino_pil_t *ipil_p, *ipil_list; 11340Sstevel@tonic-gate int32_t weight; 11350Sstevel@tonic-gate int ret = DDI_SUCCESS; 11360Sstevel@tonic-gate 113710053SEvan.Yan@Sun.COM DBG(DBG_MSIQ, dip, "px_add_msiq_intr: rdip=%s%d handler=0x%x " 113810053SEvan.Yan@Sun.COM "arg1=0x%x arg2=0x%x cpu=0x%x\n", ddi_driver_name(rdip), 113910053SEvan.Yan@Sun.COM ddi_get_instance(rdip), hdlp->ih_cb_func, hdlp->ih_cb_arg1, 114010053SEvan.Yan@Sun.COM hdlp->ih_cb_arg2, cpu_id); 11410Sstevel@tonic-gate 11420Sstevel@tonic-gate ih_p = px_ib_alloc_ih(rdip, hdlp->ih_inum, hdlp->ih_cb_func, 11430Sstevel@tonic-gate hdlp->ih_cb_arg1, hdlp->ih_cb_arg2, rec_type, msg_code); 11440Sstevel@tonic-gate 11450Sstevel@tonic-gate mutex_enter(&ib_p->ib_ino_lst_mutex); 11460Sstevel@tonic-gate 114710053SEvan.Yan@Sun.COM ret = (cpu_id == -1) ? px_msiq_alloc(px_p, rec_type, msiq_id_p) : 114810053SEvan.Yan@Sun.COM px_msiq_alloc_based_on_cpuid(px_p, rec_type, cpu_id, msiq_id_p); 114910053SEvan.Yan@Sun.COM 115010053SEvan.Yan@Sun.COM if (ret != DDI_SUCCESS) { 115110053SEvan.Yan@Sun.COM DBG(DBG_MSIQ, dip, "px_add_msiq_intr: " 115210053SEvan.Yan@Sun.COM "msiq allocation failed\n"); 115310053SEvan.Yan@Sun.COM goto fail; 115410053SEvan.Yan@Sun.COM } 115510053SEvan.Yan@Sun.COM 115610053SEvan.Yan@Sun.COM ino = px_msiqid_to_devino(px_p, *msiq_id_p); 115710053SEvan.Yan@Sun.COM 11582973Sgovinda ino_p = px_ib_locate_ino(ib_p, ino); 11592973Sgovinda ipil_list = ino_p ? ino_p->ino_ipil_p : NULL; 11602973Sgovinda 11612973Sgovinda /* Sharing ino */ 11622973Sgovinda if (ino_p && (ipil_p = px_ib_ino_locate_ipil(ino_p, hdlp->ih_pri))) { 11632973Sgovinda if (px_ib_intr_locate_ih(ipil_p, rdip, 11642973Sgovinda hdlp->ih_inum, rec_type, msg_code)) { 11650Sstevel@tonic-gate DBG(DBG_MSIQ, dip, "px_add_msiq_intr: " 11662973Sgovinda "dup intr #%d\n", hdlp->ih_inum); 11670Sstevel@tonic-gate 11680Sstevel@tonic-gate ret = DDI_FAILURE; 11690Sstevel@tonic-gate goto fail1; 11700Sstevel@tonic-gate } 11710Sstevel@tonic-gate 11720Sstevel@tonic-gate /* Save mondo value in hdlp */ 11730Sstevel@tonic-gate hdlp->ih_vector = ino_p->ino_sysino; 11740Sstevel@tonic-gate 11752973Sgovinda if ((ret = px_ib_ino_add_intr(px_p, ipil_p, 11762973Sgovinda ih_p)) != DDI_SUCCESS) 11772973Sgovinda goto fail1; 11782973Sgovinda 11792973Sgovinda goto ino_done; 11802973Sgovinda } 11812973Sgovinda 11822973Sgovinda if (hdlp->ih_pri == 0) 11838535Sevan.yan@sun.com hdlp->ih_pri = pci_class_to_pil(rdip); 11840Sstevel@tonic-gate 11852973Sgovinda ipil_p = px_ib_new_ino_pil(ib_p, ino, hdlp->ih_pri, ih_p); 11862973Sgovinda ino_p = ipil_p->ipil_ino_p; 11872973Sgovinda 11882973Sgovinda ino_p->ino_msiq_p = msiq_state_p->msiq_p + 11892973Sgovinda (*msiq_id_p - msiq_state_p->msiq_1st_msiq_id); 11900Sstevel@tonic-gate 11912973Sgovinda /* Save mondo value in hdlp */ 11922973Sgovinda hdlp->ih_vector = ino_p->ino_sysino; 11932973Sgovinda 11942973Sgovinda DBG(DBG_MSIQ, dip, "px_add_msiq_intr: pil=0x%x mondo=0x%x\n", 11952973Sgovinda hdlp->ih_pri, hdlp->ih_vector); 11960Sstevel@tonic-gate 11972973Sgovinda DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp, 11982973Sgovinda (ddi_intr_handler_t *)px_msiq_intr, (caddr_t)ipil_p, NULL); 11992973Sgovinda 12002973Sgovinda ret = i_ddi_add_ivintr(hdlp); 12010Sstevel@tonic-gate 12022973Sgovinda /* 12032973Sgovinda * Restore original interrupt handler 12042973Sgovinda * and arguments in interrupt handle. 12052973Sgovinda */ 12062973Sgovinda DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp, ih_p->ih_handler, 12072973Sgovinda ih_p->ih_handler_arg1, ih_p->ih_handler_arg2); 12080Sstevel@tonic-gate 12092973Sgovinda if (ret != DDI_SUCCESS) 12102973Sgovinda goto fail2; 12112973Sgovinda 12122973Sgovinda /* Save the pil for this ino */ 12132973Sgovinda ipil_p->ipil_pil = hdlp->ih_pri; 12142973Sgovinda 12152973Sgovinda /* Select cpu, saving it for sharing and removal */ 12162973Sgovinda if (ipil_list == NULL) { 12170Sstevel@tonic-gate /* Enable MSIQ */ 12180Sstevel@tonic-gate px_lib_msiq_setstate(dip, *msiq_id_p, PCI_MSIQ_STATE_IDLE); 12190Sstevel@tonic-gate px_lib_msiq_setvalid(dip, *msiq_id_p, PCI_MSIQ_VALID); 12200Sstevel@tonic-gate 122110053SEvan.Yan@Sun.COM if (ino_p->ino_cpuid == -1) 122210053SEvan.Yan@Sun.COM ino_p->ino_cpuid = intr_dist_cpuid(); 122310053SEvan.Yan@Sun.COM 12240Sstevel@tonic-gate /* Enable interrupt */ 12252973Sgovinda px_ib_intr_enable(px_p, ino_p->ino_cpuid, ino); 12260Sstevel@tonic-gate } 12270Sstevel@tonic-gate 12282973Sgovinda ino_done: 122910053SEvan.Yan@Sun.COM hdlp->ih_target = ino_p->ino_cpuid; 123010053SEvan.Yan@Sun.COM 12312973Sgovinda /* Add weight to the cpu that we are already targeting */ 12328535Sevan.yan@sun.com weight = pci_class_to_intr_weight(rdip); 12330Sstevel@tonic-gate intr_dist_cpuid_add_device_weight(ino_p->ino_cpuid, rdip, weight); 12340Sstevel@tonic-gate 12352973Sgovinda ih_p->ih_ipil_p = ipil_p; 123666Sesolom px_create_intr_kstats(ih_p); 12370Sstevel@tonic-gate if (ih_p->ih_ksp) 12380Sstevel@tonic-gate kstat_install(ih_p->ih_ksp); 12390Sstevel@tonic-gate mutex_exit(&ib_p->ib_ino_lst_mutex); 12400Sstevel@tonic-gate 12410Sstevel@tonic-gate DBG(DBG_MSIQ, dip, "px_add_msiq_intr: done! Interrupt 0x%x pil=%x\n", 12420Sstevel@tonic-gate ino_p->ino_sysino, hdlp->ih_pri); 12430Sstevel@tonic-gate 12440Sstevel@tonic-gate return (ret); 12450Sstevel@tonic-gate fail2: 12462973Sgovinda px_ib_delete_ino_pil(ib_p, ipil_p); 12470Sstevel@tonic-gate fail1: 124810053SEvan.Yan@Sun.COM (void) px_msiq_free(px_p, *msiq_id_p); 124910053SEvan.Yan@Sun.COM fail: 12500Sstevel@tonic-gate if (ih_p->ih_config_handle) 12510Sstevel@tonic-gate pci_config_teardown(&ih_p->ih_config_handle); 12520Sstevel@tonic-gate 12530Sstevel@tonic-gate mutex_exit(&ib_p->ib_ino_lst_mutex); 12540Sstevel@tonic-gate kmem_free(ih_p, sizeof (px_ih_t)); 12550Sstevel@tonic-gate 12560Sstevel@tonic-gate DBG(DBG_MSIQ, dip, "px_add_msiq_intr: Failed! Interrupt 0x%x pil=%x\n", 12570Sstevel@tonic-gate ino_p->ino_sysino, hdlp->ih_pri); 12580Sstevel@tonic-gate 12590Sstevel@tonic-gate return (ret); 12600Sstevel@tonic-gate } 12610Sstevel@tonic-gate 1262693Sgovinda /* 1263693Sgovinda * px_rem_msiq_intr: 1264693Sgovinda * 1265693Sgovinda * This function is called to unregister MSI/Xs and PCIe message interrupts. 1266693Sgovinda */ 12670Sstevel@tonic-gate int 12680Sstevel@tonic-gate px_rem_msiq_intr(dev_info_t *dip, dev_info_t *rdip, 12690Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, msiq_rec_type_t rec_type, 12700Sstevel@tonic-gate msgcode_t msg_code, msiqid_t msiq_id) 12710Sstevel@tonic-gate { 12720Sstevel@tonic-gate px_t *px_p = INST_TO_STATE(ddi_get_instance(dip)); 12730Sstevel@tonic-gate px_ib_t *ib_p = px_p->px_ib_p; 12740Sstevel@tonic-gate devino_t ino = px_msiqid_to_devino(px_p, msiq_id); 12750Sstevel@tonic-gate cpuid_t curr_cpu; 12762973Sgovinda px_ino_t *ino_p; 12772973Sgovinda px_ino_pil_t *ipil_p; 12780Sstevel@tonic-gate px_ih_t *ih_p; 12790Sstevel@tonic-gate int ret = DDI_SUCCESS; 12800Sstevel@tonic-gate 12810Sstevel@tonic-gate DBG(DBG_MSIQ, dip, "px_rem_msiq_intr: rdip=%s%d msiq_id=%x ino=%x\n", 12820Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip), msiq_id, ino); 12830Sstevel@tonic-gate 12840Sstevel@tonic-gate mutex_enter(&ib_p->ib_ino_lst_mutex); 12850Sstevel@tonic-gate 12860Sstevel@tonic-gate ino_p = px_ib_locate_ino(ib_p, ino); 12872973Sgovinda ipil_p = px_ib_ino_locate_ipil(ino_p, hdlp->ih_pri); 12882973Sgovinda ih_p = px_ib_intr_locate_ih(ipil_p, rdip, hdlp->ih_inum, rec_type, 12892973Sgovinda msg_code); 12900Sstevel@tonic-gate 12910Sstevel@tonic-gate /* Get the current cpu */ 12920Sstevel@tonic-gate if ((ret = px_lib_intr_gettarget(px_p->px_dip, ino_p->ino_sysino, 12930Sstevel@tonic-gate &curr_cpu)) != DDI_SUCCESS) 12940Sstevel@tonic-gate goto fail; 12950Sstevel@tonic-gate 12962973Sgovinda if ((ret = px_ib_ino_rem_intr(px_p, ipil_p, ih_p)) != DDI_SUCCESS) 12970Sstevel@tonic-gate goto fail; 12980Sstevel@tonic-gate 12990Sstevel@tonic-gate intr_dist_cpuid_rem_device_weight(ino_p->ino_cpuid, rdip); 13000Sstevel@tonic-gate 13012973Sgovinda if (ipil_p->ipil_ih_size == 0) { 13020Sstevel@tonic-gate hdlp->ih_vector = ino_p->ino_sysino; 13030Sstevel@tonic-gate i_ddi_rem_ivintr(hdlp); 13040Sstevel@tonic-gate 13052973Sgovinda px_ib_delete_ino_pil(ib_p, ipil_p); 13062973Sgovinda 13072973Sgovinda if (ino_p->ino_ipil_size == 0) 13082973Sgovinda px_lib_msiq_setvalid(dip, 13092973Sgovinda px_devino_to_msiqid(px_p, ino), PCI_MSIQ_INVALID); 13102973Sgovinda } 13112973Sgovinda 131210053SEvan.Yan@Sun.COM (void) px_msiq_free(px_p, msiq_id); 131310053SEvan.Yan@Sun.COM 131410053SEvan.Yan@Sun.COM if (ino_p->ino_ipil_size) { 13153780Segillett /* Re-enable interrupt only if mapping register still shared */ 13163780Segillett PX_INTR_ENABLE(px_p->px_dip, ino_p->ino_sysino, curr_cpu); 13170Sstevel@tonic-gate } 13180Sstevel@tonic-gate 13190Sstevel@tonic-gate fail: 13200Sstevel@tonic-gate mutex_exit(&ib_p->ib_ino_lst_mutex); 13210Sstevel@tonic-gate return (ret); 13220Sstevel@tonic-gate } 1323