10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 220Sstevel@tonic-gate /* 230Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 280Sstevel@tonic-gate 290Sstevel@tonic-gate /* 300Sstevel@tonic-gate * PX nexus interrupt handling: 310Sstevel@tonic-gate * PX device interrupt handler wrapper 320Sstevel@tonic-gate * PIL lookup routine 330Sstevel@tonic-gate * PX device interrupt related initchild code 340Sstevel@tonic-gate */ 350Sstevel@tonic-gate 360Sstevel@tonic-gate #include <sys/types.h> 370Sstevel@tonic-gate #include <sys/kmem.h> 380Sstevel@tonic-gate #include <sys/async.h> 390Sstevel@tonic-gate #include <sys/spl.h> 400Sstevel@tonic-gate #include <sys/sunddi.h> 41*27Sjchu #include <sys/fm/protocol.h> 42*27Sjchu #include <sys/fm/util.h> 430Sstevel@tonic-gate #include <sys/machsystm.h> /* e_ddi_nodeid_to_dip() */ 440Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 450Sstevel@tonic-gate #include <sys/sdt.h> 460Sstevel@tonic-gate #include <sys/atomic.h> 470Sstevel@tonic-gate #include "px_obj.h" 48*27Sjchu #include <sys/ontrap.h> 49*27Sjchu #include <sys/membar.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 740Sstevel@tonic-gate px_spurintr(px_ib_ino_info_t *ino_p) 750Sstevel@tonic-gate { 760Sstevel@tonic-gate px_ih_t *ih_p = ino_p->ino_ih_start; 770Sstevel@tonic-gate px_t *px_p = ino_p->ino_ib_p->ib_px_p; 780Sstevel@tonic-gate char *err_fmt_str; 790Sstevel@tonic-gate int i; 800Sstevel@tonic-gate 810Sstevel@tonic-gate if (ino_p->ino_unclaimed > px_unclaimed_intr_max) 820Sstevel@tonic-gate return (DDI_INTR_CLAIMED); 830Sstevel@tonic-gate 840Sstevel@tonic-gate if (!ino_p->ino_unclaimed) 850Sstevel@tonic-gate ino_p->ino_spurintr_begin = ddi_get_lbolt(); 860Sstevel@tonic-gate 870Sstevel@tonic-gate ino_p->ino_unclaimed++; 880Sstevel@tonic-gate 890Sstevel@tonic-gate if (ino_p->ino_unclaimed <= 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) { 940Sstevel@tonic-gate ino_p->ino_unclaimed = 0; 950Sstevel@tonic-gate goto clear; 960Sstevel@tonic-gate } 970Sstevel@tonic-gate err_fmt_str = "%s%d: ino 0x%x blocked"; 980Sstevel@tonic-gate goto warn; 990Sstevel@tonic-gate clear: 1000Sstevel@tonic-gate /* Clear the pending state */ 1010Sstevel@tonic-gate if (px_lib_intr_setstate(px_p->px_dip, ino_p->ino_sysino, 1020Sstevel@tonic-gate INTR_IDLE_STATE) != DDI_SUCCESS) 1030Sstevel@tonic-gate return (DDI_INTR_UNCLAIMED); 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate err_fmt_str = "!%s%d: spurious interrupt from ino 0x%x"; 1060Sstevel@tonic-gate warn: 1070Sstevel@tonic-gate cmn_err(CE_WARN, err_fmt_str, NAMEINST(px_p->px_dip), ino_p->ino_ino); 1080Sstevel@tonic-gate for (i = 0; i < ino_p->ino_ih_size; i++, ih_p = ih_p->ih_next) 1090Sstevel@tonic-gate cmn_err(CE_CONT, "!%s-%d#%x ", NAMEINST(ih_p->ih_dip), 1100Sstevel@tonic-gate ih_p->ih_inum); 1110Sstevel@tonic-gate cmn_err(CE_CONT, "!\n"); 1120Sstevel@tonic-gate return (DDI_INTR_CLAIMED); 1130Sstevel@tonic-gate } 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate extern uint64_t intr_get_time(void); 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate /* 1180Sstevel@tonic-gate * px_intx_intr (legacy or intx interrupt handler) 1190Sstevel@tonic-gate * 1200Sstevel@tonic-gate * This routine is used as wrapper around interrupt handlers installed by child 1210Sstevel@tonic-gate * device drivers. This routine invokes the driver interrupt handlers and 1220Sstevel@tonic-gate * examines the return codes. 1230Sstevel@tonic-gate * 1240Sstevel@tonic-gate * There is a count of unclaimed interrupts kept on a per-ino basis. If at 1250Sstevel@tonic-gate * least one handler claims the interrupt then the counter is halved and the 1260Sstevel@tonic-gate * interrupt state machine is idled. If no handler claims the interrupt then 1270Sstevel@tonic-gate * the counter is incremented by one and the state machine is idled. 1280Sstevel@tonic-gate * If the count ever reaches the limit value set by pci_unclaimed_intr_max 1290Sstevel@tonic-gate * then the interrupt state machine is not idled thus preventing any further 1300Sstevel@tonic-gate * interrupts on that ino. The state machine will only be idled again if a 1310Sstevel@tonic-gate * handler is subsequently added or removed. 1320Sstevel@tonic-gate * 1330Sstevel@tonic-gate * return value: DDI_INTR_CLAIMED if any handlers claimed the interrupt, 1340Sstevel@tonic-gate * DDI_INTR_UNCLAIMED otherwise. 1350Sstevel@tonic-gate */ 1360Sstevel@tonic-gate uint_t 1370Sstevel@tonic-gate px_intx_intr(caddr_t arg) 1380Sstevel@tonic-gate { 1390Sstevel@tonic-gate px_ib_ino_info_t *ino_p = (px_ib_ino_info_t *)arg; 1400Sstevel@tonic-gate px_t *px_p = ino_p->ino_ib_p->ib_px_p; 1410Sstevel@tonic-gate px_ih_t *ih_p = ino_p->ino_ih_start; 1420Sstevel@tonic-gate uint_t result = 0, r; 1430Sstevel@tonic-gate int i; 1440Sstevel@tonic-gate 1450Sstevel@tonic-gate DBG(DBG_INTX_INTR, px_p->px_dip, "px_intx_intr:" 1460Sstevel@tonic-gate "ino=%x sysino=%llx pil=%x ih_size=%x ih_lst=%x\n", 1470Sstevel@tonic-gate ino_p->ino_ino, ino_p->ino_sysino, ino_p->ino_pil, 1480Sstevel@tonic-gate ino_p->ino_ih_size, ino_p->ino_ih_head); 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate for (i = 0; i < ino_p->ino_ih_size; i++, ih_p = ih_p->ih_next) { 1510Sstevel@tonic-gate dev_info_t *dip = ih_p->ih_dip; 1520Sstevel@tonic-gate uint_t (*handler)() = ih_p->ih_handler; 1530Sstevel@tonic-gate caddr_t arg1 = ih_p->ih_handler_arg1; 1540Sstevel@tonic-gate caddr_t arg2 = ih_p->ih_handler_arg2; 1550Sstevel@tonic-gate 1560Sstevel@tonic-gate if (ih_p->ih_intr_state == PX_INTR_STATE_DISABLE) { 1570Sstevel@tonic-gate DBG(DBG_INTX_INTR, px_p->px_dip, 1580Sstevel@tonic-gate "px_intx_intr: %s%d interrupt %d is disabled\n", 1590Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip), 1600Sstevel@tonic-gate ino_p->ino_ino); 1610Sstevel@tonic-gate 1620Sstevel@tonic-gate continue; 1630Sstevel@tonic-gate } 1640Sstevel@tonic-gate 1650Sstevel@tonic-gate DBG(DBG_INTX_INTR, px_p->px_dip, "px_intx_intr:" 1660Sstevel@tonic-gate "ino=%x handler=%p arg1 =%p arg2 = %p\n", 1670Sstevel@tonic-gate ino_p->ino_ino, handler, arg1, arg2); 1680Sstevel@tonic-gate 1690Sstevel@tonic-gate DTRACE_PROBE4(interrupt__start, dev_info_t, dip, 1700Sstevel@tonic-gate void *, handler, caddr_t, arg1, caddr_t, arg2); 1710Sstevel@tonic-gate 1720Sstevel@tonic-gate r = (*handler)(arg1, arg2); 1730Sstevel@tonic-gate 1740Sstevel@tonic-gate /* 1750Sstevel@tonic-gate * Account for time used by this interrupt. Protect against 1760Sstevel@tonic-gate * conflicting writes to ih_ticks from ib_intr_dist_all() by 1770Sstevel@tonic-gate * using atomic ops. 1780Sstevel@tonic-gate */ 1790Sstevel@tonic-gate 1800Sstevel@tonic-gate if (ino_p->ino_pil <= LOCK_LEVEL) 1810Sstevel@tonic-gate atomic_add_64(&ih_p->ih_ticks, intr_get_time()); 1820Sstevel@tonic-gate 1830Sstevel@tonic-gate DTRACE_PROBE4(interrupt__complete, dev_info_t, dip, 1840Sstevel@tonic-gate void *, handler, caddr_t, arg1, int, r); 1850Sstevel@tonic-gate 1860Sstevel@tonic-gate result += r; 1870Sstevel@tonic-gate 1880Sstevel@tonic-gate if (px_check_all_handlers) 1890Sstevel@tonic-gate continue; 1900Sstevel@tonic-gate if (result) 1910Sstevel@tonic-gate break; 1920Sstevel@tonic-gate } 1930Sstevel@tonic-gate 1940Sstevel@tonic-gate if (!result && px_unclaimed_intr_block) 1950Sstevel@tonic-gate return (px_spurintr(ino_p)); 1960Sstevel@tonic-gate 1970Sstevel@tonic-gate ino_p->ino_unclaimed = 0; 1980Sstevel@tonic-gate 1990Sstevel@tonic-gate /* Clear the pending state */ 2000Sstevel@tonic-gate if (px_lib_intr_setstate(ino_p->ino_ib_p->ib_px_p->px_dip, 2010Sstevel@tonic-gate ino_p->ino_sysino, INTR_IDLE_STATE) != DDI_SUCCESS) 2020Sstevel@tonic-gate return (DDI_INTR_UNCLAIMED); 2030Sstevel@tonic-gate 2040Sstevel@tonic-gate return (DDI_INTR_CLAIMED); 2050Sstevel@tonic-gate } 2060Sstevel@tonic-gate 2070Sstevel@tonic-gate /* 2080Sstevel@tonic-gate * px_msiq_intr (MSI/MSIX/MSG interrupt handler) 2090Sstevel@tonic-gate * 2100Sstevel@tonic-gate * This routine is used as wrapper around interrupt handlers installed by child 2110Sstevel@tonic-gate * device drivers. This routine invokes the driver interrupt handlers and 2120Sstevel@tonic-gate * examines the return codes. 2130Sstevel@tonic-gate * 2140Sstevel@tonic-gate * There is a count of unclaimed interrupts kept on a per-ino basis. If at 2150Sstevel@tonic-gate * least one handler claims the interrupt then the counter is halved and the 2160Sstevel@tonic-gate * interrupt state machine is idled. If no handler claims the interrupt then 2170Sstevel@tonic-gate * the counter is incremented by one and the state machine is idled. 2180Sstevel@tonic-gate * If the count ever reaches the limit value set by pci_unclaimed_intr_max 2190Sstevel@tonic-gate * then the interrupt state machine is not idled thus preventing any further 2200Sstevel@tonic-gate * interrupts on that ino. The state machine will only be idled again if a 2210Sstevel@tonic-gate * handler is subsequently added or removed. 2220Sstevel@tonic-gate * 2230Sstevel@tonic-gate * return value: DDI_INTR_CLAIMED if any handlers claimed the interrupt, 2240Sstevel@tonic-gate * DDI_INTR_UNCLAIMED otherwise. 2250Sstevel@tonic-gate */ 2260Sstevel@tonic-gate uint_t 2270Sstevel@tonic-gate px_msiq_intr(caddr_t arg) 2280Sstevel@tonic-gate { 2290Sstevel@tonic-gate px_ib_ino_info_t *ino_p = (px_ib_ino_info_t *)arg; 2300Sstevel@tonic-gate px_t *px_p = ino_p->ino_ib_p->ib_px_p; 2310Sstevel@tonic-gate px_msiq_state_t *msiq_state_p = &px_p->px_ib_p->ib_msiq_state; 2320Sstevel@tonic-gate px_msiq_t *msiq_p = ino_p->ino_msiq_p; 2330Sstevel@tonic-gate dev_info_t *dip = px_p->px_dip; 2340Sstevel@tonic-gate msiq_rec_t msiq_rec, *msiq_rec_p = &msiq_rec; 2350Sstevel@tonic-gate msiqhead_t curr_msiq_rec_cnt, new_msiq_rec_cnt; 2360Sstevel@tonic-gate msgcode_t msg_code; 2370Sstevel@tonic-gate px_ih_t *ih_p; 2380Sstevel@tonic-gate int ret; 2390Sstevel@tonic-gate 2400Sstevel@tonic-gate DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: msiq_id =%x ino=%x pil=%x " 2410Sstevel@tonic-gate "ih_size=%x ih_lst=%x\n", msiq_p->msiq_id, ino_p->ino_ino, 2420Sstevel@tonic-gate ino_p->ino_pil, ino_p->ino_ih_size, ino_p->ino_ih_head); 2430Sstevel@tonic-gate 2440Sstevel@tonic-gate /* Read current MSIQ head index */ 2450Sstevel@tonic-gate px_lib_msiq_gethead(dip, msiq_p->msiq_id, &curr_msiq_rec_cnt); 2460Sstevel@tonic-gate msiq_p->msiq_curr = (uint64_t)((caddr_t)msiq_p->msiq_base + 2470Sstevel@tonic-gate curr_msiq_rec_cnt * sizeof (msiq_rec_t)); 2480Sstevel@tonic-gate new_msiq_rec_cnt = curr_msiq_rec_cnt; 2490Sstevel@tonic-gate 2500Sstevel@tonic-gate /* Read next MSIQ record */ 2510Sstevel@tonic-gate px_lib_get_msiq_rec(dip, msiq_p, msiq_rec_p); 2520Sstevel@tonic-gate 2530Sstevel@tonic-gate /* 2540Sstevel@tonic-gate * Process current MSIQ record as long as request id 2550Sstevel@tonic-gate * field is non-zero. 2560Sstevel@tonic-gate */ 2570Sstevel@tonic-gate while (msiq_rec_p->msiq_rec_rid) { 2580Sstevel@tonic-gate DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: MSIQ RECORD, " 2590Sstevel@tonic-gate "msiq_rec_type 0x%llx msiq_rec_rid 0x%llx\n", 2600Sstevel@tonic-gate msiq_rec_p->msiq_rec_type, msiq_rec_p->msiq_rec_rid); 2610Sstevel@tonic-gate 2620Sstevel@tonic-gate /* Get the pointer next EQ record */ 2630Sstevel@tonic-gate msiq_p->msiq_curr = (uint64_t) 2640Sstevel@tonic-gate ((caddr_t)msiq_p->msiq_curr + sizeof (msiq_rec_t)); 2650Sstevel@tonic-gate 2660Sstevel@tonic-gate /* Check for overflow condition */ 2670Sstevel@tonic-gate if (msiq_p->msiq_curr >= (uint64_t)((caddr_t)msiq_p->msiq_base + 2680Sstevel@tonic-gate msiq_state_p->msiq_rec_cnt * sizeof (msiq_rec_t))) 2690Sstevel@tonic-gate msiq_p->msiq_curr = msiq_p->msiq_base; 2700Sstevel@tonic-gate 2710Sstevel@tonic-gate /* Check MSIQ record type */ 2720Sstevel@tonic-gate switch (msiq_rec_p->msiq_rec_type) { 2730Sstevel@tonic-gate case MSG_REC: 2740Sstevel@tonic-gate msg_code = msiq_rec_p->msiq_rec_data.msg.msg_code; 2750Sstevel@tonic-gate DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: PCIE MSG " 2760Sstevel@tonic-gate "record, msg type 0x%x\n", msg_code); 2770Sstevel@tonic-gate break; 2780Sstevel@tonic-gate case MSI32_REC: 2790Sstevel@tonic-gate case MSI64_REC: 2800Sstevel@tonic-gate msg_code = msiq_rec_p->msiq_rec_data.msi.msi_data; 2810Sstevel@tonic-gate DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: MSI record, " 2820Sstevel@tonic-gate "msi 0x%x\n", msg_code); 2830Sstevel@tonic-gate 2840Sstevel@tonic-gate /* Clear MSI state */ 2850Sstevel@tonic-gate px_lib_msi_setstate(dip, (msinum_t)msg_code, 2860Sstevel@tonic-gate PCI_MSI_STATE_IDLE); 2870Sstevel@tonic-gate break; 2880Sstevel@tonic-gate default: 2890Sstevel@tonic-gate msg_code = 0; 2900Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: px_msiq_intr: 0x%x MSIQ " 2910Sstevel@tonic-gate "record type is not supported", 2920Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip), 2930Sstevel@tonic-gate msiq_rec_p->msiq_rec_type); 2940Sstevel@tonic-gate goto next_rec; 2950Sstevel@tonic-gate } 2960Sstevel@tonic-gate 2970Sstevel@tonic-gate ih_p = ino_p->ino_ih_start; 2980Sstevel@tonic-gate 2990Sstevel@tonic-gate /* 3000Sstevel@tonic-gate * Scan through px_ih_t linked list, searching for the 3010Sstevel@tonic-gate * right px_ih_t, matching MSIQ record data. 3020Sstevel@tonic-gate */ 3030Sstevel@tonic-gate while ((ih_p) && (ih_p->ih_msg_code != msg_code) && 3040Sstevel@tonic-gate (ih_p->ih_rec_type != msiq_rec_p->msiq_rec_type)) 3050Sstevel@tonic-gate ih_p = ih_p->ih_next; 3060Sstevel@tonic-gate 3070Sstevel@tonic-gate if ((ih_p->ih_msg_code == msg_code) && 3080Sstevel@tonic-gate (ih_p->ih_rec_type == msiq_rec_p->msiq_rec_type)) { 3090Sstevel@tonic-gate dev_info_t *dip = ih_p->ih_dip; 3100Sstevel@tonic-gate uint_t (*handler)() = ih_p->ih_handler; 3110Sstevel@tonic-gate caddr_t arg1 = ih_p->ih_handler_arg1; 3120Sstevel@tonic-gate caddr_t arg2 = ih_p->ih_handler_arg2; 3130Sstevel@tonic-gate 3140Sstevel@tonic-gate DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: ino=%x data=%x " 3150Sstevel@tonic-gate "handler=%p arg1 =%p arg2=%p\n", ino_p->ino_ino, 3160Sstevel@tonic-gate msg_code, handler, arg1, arg2); 3170Sstevel@tonic-gate 3180Sstevel@tonic-gate DTRACE_PROBE4(interrupt__start, dev_info_t, dip, 3190Sstevel@tonic-gate void *, handler, caddr_t, arg1, caddr_t, arg2); 3200Sstevel@tonic-gate 321*27Sjchu /* 322*27Sjchu * Special case for PCIE Error Messages. 323*27Sjchu * The current frame work doesn't fit PCIE Err Msgs 324*27Sjchu * This should be fixed when PCIE MESSAGES as a whole 325*27Sjchu * is architected correctly. 326*27Sjchu */ 327*27Sjchu if ((msg_code == PCIE_MSG_CODE_ERR_COR) || 328*27Sjchu (msg_code == PCIE_MSG_CODE_ERR_NONFATAL) || 329*27Sjchu (msg_code == PCIE_MSG_CODE_ERR_FATAL)) { 330*27Sjchu ret = px_err_fabric_intr(px_p, msg_code, 331*27Sjchu msiq_rec_p->msiq_rec_rid); 332*27Sjchu } else 333*27Sjchu ret = (*handler)(arg1, arg2); 3340Sstevel@tonic-gate 3350Sstevel@tonic-gate /* 3360Sstevel@tonic-gate * Account for time used by this interrupt. Protect 3370Sstevel@tonic-gate * against conflicting writes to ih_ticks from 3380Sstevel@tonic-gate * ib_intr_dist_all() by using atomic ops. 3390Sstevel@tonic-gate */ 3400Sstevel@tonic-gate 3410Sstevel@tonic-gate if (ino_p->ino_pil <= LOCK_LEVEL) 3420Sstevel@tonic-gate atomic_add_64(&ih_p->ih_ticks, intr_get_time()); 3430Sstevel@tonic-gate 3440Sstevel@tonic-gate DTRACE_PROBE4(interrupt__complete, dev_info_t, dip, 3450Sstevel@tonic-gate void *, handler, caddr_t, arg1, int, ret); 3460Sstevel@tonic-gate } else { 3470Sstevel@tonic-gate DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr:" 3480Sstevel@tonic-gate "Not found matching MSIQ record\n"); 3490Sstevel@tonic-gate 3500Sstevel@tonic-gate /* px_spurintr(ino_p); */ 3510Sstevel@tonic-gate ino_p->ino_unclaimed++; 3520Sstevel@tonic-gate } 3530Sstevel@tonic-gate 3540Sstevel@tonic-gate next_rec: 3550Sstevel@tonic-gate new_msiq_rec_cnt++; 3560Sstevel@tonic-gate 3570Sstevel@tonic-gate /* Zero out msiq_rec_rid field */ 3580Sstevel@tonic-gate msiq_rec_p->msiq_rec_rid = 0; 3590Sstevel@tonic-gate 3600Sstevel@tonic-gate /* Read next MSIQ record */ 3610Sstevel@tonic-gate px_lib_get_msiq_rec(dip, msiq_p, msiq_rec_p); 3620Sstevel@tonic-gate } 3630Sstevel@tonic-gate 3640Sstevel@tonic-gate DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: No of MSIQ recs processed %x\n", 3650Sstevel@tonic-gate (new_msiq_rec_cnt - curr_msiq_rec_cnt)); 3660Sstevel@tonic-gate 3670Sstevel@tonic-gate /* Update MSIQ head index with no of MSIQ records processed */ 3680Sstevel@tonic-gate if (new_msiq_rec_cnt > curr_msiq_rec_cnt) { 3690Sstevel@tonic-gate if (new_msiq_rec_cnt >= msiq_state_p->msiq_rec_cnt) 3700Sstevel@tonic-gate new_msiq_rec_cnt -= msiq_state_p->msiq_rec_cnt; 3710Sstevel@tonic-gate 3720Sstevel@tonic-gate px_lib_msiq_sethead(dip, msiq_p->msiq_id, new_msiq_rec_cnt); 3730Sstevel@tonic-gate } 3740Sstevel@tonic-gate 3750Sstevel@tonic-gate /* Clear the pending state */ 3760Sstevel@tonic-gate if (px_lib_intr_setstate(dip, ino_p->ino_sysino, 3770Sstevel@tonic-gate INTR_IDLE_STATE) != DDI_SUCCESS) 3780Sstevel@tonic-gate return (DDI_INTR_UNCLAIMED); 3790Sstevel@tonic-gate 3800Sstevel@tonic-gate return (DDI_INTR_CLAIMED); 3810Sstevel@tonic-gate } 3820Sstevel@tonic-gate 3830Sstevel@tonic-gate dev_info_t * 3840Sstevel@tonic-gate px_get_my_childs_dip(dev_info_t *dip, dev_info_t *rdip) 3850Sstevel@tonic-gate { 3860Sstevel@tonic-gate dev_info_t *cdip = rdip; 3870Sstevel@tonic-gate 3880Sstevel@tonic-gate for (; ddi_get_parent(cdip) != dip; cdip = ddi_get_parent(cdip)) 3890Sstevel@tonic-gate ; 3900Sstevel@tonic-gate 3910Sstevel@tonic-gate return (cdip); 3920Sstevel@tonic-gate } 3930Sstevel@tonic-gate 3940Sstevel@tonic-gate /* Default class to pil value mapping */ 3950Sstevel@tonic-gate px_class_val_t px_default_pil [] = { 3960Sstevel@tonic-gate {0x000000, 0xff0000, 0x1}, /* Class code for pre-2.0 devices */ 3970Sstevel@tonic-gate {0x010000, 0xff0000, 0x4}, /* Mass Storage Controller */ 3980Sstevel@tonic-gate {0x020000, 0xff0000, 0x6}, /* Network Controller */ 3990Sstevel@tonic-gate {0x030000, 0xff0000, 0x9}, /* Display Controller */ 4000Sstevel@tonic-gate {0x040000, 0xff0000, 0x9}, /* Multimedia Controller */ 4010Sstevel@tonic-gate {0x050000, 0xff0000, 0xb}, /* Memory Controller */ 4020Sstevel@tonic-gate {0x060000, 0xff0000, 0xb}, /* Bridge Controller */ 4030Sstevel@tonic-gate {0x0c0000, 0xffff00, 0x9}, /* Serial Bus, FireWire (IEEE 1394) */ 4040Sstevel@tonic-gate {0x0c0100, 0xffff00, 0x4}, /* Serial Bus, ACCESS.bus */ 4050Sstevel@tonic-gate {0x0c0200, 0xffff00, 0x4}, /* Serial Bus, SSA */ 4060Sstevel@tonic-gate {0x0c0300, 0xffff00, 0x9}, /* Serial Bus Universal Serial Bus */ 4070Sstevel@tonic-gate {0x0c0400, 0xffff00, 0x6}, /* Serial Bus, Fibre Channel */ 4080Sstevel@tonic-gate {0x0c0600, 0xffff00, 0x6} /* Serial Bus, Infiniband */ 4090Sstevel@tonic-gate }; 4100Sstevel@tonic-gate 4110Sstevel@tonic-gate /* 4120Sstevel@tonic-gate * Default class to intr_weight value mapping (% of CPU). A driver.conf 4130Sstevel@tonic-gate * entry on or above the pci node like 4140Sstevel@tonic-gate * 4150Sstevel@tonic-gate * pci-class-intr-weights= 0x020000, 0xff0000, 30; 4160Sstevel@tonic-gate * 4170Sstevel@tonic-gate * can be used to augment or override entries in the default table below. 4180Sstevel@tonic-gate * 4190Sstevel@tonic-gate * NB: The values below give NICs preference on redistribution, and provide 4200Sstevel@tonic-gate * NICs some isolation from other interrupt sources. We need better interfaces 4210Sstevel@tonic-gate * that allow the NIC driver to identify a specific NIC instance as high 4220Sstevel@tonic-gate * bandwidth, and thus deserving of separation from other low bandwidth 4230Sstevel@tonic-gate * NICs additional isolation from other interrupt sources. 4240Sstevel@tonic-gate * 4250Sstevel@tonic-gate * NB: We treat Infiniband like a NIC. 4260Sstevel@tonic-gate */ 4270Sstevel@tonic-gate px_class_val_t px_default_intr_weight [] = { 4280Sstevel@tonic-gate {0x020000, 0xff0000, 35}, /* Network Controller */ 4290Sstevel@tonic-gate {0x010000, 0xff0000, 10}, /* Mass Storage Controller */ 4300Sstevel@tonic-gate {0x0c0400, 0xffff00, 10}, /* Serial Bus, Fibre Channel */ 4310Sstevel@tonic-gate {0x0c0600, 0xffff00, 50} /* Serial Bus, Infiniband */ 4320Sstevel@tonic-gate }; 4330Sstevel@tonic-gate 4340Sstevel@tonic-gate static uint32_t 4350Sstevel@tonic-gate px_match_class_val(uint32_t key, px_class_val_t *rec_p, int nrec, 4360Sstevel@tonic-gate uint32_t default_val) 4370Sstevel@tonic-gate { 4380Sstevel@tonic-gate int i; 4390Sstevel@tonic-gate 4400Sstevel@tonic-gate for (i = 0; i < nrec; rec_p++, i++) { 4410Sstevel@tonic-gate if ((rec_p->class_code & rec_p->class_mask) == 4420Sstevel@tonic-gate (key & rec_p->class_mask)) 4430Sstevel@tonic-gate return (rec_p->class_val); 4440Sstevel@tonic-gate } 4450Sstevel@tonic-gate 4460Sstevel@tonic-gate return (default_val); 4470Sstevel@tonic-gate } 4480Sstevel@tonic-gate 4490Sstevel@tonic-gate /* 4500Sstevel@tonic-gate * px_class_to_val 4510Sstevel@tonic-gate * 4520Sstevel@tonic-gate * Return the configuration value, based on class code and sub class code, 4530Sstevel@tonic-gate * from the specified property based or default px_class_val_t table. 4540Sstevel@tonic-gate */ 4550Sstevel@tonic-gate uint32_t 4560Sstevel@tonic-gate px_class_to_val(dev_info_t *rdip, char *property_name, px_class_val_t *rec_p, 4570Sstevel@tonic-gate int nrec, uint32_t default_val) 4580Sstevel@tonic-gate { 4590Sstevel@tonic-gate int property_len; 4600Sstevel@tonic-gate uint32_t class_code; 4610Sstevel@tonic-gate px_class_val_t *conf; 4620Sstevel@tonic-gate uint32_t val = default_val; 4630Sstevel@tonic-gate 4640Sstevel@tonic-gate /* 4650Sstevel@tonic-gate * Use the "class-code" property to get the base and sub class 4660Sstevel@tonic-gate * codes for the requesting device. 4670Sstevel@tonic-gate */ 4680Sstevel@tonic-gate class_code = (uint32_t)ddi_prop_get_int(DDI_DEV_T_ANY, rdip, 4690Sstevel@tonic-gate DDI_PROP_DONTPASS, "class-code", -1); 4700Sstevel@tonic-gate 4710Sstevel@tonic-gate if (class_code == -1) 4720Sstevel@tonic-gate return (val); 4730Sstevel@tonic-gate 4740Sstevel@tonic-gate /* look up the val from the default table */ 4750Sstevel@tonic-gate val = px_match_class_val(class_code, rec_p, nrec, val); 4760Sstevel@tonic-gate 4770Sstevel@tonic-gate /* see if there is a more specific property specified value */ 4780Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_ANY, rdip, DDI_PROP_NOTPROM, 4790Sstevel@tonic-gate property_name, (caddr_t)&conf, &property_len)) 4800Sstevel@tonic-gate return (val); 4810Sstevel@tonic-gate 4820Sstevel@tonic-gate if ((property_len % sizeof (px_class_val_t)) == 0) 4830Sstevel@tonic-gate val = px_match_class_val(class_code, conf, 4840Sstevel@tonic-gate property_len / sizeof (px_class_val_t), val); 4850Sstevel@tonic-gate kmem_free(conf, property_len); 4860Sstevel@tonic-gate return (val); 4870Sstevel@tonic-gate } 4880Sstevel@tonic-gate 4890Sstevel@tonic-gate /* px_class_to_pil: return the pil for a given device. */ 4900Sstevel@tonic-gate uint32_t 4910Sstevel@tonic-gate px_class_to_pil(dev_info_t *rdip) 4920Sstevel@tonic-gate { 4930Sstevel@tonic-gate uint32_t pil; 4940Sstevel@tonic-gate 4950Sstevel@tonic-gate /* default pil is 0 (uninitialized) */ 4960Sstevel@tonic-gate pil = px_class_to_val(rdip, 4970Sstevel@tonic-gate "pci-class-priorities", px_default_pil, 4980Sstevel@tonic-gate sizeof (px_default_pil) / sizeof (px_class_val_t), 0); 4990Sstevel@tonic-gate 5000Sstevel@tonic-gate /* range check the result */ 5010Sstevel@tonic-gate if (pil >= 0xf) 5020Sstevel@tonic-gate pil = 0; 5030Sstevel@tonic-gate 5040Sstevel@tonic-gate return (pil); 5050Sstevel@tonic-gate } 5060Sstevel@tonic-gate 5070Sstevel@tonic-gate /* px_class_to_intr_weight: return the intr_weight for a given device. */ 5080Sstevel@tonic-gate static int32_t 5090Sstevel@tonic-gate px_class_to_intr_weight(dev_info_t *rdip) 5100Sstevel@tonic-gate { 5110Sstevel@tonic-gate int32_t intr_weight; 5120Sstevel@tonic-gate 5130Sstevel@tonic-gate /* default weight is 0% */ 5140Sstevel@tonic-gate intr_weight = px_class_to_val(rdip, 5150Sstevel@tonic-gate "pci-class-intr-weights", px_default_intr_weight, 5160Sstevel@tonic-gate sizeof (px_default_intr_weight) / sizeof (px_class_val_t), 0); 5170Sstevel@tonic-gate 5180Sstevel@tonic-gate /* range check the result */ 5190Sstevel@tonic-gate if (intr_weight < 0) 5200Sstevel@tonic-gate intr_weight = 0; 5210Sstevel@tonic-gate if (intr_weight > 1000) 5220Sstevel@tonic-gate intr_weight = 1000; 5230Sstevel@tonic-gate 5240Sstevel@tonic-gate return (intr_weight); 5250Sstevel@tonic-gate } 5260Sstevel@tonic-gate 5270Sstevel@tonic-gate /* ARGSUSED */ 5280Sstevel@tonic-gate int 5290Sstevel@tonic-gate px_intx_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op, 5300Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, void *result) 5310Sstevel@tonic-gate { 5320Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip); 5330Sstevel@tonic-gate ddi_ispec_t *ip = (ddi_ispec_t *)hdlp->ih_private; 5340Sstevel@tonic-gate int ret = DDI_SUCCESS; 5350Sstevel@tonic-gate 5360Sstevel@tonic-gate DBG(DBG_INTROPS, dip, "px_intx_ops: dip=%x rdip=%x intr_op=%x " 5370Sstevel@tonic-gate "handle=%p\n", dip, rdip, intr_op, hdlp); 5380Sstevel@tonic-gate 5390Sstevel@tonic-gate switch (intr_op) { 5400Sstevel@tonic-gate case DDI_INTROP_GETCAP: 5410Sstevel@tonic-gate ret = pci_intx_get_cap(rdip, (int *)result); 5420Sstevel@tonic-gate break; 5430Sstevel@tonic-gate case DDI_INTROP_SETCAP: 5440Sstevel@tonic-gate DBG(DBG_INTROPS, dip, "px_intx_ops: SetCap is not supported\n"); 5450Sstevel@tonic-gate ret = DDI_ENOTSUP; 5460Sstevel@tonic-gate break; 5470Sstevel@tonic-gate case DDI_INTROP_ALLOC: 5480Sstevel@tonic-gate *(int *)result = hdlp->ih_scratch1; 5490Sstevel@tonic-gate break; 5500Sstevel@tonic-gate case DDI_INTROP_FREE: 5510Sstevel@tonic-gate break; 5520Sstevel@tonic-gate case DDI_INTROP_GETPRI: 5530Sstevel@tonic-gate *(int *)result = ip->is_pil ? 5540Sstevel@tonic-gate ip->is_pil : px_class_to_pil(rdip); 5550Sstevel@tonic-gate break; 5560Sstevel@tonic-gate case DDI_INTROP_SETPRI: 5570Sstevel@tonic-gate ip->is_pil = (*(int *)result); 5580Sstevel@tonic-gate break; 5590Sstevel@tonic-gate case DDI_INTROP_ADDISR: 5600Sstevel@tonic-gate hdlp->ih_vector = *ip->is_intr; 5610Sstevel@tonic-gate 5620Sstevel@tonic-gate ret = px_add_intx_intr(dip, rdip, hdlp); 5630Sstevel@tonic-gate break; 5640Sstevel@tonic-gate case DDI_INTROP_REMISR: 5650Sstevel@tonic-gate hdlp->ih_vector = *ip->is_intr; 5660Sstevel@tonic-gate 5670Sstevel@tonic-gate ret = px_rem_intx_intr(dip, rdip, hdlp); 5680Sstevel@tonic-gate break; 5690Sstevel@tonic-gate case DDI_INTROP_ENABLE: 5700Sstevel@tonic-gate ret = px_ib_update_intr_state(px_p, rdip, hdlp->ih_inum, 5710Sstevel@tonic-gate *ip->is_intr, PX_INTR_STATE_ENABLE); 5720Sstevel@tonic-gate break; 5730Sstevel@tonic-gate case DDI_INTROP_DISABLE: 5740Sstevel@tonic-gate ret = px_ib_update_intr_state(px_p, rdip, hdlp->ih_inum, 5750Sstevel@tonic-gate *ip->is_intr, PX_INTR_STATE_DISABLE); 5760Sstevel@tonic-gate break; 5770Sstevel@tonic-gate case DDI_INTROP_SETMASK: 5780Sstevel@tonic-gate ret = pci_intx_set_mask(rdip); 5790Sstevel@tonic-gate break; 5800Sstevel@tonic-gate case DDI_INTROP_CLRMASK: 5810Sstevel@tonic-gate ret = pci_intx_clr_mask(rdip); 5820Sstevel@tonic-gate break; 5830Sstevel@tonic-gate case DDI_INTROP_GETPENDING: 5840Sstevel@tonic-gate ret = pci_intx_get_pending(rdip, (int *)result); 5850Sstevel@tonic-gate break; 5860Sstevel@tonic-gate case DDI_INTROP_NINTRS: 5870Sstevel@tonic-gate case DDI_INTROP_NAVAIL: 5880Sstevel@tonic-gate *(int *)result = i_ddi_get_nintrs(rdip); 5890Sstevel@tonic-gate break; 5900Sstevel@tonic-gate case DDI_INTROP_SUPPORTED_TYPES: 5910Sstevel@tonic-gate *(int *)result = DDI_INTR_TYPE_FIXED; 5920Sstevel@tonic-gate break; 5930Sstevel@tonic-gate default: 5940Sstevel@tonic-gate ret = DDI_ENOTSUP; 5950Sstevel@tonic-gate break; 5960Sstevel@tonic-gate } 5970Sstevel@tonic-gate 5980Sstevel@tonic-gate return (ret); 5990Sstevel@tonic-gate } 6000Sstevel@tonic-gate 6010Sstevel@tonic-gate /* ARGSUSED */ 6020Sstevel@tonic-gate int 6030Sstevel@tonic-gate px_msix_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op, 6040Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, void *result) 6050Sstevel@tonic-gate { 6060Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip); 6070Sstevel@tonic-gate px_msi_state_t *msi_state_p = &px_p->px_ib_p->ib_msi_state; 6080Sstevel@tonic-gate msinum_t msi_num; 6090Sstevel@tonic-gate msiqid_t msiq_id; 6100Sstevel@tonic-gate uint_t nintrs; 6110Sstevel@tonic-gate int i, ret = DDI_SUCCESS; 6120Sstevel@tonic-gate 6130Sstevel@tonic-gate DBG(DBG_INTROPS, dip, "px_msix_ops: dip=%x rdip=%x intr_op=%x " 6140Sstevel@tonic-gate "handle=%p\n", dip, rdip, intr_op, hdlp); 6150Sstevel@tonic-gate 6160Sstevel@tonic-gate switch (intr_op) { 6170Sstevel@tonic-gate case DDI_INTROP_GETCAP: 6180Sstevel@tonic-gate ret = pci_msi_get_cap(rdip, hdlp->ih_type, (int *)result); 6190Sstevel@tonic-gate break; 6200Sstevel@tonic-gate case DDI_INTROP_SETCAP: 6210Sstevel@tonic-gate DBG(DBG_INTROPS, dip, "px_msix_ops: SetCap is not supported\n"); 6220Sstevel@tonic-gate ret = DDI_ENOTSUP; 6230Sstevel@tonic-gate break; 6240Sstevel@tonic-gate case DDI_INTROP_ALLOC: 6250Sstevel@tonic-gate /* 6260Sstevel@tonic-gate * We need to restrict this allocation in future 6270Sstevel@tonic-gate * based on Resource Management policies. 6280Sstevel@tonic-gate */ 6290Sstevel@tonic-gate if ((ret = px_msi_alloc(px_p, rdip, hdlp->ih_inum, 6300Sstevel@tonic-gate hdlp->ih_scratch1, hdlp->ih_scratch2, &msi_num, 6310Sstevel@tonic-gate (int *)result)) != DDI_SUCCESS) { 6320Sstevel@tonic-gate DBG(DBG_INTROPS, dip, "px_msix_ops: MSI allocation " 6330Sstevel@tonic-gate "failed, rdip 0x%p inum 0x%x count 0x%x\n", 6340Sstevel@tonic-gate rdip, hdlp->ih_inum, hdlp->ih_scratch1); 6350Sstevel@tonic-gate 6360Sstevel@tonic-gate return (ret); 6370Sstevel@tonic-gate } 6380Sstevel@tonic-gate 6390Sstevel@tonic-gate break; 6400Sstevel@tonic-gate case DDI_INTROP_FREE: 6410Sstevel@tonic-gate (void) pci_msi_disable_mode(rdip, hdlp->ih_type, hdlp->ih_inum); 6420Sstevel@tonic-gate (void) pci_msi_unconfigure(rdip, hdlp->ih_type, hdlp->ih_inum); 6430Sstevel@tonic-gate (void) px_msi_free(px_p, rdip, hdlp->ih_inum, 6440Sstevel@tonic-gate hdlp->ih_scratch1); 6450Sstevel@tonic-gate break; 6460Sstevel@tonic-gate case DDI_INTROP_GETPRI: 6470Sstevel@tonic-gate *(int *)result = hdlp->ih_pri ? 6480Sstevel@tonic-gate hdlp->ih_pri : px_class_to_pil(rdip); 6490Sstevel@tonic-gate break; 6500Sstevel@tonic-gate case DDI_INTROP_SETPRI: 6510Sstevel@tonic-gate break; 6520Sstevel@tonic-gate case DDI_INTROP_ADDISR: 6530Sstevel@tonic-gate if ((ret = px_msi_get_msinum(px_p, hdlp->ih_dip, 6540Sstevel@tonic-gate hdlp->ih_inum, &msi_num)) != DDI_SUCCESS) 6550Sstevel@tonic-gate return (ret); 6560Sstevel@tonic-gate 6570Sstevel@tonic-gate if ((ret = px_add_msiq_intr(dip, rdip, hdlp, 6580Sstevel@tonic-gate MSI32_REC, msi_num, &msiq_id)) != DDI_SUCCESS) { 6590Sstevel@tonic-gate DBG(DBG_INTROPS, dip, "px_msix_ops: Add MSI handler " 6600Sstevel@tonic-gate "failed, rdip 0x%p msi 0x%x\n", rdip, msi_num); 6610Sstevel@tonic-gate return (ret); 6620Sstevel@tonic-gate } 6630Sstevel@tonic-gate 6640Sstevel@tonic-gate DBG(DBG_INTROPS, dip, "px_msix_ops: msiq used 0x%x\n", msiq_id); 6650Sstevel@tonic-gate 6660Sstevel@tonic-gate if ((ret = px_lib_msi_setmsiq(dip, msi_num, 6670Sstevel@tonic-gate msiq_id, MSI32_TYPE)) != DDI_SUCCESS) { 6680Sstevel@tonic-gate (void) px_rem_msiq_intr(dip, rdip, 6690Sstevel@tonic-gate hdlp, MSI32_REC, msi_num, msiq_id); 6700Sstevel@tonic-gate return (ret); 6710Sstevel@tonic-gate } 6720Sstevel@tonic-gate 6730Sstevel@tonic-gate if ((ret = px_lib_msi_setstate(dip, msi_num, 6740Sstevel@tonic-gate PCI_MSI_STATE_IDLE)) != DDI_SUCCESS) { 6750Sstevel@tonic-gate (void) px_rem_msiq_intr(dip, rdip, 6760Sstevel@tonic-gate hdlp, MSI32_REC, msi_num, msiq_id); 6770Sstevel@tonic-gate return (ret); 6780Sstevel@tonic-gate } 6790Sstevel@tonic-gate 6800Sstevel@tonic-gate hdlp->ih_vector = msi_num; 6810Sstevel@tonic-gate break; 6820Sstevel@tonic-gate case DDI_INTROP_DUPVEC: 6830Sstevel@tonic-gate DBG(DBG_INTROPS, dip, "px_msix_ops: DupIsr is not supported\n"); 6840Sstevel@tonic-gate ret = DDI_ENOTSUP; 6850Sstevel@tonic-gate break; 6860Sstevel@tonic-gate case DDI_INTROP_REMISR: 6870Sstevel@tonic-gate msi_num = hdlp->ih_vector; 6880Sstevel@tonic-gate 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 6930Sstevel@tonic-gate if ((ret = px_lib_msi_setstate(dip, msi_num, 6940Sstevel@tonic-gate PCI_MSI_STATE_DELIVERED)) != DDI_SUCCESS) 6950Sstevel@tonic-gate return (ret); 6960Sstevel@tonic-gate 6970Sstevel@tonic-gate ret = px_rem_msiq_intr(dip, rdip, 6980Sstevel@tonic-gate hdlp, MSI32_REC, msi_num, msiq_id); 6990Sstevel@tonic-gate 7000Sstevel@tonic-gate hdlp->ih_vector = 0; 7010Sstevel@tonic-gate break; 7020Sstevel@tonic-gate case DDI_INTROP_ENABLE: 7030Sstevel@tonic-gate msi_num = hdlp->ih_vector; 7040Sstevel@tonic-gate 7050Sstevel@tonic-gate if ((ret = px_lib_msi_setvalid(dip, msi_num, 7060Sstevel@tonic-gate PCI_MSI_VALID)) != DDI_SUCCESS) 7070Sstevel@tonic-gate return (ret); 7080Sstevel@tonic-gate 7090Sstevel@tonic-gate if (pci_is_msi_enabled(rdip, hdlp->ih_type) != DDI_SUCCESS) { 7100Sstevel@tonic-gate nintrs = i_ddi_intr_get_current_nintrs(hdlp->ih_dip); 7110Sstevel@tonic-gate 7120Sstevel@tonic-gate if ((ret = pci_msi_configure(rdip, hdlp->ih_type, 7130Sstevel@tonic-gate nintrs, hdlp->ih_inum, msi_state_p->msi_addr32, 7140Sstevel@tonic-gate msi_num & ~(nintrs - 1))) != DDI_SUCCESS) 7150Sstevel@tonic-gate return (ret); 7160Sstevel@tonic-gate 7170Sstevel@tonic-gate if ((ret = pci_msi_enable_mode(rdip, hdlp->ih_type, 7180Sstevel@tonic-gate hdlp->ih_inum)) != DDI_SUCCESS) 7190Sstevel@tonic-gate return (ret); 7200Sstevel@tonic-gate } 7210Sstevel@tonic-gate 7220Sstevel@tonic-gate ret = pci_msi_clr_mask(rdip, hdlp->ih_type, hdlp->ih_inum); 7230Sstevel@tonic-gate 7240Sstevel@tonic-gate break; 7250Sstevel@tonic-gate case DDI_INTROP_DISABLE: 7260Sstevel@tonic-gate msi_num = hdlp->ih_vector; 7270Sstevel@tonic-gate 7280Sstevel@tonic-gate if ((ret = pci_msi_set_mask(rdip, hdlp->ih_type, 7290Sstevel@tonic-gate hdlp->ih_inum)) != DDI_SUCCESS) 7300Sstevel@tonic-gate return (ret); 7310Sstevel@tonic-gate 7320Sstevel@tonic-gate ret = px_lib_msi_setvalid(dip, msi_num, PCI_MSI_INVALID); 7330Sstevel@tonic-gate break; 7340Sstevel@tonic-gate case DDI_INTROP_BLOCKENABLE: 7350Sstevel@tonic-gate nintrs = i_ddi_intr_get_current_nintrs(hdlp->ih_dip); 7360Sstevel@tonic-gate msi_num = hdlp->ih_vector; 7370Sstevel@tonic-gate 7380Sstevel@tonic-gate if ((ret = pci_msi_configure(rdip, hdlp->ih_type, 7390Sstevel@tonic-gate nintrs, hdlp->ih_inum, msi_state_p->msi_addr32, 7400Sstevel@tonic-gate msi_num & ~(nintrs - 1))) != DDI_SUCCESS) 7410Sstevel@tonic-gate return (ret); 7420Sstevel@tonic-gate 7430Sstevel@tonic-gate for (i = 0; i < nintrs; i++, msi_num++) { 7440Sstevel@tonic-gate if ((ret = px_lib_msi_setvalid(dip, msi_num, 7450Sstevel@tonic-gate PCI_MSI_VALID)) != DDI_SUCCESS) 7460Sstevel@tonic-gate return (ret); 7470Sstevel@tonic-gate } 7480Sstevel@tonic-gate 7490Sstevel@tonic-gate ret = pci_msi_enable_mode(rdip, hdlp->ih_type, hdlp->ih_inum); 7500Sstevel@tonic-gate break; 7510Sstevel@tonic-gate case DDI_INTROP_BLOCKDISABLE: 7520Sstevel@tonic-gate nintrs = i_ddi_intr_get_current_nintrs(hdlp->ih_dip); 7530Sstevel@tonic-gate msi_num = hdlp->ih_vector; 7540Sstevel@tonic-gate 7550Sstevel@tonic-gate if ((ret = pci_msi_disable_mode(rdip, hdlp->ih_type, 7560Sstevel@tonic-gate hdlp->ih_inum)) != DDI_SUCCESS) 7570Sstevel@tonic-gate return (ret); 7580Sstevel@tonic-gate 7590Sstevel@tonic-gate for (i = 0; i < nintrs; i++, msi_num++) { 7600Sstevel@tonic-gate if ((ret = px_lib_msi_setvalid(dip, msi_num, 7610Sstevel@tonic-gate PCI_MSI_INVALID)) != DDI_SUCCESS) 7620Sstevel@tonic-gate return (ret); 7630Sstevel@tonic-gate } 7640Sstevel@tonic-gate 7650Sstevel@tonic-gate break; 7660Sstevel@tonic-gate case DDI_INTROP_SETMASK: 7670Sstevel@tonic-gate ret = pci_msi_set_mask(rdip, hdlp->ih_type, hdlp->ih_inum); 7680Sstevel@tonic-gate break; 7690Sstevel@tonic-gate case DDI_INTROP_CLRMASK: 7700Sstevel@tonic-gate ret = pci_msi_clr_mask(rdip, hdlp->ih_type, hdlp->ih_inum); 7710Sstevel@tonic-gate break; 7720Sstevel@tonic-gate case DDI_INTROP_GETPENDING: 7730Sstevel@tonic-gate ret = pci_msi_get_pending(rdip, hdlp->ih_type, 7740Sstevel@tonic-gate hdlp->ih_inum, (int *)result); 7750Sstevel@tonic-gate break; 7760Sstevel@tonic-gate case DDI_INTROP_NINTRS: 7770Sstevel@tonic-gate ret = pci_msi_get_nintrs(rdip, hdlp->ih_type, (int *)result); 7780Sstevel@tonic-gate break; 7790Sstevel@tonic-gate case DDI_INTROP_NAVAIL: 7800Sstevel@tonic-gate /* XXX - a new interface may be needed */ 7810Sstevel@tonic-gate ret = pci_msi_get_nintrs(rdip, hdlp->ih_type, (int *)result); 7820Sstevel@tonic-gate break; 7830Sstevel@tonic-gate case DDI_INTROP_SUPPORTED_TYPES: 7840Sstevel@tonic-gate ret = pci_msi_get_supported_type(rdip, (int *)result); 7850Sstevel@tonic-gate break; 7860Sstevel@tonic-gate default: 7870Sstevel@tonic-gate ret = DDI_ENOTSUP; 7880Sstevel@tonic-gate break; 7890Sstevel@tonic-gate } 7900Sstevel@tonic-gate 7910Sstevel@tonic-gate return (ret); 7920Sstevel@tonic-gate } 7930Sstevel@tonic-gate 7940Sstevel@tonic-gate int 7950Sstevel@tonic-gate px_add_intx_intr(dev_info_t *dip, dev_info_t *rdip, 7960Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp) 7970Sstevel@tonic-gate { 7980Sstevel@tonic-gate px_t *px_p = INST_TO_STATE(ddi_get_instance(dip)); 7990Sstevel@tonic-gate px_ib_t *ib_p = px_p->px_ib_p; 8000Sstevel@tonic-gate devino_t ino; 8010Sstevel@tonic-gate px_ih_t *ih_p; 8020Sstevel@tonic-gate px_ib_ino_info_t *ino_p; 8030Sstevel@tonic-gate int32_t weight; 8040Sstevel@tonic-gate int ret = DDI_SUCCESS; 8050Sstevel@tonic-gate 8060Sstevel@tonic-gate ino = hdlp->ih_vector; 8070Sstevel@tonic-gate 8080Sstevel@tonic-gate DBG(DBG_A_INTX, dip, "px_add_intx_intr: rdip=%s%d ino=%x " 8090Sstevel@tonic-gate "handler=%x arg1=%x arg2=%x\n", ddi_driver_name(rdip), 8100Sstevel@tonic-gate ddi_get_instance(rdip), ino, hdlp->ih_cb_func, 8110Sstevel@tonic-gate hdlp->ih_cb_arg1, hdlp->ih_cb_arg2); 8120Sstevel@tonic-gate 8130Sstevel@tonic-gate ih_p = px_ib_alloc_ih(rdip, hdlp->ih_inum, 8140Sstevel@tonic-gate hdlp->ih_cb_func, hdlp->ih_cb_arg1, hdlp->ih_cb_arg2, 0, 0); 8150Sstevel@tonic-gate 8160Sstevel@tonic-gate mutex_enter(&ib_p->ib_ino_lst_mutex); 8170Sstevel@tonic-gate 8180Sstevel@tonic-gate if (ino_p = px_ib_locate_ino(ib_p, ino)) { /* sharing ino */ 8190Sstevel@tonic-gate uint32_t intr_index = hdlp->ih_inum; 8200Sstevel@tonic-gate if (px_ib_ino_locate_intr(ino_p, rdip, intr_index, 0, 0)) { 8210Sstevel@tonic-gate DBG(DBG_A_INTX, dip, "px_add_intx_intr: " 8220Sstevel@tonic-gate "dup intr #%d\n", intr_index); 8230Sstevel@tonic-gate 8240Sstevel@tonic-gate ret = DDI_FAILURE; 8250Sstevel@tonic-gate goto fail1; 8260Sstevel@tonic-gate } 8270Sstevel@tonic-gate 8280Sstevel@tonic-gate /* Save mondo value in hdlp */ 8290Sstevel@tonic-gate hdlp->ih_vector = ino_p->ino_sysino; 8300Sstevel@tonic-gate 8310Sstevel@tonic-gate if ((ret = px_ib_ino_add_intr(px_p, ino_p, ih_p)) 8320Sstevel@tonic-gate != DDI_SUCCESS) 8330Sstevel@tonic-gate goto fail1; 8340Sstevel@tonic-gate } else { 8350Sstevel@tonic-gate ino_p = px_ib_new_ino(ib_p, ino, ih_p); 8360Sstevel@tonic-gate 8370Sstevel@tonic-gate if (hdlp->ih_pri == 0) 8380Sstevel@tonic-gate hdlp->ih_pri = px_class_to_pil(rdip); 8390Sstevel@tonic-gate 8400Sstevel@tonic-gate /* Save mondo value in hdlp */ 8410Sstevel@tonic-gate hdlp->ih_vector = ino_p->ino_sysino; 8420Sstevel@tonic-gate 8430Sstevel@tonic-gate DBG(DBG_A_INTX, dip, "px_add_intx_intr: pil=0x%x mondo=0x%x\n", 8440Sstevel@tonic-gate hdlp->ih_pri, hdlp->ih_vector); 8450Sstevel@tonic-gate 8460Sstevel@tonic-gate DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp, 8470Sstevel@tonic-gate (ddi_intr_handler_t *)px_intx_intr, (caddr_t)ino_p, NULL); 8480Sstevel@tonic-gate 8490Sstevel@tonic-gate ret = i_ddi_add_ivintr(hdlp); 8500Sstevel@tonic-gate 8510Sstevel@tonic-gate /* 8520Sstevel@tonic-gate * Restore original interrupt handler 8530Sstevel@tonic-gate * and arguments in interrupt handle. 8540Sstevel@tonic-gate */ 8550Sstevel@tonic-gate DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp, ih_p->ih_handler, 8560Sstevel@tonic-gate ih_p->ih_handler_arg1, ih_p->ih_handler_arg2); 8570Sstevel@tonic-gate 8580Sstevel@tonic-gate if (ret != DDI_SUCCESS) 8590Sstevel@tonic-gate goto fail2; 8600Sstevel@tonic-gate 8610Sstevel@tonic-gate /* Save the pil for this ino */ 8620Sstevel@tonic-gate ino_p->ino_pil = hdlp->ih_pri; 8630Sstevel@tonic-gate 8640Sstevel@tonic-gate /* select cpu, saving it for sharing and removal */ 8650Sstevel@tonic-gate ino_p->ino_cpuid = intr_dist_cpuid(); 8660Sstevel@tonic-gate 8670Sstevel@tonic-gate /* Enable interrupt */ 8680Sstevel@tonic-gate px_ib_intr_enable(px_p, ino_p->ino_cpuid, ino); 8690Sstevel@tonic-gate } 8700Sstevel@tonic-gate 8710Sstevel@tonic-gate /* add weight to the cpu that we are already targeting */ 8720Sstevel@tonic-gate weight = px_class_to_intr_weight(rdip); 8730Sstevel@tonic-gate intr_dist_cpuid_add_device_weight(ino_p->ino_cpuid, rdip, weight); 8740Sstevel@tonic-gate 8750Sstevel@tonic-gate ih_p->ih_ino_p = ino_p; 8760Sstevel@tonic-gate if (ih_p->ih_ksp) 8770Sstevel@tonic-gate kstat_install(ih_p->ih_ksp); 8780Sstevel@tonic-gate mutex_exit(&ib_p->ib_ino_lst_mutex); 8790Sstevel@tonic-gate 8800Sstevel@tonic-gate DBG(DBG_A_INTX, dip, "px_add_intx_intr: done! Interrupt 0x%x pil=%x\n", 8810Sstevel@tonic-gate ino_p->ino_sysino, hdlp->ih_pri); 8820Sstevel@tonic-gate 8830Sstevel@tonic-gate return (ret); 8840Sstevel@tonic-gate fail2: 8850Sstevel@tonic-gate px_ib_delete_ino(ib_p, ino_p); 8860Sstevel@tonic-gate fail1: 8870Sstevel@tonic-gate if (ih_p->ih_config_handle) 8880Sstevel@tonic-gate pci_config_teardown(&ih_p->ih_config_handle); 8890Sstevel@tonic-gate 8900Sstevel@tonic-gate mutex_exit(&ib_p->ib_ino_lst_mutex); 8910Sstevel@tonic-gate kmem_free(ih_p, sizeof (px_ih_t)); 8920Sstevel@tonic-gate 8930Sstevel@tonic-gate DBG(DBG_A_INTX, dip, "px_add_intx_intr: Failed! Interrupt 0x%x " 8940Sstevel@tonic-gate "pil=%x\n", ino_p->ino_sysino, hdlp->ih_pri); 8950Sstevel@tonic-gate 8960Sstevel@tonic-gate return (ret); 8970Sstevel@tonic-gate } 8980Sstevel@tonic-gate 8990Sstevel@tonic-gate int 9000Sstevel@tonic-gate px_rem_intx_intr(dev_info_t *dip, dev_info_t *rdip, 9010Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp) 9020Sstevel@tonic-gate { 9030Sstevel@tonic-gate px_t *px_p = INST_TO_STATE(ddi_get_instance(dip)); 9040Sstevel@tonic-gate px_ib_t *ib_p = px_p->px_ib_p; 9050Sstevel@tonic-gate devino_t ino; 9060Sstevel@tonic-gate cpuid_t curr_cpu; 9070Sstevel@tonic-gate px_ib_ino_info_t *ino_p; 9080Sstevel@tonic-gate px_ih_t *ih_p; 9090Sstevel@tonic-gate int ret = DDI_SUCCESS; 9100Sstevel@tonic-gate 9110Sstevel@tonic-gate ino = hdlp->ih_vector; 9120Sstevel@tonic-gate 9130Sstevel@tonic-gate DBG(DBG_R_INTX, dip, "px_rem_intx_intr: rdip=%s%d ino=%x\n", 9140Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip), ino); 9150Sstevel@tonic-gate 9160Sstevel@tonic-gate mutex_enter(&ib_p->ib_ino_lst_mutex); 9170Sstevel@tonic-gate 9180Sstevel@tonic-gate ino_p = px_ib_locate_ino(ib_p, ino); 9190Sstevel@tonic-gate ih_p = px_ib_ino_locate_intr(ino_p, rdip, hdlp->ih_inum, 0, 0); 9200Sstevel@tonic-gate 9210Sstevel@tonic-gate /* Get the current cpu */ 9220Sstevel@tonic-gate if ((ret = px_lib_intr_gettarget(px_p->px_dip, ino_p->ino_sysino, 9230Sstevel@tonic-gate &curr_cpu)) != DDI_SUCCESS) 9240Sstevel@tonic-gate goto fail; 9250Sstevel@tonic-gate 9260Sstevel@tonic-gate if ((ret = px_ib_ino_rem_intr(px_p, ino_p, ih_p)) != DDI_SUCCESS) 9270Sstevel@tonic-gate goto fail; 9280Sstevel@tonic-gate 9290Sstevel@tonic-gate intr_dist_cpuid_rem_device_weight(ino_p->ino_cpuid, rdip); 9300Sstevel@tonic-gate 9310Sstevel@tonic-gate if (ino_p->ino_ih_size == 0) { 9320Sstevel@tonic-gate if ((ret = px_lib_intr_setstate(px_p->px_dip, ino_p->ino_sysino, 9330Sstevel@tonic-gate INTR_DELIVERED_STATE)) != DDI_SUCCESS) 9340Sstevel@tonic-gate goto fail; 9350Sstevel@tonic-gate 9360Sstevel@tonic-gate hdlp->ih_vector = ino_p->ino_sysino; 9370Sstevel@tonic-gate i_ddi_rem_ivintr(hdlp); 9380Sstevel@tonic-gate 9390Sstevel@tonic-gate px_ib_delete_ino(ib_p, ino_p); 9400Sstevel@tonic-gate kmem_free(ino_p, sizeof (px_ib_ino_info_t)); 9410Sstevel@tonic-gate } else { 9420Sstevel@tonic-gate /* Re-enable interrupt only if mapping regsiter still shared */ 9430Sstevel@tonic-gate if ((ret = px_lib_intr_settarget(px_p->px_dip, 9440Sstevel@tonic-gate ino_p->ino_sysino, curr_cpu)) != DDI_SUCCESS) 9450Sstevel@tonic-gate goto fail; 9460Sstevel@tonic-gate 9470Sstevel@tonic-gate ret = px_lib_intr_setvalid(px_p->px_dip, ino_p->ino_sysino, 9480Sstevel@tonic-gate INTR_VALID); 9490Sstevel@tonic-gate } 9500Sstevel@tonic-gate 9510Sstevel@tonic-gate fail: 9520Sstevel@tonic-gate mutex_exit(&ib_p->ib_ino_lst_mutex); 9530Sstevel@tonic-gate return (ret); 9540Sstevel@tonic-gate } 9550Sstevel@tonic-gate 9560Sstevel@tonic-gate int 9570Sstevel@tonic-gate px_add_msiq_intr(dev_info_t *dip, dev_info_t *rdip, 9580Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, msiq_rec_type_t rec_type, 9590Sstevel@tonic-gate msgcode_t msg_code, msiqid_t *msiq_id_p) 9600Sstevel@tonic-gate { 9610Sstevel@tonic-gate px_t *px_p = INST_TO_STATE(ddi_get_instance(dip)); 9620Sstevel@tonic-gate px_ib_t *ib_p = px_p->px_ib_p; 9630Sstevel@tonic-gate px_msiq_state_t *msiq_state_p = &ib_p->ib_msiq_state; 9640Sstevel@tonic-gate devino_t ino; 9650Sstevel@tonic-gate px_ih_t *ih_p; 9660Sstevel@tonic-gate px_ib_ino_info_t *ino_p; 9670Sstevel@tonic-gate int32_t weight; 9680Sstevel@tonic-gate int ret = DDI_SUCCESS; 9690Sstevel@tonic-gate 9700Sstevel@tonic-gate DBG(DBG_MSIQ, dip, "px_add_msiq_intr: rdip=%s%d handler=%x " 9710Sstevel@tonic-gate "arg1=%x arg2=%x\n", ddi_driver_name(rdip), ddi_get_instance(rdip), 9720Sstevel@tonic-gate hdlp->ih_cb_func, hdlp->ih_cb_arg1, hdlp->ih_cb_arg2); 9730Sstevel@tonic-gate 9740Sstevel@tonic-gate if ((ret = px_msiq_alloc(px_p, rec_type, msiq_id_p)) != DDI_SUCCESS) { 9750Sstevel@tonic-gate DBG(DBG_MSIQ, dip, "px_add_msiq_intr: " 9760Sstevel@tonic-gate "msiq allocation failed\n"); 9770Sstevel@tonic-gate return (ret); 9780Sstevel@tonic-gate } 9790Sstevel@tonic-gate 9800Sstevel@tonic-gate ino = px_msiqid_to_devino(px_p, *msiq_id_p); 9810Sstevel@tonic-gate 9820Sstevel@tonic-gate ih_p = px_ib_alloc_ih(rdip, hdlp->ih_inum, hdlp->ih_cb_func, 9830Sstevel@tonic-gate hdlp->ih_cb_arg1, hdlp->ih_cb_arg2, rec_type, msg_code); 9840Sstevel@tonic-gate 9850Sstevel@tonic-gate mutex_enter(&ib_p->ib_ino_lst_mutex); 9860Sstevel@tonic-gate 9870Sstevel@tonic-gate if (ino_p = px_ib_locate_ino(ib_p, ino)) { /* sharing ino */ 9880Sstevel@tonic-gate uint32_t intr_index = hdlp->ih_inum; 9890Sstevel@tonic-gate if (px_ib_ino_locate_intr(ino_p, rdip, 9900Sstevel@tonic-gate intr_index, rec_type, msg_code)) { 9910Sstevel@tonic-gate DBG(DBG_MSIQ, dip, "px_add_msiq_intr: " 9920Sstevel@tonic-gate "dup intr #%d\n", intr_index); 9930Sstevel@tonic-gate 9940Sstevel@tonic-gate ret = DDI_FAILURE; 9950Sstevel@tonic-gate goto fail1; 9960Sstevel@tonic-gate } 9970Sstevel@tonic-gate 9980Sstevel@tonic-gate if ((ret = px_ib_ino_add_intr(px_p, ino_p, ih_p)) 9990Sstevel@tonic-gate != DDI_SUCCESS) 10000Sstevel@tonic-gate goto fail1; 10010Sstevel@tonic-gate } else { 10020Sstevel@tonic-gate ino_p = px_ib_new_ino(ib_p, ino, ih_p); 10030Sstevel@tonic-gate 10040Sstevel@tonic-gate ino_p->ino_msiq_p = msiq_state_p->msiq_p + 10050Sstevel@tonic-gate (*msiq_id_p - msiq_state_p->msiq_1st_msiq_id); 10060Sstevel@tonic-gate 10070Sstevel@tonic-gate if (hdlp->ih_pri == 0) 10080Sstevel@tonic-gate hdlp->ih_pri = px_class_to_pil(rdip); 10090Sstevel@tonic-gate 10100Sstevel@tonic-gate /* Save mondo value in hdlp */ 10110Sstevel@tonic-gate hdlp->ih_vector = ino_p->ino_sysino; 10120Sstevel@tonic-gate 10130Sstevel@tonic-gate DBG(DBG_MSIQ, dip, "px_add_msiq_intr: pil=0x%x mondo=0x%x\n", 10140Sstevel@tonic-gate hdlp->ih_pri, hdlp->ih_vector); 10150Sstevel@tonic-gate 10160Sstevel@tonic-gate DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp, 10170Sstevel@tonic-gate (ddi_intr_handler_t *)px_msiq_intr, (caddr_t)ino_p, NULL); 10180Sstevel@tonic-gate 10190Sstevel@tonic-gate ret = i_ddi_add_ivintr(hdlp); 10200Sstevel@tonic-gate 10210Sstevel@tonic-gate /* 10220Sstevel@tonic-gate * Restore original interrupt handler 10230Sstevel@tonic-gate * and arguments in interrupt handle. 10240Sstevel@tonic-gate */ 10250Sstevel@tonic-gate DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp, ih_p->ih_handler, 10260Sstevel@tonic-gate ih_p->ih_handler_arg1, ih_p->ih_handler_arg2); 10270Sstevel@tonic-gate 10280Sstevel@tonic-gate if (ret != DDI_SUCCESS) 10290Sstevel@tonic-gate goto fail2; 10300Sstevel@tonic-gate 10310Sstevel@tonic-gate /* Save the pil for this ino */ 10320Sstevel@tonic-gate ino_p->ino_pil = hdlp->ih_pri; 10330Sstevel@tonic-gate 10340Sstevel@tonic-gate /* Enable MSIQ */ 10350Sstevel@tonic-gate px_lib_msiq_setstate(dip, *msiq_id_p, PCI_MSIQ_STATE_IDLE); 10360Sstevel@tonic-gate px_lib_msiq_setvalid(dip, *msiq_id_p, PCI_MSIQ_VALID); 10370Sstevel@tonic-gate 10380Sstevel@tonic-gate /* select cpu, saving it for sharing and removal */ 10390Sstevel@tonic-gate ino_p->ino_cpuid = intr_dist_cpuid(); 10400Sstevel@tonic-gate 10410Sstevel@tonic-gate /* Enable interrupt */ 10420Sstevel@tonic-gate px_ib_intr_enable(px_p, ino_p->ino_cpuid, ino_p->ino_ino); 10430Sstevel@tonic-gate } 10440Sstevel@tonic-gate 10450Sstevel@tonic-gate /* add weight to the cpu that we are already targeting */ 10460Sstevel@tonic-gate weight = px_class_to_intr_weight(rdip); 10470Sstevel@tonic-gate intr_dist_cpuid_add_device_weight(ino_p->ino_cpuid, rdip, weight); 10480Sstevel@tonic-gate 10490Sstevel@tonic-gate ih_p->ih_ino_p = ino_p; 10500Sstevel@tonic-gate if (ih_p->ih_ksp) 10510Sstevel@tonic-gate kstat_install(ih_p->ih_ksp); 10520Sstevel@tonic-gate mutex_exit(&ib_p->ib_ino_lst_mutex); 10530Sstevel@tonic-gate 10540Sstevel@tonic-gate DBG(DBG_MSIQ, dip, "px_add_msiq_intr: done! Interrupt 0x%x pil=%x\n", 10550Sstevel@tonic-gate ino_p->ino_sysino, hdlp->ih_pri); 10560Sstevel@tonic-gate 10570Sstevel@tonic-gate return (ret); 10580Sstevel@tonic-gate fail2: 10590Sstevel@tonic-gate px_ib_delete_ino(ib_p, ino_p); 10600Sstevel@tonic-gate fail1: 10610Sstevel@tonic-gate if (ih_p->ih_config_handle) 10620Sstevel@tonic-gate pci_config_teardown(&ih_p->ih_config_handle); 10630Sstevel@tonic-gate 10640Sstevel@tonic-gate mutex_exit(&ib_p->ib_ino_lst_mutex); 10650Sstevel@tonic-gate kmem_free(ih_p, sizeof (px_ih_t)); 10660Sstevel@tonic-gate 10670Sstevel@tonic-gate DBG(DBG_MSIQ, dip, "px_add_msiq_intr: Failed! Interrupt 0x%x pil=%x\n", 10680Sstevel@tonic-gate ino_p->ino_sysino, hdlp->ih_pri); 10690Sstevel@tonic-gate 10700Sstevel@tonic-gate return (ret); 10710Sstevel@tonic-gate } 10720Sstevel@tonic-gate 10730Sstevel@tonic-gate int 10740Sstevel@tonic-gate px_rem_msiq_intr(dev_info_t *dip, dev_info_t *rdip, 10750Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, msiq_rec_type_t rec_type, 10760Sstevel@tonic-gate msgcode_t msg_code, msiqid_t msiq_id) 10770Sstevel@tonic-gate { 10780Sstevel@tonic-gate px_t *px_p = INST_TO_STATE(ddi_get_instance(dip)); 10790Sstevel@tonic-gate px_ib_t *ib_p = px_p->px_ib_p; 10800Sstevel@tonic-gate devino_t ino = px_msiqid_to_devino(px_p, msiq_id); 10810Sstevel@tonic-gate cpuid_t curr_cpu; 10820Sstevel@tonic-gate px_ib_ino_info_t *ino_p; 10830Sstevel@tonic-gate px_ih_t *ih_p; 10840Sstevel@tonic-gate int ret = DDI_SUCCESS; 10850Sstevel@tonic-gate 10860Sstevel@tonic-gate DBG(DBG_MSIQ, dip, "px_rem_msiq_intr: rdip=%s%d msiq_id=%x ino=%x\n", 10870Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip), msiq_id, ino); 10880Sstevel@tonic-gate 10890Sstevel@tonic-gate mutex_enter(&ib_p->ib_ino_lst_mutex); 10900Sstevel@tonic-gate 10910Sstevel@tonic-gate ino_p = px_ib_locate_ino(ib_p, ino); 10920Sstevel@tonic-gate ih_p = px_ib_ino_locate_intr(ino_p, rdip, hdlp->ih_inum, 10930Sstevel@tonic-gate rec_type, msg_code); 10940Sstevel@tonic-gate 10950Sstevel@tonic-gate /* Get the current cpu */ 10960Sstevel@tonic-gate if ((ret = px_lib_intr_gettarget(px_p->px_dip, ino_p->ino_sysino, 10970Sstevel@tonic-gate &curr_cpu)) != DDI_SUCCESS) 10980Sstevel@tonic-gate goto fail; 10990Sstevel@tonic-gate 11000Sstevel@tonic-gate if ((ret = px_ib_ino_rem_intr(px_p, ino_p, ih_p)) != DDI_SUCCESS) 11010Sstevel@tonic-gate goto fail; 11020Sstevel@tonic-gate 11030Sstevel@tonic-gate intr_dist_cpuid_rem_device_weight(ino_p->ino_cpuid, rdip); 11040Sstevel@tonic-gate 11050Sstevel@tonic-gate if (ino_p->ino_ih_size == 0) { 11060Sstevel@tonic-gate if ((ret = px_lib_intr_setstate(px_p->px_dip, ino_p->ino_sysino, 11070Sstevel@tonic-gate INTR_DELIVERED_STATE)) != DDI_SUCCESS) 11080Sstevel@tonic-gate goto fail; 11090Sstevel@tonic-gate 11100Sstevel@tonic-gate px_lib_msiq_setvalid(dip, px_devino_to_msiqid(px_p, ino), 11110Sstevel@tonic-gate PCI_MSIQ_INVALID); 11120Sstevel@tonic-gate 11130Sstevel@tonic-gate hdlp->ih_vector = ino_p->ino_sysino; 11140Sstevel@tonic-gate i_ddi_rem_ivintr(hdlp); 11150Sstevel@tonic-gate 11160Sstevel@tonic-gate px_ib_delete_ino(ib_p, ino_p); 11170Sstevel@tonic-gate 11180Sstevel@tonic-gate (void) px_msiq_free(px_p, msiq_id); 11190Sstevel@tonic-gate kmem_free(ino_p, sizeof (px_ib_ino_info_t)); 11200Sstevel@tonic-gate } else { 11210Sstevel@tonic-gate /* Re-enable interrupt only if mapping regsiter still shared */ 11220Sstevel@tonic-gate if ((ret = px_lib_intr_settarget(px_p->px_dip, 1123*27Sjchu ino_p->ino_sysino, curr_cpu)) != DDI_SUCCESS) 11240Sstevel@tonic-gate goto fail; 11250Sstevel@tonic-gate 11260Sstevel@tonic-gate ret = px_lib_intr_setvalid(px_p->px_dip, ino_p->ino_sysino, 11270Sstevel@tonic-gate INTR_VALID); 11280Sstevel@tonic-gate } 11290Sstevel@tonic-gate 11300Sstevel@tonic-gate fail: 11310Sstevel@tonic-gate mutex_exit(&ib_p->ib_ino_lst_mutex); 11320Sstevel@tonic-gate return (ret); 11330Sstevel@tonic-gate } 1134