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 /* 221542Sjohnny * Copyright 2006 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 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 /* 118693Sgovinda * px_intx_intr (INTx or legacy 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 /* 208693Sgovinda * px_msiq_intr (MSI/X or PCIe 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; 235*2588Segillett msiqhead_t new_head_index = msiq_p->msiq_curr_head_idx; 236*2588Segillett msiqhead_t *curr_head_p; 237*2588Segillett msiqtail_t curr_tail_index; 2380Sstevel@tonic-gate msgcode_t msg_code; 2390Sstevel@tonic-gate px_ih_t *ih_p; 2401653Sgovinda int i, ret; 241*2588Segillett ushort_t msiq_recs2process; 2420Sstevel@tonic-gate 2430Sstevel@tonic-gate DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: msiq_id =%x ino=%x pil=%x " 2440Sstevel@tonic-gate "ih_size=%x ih_lst=%x\n", msiq_p->msiq_id, ino_p->ino_ino, 2450Sstevel@tonic-gate ino_p->ino_pil, ino_p->ino_ih_size, ino_p->ino_ih_head); 2460Sstevel@tonic-gate 247*2588Segillett /* Read current MSIQ tail index */ 248*2588Segillett px_lib_msiq_gettail(dip, msiq_p->msiq_id, &curr_tail_index); 2490Sstevel@tonic-gate 250*2588Segillett if (curr_tail_index < new_head_index) 251*2588Segillett curr_tail_index += msiq_state_p->msiq_rec_cnt; 2520Sstevel@tonic-gate 2530Sstevel@tonic-gate /* 254*2588Segillett * Calculate the number of recs to process by taking the difference 255*2588Segillett * between the head and tail pointers. For all records we always 256*2588Segillett * verify that we have a valid record type before we do any processing. 257*2588Segillett * If triggered, we should always have at least 1 valid record. 2580Sstevel@tonic-gate */ 259*2588Segillett msiq_recs2process = curr_tail_index - new_head_index; 260*2588Segillett 261*2588Segillett DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: curr_head %x " 262*2588Segillett "rec2process %x\n", new_head_index, msiq_recs2process); 263*2588Segillett 264*2588Segillett curr_head_p = (msiqhead_t *)((caddr_t)msiq_p->msiq_base_p + 265*2588Segillett new_head_index * sizeof (msiq_rec_t)); 266*2588Segillett 267*2588Segillett for (i = 0; i < msiq_recs2process; i++) { 268*2588Segillett /* Read MSIQ record */ 269*2588Segillett px_lib_get_msiq_rec(dip, curr_head_p, msiq_rec_p); 270*2588Segillett 2710Sstevel@tonic-gate DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: MSIQ RECORD, " 2720Sstevel@tonic-gate "msiq_rec_type 0x%llx msiq_rec_rid 0x%llx\n", 2730Sstevel@tonic-gate msiq_rec_p->msiq_rec_type, msiq_rec_p->msiq_rec_rid); 2740Sstevel@tonic-gate 275*2588Segillett if (!msiq_rec_p->msiq_rec_type) 276*2588Segillett break; 2770Sstevel@tonic-gate 2780Sstevel@tonic-gate /* Check MSIQ record type */ 2790Sstevel@tonic-gate switch (msiq_rec_p->msiq_rec_type) { 2800Sstevel@tonic-gate case MSG_REC: 2810Sstevel@tonic-gate msg_code = msiq_rec_p->msiq_rec_data.msg.msg_code; 2820Sstevel@tonic-gate DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: PCIE MSG " 2830Sstevel@tonic-gate "record, msg type 0x%x\n", msg_code); 2840Sstevel@tonic-gate break; 2850Sstevel@tonic-gate case MSI32_REC: 2860Sstevel@tonic-gate case MSI64_REC: 2870Sstevel@tonic-gate msg_code = msiq_rec_p->msiq_rec_data.msi.msi_data; 2880Sstevel@tonic-gate DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: MSI record, " 2890Sstevel@tonic-gate "msi 0x%x\n", msg_code); 2900Sstevel@tonic-gate 2910Sstevel@tonic-gate /* Clear MSI state */ 2920Sstevel@tonic-gate px_lib_msi_setstate(dip, (msinum_t)msg_code, 2930Sstevel@tonic-gate PCI_MSI_STATE_IDLE); 2940Sstevel@tonic-gate break; 2950Sstevel@tonic-gate default: 2960Sstevel@tonic-gate msg_code = 0; 2970Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: px_msiq_intr: 0x%x MSIQ " 2980Sstevel@tonic-gate "record type is not supported", 2990Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip), 3000Sstevel@tonic-gate msiq_rec_p->msiq_rec_type); 3010Sstevel@tonic-gate goto next_rec; 3020Sstevel@tonic-gate } 3030Sstevel@tonic-gate 3040Sstevel@tonic-gate /* 3050Sstevel@tonic-gate * Scan through px_ih_t linked list, searching for the 3060Sstevel@tonic-gate * right px_ih_t, matching MSIQ record data. 3070Sstevel@tonic-gate */ 3081653Sgovinda for (i = 0, ih_p = ino_p->ino_ih_start; 3091653Sgovinda ih_p && (i < ino_p->ino_ih_size) && 3101653Sgovinda ((ih_p->ih_msg_code != msg_code) || 3111653Sgovinda (ih_p->ih_rec_type != msiq_rec_p->msiq_rec_type)); 3121653Sgovinda ih_p = ih_p->ih_next, i++); 3130Sstevel@tonic-gate 3140Sstevel@tonic-gate if ((ih_p->ih_msg_code == msg_code) && 3150Sstevel@tonic-gate (ih_p->ih_rec_type == msiq_rec_p->msiq_rec_type)) { 3160Sstevel@tonic-gate dev_info_t *dip = ih_p->ih_dip; 3170Sstevel@tonic-gate uint_t (*handler)() = ih_p->ih_handler; 3180Sstevel@tonic-gate caddr_t arg1 = ih_p->ih_handler_arg1; 3190Sstevel@tonic-gate caddr_t arg2 = ih_p->ih_handler_arg2; 3200Sstevel@tonic-gate 3210Sstevel@tonic-gate DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: ino=%x data=%x " 3220Sstevel@tonic-gate "handler=%p arg1 =%p arg2=%p\n", ino_p->ino_ino, 3230Sstevel@tonic-gate msg_code, handler, arg1, arg2); 3240Sstevel@tonic-gate 3250Sstevel@tonic-gate DTRACE_PROBE4(interrupt__start, dev_info_t, dip, 3260Sstevel@tonic-gate void *, handler, caddr_t, arg1, caddr_t, arg2); 3270Sstevel@tonic-gate 32827Sjchu /* 32927Sjchu * Special case for PCIE Error Messages. 33027Sjchu * The current frame work doesn't fit PCIE Err Msgs 33127Sjchu * This should be fixed when PCIE MESSAGES as a whole 33227Sjchu * is architected correctly. 33327Sjchu */ 33427Sjchu if ((msg_code == PCIE_MSG_CODE_ERR_COR) || 33527Sjchu (msg_code == PCIE_MSG_CODE_ERR_NONFATAL) || 33627Sjchu (msg_code == PCIE_MSG_CODE_ERR_FATAL)) { 33727Sjchu ret = px_err_fabric_intr(px_p, msg_code, 33827Sjchu msiq_rec_p->msiq_rec_rid); 33927Sjchu } else 34027Sjchu ret = (*handler)(arg1, arg2); 3410Sstevel@tonic-gate 3420Sstevel@tonic-gate /* 3430Sstevel@tonic-gate * Account for time used by this interrupt. Protect 3440Sstevel@tonic-gate * against conflicting writes to ih_ticks from 3450Sstevel@tonic-gate * ib_intr_dist_all() by using atomic ops. 3460Sstevel@tonic-gate */ 3470Sstevel@tonic-gate 3480Sstevel@tonic-gate if (ino_p->ino_pil <= LOCK_LEVEL) 3490Sstevel@tonic-gate atomic_add_64(&ih_p->ih_ticks, intr_get_time()); 3500Sstevel@tonic-gate 3510Sstevel@tonic-gate DTRACE_PROBE4(interrupt__complete, dev_info_t, dip, 3520Sstevel@tonic-gate void *, handler, caddr_t, arg1, int, ret); 353*2588Segillett 354*2588Segillett new_head_index++; 3550Sstevel@tonic-gate } else { 3560Sstevel@tonic-gate DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr:" 357*2588Segillett "No matching MSIQ record found\n"); 358*2588Segillett } 359*2588Segillett next_rec: 360*2588Segillett /* Get the pointer next EQ record */ 361*2588Segillett curr_head_p = (msiqhead_t *) 362*2588Segillett ((caddr_t)curr_head_p + sizeof (msiq_rec_t)); 3630Sstevel@tonic-gate 364*2588Segillett /* Check for overflow condition */ 365*2588Segillett if (curr_head_p >= (msiqhead_t *)((caddr_t)msiq_p->msiq_base_p 366*2588Segillett + msiq_state_p->msiq_rec_cnt * sizeof (msiq_rec_t))) 367*2588Segillett curr_head_p = (msiqhead_t *)msiq_p->msiq_base_p; 3680Sstevel@tonic-gate 369287Smg140465 /* Zero out msiq_rec_type field */ 370287Smg140465 msiq_rec_p->msiq_rec_type = 0; 3710Sstevel@tonic-gate } 3720Sstevel@tonic-gate 373*2588Segillett DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: # of MSIQ recs processed %x\n", 374*2588Segillett (new_head_index - msiq_p->msiq_curr_head_idx)); 375*2588Segillett 376*2588Segillett if (new_head_index <= msiq_p->msiq_curr_head_idx) { 377*2588Segillett if (px_unclaimed_intr_block) { 378*2588Segillett return (px_spurintr(ino_p)); 379*2588Segillett } 380*2588Segillett } 3810Sstevel@tonic-gate 3820Sstevel@tonic-gate /* Update MSIQ head index with no of MSIQ records processed */ 383*2588Segillett if (new_head_index >= msiq_state_p->msiq_rec_cnt) 384*2588Segillett new_head_index -= msiq_state_p->msiq_rec_cnt; 3850Sstevel@tonic-gate 386*2588Segillett msiq_p->msiq_curr_head_idx = new_head_index; 387*2588Segillett px_lib_msiq_sethead(dip, msiq_p->msiq_id, new_head_index); 3880Sstevel@tonic-gate 3890Sstevel@tonic-gate /* Clear the pending state */ 3900Sstevel@tonic-gate if (px_lib_intr_setstate(dip, ino_p->ino_sysino, 3910Sstevel@tonic-gate INTR_IDLE_STATE) != DDI_SUCCESS) 3920Sstevel@tonic-gate return (DDI_INTR_UNCLAIMED); 3930Sstevel@tonic-gate 3940Sstevel@tonic-gate return (DDI_INTR_CLAIMED); 3950Sstevel@tonic-gate } 3960Sstevel@tonic-gate 3970Sstevel@tonic-gate dev_info_t * 3980Sstevel@tonic-gate px_get_my_childs_dip(dev_info_t *dip, dev_info_t *rdip) 3990Sstevel@tonic-gate { 4000Sstevel@tonic-gate dev_info_t *cdip = rdip; 4010Sstevel@tonic-gate 4020Sstevel@tonic-gate for (; ddi_get_parent(cdip) != dip; cdip = ddi_get_parent(cdip)) 4030Sstevel@tonic-gate ; 4040Sstevel@tonic-gate 4050Sstevel@tonic-gate return (cdip); 4060Sstevel@tonic-gate } 4070Sstevel@tonic-gate 4080Sstevel@tonic-gate /* Default class to pil value mapping */ 4090Sstevel@tonic-gate px_class_val_t px_default_pil [] = { 4100Sstevel@tonic-gate {0x000000, 0xff0000, 0x1}, /* Class code for pre-2.0 devices */ 4110Sstevel@tonic-gate {0x010000, 0xff0000, 0x4}, /* Mass Storage Controller */ 4120Sstevel@tonic-gate {0x020000, 0xff0000, 0x6}, /* Network Controller */ 4130Sstevel@tonic-gate {0x030000, 0xff0000, 0x9}, /* Display Controller */ 4140Sstevel@tonic-gate {0x040000, 0xff0000, 0x9}, /* Multimedia Controller */ 4151617Sgovinda {0x050000, 0xff0000, 0x9}, /* Memory Controller */ 4161617Sgovinda {0x060000, 0xff0000, 0x9}, /* Bridge Controller */ 4170Sstevel@tonic-gate {0x0c0000, 0xffff00, 0x9}, /* Serial Bus, FireWire (IEEE 1394) */ 4180Sstevel@tonic-gate {0x0c0100, 0xffff00, 0x4}, /* Serial Bus, ACCESS.bus */ 4190Sstevel@tonic-gate {0x0c0200, 0xffff00, 0x4}, /* Serial Bus, SSA */ 4200Sstevel@tonic-gate {0x0c0300, 0xffff00, 0x9}, /* Serial Bus Universal Serial Bus */ 4210Sstevel@tonic-gate {0x0c0400, 0xffff00, 0x6}, /* Serial Bus, Fibre Channel */ 4220Sstevel@tonic-gate {0x0c0600, 0xffff00, 0x6} /* Serial Bus, Infiniband */ 4230Sstevel@tonic-gate }; 4240Sstevel@tonic-gate 4250Sstevel@tonic-gate /* 4260Sstevel@tonic-gate * Default class to intr_weight value mapping (% of CPU). A driver.conf 4270Sstevel@tonic-gate * entry on or above the pci node like 4280Sstevel@tonic-gate * 4290Sstevel@tonic-gate * pci-class-intr-weights= 0x020000, 0xff0000, 30; 4300Sstevel@tonic-gate * 4310Sstevel@tonic-gate * can be used to augment or override entries in the default table below. 4320Sstevel@tonic-gate * 4330Sstevel@tonic-gate * NB: The values below give NICs preference on redistribution, and provide 4340Sstevel@tonic-gate * NICs some isolation from other interrupt sources. We need better interfaces 4350Sstevel@tonic-gate * that allow the NIC driver to identify a specific NIC instance as high 4360Sstevel@tonic-gate * bandwidth, and thus deserving of separation from other low bandwidth 4370Sstevel@tonic-gate * NICs additional isolation from other interrupt sources. 4380Sstevel@tonic-gate * 4390Sstevel@tonic-gate * NB: We treat Infiniband like a NIC. 4400Sstevel@tonic-gate */ 4410Sstevel@tonic-gate px_class_val_t px_default_intr_weight [] = { 4420Sstevel@tonic-gate {0x020000, 0xff0000, 35}, /* Network Controller */ 4430Sstevel@tonic-gate {0x010000, 0xff0000, 10}, /* Mass Storage Controller */ 4440Sstevel@tonic-gate {0x0c0400, 0xffff00, 10}, /* Serial Bus, Fibre Channel */ 4450Sstevel@tonic-gate {0x0c0600, 0xffff00, 50} /* Serial Bus, Infiniband */ 4460Sstevel@tonic-gate }; 4470Sstevel@tonic-gate 4480Sstevel@tonic-gate static uint32_t 4490Sstevel@tonic-gate px_match_class_val(uint32_t key, px_class_val_t *rec_p, int nrec, 4500Sstevel@tonic-gate uint32_t default_val) 4510Sstevel@tonic-gate { 4520Sstevel@tonic-gate int i; 4530Sstevel@tonic-gate 4540Sstevel@tonic-gate for (i = 0; i < nrec; rec_p++, i++) { 4550Sstevel@tonic-gate if ((rec_p->class_code & rec_p->class_mask) == 4560Sstevel@tonic-gate (key & rec_p->class_mask)) 4570Sstevel@tonic-gate return (rec_p->class_val); 4580Sstevel@tonic-gate } 4590Sstevel@tonic-gate 4600Sstevel@tonic-gate return (default_val); 4610Sstevel@tonic-gate } 4620Sstevel@tonic-gate 4630Sstevel@tonic-gate /* 4640Sstevel@tonic-gate * px_class_to_val 4650Sstevel@tonic-gate * 4660Sstevel@tonic-gate * Return the configuration value, based on class code and sub class code, 4670Sstevel@tonic-gate * from the specified property based or default px_class_val_t table. 4680Sstevel@tonic-gate */ 4690Sstevel@tonic-gate uint32_t 4700Sstevel@tonic-gate px_class_to_val(dev_info_t *rdip, char *property_name, px_class_val_t *rec_p, 4710Sstevel@tonic-gate int nrec, uint32_t default_val) 4720Sstevel@tonic-gate { 4730Sstevel@tonic-gate int property_len; 4740Sstevel@tonic-gate uint32_t class_code; 4750Sstevel@tonic-gate px_class_val_t *conf; 4760Sstevel@tonic-gate uint32_t val = default_val; 4770Sstevel@tonic-gate 4780Sstevel@tonic-gate /* 4790Sstevel@tonic-gate * Use the "class-code" property to get the base and sub class 4800Sstevel@tonic-gate * codes for the requesting device. 4810Sstevel@tonic-gate */ 4820Sstevel@tonic-gate class_code = (uint32_t)ddi_prop_get_int(DDI_DEV_T_ANY, rdip, 4830Sstevel@tonic-gate DDI_PROP_DONTPASS, "class-code", -1); 4840Sstevel@tonic-gate 4850Sstevel@tonic-gate if (class_code == -1) 4860Sstevel@tonic-gate return (val); 4870Sstevel@tonic-gate 4880Sstevel@tonic-gate /* look up the val from the default table */ 4890Sstevel@tonic-gate val = px_match_class_val(class_code, rec_p, nrec, val); 4900Sstevel@tonic-gate 4910Sstevel@tonic-gate /* see if there is a more specific property specified value */ 4920Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_ANY, rdip, DDI_PROP_NOTPROM, 4930Sstevel@tonic-gate property_name, (caddr_t)&conf, &property_len)) 4940Sstevel@tonic-gate return (val); 4950Sstevel@tonic-gate 4960Sstevel@tonic-gate if ((property_len % sizeof (px_class_val_t)) == 0) 4970Sstevel@tonic-gate val = px_match_class_val(class_code, conf, 4980Sstevel@tonic-gate property_len / sizeof (px_class_val_t), val); 4990Sstevel@tonic-gate kmem_free(conf, property_len); 5000Sstevel@tonic-gate return (val); 5010Sstevel@tonic-gate } 5020Sstevel@tonic-gate 5030Sstevel@tonic-gate /* px_class_to_pil: return the pil for a given device. */ 5040Sstevel@tonic-gate uint32_t 5050Sstevel@tonic-gate px_class_to_pil(dev_info_t *rdip) 5060Sstevel@tonic-gate { 5070Sstevel@tonic-gate uint32_t pil; 5080Sstevel@tonic-gate 5090Sstevel@tonic-gate /* default pil is 0 (uninitialized) */ 5100Sstevel@tonic-gate pil = px_class_to_val(rdip, 5110Sstevel@tonic-gate "pci-class-priorities", px_default_pil, 5120Sstevel@tonic-gate sizeof (px_default_pil) / sizeof (px_class_val_t), 0); 5130Sstevel@tonic-gate 5140Sstevel@tonic-gate /* range check the result */ 5150Sstevel@tonic-gate if (pil >= 0xf) 5160Sstevel@tonic-gate pil = 0; 5170Sstevel@tonic-gate 5180Sstevel@tonic-gate return (pil); 5190Sstevel@tonic-gate } 5200Sstevel@tonic-gate 5210Sstevel@tonic-gate /* px_class_to_intr_weight: return the intr_weight for a given device. */ 5220Sstevel@tonic-gate static int32_t 5230Sstevel@tonic-gate px_class_to_intr_weight(dev_info_t *rdip) 5240Sstevel@tonic-gate { 5250Sstevel@tonic-gate int32_t intr_weight; 5260Sstevel@tonic-gate 5270Sstevel@tonic-gate /* default weight is 0% */ 5280Sstevel@tonic-gate intr_weight = px_class_to_val(rdip, 5290Sstevel@tonic-gate "pci-class-intr-weights", px_default_intr_weight, 5300Sstevel@tonic-gate sizeof (px_default_intr_weight) / sizeof (px_class_val_t), 0); 5310Sstevel@tonic-gate 5320Sstevel@tonic-gate /* range check the result */ 5330Sstevel@tonic-gate if (intr_weight < 0) 5340Sstevel@tonic-gate intr_weight = 0; 5350Sstevel@tonic-gate if (intr_weight > 1000) 5360Sstevel@tonic-gate intr_weight = 1000; 5370Sstevel@tonic-gate 5380Sstevel@tonic-gate return (intr_weight); 5390Sstevel@tonic-gate } 5400Sstevel@tonic-gate 5410Sstevel@tonic-gate /* ARGSUSED */ 5420Sstevel@tonic-gate int 5430Sstevel@tonic-gate px_intx_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op, 5440Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, void *result) 5450Sstevel@tonic-gate { 546693Sgovinda px_t *px_p = DIP_TO_STATE(dip); 547693Sgovinda int ret = DDI_SUCCESS; 5480Sstevel@tonic-gate 5490Sstevel@tonic-gate DBG(DBG_INTROPS, dip, "px_intx_ops: dip=%x rdip=%x intr_op=%x " 5500Sstevel@tonic-gate "handle=%p\n", dip, rdip, intr_op, hdlp); 5510Sstevel@tonic-gate 5520Sstevel@tonic-gate switch (intr_op) { 5530Sstevel@tonic-gate case DDI_INTROP_GETCAP: 5540Sstevel@tonic-gate ret = pci_intx_get_cap(rdip, (int *)result); 5550Sstevel@tonic-gate break; 5560Sstevel@tonic-gate case DDI_INTROP_SETCAP: 5570Sstevel@tonic-gate DBG(DBG_INTROPS, dip, "px_intx_ops: SetCap is not supported\n"); 5580Sstevel@tonic-gate ret = DDI_ENOTSUP; 5590Sstevel@tonic-gate break; 5600Sstevel@tonic-gate case DDI_INTROP_ALLOC: 5610Sstevel@tonic-gate *(int *)result = hdlp->ih_scratch1; 5620Sstevel@tonic-gate break; 5630Sstevel@tonic-gate case DDI_INTROP_FREE: 5640Sstevel@tonic-gate break; 5650Sstevel@tonic-gate case DDI_INTROP_GETPRI: 566693Sgovinda *(int *)result = hdlp->ih_pri ? 567693Sgovinda hdlp->ih_pri : px_class_to_pil(rdip); 5680Sstevel@tonic-gate break; 5690Sstevel@tonic-gate case DDI_INTROP_SETPRI: 5700Sstevel@tonic-gate break; 5710Sstevel@tonic-gate case DDI_INTROP_ADDISR: 5720Sstevel@tonic-gate ret = px_add_intx_intr(dip, rdip, hdlp); 5730Sstevel@tonic-gate break; 5740Sstevel@tonic-gate case DDI_INTROP_REMISR: 5750Sstevel@tonic-gate ret = px_rem_intx_intr(dip, rdip, hdlp); 5760Sstevel@tonic-gate break; 5770Sstevel@tonic-gate case DDI_INTROP_ENABLE: 5780Sstevel@tonic-gate ret = px_ib_update_intr_state(px_p, rdip, hdlp->ih_inum, 579909Segillett hdlp->ih_vector, PX_INTR_STATE_ENABLE, 0, 0); 5800Sstevel@tonic-gate break; 5810Sstevel@tonic-gate case DDI_INTROP_DISABLE: 5820Sstevel@tonic-gate ret = px_ib_update_intr_state(px_p, rdip, hdlp->ih_inum, 583909Segillett hdlp->ih_vector, PX_INTR_STATE_DISABLE, 0, 0); 5840Sstevel@tonic-gate break; 5850Sstevel@tonic-gate case DDI_INTROP_SETMASK: 5860Sstevel@tonic-gate ret = pci_intx_set_mask(rdip); 5870Sstevel@tonic-gate break; 5880Sstevel@tonic-gate case DDI_INTROP_CLRMASK: 5890Sstevel@tonic-gate ret = pci_intx_clr_mask(rdip); 5900Sstevel@tonic-gate break; 5910Sstevel@tonic-gate case DDI_INTROP_GETPENDING: 5920Sstevel@tonic-gate ret = pci_intx_get_pending(rdip, (int *)result); 5930Sstevel@tonic-gate break; 5940Sstevel@tonic-gate case DDI_INTROP_NINTRS: 5950Sstevel@tonic-gate case DDI_INTROP_NAVAIL: 5962580Sanish *(int *)result = i_ddi_get_intx_nintrs(rdip); 5970Sstevel@tonic-gate break; 5980Sstevel@tonic-gate default: 5990Sstevel@tonic-gate ret = DDI_ENOTSUP; 6000Sstevel@tonic-gate break; 6010Sstevel@tonic-gate } 6020Sstevel@tonic-gate 6030Sstevel@tonic-gate return (ret); 6040Sstevel@tonic-gate } 6050Sstevel@tonic-gate 6060Sstevel@tonic-gate /* ARGSUSED */ 6070Sstevel@tonic-gate int 6080Sstevel@tonic-gate px_msix_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op, 6090Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, void *result) 6100Sstevel@tonic-gate { 6110Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip); 6120Sstevel@tonic-gate px_msi_state_t *msi_state_p = &px_p->px_ib_p->ib_msi_state; 613965Sgovinda msiq_rec_type_t msiq_rec_type; 614965Sgovinda msi_type_t msi_type; 615965Sgovinda uint64_t msi_addr; 6160Sstevel@tonic-gate msinum_t msi_num; 6170Sstevel@tonic-gate msiqid_t msiq_id; 6180Sstevel@tonic-gate uint_t nintrs; 6190Sstevel@tonic-gate int i, ret = DDI_SUCCESS; 6200Sstevel@tonic-gate 6210Sstevel@tonic-gate DBG(DBG_INTROPS, dip, "px_msix_ops: dip=%x rdip=%x intr_op=%x " 6220Sstevel@tonic-gate "handle=%p\n", dip, rdip, intr_op, hdlp); 6230Sstevel@tonic-gate 624965Sgovinda /* Check for MSI64 support */ 6251653Sgovinda if ((hdlp->ih_cap & DDI_INTR_FLAG_MSI64) && msi_state_p->msi_addr64) { 626965Sgovinda msiq_rec_type = MSI64_REC; 627965Sgovinda msi_type = MSI64_TYPE; 6281653Sgovinda msi_addr = msi_state_p->msi_addr64; 629965Sgovinda } else { 630965Sgovinda msiq_rec_type = MSI32_REC; 631965Sgovinda msi_type = MSI32_TYPE; 632965Sgovinda msi_addr = msi_state_p->msi_addr32; 633965Sgovinda } 634965Sgovinda 6350Sstevel@tonic-gate switch (intr_op) { 6360Sstevel@tonic-gate case DDI_INTROP_GETCAP: 6370Sstevel@tonic-gate ret = pci_msi_get_cap(rdip, hdlp->ih_type, (int *)result); 6380Sstevel@tonic-gate break; 6390Sstevel@tonic-gate case DDI_INTROP_SETCAP: 6400Sstevel@tonic-gate DBG(DBG_INTROPS, dip, "px_msix_ops: SetCap is not supported\n"); 6410Sstevel@tonic-gate ret = DDI_ENOTSUP; 6420Sstevel@tonic-gate break; 6430Sstevel@tonic-gate case DDI_INTROP_ALLOC: 6440Sstevel@tonic-gate /* 6450Sstevel@tonic-gate * We need to restrict this allocation in future 6460Sstevel@tonic-gate * based on Resource Management policies. 6470Sstevel@tonic-gate */ 6480Sstevel@tonic-gate if ((ret = px_msi_alloc(px_p, rdip, hdlp->ih_inum, 6491725Segillett hdlp->ih_scratch1, (uintptr_t)hdlp->ih_scratch2, &msi_num, 6501725Segillett (int *)result)) != DDI_SUCCESS) { 6511725Segillett DBG(DBG_INTROPS, dip, "px_msix_ops: allocation " 6521725Segillett "failed, rdip 0x%p type 0x%d inum 0x%x " 6531725Segillett "count 0x%x\n", rdip, hdlp->ih_type, hdlp->ih_inum, 6541725Segillett hdlp->ih_scratch1); 6550Sstevel@tonic-gate 6560Sstevel@tonic-gate return (ret); 6570Sstevel@tonic-gate } 6580Sstevel@tonic-gate 6591725Segillett if ((hdlp->ih_type == DDI_INTR_TYPE_MSIX) && 6601725Segillett (i_ddi_get_msix(rdip) == NULL)) { 6611725Segillett ddi_intr_msix_t *msix_p; 6621725Segillett 6631725Segillett if (msix_p = pci_msix_init(rdip)) { 6641725Segillett i_ddi_set_msix(rdip, msix_p); 6651725Segillett break; 6661725Segillett } 6671725Segillett 6681725Segillett DBG(DBG_INTROPS, dip, "px_msix_ops: MSI-X allocation " 6691725Segillett "failed, rdip 0x%p inum 0x%x\n", rdip, 6701725Segillett hdlp->ih_inum); 6711725Segillett 6721725Segillett (void) px_msi_free(px_p, rdip, hdlp->ih_inum, 6731725Segillett hdlp->ih_scratch1); 6741725Segillett 6751725Segillett return (DDI_FAILURE); 6761725Segillett } 6771725Segillett 6780Sstevel@tonic-gate break; 6790Sstevel@tonic-gate case DDI_INTROP_FREE: 6800Sstevel@tonic-gate (void) pci_msi_disable_mode(rdip, hdlp->ih_type, hdlp->ih_inum); 6810Sstevel@tonic-gate (void) pci_msi_unconfigure(rdip, hdlp->ih_type, hdlp->ih_inum); 6821725Segillett 6831725Segillett if (hdlp->ih_type == DDI_INTR_TYPE_MSI) 6841725Segillett goto msi_free; 6851725Segillett 6861725Segillett if (hdlp->ih_flags & DDI_INTR_MSIX_DUP) 6871725Segillett break; 6881725Segillett 6891725Segillett if (((i_ddi_intr_get_current_nintrs(hdlp->ih_dip) - 1) == 0) && 6901725Segillett (i_ddi_get_msix(rdip))) { 6911725Segillett pci_msix_fini(i_ddi_get_msix(rdip)); 6921725Segillett i_ddi_set_msix(rdip, NULL); 6931725Segillett } 6941725Segillett msi_free: 6950Sstevel@tonic-gate (void) px_msi_free(px_p, rdip, hdlp->ih_inum, 6960Sstevel@tonic-gate hdlp->ih_scratch1); 6970Sstevel@tonic-gate break; 6980Sstevel@tonic-gate case DDI_INTROP_GETPRI: 6990Sstevel@tonic-gate *(int *)result = hdlp->ih_pri ? 7000Sstevel@tonic-gate hdlp->ih_pri : px_class_to_pil(rdip); 7010Sstevel@tonic-gate break; 7020Sstevel@tonic-gate case DDI_INTROP_SETPRI: 7030Sstevel@tonic-gate break; 7040Sstevel@tonic-gate case DDI_INTROP_ADDISR: 7050Sstevel@tonic-gate if ((ret = px_msi_get_msinum(px_p, hdlp->ih_dip, 7060Sstevel@tonic-gate hdlp->ih_inum, &msi_num)) != DDI_SUCCESS) 7070Sstevel@tonic-gate return (ret); 7080Sstevel@tonic-gate 7090Sstevel@tonic-gate if ((ret = px_add_msiq_intr(dip, rdip, hdlp, 710965Sgovinda msiq_rec_type, msi_num, &msiq_id)) != DDI_SUCCESS) { 7110Sstevel@tonic-gate DBG(DBG_INTROPS, dip, "px_msix_ops: Add MSI handler " 7120Sstevel@tonic-gate "failed, rdip 0x%p msi 0x%x\n", rdip, msi_num); 7130Sstevel@tonic-gate return (ret); 7140Sstevel@tonic-gate } 7150Sstevel@tonic-gate 7160Sstevel@tonic-gate DBG(DBG_INTROPS, dip, "px_msix_ops: msiq used 0x%x\n", msiq_id); 7170Sstevel@tonic-gate 7180Sstevel@tonic-gate if ((ret = px_lib_msi_setmsiq(dip, msi_num, 719965Sgovinda msiq_id, msi_type)) != DDI_SUCCESS) { 7200Sstevel@tonic-gate (void) px_rem_msiq_intr(dip, rdip, 721965Sgovinda hdlp, msiq_rec_type, msi_num, msiq_id); 7220Sstevel@tonic-gate return (ret); 7230Sstevel@tonic-gate } 7240Sstevel@tonic-gate 7250Sstevel@tonic-gate if ((ret = px_lib_msi_setstate(dip, msi_num, 7260Sstevel@tonic-gate PCI_MSI_STATE_IDLE)) != DDI_SUCCESS) { 7270Sstevel@tonic-gate (void) px_rem_msiq_intr(dip, rdip, 728965Sgovinda hdlp, msiq_rec_type, msi_num, msiq_id); 7290Sstevel@tonic-gate return (ret); 7300Sstevel@tonic-gate } 7310Sstevel@tonic-gate 7320Sstevel@tonic-gate hdlp->ih_vector = msi_num; 7330Sstevel@tonic-gate break; 7340Sstevel@tonic-gate case DDI_INTROP_DUPVEC: 7351725Segillett DBG(DBG_INTROPS, dip, "px_msix_ops: dupisr - inum: %x, " 7361725Segillett "new_vector: %x\n", hdlp->ih_inum, hdlp->ih_scratch1); 7371725Segillett 7381725Segillett ret = pci_msix_dup(hdlp->ih_dip, hdlp->ih_inum, 7391725Segillett hdlp->ih_scratch1); 7400Sstevel@tonic-gate break; 7410Sstevel@tonic-gate case DDI_INTROP_REMISR: 7420Sstevel@tonic-gate msi_num = hdlp->ih_vector; 7430Sstevel@tonic-gate 7440Sstevel@tonic-gate if ((ret = px_lib_msi_getmsiq(dip, msi_num, 7450Sstevel@tonic-gate &msiq_id)) != DDI_SUCCESS) 7460Sstevel@tonic-gate return (ret); 7470Sstevel@tonic-gate 7480Sstevel@tonic-gate if ((ret = px_lib_msi_setstate(dip, msi_num, 749965Sgovinda PCI_MSI_STATE_IDLE)) != DDI_SUCCESS) 7500Sstevel@tonic-gate return (ret); 7510Sstevel@tonic-gate 7520Sstevel@tonic-gate ret = px_rem_msiq_intr(dip, rdip, 753965Sgovinda hdlp, msiq_rec_type, msi_num, msiq_id); 7540Sstevel@tonic-gate 7550Sstevel@tonic-gate hdlp->ih_vector = 0; 7560Sstevel@tonic-gate break; 7570Sstevel@tonic-gate case DDI_INTROP_ENABLE: 7580Sstevel@tonic-gate msi_num = hdlp->ih_vector; 7590Sstevel@tonic-gate 7600Sstevel@tonic-gate if ((ret = px_lib_msi_setvalid(dip, msi_num, 7610Sstevel@tonic-gate PCI_MSI_VALID)) != DDI_SUCCESS) 7620Sstevel@tonic-gate return (ret); 7630Sstevel@tonic-gate 7640Sstevel@tonic-gate if (pci_is_msi_enabled(rdip, hdlp->ih_type) != DDI_SUCCESS) { 7650Sstevel@tonic-gate nintrs = i_ddi_intr_get_current_nintrs(hdlp->ih_dip); 7660Sstevel@tonic-gate 7670Sstevel@tonic-gate if ((ret = pci_msi_configure(rdip, hdlp->ih_type, 768965Sgovinda nintrs, hdlp->ih_inum, msi_addr, 7690Sstevel@tonic-gate msi_num & ~(nintrs - 1))) != DDI_SUCCESS) 7700Sstevel@tonic-gate return (ret); 7710Sstevel@tonic-gate 7720Sstevel@tonic-gate if ((ret = pci_msi_enable_mode(rdip, hdlp->ih_type, 7730Sstevel@tonic-gate hdlp->ih_inum)) != DDI_SUCCESS) 7740Sstevel@tonic-gate return (ret); 7750Sstevel@tonic-gate } 7760Sstevel@tonic-gate 777909Segillett if ((ret = pci_msi_clr_mask(rdip, hdlp->ih_type, 778909Segillett hdlp->ih_inum)) != DDI_SUCCESS) 779909Segillett return (ret); 780909Segillett 7811725Segillett if (hdlp->ih_flags & DDI_INTR_MSIX_DUP) 7821725Segillett break; 7831725Segillett 784909Segillett if ((ret = px_lib_msi_getmsiq(dip, msi_num, 785909Segillett &msiq_id)) != DDI_SUCCESS) 786909Segillett return (ret); 787909Segillett 788909Segillett ret = px_ib_update_intr_state(px_p, rdip, hdlp->ih_inum, 789909Segillett px_msiqid_to_devino(px_p, msiq_id), PX_INTR_STATE_ENABLE, 790965Sgovinda msiq_rec_type, msi_num); 7910Sstevel@tonic-gate 7920Sstevel@tonic-gate break; 7930Sstevel@tonic-gate case DDI_INTROP_DISABLE: 7940Sstevel@tonic-gate msi_num = hdlp->ih_vector; 7950Sstevel@tonic-gate 7960Sstevel@tonic-gate if ((ret = pci_msi_set_mask(rdip, hdlp->ih_type, 7970Sstevel@tonic-gate hdlp->ih_inum)) != DDI_SUCCESS) 7980Sstevel@tonic-gate return (ret); 7990Sstevel@tonic-gate 800909Segillett if ((ret = px_lib_msi_setvalid(dip, msi_num, 801909Segillett PCI_MSI_INVALID)) != DDI_SUCCESS) 802909Segillett return (ret); 803909Segillett 8041725Segillett if (hdlp->ih_flags & DDI_INTR_MSIX_DUP) 8051725Segillett break; 8061725Segillett 807909Segillett if ((ret = px_lib_msi_getmsiq(dip, msi_num, 808909Segillett &msiq_id)) != DDI_SUCCESS) 809909Segillett return (ret); 810909Segillett 811909Segillett ret = px_ib_update_intr_state(px_p, rdip, 812909Segillett hdlp->ih_inum, px_msiqid_to_devino(px_p, msiq_id), 813965Sgovinda PX_INTR_STATE_DISABLE, msiq_rec_type, msi_num); 814909Segillett 8150Sstevel@tonic-gate break; 8160Sstevel@tonic-gate case DDI_INTROP_BLOCKENABLE: 8170Sstevel@tonic-gate nintrs = i_ddi_intr_get_current_nintrs(hdlp->ih_dip); 8180Sstevel@tonic-gate msi_num = hdlp->ih_vector; 8190Sstevel@tonic-gate 8200Sstevel@tonic-gate if ((ret = pci_msi_configure(rdip, hdlp->ih_type, 821965Sgovinda nintrs, hdlp->ih_inum, msi_addr, 8220Sstevel@tonic-gate msi_num & ~(nintrs - 1))) != DDI_SUCCESS) 8230Sstevel@tonic-gate return (ret); 8240Sstevel@tonic-gate 8250Sstevel@tonic-gate for (i = 0; i < nintrs; i++, msi_num++) { 8260Sstevel@tonic-gate if ((ret = px_lib_msi_setvalid(dip, msi_num, 8270Sstevel@tonic-gate PCI_MSI_VALID)) != DDI_SUCCESS) 8280Sstevel@tonic-gate return (ret); 829909Segillett 830909Segillett if ((ret = px_lib_msi_getmsiq(dip, msi_num, 831909Segillett &msiq_id)) != DDI_SUCCESS) 832909Segillett return (ret); 833909Segillett 834909Segillett if ((ret = px_ib_update_intr_state(px_p, rdip, 835909Segillett hdlp->ih_inum + i, px_msiqid_to_devino(px_p, 836965Sgovinda msiq_id), PX_INTR_STATE_ENABLE, msiq_rec_type, 837965Sgovinda msi_num)) != DDI_SUCCESS) 838909Segillett return (ret); 8390Sstevel@tonic-gate } 8400Sstevel@tonic-gate 8410Sstevel@tonic-gate ret = pci_msi_enable_mode(rdip, hdlp->ih_type, hdlp->ih_inum); 8420Sstevel@tonic-gate break; 8430Sstevel@tonic-gate case DDI_INTROP_BLOCKDISABLE: 8440Sstevel@tonic-gate nintrs = i_ddi_intr_get_current_nintrs(hdlp->ih_dip); 8450Sstevel@tonic-gate msi_num = hdlp->ih_vector; 8460Sstevel@tonic-gate 8470Sstevel@tonic-gate if ((ret = pci_msi_disable_mode(rdip, hdlp->ih_type, 8480Sstevel@tonic-gate hdlp->ih_inum)) != DDI_SUCCESS) 8490Sstevel@tonic-gate return (ret); 8500Sstevel@tonic-gate 8510Sstevel@tonic-gate for (i = 0; i < nintrs; i++, msi_num++) { 8520Sstevel@tonic-gate if ((ret = px_lib_msi_setvalid(dip, msi_num, 8530Sstevel@tonic-gate PCI_MSI_INVALID)) != DDI_SUCCESS) 8540Sstevel@tonic-gate return (ret); 855909Segillett 856909Segillett if ((ret = px_lib_msi_getmsiq(dip, msi_num, 857909Segillett &msiq_id)) != DDI_SUCCESS) 858909Segillett return (ret); 859909Segillett 860909Segillett if ((ret = px_ib_update_intr_state(px_p, rdip, 861909Segillett hdlp->ih_inum + i, px_msiqid_to_devino(px_p, 862965Sgovinda msiq_id), PX_INTR_STATE_DISABLE, msiq_rec_type, 863909Segillett msi_num)) != DDI_SUCCESS) 864909Segillett return (ret); 8650Sstevel@tonic-gate } 8660Sstevel@tonic-gate 8670Sstevel@tonic-gate break; 8680Sstevel@tonic-gate case DDI_INTROP_SETMASK: 8690Sstevel@tonic-gate ret = pci_msi_set_mask(rdip, hdlp->ih_type, hdlp->ih_inum); 8700Sstevel@tonic-gate break; 8710Sstevel@tonic-gate case DDI_INTROP_CLRMASK: 8720Sstevel@tonic-gate ret = pci_msi_clr_mask(rdip, hdlp->ih_type, hdlp->ih_inum); 8730Sstevel@tonic-gate break; 8740Sstevel@tonic-gate case DDI_INTROP_GETPENDING: 8750Sstevel@tonic-gate ret = pci_msi_get_pending(rdip, hdlp->ih_type, 8760Sstevel@tonic-gate hdlp->ih_inum, (int *)result); 8770Sstevel@tonic-gate break; 8780Sstevel@tonic-gate case DDI_INTROP_NINTRS: 8790Sstevel@tonic-gate ret = pci_msi_get_nintrs(rdip, hdlp->ih_type, (int *)result); 8800Sstevel@tonic-gate break; 8810Sstevel@tonic-gate case DDI_INTROP_NAVAIL: 8820Sstevel@tonic-gate /* XXX - a new interface may be needed */ 8830Sstevel@tonic-gate ret = pci_msi_get_nintrs(rdip, hdlp->ih_type, (int *)result); 8840Sstevel@tonic-gate break; 8850Sstevel@tonic-gate default: 8860Sstevel@tonic-gate ret = DDI_ENOTSUP; 8870Sstevel@tonic-gate break; 8880Sstevel@tonic-gate } 8890Sstevel@tonic-gate 8900Sstevel@tonic-gate return (ret); 8910Sstevel@tonic-gate } 8920Sstevel@tonic-gate 89366Sesolom static struct { 89466Sesolom kstat_named_t pxintr_ks_name; 89566Sesolom kstat_named_t pxintr_ks_type; 89666Sesolom kstat_named_t pxintr_ks_cpu; 89766Sesolom kstat_named_t pxintr_ks_pil; 89866Sesolom kstat_named_t pxintr_ks_time; 89966Sesolom kstat_named_t pxintr_ks_ino; 90066Sesolom kstat_named_t pxintr_ks_cookie; 90166Sesolom kstat_named_t pxintr_ks_devpath; 90266Sesolom kstat_named_t pxintr_ks_buspath; 90366Sesolom } pxintr_ks_template = { 90466Sesolom { "name", KSTAT_DATA_CHAR }, 90566Sesolom { "type", KSTAT_DATA_CHAR }, 90666Sesolom { "cpu", KSTAT_DATA_UINT64 }, 90766Sesolom { "pil", KSTAT_DATA_UINT64 }, 90866Sesolom { "time", KSTAT_DATA_UINT64 }, 90966Sesolom { "ino", KSTAT_DATA_UINT64 }, 91066Sesolom { "cookie", KSTAT_DATA_UINT64 }, 91166Sesolom { "devpath", KSTAT_DATA_STRING }, 91266Sesolom { "buspath", KSTAT_DATA_STRING }, 91366Sesolom }; 91466Sesolom 91566Sesolom static uint32_t pxintr_ks_instance; 9161811Sesolom static char ih_devpath[MAXPATHLEN]; 9171811Sesolom static char ih_buspath[MAXPATHLEN]; 91866Sesolom kmutex_t pxintr_ks_template_lock; 91966Sesolom 92066Sesolom int 92166Sesolom px_ks_update(kstat_t *ksp, int rw) 92266Sesolom { 92366Sesolom px_ih_t *ih_p = ksp->ks_private; 92466Sesolom int maxlen = sizeof (pxintr_ks_template.pxintr_ks_name.value.c); 92566Sesolom px_ib_t *ib_p = ih_p->ih_ino_p->ino_ib_p; 92666Sesolom px_t *px_p = ib_p->ib_px_p; 92766Sesolom devino_t ino; 92866Sesolom sysino_t sysino; 92966Sesolom 93066Sesolom ino = ih_p->ih_ino_p->ino_ino; 93166Sesolom (void) px_lib_intr_devino_to_sysino(px_p->px_dip, ino, &sysino); 93266Sesolom 93366Sesolom (void) snprintf(pxintr_ks_template.pxintr_ks_name.value.c, maxlen, 93466Sesolom "%s%d", ddi_driver_name(ih_p->ih_dip), 93566Sesolom ddi_get_instance(ih_p->ih_dip)); 93666Sesolom 93766Sesolom (void) ddi_pathname(ih_p->ih_dip, ih_devpath); 93866Sesolom (void) ddi_pathname(px_p->px_dip, ih_buspath); 93966Sesolom kstat_named_setstr(&pxintr_ks_template.pxintr_ks_devpath, ih_devpath); 94066Sesolom kstat_named_setstr(&pxintr_ks_template.pxintr_ks_buspath, ih_buspath); 94166Sesolom 9421087Sschwartz if (ih_p->ih_intr_state == PX_INTR_STATE_ENABLE) { 9431087Sschwartz 9441087Sschwartz (void) strcpy(pxintr_ks_template.pxintr_ks_type.value.c, 9451087Sschwartz (ih_p->ih_rec_type == 0) ? "fixed" : "msi"); 9461087Sschwartz pxintr_ks_template.pxintr_ks_cpu.value.ui64 = 9471087Sschwartz ih_p->ih_ino_p->ino_cpuid; 9481087Sschwartz pxintr_ks_template.pxintr_ks_pil.value.ui64 = 9491087Sschwartz ih_p->ih_ino_p->ino_pil; 9501087Sschwartz pxintr_ks_template.pxintr_ks_time.value.ui64 = ih_p->ih_nsec + 9511087Sschwartz (uint64_t)tick2ns((hrtime_t)ih_p->ih_ticks, 9521087Sschwartz ih_p->ih_ino_p->ino_cpuid); 9531087Sschwartz pxintr_ks_template.pxintr_ks_ino.value.ui64 = ino; 9541087Sschwartz pxintr_ks_template.pxintr_ks_cookie.value.ui64 = sysino; 9551087Sschwartz } else { 9561087Sschwartz (void) strcpy(pxintr_ks_template.pxintr_ks_type.value.c, 9571087Sschwartz "disabled"); 9581087Sschwartz pxintr_ks_template.pxintr_ks_cpu.value.ui64 = 0; 9591087Sschwartz pxintr_ks_template.pxintr_ks_pil.value.ui64 = 0; 9601087Sschwartz pxintr_ks_template.pxintr_ks_time.value.ui64 = 0; 9611087Sschwartz pxintr_ks_template.pxintr_ks_ino.value.ui64 = 0; 9621087Sschwartz pxintr_ks_template.pxintr_ks_cookie.value.ui64 = 0; 9631087Sschwartz } 96466Sesolom return (0); 96566Sesolom } 96666Sesolom 96766Sesolom void 96866Sesolom px_create_intr_kstats(px_ih_t *ih_p) 96966Sesolom { 97066Sesolom msiq_rec_type_t rec_type = ih_p->ih_rec_type; 97166Sesolom 97266Sesolom ASSERT(ih_p->ih_ksp == NULL); 97366Sesolom 97466Sesolom /* 97566Sesolom * Create pci_intrs::: kstats for all ih types except messages, 97666Sesolom * which represent unusual conditions and don't need to be tracked. 97766Sesolom */ 97866Sesolom if (rec_type == 0 || rec_type == MSI32_REC || rec_type == MSI64_REC) { 97966Sesolom ih_p->ih_ksp = kstat_create("pci_intrs", 98066Sesolom atomic_inc_32_nv(&pxintr_ks_instance), "config", 98166Sesolom "interrupts", KSTAT_TYPE_NAMED, 98266Sesolom sizeof (pxintr_ks_template) / sizeof (kstat_named_t), 98366Sesolom KSTAT_FLAG_VIRTUAL); 98466Sesolom } 98566Sesolom if (ih_p->ih_ksp != NULL) { 98666Sesolom ih_p->ih_ksp->ks_data_size += MAXPATHLEN * 2; 98766Sesolom ih_p->ih_ksp->ks_lock = &pxintr_ks_template_lock; 98866Sesolom ih_p->ih_ksp->ks_data = &pxintr_ks_template; 98966Sesolom ih_p->ih_ksp->ks_private = ih_p; 99066Sesolom ih_p->ih_ksp->ks_update = px_ks_update; 99166Sesolom } 99266Sesolom } 99366Sesolom 994693Sgovinda /* 995693Sgovinda * px_add_intx_intr: 996693Sgovinda * 997693Sgovinda * This function is called to register INTx and legacy hardware 998693Sgovinda * interrupt pins interrupts. 999693Sgovinda */ 10000Sstevel@tonic-gate int 10010Sstevel@tonic-gate px_add_intx_intr(dev_info_t *dip, dev_info_t *rdip, 10020Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp) 10030Sstevel@tonic-gate { 10040Sstevel@tonic-gate px_t *px_p = INST_TO_STATE(ddi_get_instance(dip)); 10050Sstevel@tonic-gate px_ib_t *ib_p = px_p->px_ib_p; 10060Sstevel@tonic-gate devino_t ino; 10070Sstevel@tonic-gate px_ih_t *ih_p; 10080Sstevel@tonic-gate px_ib_ino_info_t *ino_p; 10090Sstevel@tonic-gate int32_t weight; 10100Sstevel@tonic-gate int ret = DDI_SUCCESS; 10110Sstevel@tonic-gate 10120Sstevel@tonic-gate ino = hdlp->ih_vector; 10130Sstevel@tonic-gate 10140Sstevel@tonic-gate DBG(DBG_A_INTX, dip, "px_add_intx_intr: rdip=%s%d ino=%x " 10150Sstevel@tonic-gate "handler=%x arg1=%x arg2=%x\n", ddi_driver_name(rdip), 10160Sstevel@tonic-gate ddi_get_instance(rdip), ino, hdlp->ih_cb_func, 10170Sstevel@tonic-gate hdlp->ih_cb_arg1, hdlp->ih_cb_arg2); 10180Sstevel@tonic-gate 10190Sstevel@tonic-gate ih_p = px_ib_alloc_ih(rdip, hdlp->ih_inum, 10200Sstevel@tonic-gate hdlp->ih_cb_func, hdlp->ih_cb_arg1, hdlp->ih_cb_arg2, 0, 0); 10210Sstevel@tonic-gate 10220Sstevel@tonic-gate mutex_enter(&ib_p->ib_ino_lst_mutex); 10230Sstevel@tonic-gate 10240Sstevel@tonic-gate if (ino_p = px_ib_locate_ino(ib_p, ino)) { /* sharing ino */ 10250Sstevel@tonic-gate uint32_t intr_index = hdlp->ih_inum; 10260Sstevel@tonic-gate if (px_ib_ino_locate_intr(ino_p, rdip, intr_index, 0, 0)) { 10270Sstevel@tonic-gate DBG(DBG_A_INTX, dip, "px_add_intx_intr: " 10280Sstevel@tonic-gate "dup intr #%d\n", intr_index); 10290Sstevel@tonic-gate 10300Sstevel@tonic-gate ret = DDI_FAILURE; 10310Sstevel@tonic-gate goto fail1; 10320Sstevel@tonic-gate } 10330Sstevel@tonic-gate 10340Sstevel@tonic-gate /* Save mondo value in hdlp */ 10350Sstevel@tonic-gate hdlp->ih_vector = ino_p->ino_sysino; 10360Sstevel@tonic-gate 10370Sstevel@tonic-gate if ((ret = px_ib_ino_add_intr(px_p, ino_p, ih_p)) 10380Sstevel@tonic-gate != DDI_SUCCESS) 10390Sstevel@tonic-gate goto fail1; 10400Sstevel@tonic-gate } else { 10410Sstevel@tonic-gate ino_p = px_ib_new_ino(ib_p, ino, ih_p); 10420Sstevel@tonic-gate 10430Sstevel@tonic-gate if (hdlp->ih_pri == 0) 10440Sstevel@tonic-gate hdlp->ih_pri = px_class_to_pil(rdip); 10450Sstevel@tonic-gate 10460Sstevel@tonic-gate /* Save mondo value in hdlp */ 10470Sstevel@tonic-gate hdlp->ih_vector = ino_p->ino_sysino; 10480Sstevel@tonic-gate 10490Sstevel@tonic-gate DBG(DBG_A_INTX, dip, "px_add_intx_intr: pil=0x%x mondo=0x%x\n", 10500Sstevel@tonic-gate hdlp->ih_pri, hdlp->ih_vector); 10510Sstevel@tonic-gate 10520Sstevel@tonic-gate DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp, 10530Sstevel@tonic-gate (ddi_intr_handler_t *)px_intx_intr, (caddr_t)ino_p, NULL); 10540Sstevel@tonic-gate 10550Sstevel@tonic-gate ret = i_ddi_add_ivintr(hdlp); 10560Sstevel@tonic-gate 10570Sstevel@tonic-gate /* 10580Sstevel@tonic-gate * Restore original interrupt handler 10590Sstevel@tonic-gate * and arguments in interrupt handle. 10600Sstevel@tonic-gate */ 10610Sstevel@tonic-gate DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp, ih_p->ih_handler, 10620Sstevel@tonic-gate ih_p->ih_handler_arg1, ih_p->ih_handler_arg2); 10630Sstevel@tonic-gate 10640Sstevel@tonic-gate if (ret != DDI_SUCCESS) 10650Sstevel@tonic-gate goto fail2; 10660Sstevel@tonic-gate 10670Sstevel@tonic-gate /* Save the pil for this ino */ 10680Sstevel@tonic-gate ino_p->ino_pil = hdlp->ih_pri; 10690Sstevel@tonic-gate 10700Sstevel@tonic-gate /* select cpu, saving it for sharing and removal */ 10710Sstevel@tonic-gate ino_p->ino_cpuid = intr_dist_cpuid(); 10720Sstevel@tonic-gate 10730Sstevel@tonic-gate /* Enable interrupt */ 10740Sstevel@tonic-gate px_ib_intr_enable(px_p, ino_p->ino_cpuid, ino); 10750Sstevel@tonic-gate } 10760Sstevel@tonic-gate 10770Sstevel@tonic-gate /* add weight to the cpu that we are already targeting */ 10780Sstevel@tonic-gate weight = px_class_to_intr_weight(rdip); 10790Sstevel@tonic-gate intr_dist_cpuid_add_device_weight(ino_p->ino_cpuid, rdip, weight); 10800Sstevel@tonic-gate 10810Sstevel@tonic-gate ih_p->ih_ino_p = ino_p; 108266Sesolom px_create_intr_kstats(ih_p); 10830Sstevel@tonic-gate if (ih_p->ih_ksp) 10840Sstevel@tonic-gate kstat_install(ih_p->ih_ksp); 10850Sstevel@tonic-gate mutex_exit(&ib_p->ib_ino_lst_mutex); 10860Sstevel@tonic-gate 10870Sstevel@tonic-gate DBG(DBG_A_INTX, dip, "px_add_intx_intr: done! Interrupt 0x%x pil=%x\n", 10880Sstevel@tonic-gate ino_p->ino_sysino, hdlp->ih_pri); 10890Sstevel@tonic-gate 10900Sstevel@tonic-gate return (ret); 10910Sstevel@tonic-gate fail2: 10920Sstevel@tonic-gate px_ib_delete_ino(ib_p, ino_p); 10930Sstevel@tonic-gate fail1: 10940Sstevel@tonic-gate if (ih_p->ih_config_handle) 10950Sstevel@tonic-gate pci_config_teardown(&ih_p->ih_config_handle); 10960Sstevel@tonic-gate 10970Sstevel@tonic-gate mutex_exit(&ib_p->ib_ino_lst_mutex); 10980Sstevel@tonic-gate kmem_free(ih_p, sizeof (px_ih_t)); 10990Sstevel@tonic-gate 11000Sstevel@tonic-gate DBG(DBG_A_INTX, dip, "px_add_intx_intr: Failed! Interrupt 0x%x " 11010Sstevel@tonic-gate "pil=%x\n", ino_p->ino_sysino, hdlp->ih_pri); 11020Sstevel@tonic-gate 11030Sstevel@tonic-gate return (ret); 11040Sstevel@tonic-gate } 11050Sstevel@tonic-gate 1106693Sgovinda /* 1107693Sgovinda * px_rem_intx_intr: 1108693Sgovinda * 1109693Sgovinda * This function is called to unregister INTx and legacy hardware 1110693Sgovinda * interrupt pins interrupts. 1111693Sgovinda */ 11120Sstevel@tonic-gate int 11130Sstevel@tonic-gate px_rem_intx_intr(dev_info_t *dip, dev_info_t *rdip, 11140Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp) 11150Sstevel@tonic-gate { 11160Sstevel@tonic-gate px_t *px_p = INST_TO_STATE(ddi_get_instance(dip)); 11170Sstevel@tonic-gate px_ib_t *ib_p = px_p->px_ib_p; 11180Sstevel@tonic-gate devino_t ino; 11190Sstevel@tonic-gate cpuid_t curr_cpu; 11200Sstevel@tonic-gate px_ib_ino_info_t *ino_p; 11210Sstevel@tonic-gate px_ih_t *ih_p; 11220Sstevel@tonic-gate int ret = DDI_SUCCESS; 11230Sstevel@tonic-gate 11240Sstevel@tonic-gate ino = hdlp->ih_vector; 11250Sstevel@tonic-gate 11260Sstevel@tonic-gate DBG(DBG_R_INTX, dip, "px_rem_intx_intr: rdip=%s%d ino=%x\n", 11270Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip), ino); 11280Sstevel@tonic-gate 11290Sstevel@tonic-gate mutex_enter(&ib_p->ib_ino_lst_mutex); 11300Sstevel@tonic-gate 11310Sstevel@tonic-gate ino_p = px_ib_locate_ino(ib_p, ino); 11320Sstevel@tonic-gate ih_p = px_ib_ino_locate_intr(ino_p, rdip, hdlp->ih_inum, 0, 0); 11330Sstevel@tonic-gate 11340Sstevel@tonic-gate /* Get the current cpu */ 11350Sstevel@tonic-gate if ((ret = px_lib_intr_gettarget(px_p->px_dip, ino_p->ino_sysino, 11360Sstevel@tonic-gate &curr_cpu)) != DDI_SUCCESS) 11370Sstevel@tonic-gate goto fail; 11380Sstevel@tonic-gate 11390Sstevel@tonic-gate if ((ret = px_ib_ino_rem_intr(px_p, ino_p, ih_p)) != DDI_SUCCESS) 11400Sstevel@tonic-gate goto fail; 11410Sstevel@tonic-gate 11420Sstevel@tonic-gate intr_dist_cpuid_rem_device_weight(ino_p->ino_cpuid, rdip); 11430Sstevel@tonic-gate 11440Sstevel@tonic-gate if (ino_p->ino_ih_size == 0) { 11450Sstevel@tonic-gate if ((ret = px_lib_intr_setstate(px_p->px_dip, ino_p->ino_sysino, 11460Sstevel@tonic-gate INTR_DELIVERED_STATE)) != DDI_SUCCESS) 11470Sstevel@tonic-gate goto fail; 11480Sstevel@tonic-gate 11490Sstevel@tonic-gate hdlp->ih_vector = ino_p->ino_sysino; 11500Sstevel@tonic-gate i_ddi_rem_ivintr(hdlp); 11510Sstevel@tonic-gate 11520Sstevel@tonic-gate px_ib_delete_ino(ib_p, ino_p); 11530Sstevel@tonic-gate kmem_free(ino_p, sizeof (px_ib_ino_info_t)); 11540Sstevel@tonic-gate } else { 11550Sstevel@tonic-gate /* Re-enable interrupt only if mapping regsiter still shared */ 1156693Sgovinda PX_INTR_ENABLE(px_p->px_dip, ino_p->ino_sysino, curr_cpu); 11570Sstevel@tonic-gate } 11580Sstevel@tonic-gate 11590Sstevel@tonic-gate fail: 11600Sstevel@tonic-gate mutex_exit(&ib_p->ib_ino_lst_mutex); 11610Sstevel@tonic-gate return (ret); 11620Sstevel@tonic-gate } 11630Sstevel@tonic-gate 1164693Sgovinda /* 1165693Sgovinda * px_add_msiq_intr: 1166693Sgovinda * 1167693Sgovinda * This function is called to register MSI/Xs and PCIe message interrupts. 1168693Sgovinda */ 11690Sstevel@tonic-gate int 11700Sstevel@tonic-gate px_add_msiq_intr(dev_info_t *dip, dev_info_t *rdip, 11710Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, msiq_rec_type_t rec_type, 11720Sstevel@tonic-gate msgcode_t msg_code, msiqid_t *msiq_id_p) 11730Sstevel@tonic-gate { 11740Sstevel@tonic-gate px_t *px_p = INST_TO_STATE(ddi_get_instance(dip)); 11750Sstevel@tonic-gate px_ib_t *ib_p = px_p->px_ib_p; 11760Sstevel@tonic-gate px_msiq_state_t *msiq_state_p = &ib_p->ib_msiq_state; 11770Sstevel@tonic-gate devino_t ino; 11780Sstevel@tonic-gate px_ih_t *ih_p; 11790Sstevel@tonic-gate px_ib_ino_info_t *ino_p; 11800Sstevel@tonic-gate int32_t weight; 11810Sstevel@tonic-gate int ret = DDI_SUCCESS; 11820Sstevel@tonic-gate 11830Sstevel@tonic-gate DBG(DBG_MSIQ, dip, "px_add_msiq_intr: rdip=%s%d handler=%x " 11840Sstevel@tonic-gate "arg1=%x arg2=%x\n", ddi_driver_name(rdip), ddi_get_instance(rdip), 11850Sstevel@tonic-gate hdlp->ih_cb_func, hdlp->ih_cb_arg1, hdlp->ih_cb_arg2); 11860Sstevel@tonic-gate 11870Sstevel@tonic-gate if ((ret = px_msiq_alloc(px_p, rec_type, msiq_id_p)) != DDI_SUCCESS) { 11880Sstevel@tonic-gate DBG(DBG_MSIQ, dip, "px_add_msiq_intr: " 11890Sstevel@tonic-gate "msiq allocation failed\n"); 11900Sstevel@tonic-gate return (ret); 11910Sstevel@tonic-gate } 11920Sstevel@tonic-gate 11930Sstevel@tonic-gate ino = px_msiqid_to_devino(px_p, *msiq_id_p); 11940Sstevel@tonic-gate 11950Sstevel@tonic-gate ih_p = px_ib_alloc_ih(rdip, hdlp->ih_inum, hdlp->ih_cb_func, 11960Sstevel@tonic-gate hdlp->ih_cb_arg1, hdlp->ih_cb_arg2, rec_type, msg_code); 11970Sstevel@tonic-gate 11980Sstevel@tonic-gate mutex_enter(&ib_p->ib_ino_lst_mutex); 11990Sstevel@tonic-gate 12000Sstevel@tonic-gate if (ino_p = px_ib_locate_ino(ib_p, ino)) { /* sharing ino */ 12010Sstevel@tonic-gate uint32_t intr_index = hdlp->ih_inum; 12020Sstevel@tonic-gate if (px_ib_ino_locate_intr(ino_p, rdip, 12030Sstevel@tonic-gate intr_index, rec_type, msg_code)) { 12040Sstevel@tonic-gate DBG(DBG_MSIQ, dip, "px_add_msiq_intr: " 12050Sstevel@tonic-gate "dup intr #%d\n", intr_index); 12060Sstevel@tonic-gate 12070Sstevel@tonic-gate ret = DDI_FAILURE; 12080Sstevel@tonic-gate goto fail1; 12090Sstevel@tonic-gate } 12100Sstevel@tonic-gate 12110Sstevel@tonic-gate if ((ret = px_ib_ino_add_intr(px_p, ino_p, ih_p)) 12120Sstevel@tonic-gate != DDI_SUCCESS) 12130Sstevel@tonic-gate goto fail1; 12140Sstevel@tonic-gate } else { 12150Sstevel@tonic-gate ino_p = px_ib_new_ino(ib_p, ino, ih_p); 12160Sstevel@tonic-gate 12170Sstevel@tonic-gate ino_p->ino_msiq_p = msiq_state_p->msiq_p + 12180Sstevel@tonic-gate (*msiq_id_p - msiq_state_p->msiq_1st_msiq_id); 12190Sstevel@tonic-gate 12200Sstevel@tonic-gate if (hdlp->ih_pri == 0) 12210Sstevel@tonic-gate hdlp->ih_pri = px_class_to_pil(rdip); 12220Sstevel@tonic-gate 12230Sstevel@tonic-gate /* Save mondo value in hdlp */ 12240Sstevel@tonic-gate hdlp->ih_vector = ino_p->ino_sysino; 12250Sstevel@tonic-gate 12260Sstevel@tonic-gate DBG(DBG_MSIQ, dip, "px_add_msiq_intr: pil=0x%x mondo=0x%x\n", 12270Sstevel@tonic-gate hdlp->ih_pri, hdlp->ih_vector); 12280Sstevel@tonic-gate 12290Sstevel@tonic-gate DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp, 12300Sstevel@tonic-gate (ddi_intr_handler_t *)px_msiq_intr, (caddr_t)ino_p, NULL); 12310Sstevel@tonic-gate 12320Sstevel@tonic-gate ret = i_ddi_add_ivintr(hdlp); 12330Sstevel@tonic-gate 12340Sstevel@tonic-gate /* 12350Sstevel@tonic-gate * Restore original interrupt handler 12360Sstevel@tonic-gate * and arguments in interrupt handle. 12370Sstevel@tonic-gate */ 12380Sstevel@tonic-gate DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp, ih_p->ih_handler, 12390Sstevel@tonic-gate ih_p->ih_handler_arg1, ih_p->ih_handler_arg2); 12400Sstevel@tonic-gate 12410Sstevel@tonic-gate if (ret != DDI_SUCCESS) 12420Sstevel@tonic-gate goto fail2; 12430Sstevel@tonic-gate 12440Sstevel@tonic-gate /* Save the pil for this ino */ 12450Sstevel@tonic-gate ino_p->ino_pil = hdlp->ih_pri; 12460Sstevel@tonic-gate 12470Sstevel@tonic-gate /* Enable MSIQ */ 12480Sstevel@tonic-gate px_lib_msiq_setstate(dip, *msiq_id_p, PCI_MSIQ_STATE_IDLE); 12490Sstevel@tonic-gate px_lib_msiq_setvalid(dip, *msiq_id_p, PCI_MSIQ_VALID); 12500Sstevel@tonic-gate 12510Sstevel@tonic-gate /* select cpu, saving it for sharing and removal */ 12520Sstevel@tonic-gate ino_p->ino_cpuid = intr_dist_cpuid(); 12530Sstevel@tonic-gate 12540Sstevel@tonic-gate /* Enable interrupt */ 12550Sstevel@tonic-gate px_ib_intr_enable(px_p, ino_p->ino_cpuid, ino_p->ino_ino); 12560Sstevel@tonic-gate } 12570Sstevel@tonic-gate 12580Sstevel@tonic-gate /* add weight to the cpu that we are already targeting */ 12590Sstevel@tonic-gate weight = px_class_to_intr_weight(rdip); 12600Sstevel@tonic-gate intr_dist_cpuid_add_device_weight(ino_p->ino_cpuid, rdip, weight); 12610Sstevel@tonic-gate 12620Sstevel@tonic-gate ih_p->ih_ino_p = ino_p; 126366Sesolom px_create_intr_kstats(ih_p); 12640Sstevel@tonic-gate if (ih_p->ih_ksp) 12650Sstevel@tonic-gate kstat_install(ih_p->ih_ksp); 12660Sstevel@tonic-gate mutex_exit(&ib_p->ib_ino_lst_mutex); 12670Sstevel@tonic-gate 12680Sstevel@tonic-gate DBG(DBG_MSIQ, dip, "px_add_msiq_intr: done! Interrupt 0x%x pil=%x\n", 12690Sstevel@tonic-gate ino_p->ino_sysino, hdlp->ih_pri); 12700Sstevel@tonic-gate 12710Sstevel@tonic-gate return (ret); 12720Sstevel@tonic-gate fail2: 12730Sstevel@tonic-gate px_ib_delete_ino(ib_p, ino_p); 12740Sstevel@tonic-gate fail1: 12750Sstevel@tonic-gate if (ih_p->ih_config_handle) 12760Sstevel@tonic-gate pci_config_teardown(&ih_p->ih_config_handle); 12770Sstevel@tonic-gate 12780Sstevel@tonic-gate mutex_exit(&ib_p->ib_ino_lst_mutex); 12790Sstevel@tonic-gate kmem_free(ih_p, sizeof (px_ih_t)); 12800Sstevel@tonic-gate 12810Sstevel@tonic-gate DBG(DBG_MSIQ, dip, "px_add_msiq_intr: Failed! Interrupt 0x%x pil=%x\n", 12820Sstevel@tonic-gate ino_p->ino_sysino, hdlp->ih_pri); 12830Sstevel@tonic-gate 12840Sstevel@tonic-gate return (ret); 12850Sstevel@tonic-gate } 12860Sstevel@tonic-gate 1287693Sgovinda /* 1288693Sgovinda * px_rem_msiq_intr: 1289693Sgovinda * 1290693Sgovinda * This function is called to unregister MSI/Xs and PCIe message interrupts. 1291693Sgovinda */ 12920Sstevel@tonic-gate int 12930Sstevel@tonic-gate px_rem_msiq_intr(dev_info_t *dip, dev_info_t *rdip, 12940Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, msiq_rec_type_t rec_type, 12950Sstevel@tonic-gate msgcode_t msg_code, msiqid_t msiq_id) 12960Sstevel@tonic-gate { 12970Sstevel@tonic-gate px_t *px_p = INST_TO_STATE(ddi_get_instance(dip)); 12980Sstevel@tonic-gate px_ib_t *ib_p = px_p->px_ib_p; 12990Sstevel@tonic-gate devino_t ino = px_msiqid_to_devino(px_p, msiq_id); 13000Sstevel@tonic-gate cpuid_t curr_cpu; 13010Sstevel@tonic-gate px_ib_ino_info_t *ino_p; 13020Sstevel@tonic-gate px_ih_t *ih_p; 13030Sstevel@tonic-gate int ret = DDI_SUCCESS; 13040Sstevel@tonic-gate 13050Sstevel@tonic-gate DBG(DBG_MSIQ, dip, "px_rem_msiq_intr: rdip=%s%d msiq_id=%x ino=%x\n", 13060Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip), msiq_id, ino); 13070Sstevel@tonic-gate 13080Sstevel@tonic-gate mutex_enter(&ib_p->ib_ino_lst_mutex); 13090Sstevel@tonic-gate 13100Sstevel@tonic-gate ino_p = px_ib_locate_ino(ib_p, ino); 13110Sstevel@tonic-gate ih_p = px_ib_ino_locate_intr(ino_p, rdip, hdlp->ih_inum, 13120Sstevel@tonic-gate rec_type, msg_code); 13130Sstevel@tonic-gate 13140Sstevel@tonic-gate /* Get the current cpu */ 13150Sstevel@tonic-gate if ((ret = px_lib_intr_gettarget(px_p->px_dip, ino_p->ino_sysino, 13160Sstevel@tonic-gate &curr_cpu)) != DDI_SUCCESS) 13170Sstevel@tonic-gate goto fail; 13180Sstevel@tonic-gate 13190Sstevel@tonic-gate if ((ret = px_ib_ino_rem_intr(px_p, ino_p, ih_p)) != DDI_SUCCESS) 13200Sstevel@tonic-gate goto fail; 13210Sstevel@tonic-gate 13220Sstevel@tonic-gate intr_dist_cpuid_rem_device_weight(ino_p->ino_cpuid, rdip); 13230Sstevel@tonic-gate 13240Sstevel@tonic-gate if (ino_p->ino_ih_size == 0) { 13250Sstevel@tonic-gate if ((ret = px_lib_intr_setstate(px_p->px_dip, ino_p->ino_sysino, 13260Sstevel@tonic-gate INTR_DELIVERED_STATE)) != DDI_SUCCESS) 13270Sstevel@tonic-gate goto fail; 13280Sstevel@tonic-gate 13290Sstevel@tonic-gate px_lib_msiq_setvalid(dip, px_devino_to_msiqid(px_p, ino), 13300Sstevel@tonic-gate PCI_MSIQ_INVALID); 13310Sstevel@tonic-gate 13320Sstevel@tonic-gate hdlp->ih_vector = ino_p->ino_sysino; 13330Sstevel@tonic-gate i_ddi_rem_ivintr(hdlp); 13340Sstevel@tonic-gate 13350Sstevel@tonic-gate px_ib_delete_ino(ib_p, ino_p); 13360Sstevel@tonic-gate 13370Sstevel@tonic-gate (void) px_msiq_free(px_p, msiq_id); 13380Sstevel@tonic-gate kmem_free(ino_p, sizeof (px_ib_ino_info_t)); 13390Sstevel@tonic-gate } else { 13400Sstevel@tonic-gate /* Re-enable interrupt only if mapping regsiter still shared */ 1341693Sgovinda PX_INTR_ENABLE(px_p->px_dip, ino_p->ino_sysino, curr_cpu); 13420Sstevel@tonic-gate } 13430Sstevel@tonic-gate 13440Sstevel@tonic-gate fail: 13450Sstevel@tonic-gate mutex_exit(&ib_p->ib_ino_lst_mutex); 13460Sstevel@tonic-gate return (ret); 13470Sstevel@tonic-gate } 1348