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 /* 22*3780Segillett * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate /* 290Sstevel@tonic-gate * PX nexus interrupt handling: 300Sstevel@tonic-gate * PX device interrupt handler wrapper 310Sstevel@tonic-gate * PIL lookup routine 320Sstevel@tonic-gate * PX device interrupt related initchild code 330Sstevel@tonic-gate */ 340Sstevel@tonic-gate 350Sstevel@tonic-gate #include <sys/types.h> 360Sstevel@tonic-gate #include <sys/kmem.h> 370Sstevel@tonic-gate #include <sys/async.h> 380Sstevel@tonic-gate #include <sys/spl.h> 390Sstevel@tonic-gate #include <sys/sunddi.h> 4027Sjchu #include <sys/fm/protocol.h> 4127Sjchu #include <sys/fm/util.h> 420Sstevel@tonic-gate #include <sys/machsystm.h> /* e_ddi_nodeid_to_dip() */ 430Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 440Sstevel@tonic-gate #include <sys/sdt.h> 450Sstevel@tonic-gate #include <sys/atomic.h> 460Sstevel@tonic-gate #include "px_obj.h" 4727Sjchu #include <sys/ontrap.h> 4827Sjchu #include <sys/membar.h> 4966Sesolom #include <sys/clock.h> 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 * px_intr_wrapper() which normally idles the ino's state machine which would 580Sstevel@tonic-gate * precipitate another trip round the loop. 590Sstevel@tonic-gate * 600Sstevel@tonic-gate * The loop can be broken by preventing the ino's state machine from being 610Sstevel@tonic-gate * idled when an interrupt line is jabbering. See the comment at the 620Sstevel@tonic-gate * beginning of px_intr_wrapper() explaining how the 'interrupt jabber 630Sstevel@tonic-gate * protection' code does this. 640Sstevel@tonic-gate */ 650Sstevel@tonic-gate 660Sstevel@tonic-gate /*LINTLIBRARY*/ 670Sstevel@tonic-gate 680Sstevel@tonic-gate /* 690Sstevel@tonic-gate * If the unclaimed interrupt count has reached the limit set by 700Sstevel@tonic-gate * pci_unclaimed_intr_max within the time limit, then all interrupts 710Sstevel@tonic-gate * on this ino is blocked by not idling the interrupt state machine. 720Sstevel@tonic-gate */ 730Sstevel@tonic-gate static int 742973Sgovinda px_spurintr(px_ino_pil_t *ipil_p) 750Sstevel@tonic-gate { 762973Sgovinda px_ino_t *ino_p = ipil_p->ipil_ino_p; 772973Sgovinda px_ih_t *ih_p = ipil_p->ipil_ih_start; 782973Sgovinda px_t *px_p = ino_p->ino_ib_p->ib_px_p; 792973Sgovinda char *err_fmt_str; 802973Sgovinda boolean_t blocked = B_FALSE; 812973Sgovinda int i; 820Sstevel@tonic-gate 832973Sgovinda if (ino_p->ino_unclaimed_intrs > px_unclaimed_intr_max) 840Sstevel@tonic-gate return (DDI_INTR_CLAIMED); 850Sstevel@tonic-gate 862973Sgovinda if (!ino_p->ino_unclaimed_intrs) 870Sstevel@tonic-gate ino_p->ino_spurintr_begin = ddi_get_lbolt(); 880Sstevel@tonic-gate 892973Sgovinda ino_p->ino_unclaimed_intrs++; 900Sstevel@tonic-gate 912973Sgovinda if (ino_p->ino_unclaimed_intrs <= px_unclaimed_intr_max) 920Sstevel@tonic-gate goto clear; 930Sstevel@tonic-gate 940Sstevel@tonic-gate if (drv_hztousec(ddi_get_lbolt() - ino_p->ino_spurintr_begin) 950Sstevel@tonic-gate > px_spurintr_duration) { 962973Sgovinda ino_p->ino_unclaimed_intrs = 0; 970Sstevel@tonic-gate goto clear; 980Sstevel@tonic-gate } 990Sstevel@tonic-gate err_fmt_str = "%s%d: ino 0x%x blocked"; 1002973Sgovinda blocked = B_TRUE; 1010Sstevel@tonic-gate goto warn; 1020Sstevel@tonic-gate clear: 1030Sstevel@tonic-gate err_fmt_str = "!%s%d: spurious interrupt from ino 0x%x"; 1040Sstevel@tonic-gate warn: 1050Sstevel@tonic-gate cmn_err(CE_WARN, err_fmt_str, NAMEINST(px_p->px_dip), ino_p->ino_ino); 1062973Sgovinda for (i = 0; i < ipil_p->ipil_ih_size; i++, ih_p = ih_p->ih_next) 1070Sstevel@tonic-gate cmn_err(CE_CONT, "!%s-%d#%x ", NAMEINST(ih_p->ih_dip), 1080Sstevel@tonic-gate ih_p->ih_inum); 1090Sstevel@tonic-gate cmn_err(CE_CONT, "!\n"); 1102973Sgovinda 1112973Sgovinda /* Clear the pending state */ 1122973Sgovinda if (blocked == B_FALSE) { 1132973Sgovinda if (px_lib_intr_setstate(px_p->px_dip, ino_p->ino_sysino, 1142973Sgovinda INTR_IDLE_STATE) != DDI_SUCCESS) 1152973Sgovinda return (DDI_INTR_UNCLAIMED); 1162973Sgovinda } 1172973Sgovinda 1180Sstevel@tonic-gate return (DDI_INTR_CLAIMED); 1190Sstevel@tonic-gate } 1200Sstevel@tonic-gate 1210Sstevel@tonic-gate extern uint64_t intr_get_time(void); 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate /* 124693Sgovinda * px_intx_intr (INTx or legacy interrupt handler) 1250Sstevel@tonic-gate * 1260Sstevel@tonic-gate * This routine is used as wrapper around interrupt handlers installed by child 1270Sstevel@tonic-gate * device drivers. This routine invokes the driver interrupt handlers and 1280Sstevel@tonic-gate * examines the return codes. 1290Sstevel@tonic-gate * 1300Sstevel@tonic-gate * There is a count of unclaimed interrupts kept on a per-ino basis. If at 1310Sstevel@tonic-gate * least one handler claims the interrupt then the counter is halved and the 1320Sstevel@tonic-gate * interrupt state machine is idled. If no handler claims the interrupt then 1330Sstevel@tonic-gate * the counter is incremented by one and the state machine is idled. 1340Sstevel@tonic-gate * If the count ever reaches the limit value set by pci_unclaimed_intr_max 1350Sstevel@tonic-gate * then the interrupt state machine is not idled thus preventing any further 1360Sstevel@tonic-gate * interrupts on that ino. The state machine will only be idled again if a 1370Sstevel@tonic-gate * handler is subsequently added or removed. 1380Sstevel@tonic-gate * 1390Sstevel@tonic-gate * return value: DDI_INTR_CLAIMED if any handlers claimed the interrupt, 1400Sstevel@tonic-gate * DDI_INTR_UNCLAIMED otherwise. 1410Sstevel@tonic-gate */ 1420Sstevel@tonic-gate uint_t 1430Sstevel@tonic-gate px_intx_intr(caddr_t arg) 1440Sstevel@tonic-gate { 1452973Sgovinda px_ino_pil_t *ipil_p = (px_ino_pil_t *)arg; 1462973Sgovinda px_ino_t *ino_p = ipil_p->ipil_ino_p; 1470Sstevel@tonic-gate px_t *px_p = ino_p->ino_ib_p->ib_px_p; 1482973Sgovinda px_ih_t *ih_p = ipil_p->ipil_ih_start; 1492973Sgovinda ushort_t pil = ipil_p->ipil_pil; 1502973Sgovinda uint_t result = 0, r = DDI_INTR_UNCLAIMED; 1510Sstevel@tonic-gate int i; 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate DBG(DBG_INTX_INTR, px_p->px_dip, "px_intx_intr:" 1540Sstevel@tonic-gate "ino=%x sysino=%llx pil=%x ih_size=%x ih_lst=%x\n", 1552973Sgovinda ino_p->ino_ino, ino_p->ino_sysino, ipil_p->ipil_pil, 1562973Sgovinda ipil_p->ipil_ih_size, ipil_p->ipil_ih_head); 1570Sstevel@tonic-gate 1582973Sgovinda for (i = 0; i < ipil_p->ipil_ih_size; i++, ih_p = ih_p->ih_next) { 1590Sstevel@tonic-gate dev_info_t *dip = ih_p->ih_dip; 1600Sstevel@tonic-gate uint_t (*handler)() = ih_p->ih_handler; 1610Sstevel@tonic-gate caddr_t arg1 = ih_p->ih_handler_arg1; 1620Sstevel@tonic-gate caddr_t arg2 = ih_p->ih_handler_arg2; 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate if (ih_p->ih_intr_state == PX_INTR_STATE_DISABLE) { 1650Sstevel@tonic-gate DBG(DBG_INTX_INTR, px_p->px_dip, 1660Sstevel@tonic-gate "px_intx_intr: %s%d interrupt %d is disabled\n", 1670Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip), 1680Sstevel@tonic-gate ino_p->ino_ino); 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate continue; 1710Sstevel@tonic-gate } 1720Sstevel@tonic-gate 1730Sstevel@tonic-gate DBG(DBG_INTX_INTR, px_p->px_dip, "px_intx_intr:" 1740Sstevel@tonic-gate "ino=%x handler=%p arg1 =%p arg2 = %p\n", 1750Sstevel@tonic-gate ino_p->ino_ino, handler, arg1, arg2); 1760Sstevel@tonic-gate 1770Sstevel@tonic-gate DTRACE_PROBE4(interrupt__start, dev_info_t, dip, 1780Sstevel@tonic-gate void *, handler, caddr_t, arg1, caddr_t, arg2); 1790Sstevel@tonic-gate 1800Sstevel@tonic-gate r = (*handler)(arg1, arg2); 1810Sstevel@tonic-gate 1820Sstevel@tonic-gate /* 1830Sstevel@tonic-gate * Account for time used by this interrupt. Protect against 1840Sstevel@tonic-gate * conflicting writes to ih_ticks from ib_intr_dist_all() by 1850Sstevel@tonic-gate * using atomic ops. 1860Sstevel@tonic-gate */ 1870Sstevel@tonic-gate 1882973Sgovinda if (pil <= LOCK_LEVEL) 1890Sstevel@tonic-gate atomic_add_64(&ih_p->ih_ticks, intr_get_time()); 1900Sstevel@tonic-gate 1910Sstevel@tonic-gate DTRACE_PROBE4(interrupt__complete, dev_info_t, dip, 1920Sstevel@tonic-gate void *, handler, caddr_t, arg1, int, r); 1930Sstevel@tonic-gate 1940Sstevel@tonic-gate result += r; 1950Sstevel@tonic-gate 1960Sstevel@tonic-gate if (px_check_all_handlers) 1970Sstevel@tonic-gate continue; 1980Sstevel@tonic-gate if (result) 1990Sstevel@tonic-gate break; 2000Sstevel@tonic-gate } 2010Sstevel@tonic-gate 2022973Sgovinda if (result) 2032973Sgovinda ino_p->ino_claimed |= (1 << pil); 2042973Sgovinda 2052973Sgovinda /* Interrupt can only be cleared after all pil levels are handled */ 2062973Sgovinda if (pil != ino_p->ino_lopil) 2072973Sgovinda return (DDI_INTR_CLAIMED); 2080Sstevel@tonic-gate 2092973Sgovinda if (!ino_p->ino_claimed) { 2102973Sgovinda if (px_unclaimed_intr_block) 2112973Sgovinda return (px_spurintr(ipil_p)); 2122973Sgovinda } 2132973Sgovinda 2142973Sgovinda ino_p->ino_unclaimed_intrs = 0; 2152973Sgovinda ino_p->ino_claimed = 0; 2160Sstevel@tonic-gate 2170Sstevel@tonic-gate /* Clear the pending state */ 2182973Sgovinda if (px_lib_intr_setstate(px_p->px_dip, 2190Sstevel@tonic-gate ino_p->ino_sysino, INTR_IDLE_STATE) != DDI_SUCCESS) 2200Sstevel@tonic-gate return (DDI_INTR_UNCLAIMED); 2210Sstevel@tonic-gate 2220Sstevel@tonic-gate return (DDI_INTR_CLAIMED); 2230Sstevel@tonic-gate } 2240Sstevel@tonic-gate 2250Sstevel@tonic-gate /* 226693Sgovinda * px_msiq_intr (MSI/X or PCIe MSG interrupt handler) 2270Sstevel@tonic-gate * 2280Sstevel@tonic-gate * This routine is used as wrapper around interrupt handlers installed by child 2290Sstevel@tonic-gate * device drivers. This routine invokes the driver interrupt handlers and 2300Sstevel@tonic-gate * examines the return codes. 2310Sstevel@tonic-gate * 2320Sstevel@tonic-gate * There is a count of unclaimed interrupts kept on a per-ino basis. If at 2330Sstevel@tonic-gate * least one handler claims the interrupt then the counter is halved and the 2340Sstevel@tonic-gate * interrupt state machine is idled. If no handler claims the interrupt then 2350Sstevel@tonic-gate * the counter is incremented by one and the state machine is idled. 2360Sstevel@tonic-gate * If the count ever reaches the limit value set by pci_unclaimed_intr_max 2370Sstevel@tonic-gate * then the interrupt state machine is not idled thus preventing any further 2380Sstevel@tonic-gate * interrupts on that ino. The state machine will only be idled again if a 2390Sstevel@tonic-gate * handler is subsequently added or removed. 2400Sstevel@tonic-gate * 2410Sstevel@tonic-gate * return value: DDI_INTR_CLAIMED if any handlers claimed the interrupt, 2420Sstevel@tonic-gate * DDI_INTR_UNCLAIMED otherwise. 2430Sstevel@tonic-gate */ 2440Sstevel@tonic-gate uint_t 2450Sstevel@tonic-gate px_msiq_intr(caddr_t arg) 2460Sstevel@tonic-gate { 2472973Sgovinda px_ino_pil_t *ipil_p = (px_ino_pil_t *)arg; 2482973Sgovinda px_ino_t *ino_p = ipil_p->ipil_ino_p; 2490Sstevel@tonic-gate px_t *px_p = ino_p->ino_ib_p->ib_px_p; 2500Sstevel@tonic-gate px_msiq_state_t *msiq_state_p = &px_p->px_ib_p->ib_msiq_state; 2510Sstevel@tonic-gate px_msiq_t *msiq_p = ino_p->ino_msiq_p; 2520Sstevel@tonic-gate dev_info_t *dip = px_p->px_dip; 2532973Sgovinda ushort_t pil = ipil_p->ipil_pil; 2540Sstevel@tonic-gate msiq_rec_t msiq_rec, *msiq_rec_p = &msiq_rec; 2552588Segillett msiqhead_t *curr_head_p; 2562588Segillett msiqtail_t curr_tail_index; 2570Sstevel@tonic-gate msgcode_t msg_code; 2580Sstevel@tonic-gate px_ih_t *ih_p; 2592973Sgovinda uint_t ret = DDI_INTR_UNCLAIMED; 2602973Sgovinda int i, j; 2610Sstevel@tonic-gate 2620Sstevel@tonic-gate DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: msiq_id =%x ino=%x pil=%x " 2630Sstevel@tonic-gate "ih_size=%x ih_lst=%x\n", msiq_p->msiq_id, ino_p->ino_ino, 2642973Sgovinda ipil_p->ipil_pil, ipil_p->ipil_ih_size, ipil_p->ipil_ih_head); 2652973Sgovinda 2662973Sgovinda /* 2672973Sgovinda * The px_msiq_intr() handles multiple interrupt priorities and it 2682973Sgovinda * will set msiq->msiq_rec2process to the number of MSIQ records to 2692973Sgovinda * process while handling the highest priority interrupt. Subsequent 2702973Sgovinda * lower priority interrupts will just process any unprocessed MSIQ 2712973Sgovinda * records or will just return immediately. 2722973Sgovinda */ 2732973Sgovinda if (msiq_p->msiq_recs2process == 0) { 2742973Sgovinda /* Read current MSIQ tail index */ 2752973Sgovinda px_lib_msiq_gettail(dip, msiq_p->msiq_id, &curr_tail_index); 2762973Sgovinda msiq_p->msiq_new_head_index = msiq_p->msiq_curr_head_index; 2770Sstevel@tonic-gate 2782973Sgovinda if (curr_tail_index < msiq_p->msiq_curr_head_index) 2792973Sgovinda curr_tail_index += msiq_state_p->msiq_rec_cnt; 2802973Sgovinda 2812973Sgovinda msiq_p->msiq_recs2process = curr_tail_index - 2822973Sgovinda msiq_p->msiq_curr_head_index; 2832973Sgovinda } 2840Sstevel@tonic-gate 2852973Sgovinda DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: curr_head %x new_head %x " 2862973Sgovinda "rec2process %x\n", msiq_p->msiq_curr_head_index, 2872973Sgovinda msiq_p->msiq_new_head_index, msiq_p->msiq_recs2process); 2882973Sgovinda 2892973Sgovinda /* If all MSIQ records are already processed, just return immediately */ 2902973Sgovinda if ((msiq_p->msiq_new_head_index - msiq_p->msiq_curr_head_index) 2912973Sgovinda == msiq_p->msiq_recs2process) 2922973Sgovinda goto intr_done; 2932973Sgovinda 2942973Sgovinda curr_head_p = (msiqhead_t *)((caddr_t)msiq_p->msiq_base_p + 2952973Sgovinda (msiq_p->msiq_curr_head_index * sizeof (msiq_rec_t))); 2960Sstevel@tonic-gate 2970Sstevel@tonic-gate /* 2982588Segillett * Calculate the number of recs to process by taking the difference 2992588Segillett * between the head and tail pointers. For all records we always 3002588Segillett * verify that we have a valid record type before we do any processing. 3012973Sgovinda * If triggered, we should always have at least one valid record. 3020Sstevel@tonic-gate */ 3032973Sgovinda for (i = 0; i < msiq_p->msiq_recs2process; i++) { 3042973Sgovinda /* Read next MSIQ record */ 3052588Segillett px_lib_get_msiq_rec(dip, curr_head_p, msiq_rec_p); 3062588Segillett 3070Sstevel@tonic-gate DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: MSIQ RECORD, " 3080Sstevel@tonic-gate "msiq_rec_type 0x%llx msiq_rec_rid 0x%llx\n", 3090Sstevel@tonic-gate msiq_rec_p->msiq_rec_type, msiq_rec_p->msiq_rec_rid); 3100Sstevel@tonic-gate 3112588Segillett if (!msiq_rec_p->msiq_rec_type) 3122973Sgovinda goto next_rec; 3130Sstevel@tonic-gate 3140Sstevel@tonic-gate /* Check MSIQ record type */ 3150Sstevel@tonic-gate switch (msiq_rec_p->msiq_rec_type) { 3160Sstevel@tonic-gate case MSG_REC: 3170Sstevel@tonic-gate msg_code = msiq_rec_p->msiq_rec_data.msg.msg_code; 3180Sstevel@tonic-gate DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: PCIE MSG " 3190Sstevel@tonic-gate "record, msg type 0x%x\n", msg_code); 3200Sstevel@tonic-gate break; 3210Sstevel@tonic-gate case MSI32_REC: 3220Sstevel@tonic-gate case MSI64_REC: 3230Sstevel@tonic-gate msg_code = msiq_rec_p->msiq_rec_data.msi.msi_data; 3240Sstevel@tonic-gate DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: MSI record, " 3250Sstevel@tonic-gate "msi 0x%x\n", msg_code); 3260Sstevel@tonic-gate 3270Sstevel@tonic-gate /* Clear MSI state */ 3280Sstevel@tonic-gate px_lib_msi_setstate(dip, (msinum_t)msg_code, 3290Sstevel@tonic-gate PCI_MSI_STATE_IDLE); 3300Sstevel@tonic-gate break; 3310Sstevel@tonic-gate default: 3320Sstevel@tonic-gate msg_code = 0; 3330Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: px_msiq_intr: 0x%x MSIQ " 3340Sstevel@tonic-gate "record type is not supported", 3350Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip), 3360Sstevel@tonic-gate msiq_rec_p->msiq_rec_type); 3372973Sgovinda 3380Sstevel@tonic-gate goto next_rec; 3390Sstevel@tonic-gate } 3400Sstevel@tonic-gate 3410Sstevel@tonic-gate /* 3420Sstevel@tonic-gate * Scan through px_ih_t linked list, searching for the 3430Sstevel@tonic-gate * right px_ih_t, matching MSIQ record data. 3440Sstevel@tonic-gate */ 3452973Sgovinda for (j = 0, ih_p = ipil_p->ipil_ih_start; 3462973Sgovinda ih_p && (j < ipil_p->ipil_ih_size) && 3471653Sgovinda ((ih_p->ih_msg_code != msg_code) || 3481653Sgovinda (ih_p->ih_rec_type != msiq_rec_p->msiq_rec_type)); 3492942Segillett ih_p = ih_p->ih_next, j++); 3500Sstevel@tonic-gate 3510Sstevel@tonic-gate if ((ih_p->ih_msg_code == msg_code) && 3520Sstevel@tonic-gate (ih_p->ih_rec_type == msiq_rec_p->msiq_rec_type)) { 3530Sstevel@tonic-gate dev_info_t *dip = ih_p->ih_dip; 3540Sstevel@tonic-gate uint_t (*handler)() = ih_p->ih_handler; 3550Sstevel@tonic-gate caddr_t arg1 = ih_p->ih_handler_arg1; 3560Sstevel@tonic-gate caddr_t arg2 = ih_p->ih_handler_arg2; 3570Sstevel@tonic-gate 3580Sstevel@tonic-gate DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: ino=%x data=%x " 3590Sstevel@tonic-gate "handler=%p arg1 =%p arg2=%p\n", ino_p->ino_ino, 3600Sstevel@tonic-gate msg_code, handler, arg1, arg2); 3610Sstevel@tonic-gate 3620Sstevel@tonic-gate DTRACE_PROBE4(interrupt__start, dev_info_t, dip, 3630Sstevel@tonic-gate void *, handler, caddr_t, arg1, caddr_t, arg2); 3640Sstevel@tonic-gate 36527Sjchu /* 36627Sjchu * Special case for PCIE Error Messages. 36727Sjchu * The current frame work doesn't fit PCIE Err Msgs 36827Sjchu * This should be fixed when PCIE MESSAGES as a whole 36927Sjchu * is architected correctly. 37027Sjchu */ 37127Sjchu if ((msg_code == PCIE_MSG_CODE_ERR_COR) || 37227Sjchu (msg_code == PCIE_MSG_CODE_ERR_NONFATAL) || 37327Sjchu (msg_code == PCIE_MSG_CODE_ERR_FATAL)) { 37427Sjchu ret = px_err_fabric_intr(px_p, msg_code, 37527Sjchu msiq_rec_p->msiq_rec_rid); 37627Sjchu } else 37727Sjchu ret = (*handler)(arg1, arg2); 3780Sstevel@tonic-gate 3790Sstevel@tonic-gate /* 3800Sstevel@tonic-gate * Account for time used by this interrupt. Protect 3810Sstevel@tonic-gate * against conflicting writes to ih_ticks from 3820Sstevel@tonic-gate * ib_intr_dist_all() by using atomic ops. 3830Sstevel@tonic-gate */ 3840Sstevel@tonic-gate 3852973Sgovinda if (pil <= LOCK_LEVEL) 3860Sstevel@tonic-gate atomic_add_64(&ih_p->ih_ticks, intr_get_time()); 3870Sstevel@tonic-gate 3880Sstevel@tonic-gate DTRACE_PROBE4(interrupt__complete, dev_info_t, dip, 3890Sstevel@tonic-gate void *, handler, caddr_t, arg1, int, ret); 3902588Segillett 3912973Sgovinda msiq_p->msiq_new_head_index++; 3922973Sgovinda px_lib_clr_msiq_rec(dip, curr_head_p); 3930Sstevel@tonic-gate } else { 3940Sstevel@tonic-gate DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr:" 3952588Segillett "No matching MSIQ record found\n"); 3962588Segillett } 3972588Segillett next_rec: 3982588Segillett /* Get the pointer next EQ record */ 3992588Segillett curr_head_p = (msiqhead_t *) 4002588Segillett ((caddr_t)curr_head_p + sizeof (msiq_rec_t)); 4010Sstevel@tonic-gate 4022588Segillett /* Check for overflow condition */ 4032588Segillett if (curr_head_p >= (msiqhead_t *)((caddr_t)msiq_p->msiq_base_p 4042973Sgovinda + (msiq_state_p->msiq_rec_cnt * sizeof (msiq_rec_t)))) 4052588Segillett curr_head_p = (msiqhead_t *)msiq_p->msiq_base_p; 4060Sstevel@tonic-gate } 4070Sstevel@tonic-gate 4082973Sgovinda DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: No of MSIQ recs processed %x\n", 4092973Sgovinda (msiq_p->msiq_new_head_index - msiq_p->msiq_curr_head_index)); 4102973Sgovinda 4112973Sgovinda DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: curr_head %x new_head %x " 4122973Sgovinda "rec2process %x\n", msiq_p->msiq_curr_head_index, 4132973Sgovinda msiq_p->msiq_new_head_index, msiq_p->msiq_recs2process); 4142588Segillett 4152973Sgovinda /* ino_claimed used just for debugging purpose */ 4162973Sgovinda if (ret) 4172973Sgovinda ino_p->ino_claimed |= (1 << pil); 4182973Sgovinda 4192973Sgovinda intr_done: 4202973Sgovinda /* Interrupt can only be cleared after all pil levels are handled */ 4212973Sgovinda if (pil != ino_p->ino_lopil) 4222973Sgovinda return (DDI_INTR_CLAIMED); 4232973Sgovinda 4242973Sgovinda if (msiq_p->msiq_new_head_index <= msiq_p->msiq_curr_head_index) { 4252973Sgovinda if (px_unclaimed_intr_block) 4262973Sgovinda return (px_spurintr(ipil_p)); 4272588Segillett } 4280Sstevel@tonic-gate 4290Sstevel@tonic-gate /* Update MSIQ head index with no of MSIQ records processed */ 4302973Sgovinda if (msiq_p->msiq_new_head_index >= msiq_state_p->msiq_rec_cnt) 4312973Sgovinda msiq_p->msiq_new_head_index -= msiq_state_p->msiq_rec_cnt; 4320Sstevel@tonic-gate 4332973Sgovinda msiq_p->msiq_curr_head_index = msiq_p->msiq_new_head_index; 4342973Sgovinda px_lib_msiq_sethead(dip, msiq_p->msiq_id, msiq_p->msiq_new_head_index); 4352973Sgovinda 4362973Sgovinda msiq_p->msiq_new_head_index = 0; 4372973Sgovinda msiq_p->msiq_recs2process = 0; 4382973Sgovinda ino_p->ino_claimed = 0; 4390Sstevel@tonic-gate 4400Sstevel@tonic-gate /* Clear the pending state */ 4410Sstevel@tonic-gate if (px_lib_intr_setstate(dip, ino_p->ino_sysino, 4420Sstevel@tonic-gate INTR_IDLE_STATE) != DDI_SUCCESS) 4430Sstevel@tonic-gate return (DDI_INTR_UNCLAIMED); 4440Sstevel@tonic-gate 4450Sstevel@tonic-gate return (DDI_INTR_CLAIMED); 4460Sstevel@tonic-gate } 4470Sstevel@tonic-gate 4480Sstevel@tonic-gate dev_info_t * 4490Sstevel@tonic-gate px_get_my_childs_dip(dev_info_t *dip, dev_info_t *rdip) 4500Sstevel@tonic-gate { 4510Sstevel@tonic-gate dev_info_t *cdip = rdip; 4520Sstevel@tonic-gate 4530Sstevel@tonic-gate for (; ddi_get_parent(cdip) != dip; cdip = ddi_get_parent(cdip)) 4540Sstevel@tonic-gate ; 4550Sstevel@tonic-gate 4560Sstevel@tonic-gate return (cdip); 4570Sstevel@tonic-gate } 4580Sstevel@tonic-gate 4590Sstevel@tonic-gate /* Default class to pil value mapping */ 4600Sstevel@tonic-gate px_class_val_t px_default_pil [] = { 4610Sstevel@tonic-gate {0x000000, 0xff0000, 0x1}, /* Class code for pre-2.0 devices */ 4620Sstevel@tonic-gate {0x010000, 0xff0000, 0x4}, /* Mass Storage Controller */ 4630Sstevel@tonic-gate {0x020000, 0xff0000, 0x6}, /* Network Controller */ 4640Sstevel@tonic-gate {0x030000, 0xff0000, 0x9}, /* Display Controller */ 4650Sstevel@tonic-gate {0x040000, 0xff0000, 0x9}, /* Multimedia Controller */ 4661617Sgovinda {0x050000, 0xff0000, 0x9}, /* Memory Controller */ 4671617Sgovinda {0x060000, 0xff0000, 0x9}, /* Bridge Controller */ 4680Sstevel@tonic-gate {0x0c0000, 0xffff00, 0x9}, /* Serial Bus, FireWire (IEEE 1394) */ 4690Sstevel@tonic-gate {0x0c0100, 0xffff00, 0x4}, /* Serial Bus, ACCESS.bus */ 4700Sstevel@tonic-gate {0x0c0200, 0xffff00, 0x4}, /* Serial Bus, SSA */ 4710Sstevel@tonic-gate {0x0c0300, 0xffff00, 0x9}, /* Serial Bus Universal Serial Bus */ 4720Sstevel@tonic-gate {0x0c0400, 0xffff00, 0x6}, /* Serial Bus, Fibre Channel */ 4730Sstevel@tonic-gate {0x0c0600, 0xffff00, 0x6} /* Serial Bus, Infiniband */ 4740Sstevel@tonic-gate }; 4750Sstevel@tonic-gate 4760Sstevel@tonic-gate /* 4770Sstevel@tonic-gate * Default class to intr_weight value mapping (% of CPU). A driver.conf 4780Sstevel@tonic-gate * entry on or above the pci node like 4790Sstevel@tonic-gate * 4800Sstevel@tonic-gate * pci-class-intr-weights= 0x020000, 0xff0000, 30; 4810Sstevel@tonic-gate * 4820Sstevel@tonic-gate * can be used to augment or override entries in the default table below. 4830Sstevel@tonic-gate * 4840Sstevel@tonic-gate * NB: The values below give NICs preference on redistribution, and provide 4850Sstevel@tonic-gate * NICs some isolation from other interrupt sources. We need better interfaces 4860Sstevel@tonic-gate * that allow the NIC driver to identify a specific NIC instance as high 4870Sstevel@tonic-gate * bandwidth, and thus deserving of separation from other low bandwidth 4880Sstevel@tonic-gate * NICs additional isolation from other interrupt sources. 4890Sstevel@tonic-gate * 4900Sstevel@tonic-gate * NB: We treat Infiniband like a NIC. 4910Sstevel@tonic-gate */ 4920Sstevel@tonic-gate px_class_val_t px_default_intr_weight [] = { 4930Sstevel@tonic-gate {0x020000, 0xff0000, 35}, /* Network Controller */ 4940Sstevel@tonic-gate {0x010000, 0xff0000, 10}, /* Mass Storage Controller */ 4950Sstevel@tonic-gate {0x0c0400, 0xffff00, 10}, /* Serial Bus, Fibre Channel */ 4960Sstevel@tonic-gate {0x0c0600, 0xffff00, 50} /* Serial Bus, Infiniband */ 4970Sstevel@tonic-gate }; 4980Sstevel@tonic-gate 4990Sstevel@tonic-gate static uint32_t 5000Sstevel@tonic-gate px_match_class_val(uint32_t key, px_class_val_t *rec_p, int nrec, 5010Sstevel@tonic-gate uint32_t default_val) 5020Sstevel@tonic-gate { 5030Sstevel@tonic-gate int i; 5040Sstevel@tonic-gate 5050Sstevel@tonic-gate for (i = 0; i < nrec; rec_p++, i++) { 5060Sstevel@tonic-gate if ((rec_p->class_code & rec_p->class_mask) == 5070Sstevel@tonic-gate (key & rec_p->class_mask)) 5080Sstevel@tonic-gate return (rec_p->class_val); 5090Sstevel@tonic-gate } 5100Sstevel@tonic-gate 5110Sstevel@tonic-gate return (default_val); 5120Sstevel@tonic-gate } 5130Sstevel@tonic-gate 5140Sstevel@tonic-gate /* 5150Sstevel@tonic-gate * px_class_to_val 5160Sstevel@tonic-gate * 5170Sstevel@tonic-gate * Return the configuration value, based on class code and sub class code, 5180Sstevel@tonic-gate * from the specified property based or default px_class_val_t table. 5190Sstevel@tonic-gate */ 5200Sstevel@tonic-gate uint32_t 5210Sstevel@tonic-gate px_class_to_val(dev_info_t *rdip, char *property_name, px_class_val_t *rec_p, 5220Sstevel@tonic-gate int nrec, uint32_t default_val) 5230Sstevel@tonic-gate { 5240Sstevel@tonic-gate int property_len; 5250Sstevel@tonic-gate uint32_t class_code; 5260Sstevel@tonic-gate px_class_val_t *conf; 5270Sstevel@tonic-gate uint32_t val = default_val; 5280Sstevel@tonic-gate 5290Sstevel@tonic-gate /* 5300Sstevel@tonic-gate * Use the "class-code" property to get the base and sub class 5310Sstevel@tonic-gate * codes for the requesting device. 5320Sstevel@tonic-gate */ 5330Sstevel@tonic-gate class_code = (uint32_t)ddi_prop_get_int(DDI_DEV_T_ANY, rdip, 5340Sstevel@tonic-gate DDI_PROP_DONTPASS, "class-code", -1); 5350Sstevel@tonic-gate 5360Sstevel@tonic-gate if (class_code == -1) 5370Sstevel@tonic-gate return (val); 5380Sstevel@tonic-gate 5390Sstevel@tonic-gate /* look up the val from the default table */ 5400Sstevel@tonic-gate val = px_match_class_val(class_code, rec_p, nrec, val); 5410Sstevel@tonic-gate 5420Sstevel@tonic-gate /* see if there is a more specific property specified value */ 5430Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_ANY, rdip, DDI_PROP_NOTPROM, 5440Sstevel@tonic-gate property_name, (caddr_t)&conf, &property_len)) 5450Sstevel@tonic-gate return (val); 5460Sstevel@tonic-gate 5470Sstevel@tonic-gate if ((property_len % sizeof (px_class_val_t)) == 0) 5480Sstevel@tonic-gate val = px_match_class_val(class_code, conf, 5490Sstevel@tonic-gate property_len / sizeof (px_class_val_t), val); 5500Sstevel@tonic-gate kmem_free(conf, property_len); 5510Sstevel@tonic-gate return (val); 5520Sstevel@tonic-gate } 5530Sstevel@tonic-gate 5540Sstevel@tonic-gate /* px_class_to_pil: return the pil for a given device. */ 5550Sstevel@tonic-gate uint32_t 5560Sstevel@tonic-gate px_class_to_pil(dev_info_t *rdip) 5570Sstevel@tonic-gate { 5580Sstevel@tonic-gate uint32_t pil; 5590Sstevel@tonic-gate 5603249Sgovinda /* Default pil is 1 */ 5610Sstevel@tonic-gate pil = px_class_to_val(rdip, 5620Sstevel@tonic-gate "pci-class-priorities", px_default_pil, 5633249Sgovinda sizeof (px_default_pil) / sizeof (px_class_val_t), 1); 5640Sstevel@tonic-gate 5653249Sgovinda /* Range check the result */ 5660Sstevel@tonic-gate if (pil >= 0xf) 5673249Sgovinda pil = 1; 5680Sstevel@tonic-gate 5690Sstevel@tonic-gate return (pil); 5700Sstevel@tonic-gate } 5710Sstevel@tonic-gate 5720Sstevel@tonic-gate /* px_class_to_intr_weight: return the intr_weight for a given device. */ 5730Sstevel@tonic-gate static int32_t 5740Sstevel@tonic-gate px_class_to_intr_weight(dev_info_t *rdip) 5750Sstevel@tonic-gate { 5760Sstevel@tonic-gate int32_t intr_weight; 5770Sstevel@tonic-gate 5780Sstevel@tonic-gate /* default weight is 0% */ 5790Sstevel@tonic-gate intr_weight = px_class_to_val(rdip, 5800Sstevel@tonic-gate "pci-class-intr-weights", px_default_intr_weight, 5810Sstevel@tonic-gate sizeof (px_default_intr_weight) / sizeof (px_class_val_t), 0); 5820Sstevel@tonic-gate 5830Sstevel@tonic-gate /* range check the result */ 5840Sstevel@tonic-gate if (intr_weight < 0) 5850Sstevel@tonic-gate intr_weight = 0; 5860Sstevel@tonic-gate if (intr_weight > 1000) 5870Sstevel@tonic-gate intr_weight = 1000; 5880Sstevel@tonic-gate 5890Sstevel@tonic-gate return (intr_weight); 5900Sstevel@tonic-gate } 5910Sstevel@tonic-gate 5920Sstevel@tonic-gate /* ARGSUSED */ 5930Sstevel@tonic-gate int 5940Sstevel@tonic-gate px_intx_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op, 5950Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, void *result) 5960Sstevel@tonic-gate { 597693Sgovinda px_t *px_p = DIP_TO_STATE(dip); 598693Sgovinda int ret = DDI_SUCCESS; 5990Sstevel@tonic-gate 6000Sstevel@tonic-gate DBG(DBG_INTROPS, dip, "px_intx_ops: dip=%x rdip=%x intr_op=%x " 6010Sstevel@tonic-gate "handle=%p\n", dip, rdip, intr_op, hdlp); 6020Sstevel@tonic-gate 6030Sstevel@tonic-gate switch (intr_op) { 6040Sstevel@tonic-gate case DDI_INTROP_GETCAP: 6050Sstevel@tonic-gate ret = pci_intx_get_cap(rdip, (int *)result); 6060Sstevel@tonic-gate break; 6070Sstevel@tonic-gate case DDI_INTROP_SETCAP: 6080Sstevel@tonic-gate DBG(DBG_INTROPS, dip, "px_intx_ops: SetCap is not supported\n"); 6090Sstevel@tonic-gate ret = DDI_ENOTSUP; 6100Sstevel@tonic-gate break; 6110Sstevel@tonic-gate case DDI_INTROP_ALLOC: 6120Sstevel@tonic-gate *(int *)result = hdlp->ih_scratch1; 6130Sstevel@tonic-gate break; 6140Sstevel@tonic-gate case DDI_INTROP_FREE: 6150Sstevel@tonic-gate break; 6160Sstevel@tonic-gate case DDI_INTROP_GETPRI: 617693Sgovinda *(int *)result = hdlp->ih_pri ? 618693Sgovinda hdlp->ih_pri : px_class_to_pil(rdip); 6190Sstevel@tonic-gate break; 6200Sstevel@tonic-gate case DDI_INTROP_SETPRI: 6210Sstevel@tonic-gate break; 6220Sstevel@tonic-gate case DDI_INTROP_ADDISR: 6230Sstevel@tonic-gate ret = px_add_intx_intr(dip, rdip, hdlp); 6240Sstevel@tonic-gate break; 6250Sstevel@tonic-gate case DDI_INTROP_REMISR: 6260Sstevel@tonic-gate ret = px_rem_intx_intr(dip, rdip, hdlp); 6270Sstevel@tonic-gate break; 6280Sstevel@tonic-gate case DDI_INTROP_ENABLE: 6290Sstevel@tonic-gate ret = px_ib_update_intr_state(px_p, rdip, hdlp->ih_inum, 6302973Sgovinda hdlp->ih_vector, hdlp->ih_pri, PX_INTR_STATE_ENABLE, 0, 0); 6310Sstevel@tonic-gate break; 6320Sstevel@tonic-gate case DDI_INTROP_DISABLE: 6330Sstevel@tonic-gate ret = px_ib_update_intr_state(px_p, rdip, hdlp->ih_inum, 6342973Sgovinda hdlp->ih_vector, hdlp->ih_pri, PX_INTR_STATE_DISABLE, 0, 0); 6350Sstevel@tonic-gate break; 6360Sstevel@tonic-gate case DDI_INTROP_SETMASK: 6370Sstevel@tonic-gate ret = pci_intx_set_mask(rdip); 6380Sstevel@tonic-gate break; 6390Sstevel@tonic-gate case DDI_INTROP_CLRMASK: 6400Sstevel@tonic-gate ret = pci_intx_clr_mask(rdip); 6410Sstevel@tonic-gate break; 6420Sstevel@tonic-gate case DDI_INTROP_GETPENDING: 6430Sstevel@tonic-gate ret = pci_intx_get_pending(rdip, (int *)result); 6440Sstevel@tonic-gate break; 6450Sstevel@tonic-gate case DDI_INTROP_NINTRS: 6460Sstevel@tonic-gate case DDI_INTROP_NAVAIL: 6472580Sanish *(int *)result = i_ddi_get_intx_nintrs(rdip); 6480Sstevel@tonic-gate break; 6490Sstevel@tonic-gate default: 6500Sstevel@tonic-gate ret = DDI_ENOTSUP; 6510Sstevel@tonic-gate break; 6520Sstevel@tonic-gate } 6530Sstevel@tonic-gate 6540Sstevel@tonic-gate return (ret); 6550Sstevel@tonic-gate } 6560Sstevel@tonic-gate 6570Sstevel@tonic-gate /* ARGSUSED */ 6580Sstevel@tonic-gate int 6590Sstevel@tonic-gate px_msix_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op, 6600Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, void *result) 6610Sstevel@tonic-gate { 6620Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip); 6630Sstevel@tonic-gate px_msi_state_t *msi_state_p = &px_p->px_ib_p->ib_msi_state; 664965Sgovinda msiq_rec_type_t msiq_rec_type; 665965Sgovinda msi_type_t msi_type; 666965Sgovinda uint64_t msi_addr; 6670Sstevel@tonic-gate msinum_t msi_num; 6680Sstevel@tonic-gate msiqid_t msiq_id; 6690Sstevel@tonic-gate uint_t nintrs; 6700Sstevel@tonic-gate int i, ret = DDI_SUCCESS; 6710Sstevel@tonic-gate 6720Sstevel@tonic-gate DBG(DBG_INTROPS, dip, "px_msix_ops: dip=%x rdip=%x intr_op=%x " 6730Sstevel@tonic-gate "handle=%p\n", dip, rdip, intr_op, hdlp); 6740Sstevel@tonic-gate 675965Sgovinda /* Check for MSI64 support */ 6761653Sgovinda if ((hdlp->ih_cap & DDI_INTR_FLAG_MSI64) && msi_state_p->msi_addr64) { 677965Sgovinda msiq_rec_type = MSI64_REC; 678965Sgovinda msi_type = MSI64_TYPE; 6791653Sgovinda msi_addr = msi_state_p->msi_addr64; 680965Sgovinda } else { 681965Sgovinda msiq_rec_type = MSI32_REC; 682965Sgovinda msi_type = MSI32_TYPE; 683965Sgovinda msi_addr = msi_state_p->msi_addr32; 684965Sgovinda } 685965Sgovinda 6860Sstevel@tonic-gate switch (intr_op) { 6870Sstevel@tonic-gate case DDI_INTROP_GETCAP: 6880Sstevel@tonic-gate ret = pci_msi_get_cap(rdip, hdlp->ih_type, (int *)result); 6890Sstevel@tonic-gate break; 6900Sstevel@tonic-gate case DDI_INTROP_SETCAP: 6910Sstevel@tonic-gate DBG(DBG_INTROPS, dip, "px_msix_ops: SetCap is not supported\n"); 6920Sstevel@tonic-gate ret = DDI_ENOTSUP; 6930Sstevel@tonic-gate break; 6940Sstevel@tonic-gate case DDI_INTROP_ALLOC: 6950Sstevel@tonic-gate /* 6960Sstevel@tonic-gate * We need to restrict this allocation in future 6970Sstevel@tonic-gate * based on Resource Management policies. 6980Sstevel@tonic-gate */ 6990Sstevel@tonic-gate if ((ret = px_msi_alloc(px_p, rdip, hdlp->ih_inum, 7001725Segillett hdlp->ih_scratch1, (uintptr_t)hdlp->ih_scratch2, &msi_num, 7011725Segillett (int *)result)) != DDI_SUCCESS) { 7021725Segillett DBG(DBG_INTROPS, dip, "px_msix_ops: allocation " 7031725Segillett "failed, rdip 0x%p type 0x%d inum 0x%x " 7041725Segillett "count 0x%x\n", rdip, hdlp->ih_type, hdlp->ih_inum, 7051725Segillett hdlp->ih_scratch1); 7060Sstevel@tonic-gate 7070Sstevel@tonic-gate return (ret); 7080Sstevel@tonic-gate } 7090Sstevel@tonic-gate 7101725Segillett if ((hdlp->ih_type == DDI_INTR_TYPE_MSIX) && 7111725Segillett (i_ddi_get_msix(rdip) == NULL)) { 7121725Segillett ddi_intr_msix_t *msix_p; 7131725Segillett 7141725Segillett if (msix_p = pci_msix_init(rdip)) { 7151725Segillett i_ddi_set_msix(rdip, msix_p); 7161725Segillett break; 7171725Segillett } 7181725Segillett 7191725Segillett DBG(DBG_INTROPS, dip, "px_msix_ops: MSI-X allocation " 7201725Segillett "failed, rdip 0x%p inum 0x%x\n", rdip, 7211725Segillett hdlp->ih_inum); 7221725Segillett 7231725Segillett (void) px_msi_free(px_p, rdip, hdlp->ih_inum, 7241725Segillett hdlp->ih_scratch1); 7251725Segillett 7261725Segillett return (DDI_FAILURE); 7271725Segillett } 7281725Segillett 7290Sstevel@tonic-gate break; 7300Sstevel@tonic-gate case DDI_INTROP_FREE: 7312755Segillett (void) pci_msi_disable_mode(rdip, hdlp->ih_type, NULL); 7320Sstevel@tonic-gate (void) pci_msi_unconfigure(rdip, hdlp->ih_type, hdlp->ih_inum); 7331725Segillett 7341725Segillett if (hdlp->ih_type == DDI_INTR_TYPE_MSI) 7351725Segillett goto msi_free; 7361725Segillett 7371725Segillett if (hdlp->ih_flags & DDI_INTR_MSIX_DUP) 7381725Segillett break; 7391725Segillett 7401725Segillett if (((i_ddi_intr_get_current_nintrs(hdlp->ih_dip) - 1) == 0) && 7411725Segillett (i_ddi_get_msix(rdip))) { 7421725Segillett pci_msix_fini(i_ddi_get_msix(rdip)); 7431725Segillett i_ddi_set_msix(rdip, NULL); 7441725Segillett } 7451725Segillett msi_free: 7460Sstevel@tonic-gate (void) px_msi_free(px_p, rdip, hdlp->ih_inum, 7470Sstevel@tonic-gate hdlp->ih_scratch1); 7480Sstevel@tonic-gate break; 7490Sstevel@tonic-gate case DDI_INTROP_GETPRI: 7500Sstevel@tonic-gate *(int *)result = hdlp->ih_pri ? 7510Sstevel@tonic-gate hdlp->ih_pri : px_class_to_pil(rdip); 7520Sstevel@tonic-gate break; 7530Sstevel@tonic-gate case DDI_INTROP_SETPRI: 7540Sstevel@tonic-gate break; 7550Sstevel@tonic-gate case DDI_INTROP_ADDISR: 7560Sstevel@tonic-gate if ((ret = px_msi_get_msinum(px_p, hdlp->ih_dip, 7570Sstevel@tonic-gate hdlp->ih_inum, &msi_num)) != DDI_SUCCESS) 7580Sstevel@tonic-gate return (ret); 7590Sstevel@tonic-gate 7600Sstevel@tonic-gate if ((ret = px_add_msiq_intr(dip, rdip, hdlp, 761965Sgovinda msiq_rec_type, msi_num, &msiq_id)) != DDI_SUCCESS) { 7620Sstevel@tonic-gate DBG(DBG_INTROPS, dip, "px_msix_ops: Add MSI handler " 7630Sstevel@tonic-gate "failed, rdip 0x%p msi 0x%x\n", rdip, msi_num); 7640Sstevel@tonic-gate return (ret); 7650Sstevel@tonic-gate } 7660Sstevel@tonic-gate 7670Sstevel@tonic-gate DBG(DBG_INTROPS, dip, "px_msix_ops: msiq used 0x%x\n", msiq_id); 7680Sstevel@tonic-gate 7690Sstevel@tonic-gate if ((ret = px_lib_msi_setmsiq(dip, msi_num, 770965Sgovinda msiq_id, msi_type)) != DDI_SUCCESS) { 7710Sstevel@tonic-gate (void) px_rem_msiq_intr(dip, rdip, 772965Sgovinda hdlp, msiq_rec_type, msi_num, msiq_id); 7730Sstevel@tonic-gate return (ret); 7740Sstevel@tonic-gate } 7750Sstevel@tonic-gate 7760Sstevel@tonic-gate if ((ret = px_lib_msi_setstate(dip, msi_num, 7770Sstevel@tonic-gate PCI_MSI_STATE_IDLE)) != DDI_SUCCESS) { 7780Sstevel@tonic-gate (void) px_rem_msiq_intr(dip, rdip, 779965Sgovinda hdlp, msiq_rec_type, msi_num, msiq_id); 7800Sstevel@tonic-gate return (ret); 7810Sstevel@tonic-gate } 7820Sstevel@tonic-gate 7830Sstevel@tonic-gate hdlp->ih_vector = msi_num; 7840Sstevel@tonic-gate break; 7850Sstevel@tonic-gate case DDI_INTROP_DUPVEC: 7861725Segillett DBG(DBG_INTROPS, dip, "px_msix_ops: dupisr - inum: %x, " 7871725Segillett "new_vector: %x\n", hdlp->ih_inum, hdlp->ih_scratch1); 7881725Segillett 7891725Segillett ret = pci_msix_dup(hdlp->ih_dip, hdlp->ih_inum, 7901725Segillett hdlp->ih_scratch1); 7910Sstevel@tonic-gate break; 7920Sstevel@tonic-gate case DDI_INTROP_REMISR: 7930Sstevel@tonic-gate msi_num = hdlp->ih_vector; 7940Sstevel@tonic-gate 7950Sstevel@tonic-gate if ((ret = px_lib_msi_getmsiq(dip, msi_num, 7960Sstevel@tonic-gate &msiq_id)) != DDI_SUCCESS) 7970Sstevel@tonic-gate return (ret); 7980Sstevel@tonic-gate 7990Sstevel@tonic-gate if ((ret = px_lib_msi_setstate(dip, msi_num, 800965Sgovinda PCI_MSI_STATE_IDLE)) != DDI_SUCCESS) 8010Sstevel@tonic-gate return (ret); 8020Sstevel@tonic-gate 8030Sstevel@tonic-gate ret = px_rem_msiq_intr(dip, rdip, 804965Sgovinda hdlp, msiq_rec_type, msi_num, msiq_id); 8050Sstevel@tonic-gate 8060Sstevel@tonic-gate hdlp->ih_vector = 0; 8070Sstevel@tonic-gate break; 8080Sstevel@tonic-gate case DDI_INTROP_ENABLE: 8090Sstevel@tonic-gate msi_num = hdlp->ih_vector; 8100Sstevel@tonic-gate 8110Sstevel@tonic-gate if ((ret = px_lib_msi_setvalid(dip, msi_num, 8120Sstevel@tonic-gate PCI_MSI_VALID)) != DDI_SUCCESS) 8130Sstevel@tonic-gate return (ret); 8140Sstevel@tonic-gate 8152755Segillett if ((pci_is_msi_enabled(rdip, hdlp->ih_type) != DDI_SUCCESS) || 8162755Segillett (hdlp->ih_type == DDI_INTR_TYPE_MSIX)) { 8170Sstevel@tonic-gate nintrs = i_ddi_intr_get_current_nintrs(hdlp->ih_dip); 8180Sstevel@tonic-gate 8190Sstevel@tonic-gate if ((ret = pci_msi_configure(rdip, hdlp->ih_type, 820965Sgovinda nintrs, hdlp->ih_inum, msi_addr, 8212755Segillett hdlp->ih_type == DDI_INTR_TYPE_MSIX ? 8222755Segillett msi_num : msi_num & ~(nintrs - 1))) != DDI_SUCCESS) 8230Sstevel@tonic-gate return (ret); 8240Sstevel@tonic-gate 8252755Segillett if ((ret = pci_msi_enable_mode(rdip, hdlp->ih_type)) 8262755Segillett != DDI_SUCCESS) 8270Sstevel@tonic-gate return (ret); 8280Sstevel@tonic-gate } 8290Sstevel@tonic-gate 830909Segillett if ((ret = pci_msi_clr_mask(rdip, hdlp->ih_type, 831909Segillett hdlp->ih_inum)) != DDI_SUCCESS) 832909Segillett return (ret); 833909Segillett 8341725Segillett if (hdlp->ih_flags & DDI_INTR_MSIX_DUP) 8351725Segillett break; 8361725Segillett 837909Segillett if ((ret = px_lib_msi_getmsiq(dip, msi_num, 838909Segillett &msiq_id)) != DDI_SUCCESS) 839909Segillett return (ret); 840909Segillett 841909Segillett ret = px_ib_update_intr_state(px_p, rdip, hdlp->ih_inum, 8422973Sgovinda px_msiqid_to_devino(px_p, msiq_id), hdlp->ih_pri, 8432973Sgovinda PX_INTR_STATE_ENABLE, msiq_rec_type, msi_num); 8440Sstevel@tonic-gate 8450Sstevel@tonic-gate break; 8460Sstevel@tonic-gate case DDI_INTROP_DISABLE: 8470Sstevel@tonic-gate msi_num = hdlp->ih_vector; 8480Sstevel@tonic-gate 8490Sstevel@tonic-gate if ((ret = pci_msi_set_mask(rdip, hdlp->ih_type, 8500Sstevel@tonic-gate hdlp->ih_inum)) != DDI_SUCCESS) 8510Sstevel@tonic-gate return (ret); 8520Sstevel@tonic-gate 853909Segillett if ((ret = px_lib_msi_setvalid(dip, msi_num, 854909Segillett PCI_MSI_INVALID)) != DDI_SUCCESS) 855909Segillett return (ret); 856909Segillett 8571725Segillett if (hdlp->ih_flags & DDI_INTR_MSIX_DUP) 8581725Segillett break; 8591725Segillett 860909Segillett if ((ret = px_lib_msi_getmsiq(dip, msi_num, 861909Segillett &msiq_id)) != DDI_SUCCESS) 862909Segillett return (ret); 863909Segillett 864909Segillett ret = px_ib_update_intr_state(px_p, rdip, 865909Segillett hdlp->ih_inum, px_msiqid_to_devino(px_p, msiq_id), 8662973Sgovinda hdlp->ih_pri, PX_INTR_STATE_DISABLE, msiq_rec_type, 8672973Sgovinda msi_num); 868909Segillett 8690Sstevel@tonic-gate break; 8700Sstevel@tonic-gate case DDI_INTROP_BLOCKENABLE: 8710Sstevel@tonic-gate nintrs = i_ddi_intr_get_current_nintrs(hdlp->ih_dip); 8720Sstevel@tonic-gate msi_num = hdlp->ih_vector; 8730Sstevel@tonic-gate 8740Sstevel@tonic-gate if ((ret = pci_msi_configure(rdip, hdlp->ih_type, 875965Sgovinda nintrs, hdlp->ih_inum, msi_addr, 8760Sstevel@tonic-gate msi_num & ~(nintrs - 1))) != DDI_SUCCESS) 8770Sstevel@tonic-gate return (ret); 8780Sstevel@tonic-gate 8790Sstevel@tonic-gate for (i = 0; i < nintrs; i++, msi_num++) { 8800Sstevel@tonic-gate if ((ret = px_lib_msi_setvalid(dip, msi_num, 8810Sstevel@tonic-gate PCI_MSI_VALID)) != DDI_SUCCESS) 8820Sstevel@tonic-gate return (ret); 883909Segillett 884909Segillett if ((ret = px_lib_msi_getmsiq(dip, msi_num, 885909Segillett &msiq_id)) != DDI_SUCCESS) 886909Segillett return (ret); 887909Segillett 888909Segillett if ((ret = px_ib_update_intr_state(px_p, rdip, 889909Segillett hdlp->ih_inum + i, px_msiqid_to_devino(px_p, 8902973Sgovinda msiq_id), hdlp->ih_pri, PX_INTR_STATE_ENABLE, 8912973Sgovinda msiq_rec_type, msi_num)) != DDI_SUCCESS) 892909Segillett return (ret); 8930Sstevel@tonic-gate } 8940Sstevel@tonic-gate 8952755Segillett ret = pci_msi_enable_mode(rdip, hdlp->ih_type); 8960Sstevel@tonic-gate break; 8970Sstevel@tonic-gate case DDI_INTROP_BLOCKDISABLE: 8980Sstevel@tonic-gate nintrs = i_ddi_intr_get_current_nintrs(hdlp->ih_dip); 8990Sstevel@tonic-gate msi_num = hdlp->ih_vector; 9000Sstevel@tonic-gate 9010Sstevel@tonic-gate if ((ret = pci_msi_disable_mode(rdip, hdlp->ih_type, 9022755Segillett hdlp->ih_cap & DDI_INTR_FLAG_BLOCK)) != DDI_SUCCESS) 9030Sstevel@tonic-gate return (ret); 9040Sstevel@tonic-gate 9050Sstevel@tonic-gate for (i = 0; i < nintrs; i++, msi_num++) { 9060Sstevel@tonic-gate if ((ret = px_lib_msi_setvalid(dip, msi_num, 9070Sstevel@tonic-gate PCI_MSI_INVALID)) != DDI_SUCCESS) 9080Sstevel@tonic-gate return (ret); 909909Segillett 910909Segillett if ((ret = px_lib_msi_getmsiq(dip, msi_num, 911909Segillett &msiq_id)) != DDI_SUCCESS) 912909Segillett return (ret); 913909Segillett 914909Segillett if ((ret = px_ib_update_intr_state(px_p, rdip, 915909Segillett hdlp->ih_inum + i, px_msiqid_to_devino(px_p, 9162973Sgovinda msiq_id), hdlp->ih_pri, PX_INTR_STATE_DISABLE, 9172973Sgovinda msiq_rec_type, msi_num)) != DDI_SUCCESS) 918909Segillett return (ret); 9190Sstevel@tonic-gate } 9200Sstevel@tonic-gate 9210Sstevel@tonic-gate break; 9220Sstevel@tonic-gate case DDI_INTROP_SETMASK: 9230Sstevel@tonic-gate ret = pci_msi_set_mask(rdip, hdlp->ih_type, hdlp->ih_inum); 9240Sstevel@tonic-gate break; 9250Sstevel@tonic-gate case DDI_INTROP_CLRMASK: 9260Sstevel@tonic-gate ret = pci_msi_clr_mask(rdip, hdlp->ih_type, hdlp->ih_inum); 9270Sstevel@tonic-gate break; 9280Sstevel@tonic-gate case DDI_INTROP_GETPENDING: 9290Sstevel@tonic-gate ret = pci_msi_get_pending(rdip, hdlp->ih_type, 9300Sstevel@tonic-gate hdlp->ih_inum, (int *)result); 9310Sstevel@tonic-gate break; 9320Sstevel@tonic-gate case DDI_INTROP_NINTRS: 9330Sstevel@tonic-gate ret = pci_msi_get_nintrs(rdip, hdlp->ih_type, (int *)result); 9340Sstevel@tonic-gate break; 9350Sstevel@tonic-gate case DDI_INTROP_NAVAIL: 9360Sstevel@tonic-gate /* XXX - a new interface may be needed */ 9370Sstevel@tonic-gate ret = pci_msi_get_nintrs(rdip, hdlp->ih_type, (int *)result); 9380Sstevel@tonic-gate break; 9390Sstevel@tonic-gate default: 9400Sstevel@tonic-gate ret = DDI_ENOTSUP; 9410Sstevel@tonic-gate break; 9420Sstevel@tonic-gate } 9430Sstevel@tonic-gate 9440Sstevel@tonic-gate return (ret); 9450Sstevel@tonic-gate } 9460Sstevel@tonic-gate 94766Sesolom static struct { 94866Sesolom kstat_named_t pxintr_ks_name; 94966Sesolom kstat_named_t pxintr_ks_type; 95066Sesolom kstat_named_t pxintr_ks_cpu; 95166Sesolom kstat_named_t pxintr_ks_pil; 95266Sesolom kstat_named_t pxintr_ks_time; 95366Sesolom kstat_named_t pxintr_ks_ino; 95466Sesolom kstat_named_t pxintr_ks_cookie; 95566Sesolom kstat_named_t pxintr_ks_devpath; 95666Sesolom kstat_named_t pxintr_ks_buspath; 95766Sesolom } pxintr_ks_template = { 95866Sesolom { "name", KSTAT_DATA_CHAR }, 95966Sesolom { "type", KSTAT_DATA_CHAR }, 96066Sesolom { "cpu", KSTAT_DATA_UINT64 }, 96166Sesolom { "pil", KSTAT_DATA_UINT64 }, 96266Sesolom { "time", KSTAT_DATA_UINT64 }, 96366Sesolom { "ino", KSTAT_DATA_UINT64 }, 96466Sesolom { "cookie", KSTAT_DATA_UINT64 }, 96566Sesolom { "devpath", KSTAT_DATA_STRING }, 96666Sesolom { "buspath", KSTAT_DATA_STRING }, 96766Sesolom }; 96866Sesolom 96966Sesolom static uint32_t pxintr_ks_instance; 9701811Sesolom static char ih_devpath[MAXPATHLEN]; 9711811Sesolom static char ih_buspath[MAXPATHLEN]; 97266Sesolom kmutex_t pxintr_ks_template_lock; 97366Sesolom 97466Sesolom int 97566Sesolom px_ks_update(kstat_t *ksp, int rw) 97666Sesolom { 97766Sesolom px_ih_t *ih_p = ksp->ks_private; 97866Sesolom int maxlen = sizeof (pxintr_ks_template.pxintr_ks_name.value.c); 9792973Sgovinda px_ino_pil_t *ipil_p = ih_p->ih_ipil_p; 9802973Sgovinda px_ino_t *ino_p = ipil_p->ipil_ino_p; 9812973Sgovinda px_t *px_p = ino_p->ino_ib_p->ib_px_p; 98266Sesolom devino_t ino; 98366Sesolom sysino_t sysino; 98466Sesolom 9852973Sgovinda ino = ino_p->ino_ino; 98666Sesolom (void) px_lib_intr_devino_to_sysino(px_p->px_dip, ino, &sysino); 98766Sesolom 98866Sesolom (void) snprintf(pxintr_ks_template.pxintr_ks_name.value.c, maxlen, 98966Sesolom "%s%d", ddi_driver_name(ih_p->ih_dip), 99066Sesolom ddi_get_instance(ih_p->ih_dip)); 99166Sesolom 99266Sesolom (void) ddi_pathname(ih_p->ih_dip, ih_devpath); 99366Sesolom (void) ddi_pathname(px_p->px_dip, ih_buspath); 99466Sesolom kstat_named_setstr(&pxintr_ks_template.pxintr_ks_devpath, ih_devpath); 99566Sesolom kstat_named_setstr(&pxintr_ks_template.pxintr_ks_buspath, ih_buspath); 99666Sesolom 9971087Sschwartz if (ih_p->ih_intr_state == PX_INTR_STATE_ENABLE) { 9981087Sschwartz 9991087Sschwartz (void) strcpy(pxintr_ks_template.pxintr_ks_type.value.c, 10001087Sschwartz (ih_p->ih_rec_type == 0) ? "fixed" : "msi"); 10012973Sgovinda pxintr_ks_template.pxintr_ks_cpu.value.ui64 = ino_p->ino_cpuid; 10022973Sgovinda pxintr_ks_template.pxintr_ks_pil.value.ui64 = ipil_p->ipil_pil; 10031087Sschwartz pxintr_ks_template.pxintr_ks_time.value.ui64 = ih_p->ih_nsec + 10041087Sschwartz (uint64_t)tick2ns((hrtime_t)ih_p->ih_ticks, 10052973Sgovinda ino_p->ino_cpuid); 10061087Sschwartz pxintr_ks_template.pxintr_ks_ino.value.ui64 = ino; 10071087Sschwartz pxintr_ks_template.pxintr_ks_cookie.value.ui64 = sysino; 10081087Sschwartz } else { 10091087Sschwartz (void) strcpy(pxintr_ks_template.pxintr_ks_type.value.c, 10101087Sschwartz "disabled"); 10111087Sschwartz pxintr_ks_template.pxintr_ks_cpu.value.ui64 = 0; 10121087Sschwartz pxintr_ks_template.pxintr_ks_pil.value.ui64 = 0; 10131087Sschwartz pxintr_ks_template.pxintr_ks_time.value.ui64 = 0; 10141087Sschwartz pxintr_ks_template.pxintr_ks_ino.value.ui64 = 0; 10151087Sschwartz pxintr_ks_template.pxintr_ks_cookie.value.ui64 = 0; 10161087Sschwartz } 101766Sesolom return (0); 101866Sesolom } 101966Sesolom 102066Sesolom void 102166Sesolom px_create_intr_kstats(px_ih_t *ih_p) 102266Sesolom { 102366Sesolom msiq_rec_type_t rec_type = ih_p->ih_rec_type; 102466Sesolom 102566Sesolom ASSERT(ih_p->ih_ksp == NULL); 102666Sesolom 102766Sesolom /* 102866Sesolom * Create pci_intrs::: kstats for all ih types except messages, 102966Sesolom * which represent unusual conditions and don't need to be tracked. 103066Sesolom */ 103166Sesolom if (rec_type == 0 || rec_type == MSI32_REC || rec_type == MSI64_REC) { 103266Sesolom ih_p->ih_ksp = kstat_create("pci_intrs", 103366Sesolom atomic_inc_32_nv(&pxintr_ks_instance), "config", 103466Sesolom "interrupts", KSTAT_TYPE_NAMED, 103566Sesolom sizeof (pxintr_ks_template) / sizeof (kstat_named_t), 103666Sesolom KSTAT_FLAG_VIRTUAL); 103766Sesolom } 103866Sesolom if (ih_p->ih_ksp != NULL) { 103966Sesolom ih_p->ih_ksp->ks_data_size += MAXPATHLEN * 2; 104066Sesolom ih_p->ih_ksp->ks_lock = &pxintr_ks_template_lock; 104166Sesolom ih_p->ih_ksp->ks_data = &pxintr_ks_template; 104266Sesolom ih_p->ih_ksp->ks_private = ih_p; 104366Sesolom ih_p->ih_ksp->ks_update = px_ks_update; 104466Sesolom } 104566Sesolom } 104666Sesolom 1047693Sgovinda /* 1048693Sgovinda * px_add_intx_intr: 1049693Sgovinda * 1050693Sgovinda * This function is called to register INTx and legacy hardware 1051693Sgovinda * interrupt pins interrupts. 1052693Sgovinda */ 10530Sstevel@tonic-gate int 10540Sstevel@tonic-gate px_add_intx_intr(dev_info_t *dip, dev_info_t *rdip, 10550Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp) 10560Sstevel@tonic-gate { 10570Sstevel@tonic-gate px_t *px_p = INST_TO_STATE(ddi_get_instance(dip)); 10580Sstevel@tonic-gate px_ib_t *ib_p = px_p->px_ib_p; 10590Sstevel@tonic-gate devino_t ino; 10600Sstevel@tonic-gate px_ih_t *ih_p; 10612973Sgovinda px_ino_t *ino_p; 10622973Sgovinda px_ino_pil_t *ipil_p, *ipil_list; 10630Sstevel@tonic-gate int32_t weight; 10640Sstevel@tonic-gate int ret = DDI_SUCCESS; 10650Sstevel@tonic-gate 10660Sstevel@tonic-gate ino = hdlp->ih_vector; 10670Sstevel@tonic-gate 10680Sstevel@tonic-gate DBG(DBG_A_INTX, dip, "px_add_intx_intr: rdip=%s%d ino=%x " 10690Sstevel@tonic-gate "handler=%x arg1=%x arg2=%x\n", ddi_driver_name(rdip), 10700Sstevel@tonic-gate ddi_get_instance(rdip), ino, hdlp->ih_cb_func, 10710Sstevel@tonic-gate hdlp->ih_cb_arg1, hdlp->ih_cb_arg2); 10720Sstevel@tonic-gate 10730Sstevel@tonic-gate ih_p = px_ib_alloc_ih(rdip, hdlp->ih_inum, 10740Sstevel@tonic-gate hdlp->ih_cb_func, hdlp->ih_cb_arg1, hdlp->ih_cb_arg2, 0, 0); 10750Sstevel@tonic-gate 10760Sstevel@tonic-gate mutex_enter(&ib_p->ib_ino_lst_mutex); 10770Sstevel@tonic-gate 10782973Sgovinda ino_p = px_ib_locate_ino(ib_p, ino); 10792973Sgovinda ipil_list = ino_p ? ino_p->ino_ipil_p : NULL; 10802973Sgovinda 10812973Sgovinda /* Sharing ino */ 10822973Sgovinda if (ino_p && (ipil_p = px_ib_ino_locate_ipil(ino_p, hdlp->ih_pri))) { 10832973Sgovinda if (px_ib_intr_locate_ih(ipil_p, rdip, hdlp->ih_inum, 0, 0)) { 10840Sstevel@tonic-gate DBG(DBG_A_INTX, dip, "px_add_intx_intr: " 10852973Sgovinda "dup intr #%d\n", hdlp->ih_inum); 10860Sstevel@tonic-gate 10870Sstevel@tonic-gate ret = DDI_FAILURE; 10880Sstevel@tonic-gate goto fail1; 10890Sstevel@tonic-gate } 10900Sstevel@tonic-gate 10910Sstevel@tonic-gate /* Save mondo value in hdlp */ 10920Sstevel@tonic-gate hdlp->ih_vector = ino_p->ino_sysino; 10930Sstevel@tonic-gate 10942973Sgovinda if ((ret = px_ib_ino_add_intr(px_p, ipil_p, 10952973Sgovinda ih_p)) != DDI_SUCCESS) 10960Sstevel@tonic-gate goto fail1; 10972973Sgovinda 10982973Sgovinda goto ino_done; 10992973Sgovinda } 11000Sstevel@tonic-gate 11012973Sgovinda if (hdlp->ih_pri == 0) 11022973Sgovinda hdlp->ih_pri = px_class_to_pil(rdip); 11032973Sgovinda 11042973Sgovinda ipil_p = px_ib_new_ino_pil(ib_p, ino, hdlp->ih_pri, ih_p); 11052973Sgovinda ino_p = ipil_p->ipil_ino_p; 11060Sstevel@tonic-gate 11072973Sgovinda /* Save mondo value in hdlp */ 11082973Sgovinda hdlp->ih_vector = ino_p->ino_sysino; 11090Sstevel@tonic-gate 11102973Sgovinda DBG(DBG_A_INTX, dip, "px_add_intx_intr: pil=0x%x mondo=0x%x\n", 11112973Sgovinda hdlp->ih_pri, hdlp->ih_vector); 11120Sstevel@tonic-gate 11132973Sgovinda DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp, 11142973Sgovinda (ddi_intr_handler_t *)px_intx_intr, (caddr_t)ipil_p, NULL); 11150Sstevel@tonic-gate 11162973Sgovinda ret = i_ddi_add_ivintr(hdlp); 11170Sstevel@tonic-gate 11182973Sgovinda /* 11192973Sgovinda * Restore original interrupt handler 11202973Sgovinda * and arguments in interrupt handle. 11212973Sgovinda */ 11222973Sgovinda DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp, ih_p->ih_handler, 11232973Sgovinda ih_p->ih_handler_arg1, ih_p->ih_handler_arg2); 11240Sstevel@tonic-gate 11252973Sgovinda if (ret != DDI_SUCCESS) 11262973Sgovinda goto fail2; 11270Sstevel@tonic-gate 11282973Sgovinda /* Save the pil for this ino */ 11292973Sgovinda ipil_p->ipil_pil = hdlp->ih_pri; 11300Sstevel@tonic-gate 11312973Sgovinda /* Select cpu, saving it for sharing and removal */ 11322973Sgovinda if (ipil_list == NULL) { 11330Sstevel@tonic-gate ino_p->ino_cpuid = intr_dist_cpuid(); 11340Sstevel@tonic-gate 11350Sstevel@tonic-gate /* Enable interrupt */ 11360Sstevel@tonic-gate px_ib_intr_enable(px_p, ino_p->ino_cpuid, ino); 11370Sstevel@tonic-gate } 11380Sstevel@tonic-gate 11392973Sgovinda ino_done: 11402973Sgovinda /* Add weight to the cpu that we are already targeting */ 11410Sstevel@tonic-gate weight = px_class_to_intr_weight(rdip); 11420Sstevel@tonic-gate intr_dist_cpuid_add_device_weight(ino_p->ino_cpuid, rdip, weight); 11430Sstevel@tonic-gate 11442973Sgovinda ih_p->ih_ipil_p = ipil_p; 114566Sesolom px_create_intr_kstats(ih_p); 11460Sstevel@tonic-gate if (ih_p->ih_ksp) 11470Sstevel@tonic-gate kstat_install(ih_p->ih_ksp); 11480Sstevel@tonic-gate mutex_exit(&ib_p->ib_ino_lst_mutex); 11490Sstevel@tonic-gate 11500Sstevel@tonic-gate DBG(DBG_A_INTX, dip, "px_add_intx_intr: done! Interrupt 0x%x pil=%x\n", 11510Sstevel@tonic-gate ino_p->ino_sysino, hdlp->ih_pri); 11520Sstevel@tonic-gate 11530Sstevel@tonic-gate return (ret); 11540Sstevel@tonic-gate fail2: 11552973Sgovinda px_ib_delete_ino_pil(ib_p, ipil_p); 11560Sstevel@tonic-gate fail1: 11570Sstevel@tonic-gate if (ih_p->ih_config_handle) 11580Sstevel@tonic-gate pci_config_teardown(&ih_p->ih_config_handle); 11590Sstevel@tonic-gate 11600Sstevel@tonic-gate mutex_exit(&ib_p->ib_ino_lst_mutex); 11610Sstevel@tonic-gate kmem_free(ih_p, sizeof (px_ih_t)); 11620Sstevel@tonic-gate 11630Sstevel@tonic-gate DBG(DBG_A_INTX, dip, "px_add_intx_intr: Failed! Interrupt 0x%x " 11640Sstevel@tonic-gate "pil=%x\n", ino_p->ino_sysino, hdlp->ih_pri); 11650Sstevel@tonic-gate 11660Sstevel@tonic-gate return (ret); 11670Sstevel@tonic-gate } 11680Sstevel@tonic-gate 1169693Sgovinda /* 1170693Sgovinda * px_rem_intx_intr: 1171693Sgovinda * 1172693Sgovinda * This function is called to unregister INTx and legacy hardware 1173693Sgovinda * interrupt pins interrupts. 1174693Sgovinda */ 11750Sstevel@tonic-gate int 11760Sstevel@tonic-gate px_rem_intx_intr(dev_info_t *dip, dev_info_t *rdip, 11770Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp) 11780Sstevel@tonic-gate { 11790Sstevel@tonic-gate px_t *px_p = INST_TO_STATE(ddi_get_instance(dip)); 11800Sstevel@tonic-gate px_ib_t *ib_p = px_p->px_ib_p; 11810Sstevel@tonic-gate devino_t ino; 11820Sstevel@tonic-gate cpuid_t curr_cpu; 11832973Sgovinda px_ino_t *ino_p; 11842973Sgovinda px_ino_pil_t *ipil_p; 11850Sstevel@tonic-gate px_ih_t *ih_p; 11860Sstevel@tonic-gate int ret = DDI_SUCCESS; 11870Sstevel@tonic-gate 11880Sstevel@tonic-gate ino = hdlp->ih_vector; 11890Sstevel@tonic-gate 11900Sstevel@tonic-gate DBG(DBG_R_INTX, dip, "px_rem_intx_intr: rdip=%s%d ino=%x\n", 11910Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip), ino); 11920Sstevel@tonic-gate 11930Sstevel@tonic-gate mutex_enter(&ib_p->ib_ino_lst_mutex); 11940Sstevel@tonic-gate 11950Sstevel@tonic-gate ino_p = px_ib_locate_ino(ib_p, ino); 11962973Sgovinda ipil_p = px_ib_ino_locate_ipil(ino_p, hdlp->ih_pri); 11972973Sgovinda ih_p = px_ib_intr_locate_ih(ipil_p, rdip, hdlp->ih_inum, 0, 0); 11980Sstevel@tonic-gate 11990Sstevel@tonic-gate /* Get the current cpu */ 12000Sstevel@tonic-gate if ((ret = px_lib_intr_gettarget(px_p->px_dip, ino_p->ino_sysino, 12010Sstevel@tonic-gate &curr_cpu)) != DDI_SUCCESS) 12020Sstevel@tonic-gate goto fail; 12030Sstevel@tonic-gate 12042973Sgovinda if ((ret = px_ib_ino_rem_intr(px_p, ipil_p, ih_p)) != DDI_SUCCESS) 12050Sstevel@tonic-gate goto fail; 12060Sstevel@tonic-gate 12070Sstevel@tonic-gate intr_dist_cpuid_rem_device_weight(ino_p->ino_cpuid, rdip); 12080Sstevel@tonic-gate 12092973Sgovinda if (ipil_p->ipil_ih_size == 0) { 12100Sstevel@tonic-gate hdlp->ih_vector = ino_p->ino_sysino; 12110Sstevel@tonic-gate i_ddi_rem_ivintr(hdlp); 12120Sstevel@tonic-gate 12132973Sgovinda px_ib_delete_ino_pil(ib_p, ipil_p); 12142973Sgovinda } 12152973Sgovinda 12162973Sgovinda if (ino_p->ino_ipil_size == 0) { 12172973Sgovinda kmem_free(ino_p, sizeof (px_ino_t)); 12180Sstevel@tonic-gate } else { 1219*3780Segillett /* Re-enable interrupt only if mapping register still shared */ 1220*3780Segillett PX_INTR_ENABLE(px_p->px_dip, ino_p->ino_sysino, curr_cpu); 12210Sstevel@tonic-gate } 12220Sstevel@tonic-gate 12230Sstevel@tonic-gate fail: 12240Sstevel@tonic-gate mutex_exit(&ib_p->ib_ino_lst_mutex); 12250Sstevel@tonic-gate return (ret); 12260Sstevel@tonic-gate } 12270Sstevel@tonic-gate 1228693Sgovinda /* 1229693Sgovinda * px_add_msiq_intr: 1230693Sgovinda * 1231693Sgovinda * This function is called to register MSI/Xs and PCIe message interrupts. 1232693Sgovinda */ 12330Sstevel@tonic-gate int 12340Sstevel@tonic-gate px_add_msiq_intr(dev_info_t *dip, dev_info_t *rdip, 12350Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, msiq_rec_type_t rec_type, 12360Sstevel@tonic-gate msgcode_t msg_code, msiqid_t *msiq_id_p) 12370Sstevel@tonic-gate { 12380Sstevel@tonic-gate px_t *px_p = INST_TO_STATE(ddi_get_instance(dip)); 12390Sstevel@tonic-gate px_ib_t *ib_p = px_p->px_ib_p; 12400Sstevel@tonic-gate px_msiq_state_t *msiq_state_p = &ib_p->ib_msiq_state; 12410Sstevel@tonic-gate devino_t ino; 12420Sstevel@tonic-gate px_ih_t *ih_p; 12432973Sgovinda px_ino_t *ino_p; 12442973Sgovinda px_ino_pil_t *ipil_p, *ipil_list; 12450Sstevel@tonic-gate int32_t weight; 12460Sstevel@tonic-gate int ret = DDI_SUCCESS; 12470Sstevel@tonic-gate 12480Sstevel@tonic-gate DBG(DBG_MSIQ, dip, "px_add_msiq_intr: rdip=%s%d handler=%x " 12490Sstevel@tonic-gate "arg1=%x arg2=%x\n", ddi_driver_name(rdip), ddi_get_instance(rdip), 12500Sstevel@tonic-gate hdlp->ih_cb_func, hdlp->ih_cb_arg1, hdlp->ih_cb_arg2); 12510Sstevel@tonic-gate 12520Sstevel@tonic-gate if ((ret = px_msiq_alloc(px_p, rec_type, msiq_id_p)) != DDI_SUCCESS) { 12530Sstevel@tonic-gate DBG(DBG_MSIQ, dip, "px_add_msiq_intr: " 12540Sstevel@tonic-gate "msiq allocation failed\n"); 12550Sstevel@tonic-gate return (ret); 12560Sstevel@tonic-gate } 12570Sstevel@tonic-gate 12580Sstevel@tonic-gate ino = px_msiqid_to_devino(px_p, *msiq_id_p); 12590Sstevel@tonic-gate 12600Sstevel@tonic-gate ih_p = px_ib_alloc_ih(rdip, hdlp->ih_inum, hdlp->ih_cb_func, 12610Sstevel@tonic-gate hdlp->ih_cb_arg1, hdlp->ih_cb_arg2, rec_type, msg_code); 12620Sstevel@tonic-gate 12630Sstevel@tonic-gate mutex_enter(&ib_p->ib_ino_lst_mutex); 12640Sstevel@tonic-gate 12652973Sgovinda ino_p = px_ib_locate_ino(ib_p, ino); 12662973Sgovinda ipil_list = ino_p ? ino_p->ino_ipil_p : NULL; 12672973Sgovinda 12682973Sgovinda /* Sharing ino */ 12692973Sgovinda if (ino_p && (ipil_p = px_ib_ino_locate_ipil(ino_p, hdlp->ih_pri))) { 12702973Sgovinda if (px_ib_intr_locate_ih(ipil_p, rdip, 12712973Sgovinda hdlp->ih_inum, rec_type, msg_code)) { 12720Sstevel@tonic-gate DBG(DBG_MSIQ, dip, "px_add_msiq_intr: " 12732973Sgovinda "dup intr #%d\n", hdlp->ih_inum); 12740Sstevel@tonic-gate 12750Sstevel@tonic-gate ret = DDI_FAILURE; 12760Sstevel@tonic-gate goto fail1; 12770Sstevel@tonic-gate } 12780Sstevel@tonic-gate 12790Sstevel@tonic-gate /* Save mondo value in hdlp */ 12800Sstevel@tonic-gate hdlp->ih_vector = ino_p->ino_sysino; 12810Sstevel@tonic-gate 12822973Sgovinda if ((ret = px_ib_ino_add_intr(px_p, ipil_p, 12832973Sgovinda ih_p)) != DDI_SUCCESS) 12842973Sgovinda goto fail1; 12852973Sgovinda 12862973Sgovinda goto ino_done; 12872973Sgovinda } 12882973Sgovinda 12892973Sgovinda if (hdlp->ih_pri == 0) 12902973Sgovinda hdlp->ih_pri = px_class_to_pil(rdip); 12910Sstevel@tonic-gate 12922973Sgovinda ipil_p = px_ib_new_ino_pil(ib_p, ino, hdlp->ih_pri, ih_p); 12932973Sgovinda ino_p = ipil_p->ipil_ino_p; 12942973Sgovinda 12952973Sgovinda ino_p->ino_msiq_p = msiq_state_p->msiq_p + 12962973Sgovinda (*msiq_id_p - msiq_state_p->msiq_1st_msiq_id); 12970Sstevel@tonic-gate 12982973Sgovinda /* Save mondo value in hdlp */ 12992973Sgovinda hdlp->ih_vector = ino_p->ino_sysino; 13002973Sgovinda 13012973Sgovinda DBG(DBG_MSIQ, dip, "px_add_msiq_intr: pil=0x%x mondo=0x%x\n", 13022973Sgovinda hdlp->ih_pri, hdlp->ih_vector); 13030Sstevel@tonic-gate 13042973Sgovinda DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp, 13052973Sgovinda (ddi_intr_handler_t *)px_msiq_intr, (caddr_t)ipil_p, NULL); 13062973Sgovinda 13072973Sgovinda ret = i_ddi_add_ivintr(hdlp); 13080Sstevel@tonic-gate 13092973Sgovinda /* 13102973Sgovinda * Restore original interrupt handler 13112973Sgovinda * and arguments in interrupt handle. 13122973Sgovinda */ 13132973Sgovinda DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp, ih_p->ih_handler, 13142973Sgovinda ih_p->ih_handler_arg1, ih_p->ih_handler_arg2); 13150Sstevel@tonic-gate 13162973Sgovinda if (ret != DDI_SUCCESS) 13172973Sgovinda goto fail2; 13182973Sgovinda 13192973Sgovinda /* Save the pil for this ino */ 13202973Sgovinda ipil_p->ipil_pil = hdlp->ih_pri; 13212973Sgovinda 13222973Sgovinda /* Select cpu, saving it for sharing and removal */ 13232973Sgovinda if (ipil_list == NULL) { 13242973Sgovinda ino_p->ino_cpuid = intr_dist_cpuid(); 13250Sstevel@tonic-gate 13260Sstevel@tonic-gate /* Enable MSIQ */ 13270Sstevel@tonic-gate px_lib_msiq_setstate(dip, *msiq_id_p, PCI_MSIQ_STATE_IDLE); 13280Sstevel@tonic-gate px_lib_msiq_setvalid(dip, *msiq_id_p, PCI_MSIQ_VALID); 13290Sstevel@tonic-gate 13300Sstevel@tonic-gate /* Enable interrupt */ 13312973Sgovinda px_ib_intr_enable(px_p, ino_p->ino_cpuid, ino); 13320Sstevel@tonic-gate } 13330Sstevel@tonic-gate 13342973Sgovinda ino_done: 13352973Sgovinda /* Add weight to the cpu that we are already targeting */ 13360Sstevel@tonic-gate weight = px_class_to_intr_weight(rdip); 13370Sstevel@tonic-gate intr_dist_cpuid_add_device_weight(ino_p->ino_cpuid, rdip, weight); 13380Sstevel@tonic-gate 13392973Sgovinda ih_p->ih_ipil_p = ipil_p; 134066Sesolom px_create_intr_kstats(ih_p); 13410Sstevel@tonic-gate if (ih_p->ih_ksp) 13420Sstevel@tonic-gate kstat_install(ih_p->ih_ksp); 13430Sstevel@tonic-gate mutex_exit(&ib_p->ib_ino_lst_mutex); 13440Sstevel@tonic-gate 13450Sstevel@tonic-gate DBG(DBG_MSIQ, dip, "px_add_msiq_intr: done! Interrupt 0x%x pil=%x\n", 13460Sstevel@tonic-gate ino_p->ino_sysino, hdlp->ih_pri); 13470Sstevel@tonic-gate 13480Sstevel@tonic-gate return (ret); 13490Sstevel@tonic-gate fail2: 13502973Sgovinda px_ib_delete_ino_pil(ib_p, ipil_p); 13510Sstevel@tonic-gate fail1: 13520Sstevel@tonic-gate if (ih_p->ih_config_handle) 13530Sstevel@tonic-gate pci_config_teardown(&ih_p->ih_config_handle); 13540Sstevel@tonic-gate 13550Sstevel@tonic-gate mutex_exit(&ib_p->ib_ino_lst_mutex); 13560Sstevel@tonic-gate kmem_free(ih_p, sizeof (px_ih_t)); 13570Sstevel@tonic-gate 13580Sstevel@tonic-gate DBG(DBG_MSIQ, dip, "px_add_msiq_intr: Failed! Interrupt 0x%x pil=%x\n", 13590Sstevel@tonic-gate ino_p->ino_sysino, hdlp->ih_pri); 13600Sstevel@tonic-gate 13610Sstevel@tonic-gate return (ret); 13620Sstevel@tonic-gate } 13630Sstevel@tonic-gate 1364693Sgovinda /* 1365693Sgovinda * px_rem_msiq_intr: 1366693Sgovinda * 1367693Sgovinda * This function is called to unregister MSI/Xs and PCIe message interrupts. 1368693Sgovinda */ 13690Sstevel@tonic-gate int 13700Sstevel@tonic-gate px_rem_msiq_intr(dev_info_t *dip, dev_info_t *rdip, 13710Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, msiq_rec_type_t rec_type, 13720Sstevel@tonic-gate msgcode_t msg_code, msiqid_t msiq_id) 13730Sstevel@tonic-gate { 13740Sstevel@tonic-gate px_t *px_p = INST_TO_STATE(ddi_get_instance(dip)); 13750Sstevel@tonic-gate px_ib_t *ib_p = px_p->px_ib_p; 13760Sstevel@tonic-gate devino_t ino = px_msiqid_to_devino(px_p, msiq_id); 13770Sstevel@tonic-gate cpuid_t curr_cpu; 13782973Sgovinda px_ino_t *ino_p; 13792973Sgovinda px_ino_pil_t *ipil_p; 13800Sstevel@tonic-gate px_ih_t *ih_p; 13810Sstevel@tonic-gate int ret = DDI_SUCCESS; 13820Sstevel@tonic-gate 13830Sstevel@tonic-gate DBG(DBG_MSIQ, dip, "px_rem_msiq_intr: rdip=%s%d msiq_id=%x ino=%x\n", 13840Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip), msiq_id, ino); 13850Sstevel@tonic-gate 13860Sstevel@tonic-gate mutex_enter(&ib_p->ib_ino_lst_mutex); 13870Sstevel@tonic-gate 13880Sstevel@tonic-gate ino_p = px_ib_locate_ino(ib_p, ino); 13892973Sgovinda ipil_p = px_ib_ino_locate_ipil(ino_p, hdlp->ih_pri); 13902973Sgovinda ih_p = px_ib_intr_locate_ih(ipil_p, rdip, hdlp->ih_inum, rec_type, 13912973Sgovinda msg_code); 13920Sstevel@tonic-gate 13930Sstevel@tonic-gate /* Get the current cpu */ 13940Sstevel@tonic-gate if ((ret = px_lib_intr_gettarget(px_p->px_dip, ino_p->ino_sysino, 13950Sstevel@tonic-gate &curr_cpu)) != DDI_SUCCESS) 13960Sstevel@tonic-gate goto fail; 13970Sstevel@tonic-gate 13982973Sgovinda if ((ret = px_ib_ino_rem_intr(px_p, ipil_p, ih_p)) != DDI_SUCCESS) 13990Sstevel@tonic-gate goto fail; 14000Sstevel@tonic-gate 14010Sstevel@tonic-gate intr_dist_cpuid_rem_device_weight(ino_p->ino_cpuid, rdip); 14020Sstevel@tonic-gate 14032973Sgovinda if (ipil_p->ipil_ih_size == 0) { 14040Sstevel@tonic-gate hdlp->ih_vector = ino_p->ino_sysino; 14050Sstevel@tonic-gate i_ddi_rem_ivintr(hdlp); 14060Sstevel@tonic-gate 14072973Sgovinda px_ib_delete_ino_pil(ib_p, ipil_p); 14082973Sgovinda 14092973Sgovinda if (ino_p->ino_ipil_size == 0) 14102973Sgovinda px_lib_msiq_setvalid(dip, 14112973Sgovinda px_devino_to_msiqid(px_p, ino), PCI_MSIQ_INVALID); 14120Sstevel@tonic-gate 14130Sstevel@tonic-gate (void) px_msiq_free(px_p, msiq_id); 14142973Sgovinda } 14152973Sgovinda 14162973Sgovinda if (ino_p->ino_ipil_size == 0) { 14172973Sgovinda kmem_free(ino_p, sizeof (px_ino_t)); 14180Sstevel@tonic-gate } else { 1419*3780Segillett /* Re-enable interrupt only if mapping register still shared */ 1420*3780Segillett PX_INTR_ENABLE(px_p->px_dip, ino_p->ino_sysino, curr_cpu); 14210Sstevel@tonic-gate } 14220Sstevel@tonic-gate 14230Sstevel@tonic-gate fail: 14240Sstevel@tonic-gate mutex_exit(&ib_p->ib_ino_lst_mutex); 14250Sstevel@tonic-gate return (ret); 14260Sstevel@tonic-gate } 1427