xref: /onnv-gate/usr/src/uts/sun4/io/px/px_intr.c (revision 12603:4f17200860f5)
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 /*
2212564SGongtian.Zhao@Sun.COM  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate  */
240Sstevel@tonic-gate 
250Sstevel@tonic-gate /*
260Sstevel@tonic-gate  * PX nexus interrupt handling:
270Sstevel@tonic-gate  *	PX device interrupt handler wrapper
280Sstevel@tonic-gate  *	PIL lookup routine
290Sstevel@tonic-gate  *	PX device interrupt related initchild code
300Sstevel@tonic-gate  */
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #include <sys/types.h>
330Sstevel@tonic-gate #include <sys/kmem.h>
340Sstevel@tonic-gate #include <sys/async.h>
350Sstevel@tonic-gate #include <sys/spl.h>
360Sstevel@tonic-gate #include <sys/sunddi.h>
3727Sjchu #include <sys/fm/protocol.h>
3827Sjchu #include <sys/fm/util.h>
390Sstevel@tonic-gate #include <sys/machsystm.h>	/* e_ddi_nodeid_to_dip() */
400Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
410Sstevel@tonic-gate #include <sys/sdt.h>
420Sstevel@tonic-gate #include <sys/atomic.h>
430Sstevel@tonic-gate #include "px_obj.h"
4427Sjchu #include <sys/ontrap.h>
4527Sjchu #include <sys/membar.h>
4666Sesolom #include <sys/clock.h>
470Sstevel@tonic-gate 
480Sstevel@tonic-gate /*
490Sstevel@tonic-gate  * interrupt jabber:
500Sstevel@tonic-gate  *
510Sstevel@tonic-gate  * When an interrupt line is jabbering, every time the state machine for the
520Sstevel@tonic-gate  * associated ino is idled, a new mondo will be sent and the ino will go into
530Sstevel@tonic-gate  * the pending state again. The mondo will cause a new call to
540Sstevel@tonic-gate  * px_intr_wrapper() which normally idles the ino's state machine which would
550Sstevel@tonic-gate  * precipitate another trip round the loop.
560Sstevel@tonic-gate  *
570Sstevel@tonic-gate  * The loop can be broken by preventing the ino's state machine from being
580Sstevel@tonic-gate  * idled when an interrupt line is jabbering. See the comment at the
590Sstevel@tonic-gate  * beginning of px_intr_wrapper() explaining how the 'interrupt jabber
600Sstevel@tonic-gate  * protection' code does this.
610Sstevel@tonic-gate  */
620Sstevel@tonic-gate 
630Sstevel@tonic-gate /*LINTLIBRARY*/
640Sstevel@tonic-gate 
650Sstevel@tonic-gate /*
660Sstevel@tonic-gate  * If the unclaimed interrupt count has reached the limit set by
670Sstevel@tonic-gate  * pci_unclaimed_intr_max within the time limit, then all interrupts
680Sstevel@tonic-gate  * on this ino is blocked by not idling the interrupt state machine.
690Sstevel@tonic-gate  */
700Sstevel@tonic-gate static int
px_spurintr(px_ino_pil_t * ipil_p)712973Sgovinda px_spurintr(px_ino_pil_t *ipil_p)
720Sstevel@tonic-gate {
732973Sgovinda 	px_ino_t	*ino_p = ipil_p->ipil_ino_p;
7410596SDaniel.Ice@Sun.COM 	px_ih_t		*ih_p;
752973Sgovinda 	px_t		*px_p = ino_p->ino_ib_p->ib_px_p;
762973Sgovinda 	char		*err_fmt_str;
772973Sgovinda 	boolean_t	blocked = B_FALSE;
782973Sgovinda 	int		i;
790Sstevel@tonic-gate 
802973Sgovinda 	if (ino_p->ino_unclaimed_intrs > px_unclaimed_intr_max)
810Sstevel@tonic-gate 		return (DDI_INTR_CLAIMED);
820Sstevel@tonic-gate 
832973Sgovinda 	if (!ino_p->ino_unclaimed_intrs)
840Sstevel@tonic-gate 		ino_p->ino_spurintr_begin = ddi_get_lbolt();
850Sstevel@tonic-gate 
862973Sgovinda 	ino_p->ino_unclaimed_intrs++;
870Sstevel@tonic-gate 
882973Sgovinda 	if (ino_p->ino_unclaimed_intrs <= px_unclaimed_intr_max)
890Sstevel@tonic-gate 		goto clear;
900Sstevel@tonic-gate 
910Sstevel@tonic-gate 	if (drv_hztousec(ddi_get_lbolt() - ino_p->ino_spurintr_begin)
920Sstevel@tonic-gate 	    > px_spurintr_duration) {
932973Sgovinda 		ino_p->ino_unclaimed_intrs = 0;
940Sstevel@tonic-gate 		goto clear;
950Sstevel@tonic-gate 	}
960Sstevel@tonic-gate 	err_fmt_str = "%s%d: ino 0x%x blocked";
972973Sgovinda 	blocked = B_TRUE;
980Sstevel@tonic-gate 	goto warn;
990Sstevel@tonic-gate clear:
1000Sstevel@tonic-gate 	err_fmt_str = "!%s%d: spurious interrupt from ino 0x%x";
1010Sstevel@tonic-gate warn:
1020Sstevel@tonic-gate 	cmn_err(CE_WARN, err_fmt_str, NAMEINST(px_p->px_dip), ino_p->ino_ino);
10310596SDaniel.Ice@Sun.COM 	for (ipil_p = ino_p->ino_ipil_p; ipil_p;
10410596SDaniel.Ice@Sun.COM 	    ipil_p = ipil_p->ipil_next_p) {
10510596SDaniel.Ice@Sun.COM 		for (i = 0, ih_p = ipil_p->ipil_ih_start;
10610596SDaniel.Ice@Sun.COM 		    i < ipil_p->ipil_ih_size; i++, ih_p = ih_p->ih_next)
10710596SDaniel.Ice@Sun.COM 			cmn_err(CE_CONT, "!%s-%d#%x ", NAMEINST(ih_p->ih_dip),
10810596SDaniel.Ice@Sun.COM 			    ih_p->ih_inum);
10910596SDaniel.Ice@Sun.COM 	}
1100Sstevel@tonic-gate 	cmn_err(CE_CONT, "!\n");
1112973Sgovinda 
1122973Sgovinda 	/* Clear the pending state */
1132973Sgovinda 	if (blocked == B_FALSE) {
1142973Sgovinda 		if (px_lib_intr_setstate(px_p->px_dip, ino_p->ino_sysino,
1152973Sgovinda 		    INTR_IDLE_STATE) != DDI_SUCCESS)
1162973Sgovinda 			return (DDI_INTR_UNCLAIMED);
1172973Sgovinda 	}
1182973Sgovinda 
1190Sstevel@tonic-gate 	return (DDI_INTR_CLAIMED);
1200Sstevel@tonic-gate }
1210Sstevel@tonic-gate 
1220Sstevel@tonic-gate extern uint64_t intr_get_time(void);
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate /*
125693Sgovinda  * px_intx_intr (INTx or legacy interrupt handler)
1260Sstevel@tonic-gate  *
1270Sstevel@tonic-gate  * This routine is used as wrapper around interrupt handlers installed by child
1280Sstevel@tonic-gate  * device drivers.  This routine invokes the driver interrupt handlers and
1290Sstevel@tonic-gate  * examines the return codes.
1300Sstevel@tonic-gate  *
1310Sstevel@tonic-gate  * There is a count of unclaimed interrupts kept on a per-ino basis. If at
1320Sstevel@tonic-gate  * least one handler claims the interrupt then the counter is halved and the
1330Sstevel@tonic-gate  * interrupt state machine is idled. If no handler claims the interrupt then
1340Sstevel@tonic-gate  * the counter is incremented by one and the state machine is idled.
1350Sstevel@tonic-gate  * If the count ever reaches the limit value set by pci_unclaimed_intr_max
1360Sstevel@tonic-gate  * then the interrupt state machine is not idled thus preventing any further
1370Sstevel@tonic-gate  * interrupts on that ino. The state machine will only be idled again if a
1380Sstevel@tonic-gate  * handler is subsequently added or removed.
1390Sstevel@tonic-gate  *
1400Sstevel@tonic-gate  * return value: DDI_INTR_CLAIMED if any handlers claimed the interrupt,
1410Sstevel@tonic-gate  * DDI_INTR_UNCLAIMED otherwise.
1420Sstevel@tonic-gate  */
1430Sstevel@tonic-gate uint_t
px_intx_intr(caddr_t arg)1440Sstevel@tonic-gate px_intx_intr(caddr_t arg)
1450Sstevel@tonic-gate {
1462973Sgovinda 	px_ino_pil_t	*ipil_p = (px_ino_pil_t *)arg;
1472973Sgovinda 	px_ino_t	*ino_p = ipil_p->ipil_ino_p;
1480Sstevel@tonic-gate 	px_t		*px_p = ino_p->ino_ib_p->ib_px_p;
1492973Sgovinda 	px_ih_t		*ih_p = ipil_p->ipil_ih_start;
1502973Sgovinda 	ushort_t	pil = ipil_p->ipil_pil;
1512973Sgovinda 	uint_t		result = 0, r = DDI_INTR_UNCLAIMED;
1520Sstevel@tonic-gate 	int		i;
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate 	DBG(DBG_INTX_INTR, px_p->px_dip, "px_intx_intr:"
1550Sstevel@tonic-gate 	    "ino=%x sysino=%llx pil=%x ih_size=%x ih_lst=%x\n",
1562973Sgovinda 	    ino_p->ino_ino, ino_p->ino_sysino, ipil_p->ipil_pil,
1572973Sgovinda 	    ipil_p->ipil_ih_size, ipil_p->ipil_ih_head);
1580Sstevel@tonic-gate 
1592973Sgovinda 	for (i = 0; i < ipil_p->ipil_ih_size; i++, ih_p = ih_p->ih_next) {
1600Sstevel@tonic-gate 		dev_info_t *dip = ih_p->ih_dip;
1610Sstevel@tonic-gate 		uint_t (*handler)() = ih_p->ih_handler;
1620Sstevel@tonic-gate 		caddr_t arg1 = ih_p->ih_handler_arg1;
1630Sstevel@tonic-gate 		caddr_t arg2 = ih_p->ih_handler_arg2;
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate 		if (ih_p->ih_intr_state == PX_INTR_STATE_DISABLE) {
1660Sstevel@tonic-gate 			DBG(DBG_INTX_INTR, px_p->px_dip,
1670Sstevel@tonic-gate 			    "px_intx_intr: %s%d interrupt %d is disabled\n",
1680Sstevel@tonic-gate 			    ddi_driver_name(dip), ddi_get_instance(dip),
1690Sstevel@tonic-gate 			    ino_p->ino_ino);
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate 			continue;
1720Sstevel@tonic-gate 		}
1730Sstevel@tonic-gate 
1740Sstevel@tonic-gate 		DBG(DBG_INTX_INTR, px_p->px_dip, "px_intx_intr:"
1750Sstevel@tonic-gate 		    "ino=%x handler=%p arg1 =%p arg2 = %p\n",
1760Sstevel@tonic-gate 		    ino_p->ino_ino, handler, arg1, arg2);
1770Sstevel@tonic-gate 
1780Sstevel@tonic-gate 		DTRACE_PROBE4(interrupt__start, dev_info_t, dip,
1790Sstevel@tonic-gate 		    void *, handler, caddr_t, arg1, caddr_t, arg2);
1800Sstevel@tonic-gate 
1810Sstevel@tonic-gate 		r = (*handler)(arg1, arg2);
1820Sstevel@tonic-gate 
1830Sstevel@tonic-gate 		/*
1840Sstevel@tonic-gate 		 * Account for time used by this interrupt. Protect against
1850Sstevel@tonic-gate 		 * conflicting writes to ih_ticks from ib_intr_dist_all() by
1860Sstevel@tonic-gate 		 * using atomic ops.
1870Sstevel@tonic-gate 		 */
1880Sstevel@tonic-gate 
1892973Sgovinda 		if (pil <= LOCK_LEVEL)
1900Sstevel@tonic-gate 			atomic_add_64(&ih_p->ih_ticks, intr_get_time());
1910Sstevel@tonic-gate 
1920Sstevel@tonic-gate 		DTRACE_PROBE4(interrupt__complete, dev_info_t, dip,
1930Sstevel@tonic-gate 		    void *, handler, caddr_t, arg1, int, r);
1940Sstevel@tonic-gate 
1950Sstevel@tonic-gate 		result += r;
1960Sstevel@tonic-gate 
1970Sstevel@tonic-gate 		if (px_check_all_handlers)
1980Sstevel@tonic-gate 			continue;
1990Sstevel@tonic-gate 		if (result)
2000Sstevel@tonic-gate 			break;
2010Sstevel@tonic-gate 	}
2020Sstevel@tonic-gate 
2032973Sgovinda 	if (result)
2042973Sgovinda 		ino_p->ino_claimed |= (1 << pil);
2052973Sgovinda 
2062973Sgovinda 	/* Interrupt can only be cleared after all pil levels are handled */
2072973Sgovinda 	if (pil != ino_p->ino_lopil)
2082973Sgovinda 		return (DDI_INTR_CLAIMED);
2090Sstevel@tonic-gate 
2102973Sgovinda 	if (!ino_p->ino_claimed) {
2112973Sgovinda 		if (px_unclaimed_intr_block)
2122973Sgovinda 			return (px_spurintr(ipil_p));
2132973Sgovinda 	}
2142973Sgovinda 
2152973Sgovinda 	ino_p->ino_unclaimed_intrs = 0;
2162973Sgovinda 	ino_p->ino_claimed = 0;
2170Sstevel@tonic-gate 
2180Sstevel@tonic-gate 	/* Clear the pending state */
2192973Sgovinda 	if (px_lib_intr_setstate(px_p->px_dip,
2200Sstevel@tonic-gate 	    ino_p->ino_sysino, INTR_IDLE_STATE) != DDI_SUCCESS)
2210Sstevel@tonic-gate 		return (DDI_INTR_UNCLAIMED);
2220Sstevel@tonic-gate 
2230Sstevel@tonic-gate 	return (DDI_INTR_CLAIMED);
2240Sstevel@tonic-gate }
2250Sstevel@tonic-gate 
2260Sstevel@tonic-gate /*
227693Sgovinda  * px_msiq_intr (MSI/X or PCIe MSG interrupt handler)
2280Sstevel@tonic-gate  *
2290Sstevel@tonic-gate  * This routine is used as wrapper around interrupt handlers installed by child
2300Sstevel@tonic-gate  * device drivers.  This routine invokes the driver interrupt handlers and
2310Sstevel@tonic-gate  * examines the return codes.
2320Sstevel@tonic-gate  *
2330Sstevel@tonic-gate  * There is a count of unclaimed interrupts kept on a per-ino basis. If at
2340Sstevel@tonic-gate  * least one handler claims the interrupt then the counter is halved and the
2350Sstevel@tonic-gate  * interrupt state machine is idled. If no handler claims the interrupt then
2360Sstevel@tonic-gate  * the counter is incremented by one and the state machine is idled.
2370Sstevel@tonic-gate  * If the count ever reaches the limit value set by pci_unclaimed_intr_max
2380Sstevel@tonic-gate  * then the interrupt state machine is not idled thus preventing any further
2390Sstevel@tonic-gate  * interrupts on that ino. The state machine will only be idled again if a
2400Sstevel@tonic-gate  * handler is subsequently added or removed.
2410Sstevel@tonic-gate  *
2420Sstevel@tonic-gate  * return value: DDI_INTR_CLAIMED if any handlers claimed the interrupt,
2430Sstevel@tonic-gate  * DDI_INTR_UNCLAIMED otherwise.
2440Sstevel@tonic-gate  */
2450Sstevel@tonic-gate uint_t
px_msiq_intr(caddr_t arg)2460Sstevel@tonic-gate px_msiq_intr(caddr_t arg)
2470Sstevel@tonic-gate {
2482973Sgovinda 	px_ino_pil_t	*ipil_p = (px_ino_pil_t *)arg;
2492973Sgovinda 	px_ino_t	*ino_p = ipil_p->ipil_ino_p;
2500Sstevel@tonic-gate 	px_t		*px_p = ino_p->ino_ib_p->ib_px_p;
2510Sstevel@tonic-gate 	px_msiq_state_t	*msiq_state_p = &px_p->px_ib_p->ib_msiq_state;
2520Sstevel@tonic-gate 	px_msiq_t	*msiq_p = ino_p->ino_msiq_p;
2530Sstevel@tonic-gate 	dev_info_t	*dip = px_p->px_dip;
2542973Sgovinda 	ushort_t	pil = ipil_p->ipil_pil;
2550Sstevel@tonic-gate 	msiq_rec_t	msiq_rec, *msiq_rec_p = &msiq_rec;
2562588Segillett 	msiqhead_t	*curr_head_p;
2572588Segillett 	msiqtail_t	curr_tail_index;
2580Sstevel@tonic-gate 	msgcode_t	msg_code;
2590Sstevel@tonic-gate 	px_ih_t		*ih_p;
2602973Sgovinda 	uint_t		ret = DDI_INTR_UNCLAIMED;
2612973Sgovinda 	int		i, j;
2620Sstevel@tonic-gate 
2630Sstevel@tonic-gate 	DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: msiq_id =%x ino=%x pil=%x "
2640Sstevel@tonic-gate 	    "ih_size=%x ih_lst=%x\n", msiq_p->msiq_id, ino_p->ino_ino,
2652973Sgovinda 	    ipil_p->ipil_pil, ipil_p->ipil_ih_size, ipil_p->ipil_ih_head);
2662973Sgovinda 
2672973Sgovinda 	/*
2682973Sgovinda 	 * The px_msiq_intr() handles multiple interrupt priorities and it
2692973Sgovinda 	 * will set msiq->msiq_rec2process to the number of MSIQ records to
2702973Sgovinda 	 * process while handling the highest priority interrupt. Subsequent
2712973Sgovinda 	 * lower priority interrupts will just process any unprocessed MSIQ
2722973Sgovinda 	 * records or will just return immediately.
2732973Sgovinda 	 */
2742973Sgovinda 	if (msiq_p->msiq_recs2process == 0) {
27510596SDaniel.Ice@Sun.COM 		ASSERT(ino_p->ino_ipil_cntr == 0);
27610596SDaniel.Ice@Sun.COM 		ino_p->ino_ipil_cntr = ino_p->ino_ipil_size;
27710596SDaniel.Ice@Sun.COM 
2782973Sgovinda 		/* Read current MSIQ tail index */
2792973Sgovinda 		px_lib_msiq_gettail(dip, msiq_p->msiq_id, &curr_tail_index);
2802973Sgovinda 		msiq_p->msiq_new_head_index = msiq_p->msiq_curr_head_index;
2810Sstevel@tonic-gate 
2822973Sgovinda 		if (curr_tail_index < msiq_p->msiq_curr_head_index)
2832973Sgovinda 			curr_tail_index += msiq_state_p->msiq_rec_cnt;
2842973Sgovinda 
2852973Sgovinda 		msiq_p->msiq_recs2process = curr_tail_index -
2862973Sgovinda 		    msiq_p->msiq_curr_head_index;
2872973Sgovinda 	}
2880Sstevel@tonic-gate 
2892973Sgovinda 	DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: curr_head %x new_head %x "
2902973Sgovinda 	    "rec2process %x\n", msiq_p->msiq_curr_head_index,
2912973Sgovinda 	    msiq_p->msiq_new_head_index, msiq_p->msiq_recs2process);
2922973Sgovinda 
2932973Sgovinda 	/* If all MSIQ records are already processed, just return immediately */
2942973Sgovinda 	if ((msiq_p->msiq_new_head_index - msiq_p->msiq_curr_head_index)
2952973Sgovinda 	    == msiq_p->msiq_recs2process)
2962973Sgovinda 		goto intr_done;
2972973Sgovinda 
2982973Sgovinda 	curr_head_p = (msiqhead_t *)((caddr_t)msiq_p->msiq_base_p +
2992973Sgovinda 	    (msiq_p->msiq_curr_head_index * sizeof (msiq_rec_t)));
3000Sstevel@tonic-gate 
3010Sstevel@tonic-gate 	/*
3022588Segillett 	 * Calculate the number of recs to process by taking the difference
3032588Segillett 	 * between the head and tail pointers. For all records we always
3042588Segillett 	 * verify that we have a valid record type before we do any processing.
3052973Sgovinda 	 * If triggered, we should always have at least one valid record.
3060Sstevel@tonic-gate 	 */
3072973Sgovinda 	for (i = 0; i < msiq_p->msiq_recs2process; i++) {
3089686SAlan.Adamson@Sun.COM 		msiq_rec_type_t rec_type;
3099686SAlan.Adamson@Sun.COM 
3102973Sgovinda 		/* Read next MSIQ record */
3112588Segillett 		px_lib_get_msiq_rec(dip, curr_head_p, msiq_rec_p);
3122588Segillett 
3139686SAlan.Adamson@Sun.COM 		rec_type = msiq_rec_p->msiq_rec_type;
3149686SAlan.Adamson@Sun.COM 
3150Sstevel@tonic-gate 		DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: MSIQ RECORD, "
3160Sstevel@tonic-gate 		    "msiq_rec_type 0x%llx msiq_rec_rid 0x%llx\n",
3179686SAlan.Adamson@Sun.COM 		    rec_type, msiq_rec_p->msiq_rec_rid);
3180Sstevel@tonic-gate 
3199686SAlan.Adamson@Sun.COM 		if (!rec_type)
3202973Sgovinda 			goto next_rec;
3210Sstevel@tonic-gate 
3220Sstevel@tonic-gate 		/* Check MSIQ record type */
3239686SAlan.Adamson@Sun.COM 		switch (rec_type) {
3240Sstevel@tonic-gate 		case MSG_REC:
3250Sstevel@tonic-gate 			msg_code = msiq_rec_p->msiq_rec_data.msg.msg_code;
3260Sstevel@tonic-gate 			DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: PCIE MSG "
3270Sstevel@tonic-gate 			    "record, msg type 0x%x\n", msg_code);
3280Sstevel@tonic-gate 			break;
3290Sstevel@tonic-gate 		case MSI32_REC:
3300Sstevel@tonic-gate 		case MSI64_REC:
3310Sstevel@tonic-gate 			msg_code = msiq_rec_p->msiq_rec_data.msi.msi_data;
3320Sstevel@tonic-gate 			DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: MSI record, "
3330Sstevel@tonic-gate 			    "msi 0x%x\n", msg_code);
3340Sstevel@tonic-gate 			break;
3350Sstevel@tonic-gate 		default:
3360Sstevel@tonic-gate 			msg_code = 0;
3370Sstevel@tonic-gate 			cmn_err(CE_WARN, "%s%d: px_msiq_intr: 0x%x MSIQ "
3380Sstevel@tonic-gate 			    "record type is not supported",
3390Sstevel@tonic-gate 			    ddi_driver_name(dip), ddi_get_instance(dip),
3409686SAlan.Adamson@Sun.COM 			    rec_type);
3412973Sgovinda 
3420Sstevel@tonic-gate 			goto next_rec;
3430Sstevel@tonic-gate 		}
3440Sstevel@tonic-gate 
3450Sstevel@tonic-gate 		/*
3460Sstevel@tonic-gate 		 * Scan through px_ih_t linked list, searching for the
3470Sstevel@tonic-gate 		 * right px_ih_t, matching MSIQ record data.
3480Sstevel@tonic-gate 		 */
3492973Sgovinda 		for (j = 0, ih_p = ipil_p->ipil_ih_start;
3502973Sgovinda 		    ih_p && (j < ipil_p->ipil_ih_size) &&
3511653Sgovinda 		    ((ih_p->ih_msg_code != msg_code) ||
3529686SAlan.Adamson@Sun.COM 		    (ih_p->ih_rec_type != rec_type));
3534397Sschwartz 		    ih_p = ih_p->ih_next, j++)
3544397Sschwartz 			;
3550Sstevel@tonic-gate 
3560Sstevel@tonic-gate 		if ((ih_p->ih_msg_code == msg_code) &&
3579686SAlan.Adamson@Sun.COM 		    (ih_p->ih_rec_type == rec_type)) {
35811520SScott.Carter@Sun.COM 			dev_info_t *ih_dip = ih_p->ih_dip;
3590Sstevel@tonic-gate 			uint_t (*handler)() = ih_p->ih_handler;
3600Sstevel@tonic-gate 			caddr_t arg1 = ih_p->ih_handler_arg1;
3610Sstevel@tonic-gate 			caddr_t arg2 = ih_p->ih_handler_arg2;
3620Sstevel@tonic-gate 
36311520SScott.Carter@Sun.COM 			DBG(DBG_MSIQ_INTR, ih_dip, "px_msiq_intr: ino=%x "
36411520SScott.Carter@Sun.COM 			    "data=%x handler=%p arg1 =%p arg2=%p\n",
36511520SScott.Carter@Sun.COM 			    ino_p->ino_ino, msg_code, handler, arg1, arg2);
3660Sstevel@tonic-gate 
36711520SScott.Carter@Sun.COM 			DTRACE_PROBE4(interrupt__start, dev_info_t, ih_dip,
3680Sstevel@tonic-gate 			    void *, handler, caddr_t, arg1, caddr_t, arg2);
3690Sstevel@tonic-gate 
37011520SScott.Carter@Sun.COM 			ih_p->ih_intr_flags = PX_INTR_PENDING;
37110053SEvan.Yan@Sun.COM 
37227Sjchu 			/*
37327Sjchu 			 * Special case for PCIE Error Messages.
37427Sjchu 			 * The current frame work doesn't fit PCIE Err Msgs
37527Sjchu 			 * This should be fixed when PCIE MESSAGES as a whole
37627Sjchu 			 * is architected correctly.
37727Sjchu 			 */
3789686SAlan.Adamson@Sun.COM 			if ((rec_type == MSG_REC) &&
3799686SAlan.Adamson@Sun.COM 			    ((msg_code == PCIE_MSG_CODE_ERR_COR) ||
38027Sjchu 			    (msg_code == PCIE_MSG_CODE_ERR_NONFATAL) ||
3819686SAlan.Adamson@Sun.COM 			    (msg_code == PCIE_MSG_CODE_ERR_FATAL))) {
38227Sjchu 				ret = px_err_fabric_intr(px_p, msg_code,
38327Sjchu 				    msiq_rec_p->msiq_rec_rid);
38411520SScott.Carter@Sun.COM 			} else {
38511520SScott.Carter@Sun.COM 				/* Clear MSI state */
38611520SScott.Carter@Sun.COM 				px_lib_msi_setstate(dip, (msinum_t)msg_code,
38711520SScott.Carter@Sun.COM 				    PCI_MSI_STATE_IDLE);
38811520SScott.Carter@Sun.COM 
38927Sjchu 				ret = (*handler)(arg1, arg2);
39011520SScott.Carter@Sun.COM 			}
3910Sstevel@tonic-gate 
3920Sstevel@tonic-gate 			/*
3930Sstevel@tonic-gate 			 * Account for time used by this interrupt. Protect
3940Sstevel@tonic-gate 			 * against conflicting writes to ih_ticks from
3950Sstevel@tonic-gate 			 * ib_intr_dist_all() by using atomic ops.
3960Sstevel@tonic-gate 			 */
3970Sstevel@tonic-gate 
3982973Sgovinda 			if (pil <= LOCK_LEVEL)
3990Sstevel@tonic-gate 				atomic_add_64(&ih_p->ih_ticks, intr_get_time());
4000Sstevel@tonic-gate 
40111520SScott.Carter@Sun.COM 			DTRACE_PROBE4(interrupt__complete, dev_info_t, ih_dip,
4020Sstevel@tonic-gate 			    void *, handler, caddr_t, arg1, int, ret);
4032588Segillett 
40411520SScott.Carter@Sun.COM 			/* clear handler status flags */
40511520SScott.Carter@Sun.COM 			ih_p->ih_intr_flags = PX_INTR_IDLE;
40611520SScott.Carter@Sun.COM 
4072973Sgovinda 			msiq_p->msiq_new_head_index++;
40811520SScott.Carter@Sun.COM 			px_lib_clr_msiq_rec(ih_dip, curr_head_p);
4090Sstevel@tonic-gate 		} else {
41011520SScott.Carter@Sun.COM 			DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: "
4112588Segillett 			    "No matching MSIQ record found\n");
4122588Segillett 		}
4132588Segillett next_rec:
4142588Segillett 		/* Get the pointer next EQ record */
4152588Segillett 		curr_head_p = (msiqhead_t *)
4162588Segillett 		    ((caddr_t)curr_head_p + sizeof (msiq_rec_t));
4170Sstevel@tonic-gate 
4182588Segillett 		/* Check for overflow condition */
4192588Segillett 		if (curr_head_p >= (msiqhead_t *)((caddr_t)msiq_p->msiq_base_p
4202973Sgovinda 		    + (msiq_state_p->msiq_rec_cnt * sizeof (msiq_rec_t))))
4212588Segillett 			curr_head_p = (msiqhead_t *)msiq_p->msiq_base_p;
4220Sstevel@tonic-gate 	}
4230Sstevel@tonic-gate 
4242973Sgovinda 	DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: No of MSIQ recs processed %x\n",
4252973Sgovinda 	    (msiq_p->msiq_new_head_index - msiq_p->msiq_curr_head_index));
4262973Sgovinda 
4272973Sgovinda 	DBG(DBG_MSIQ_INTR, dip, "px_msiq_intr: curr_head %x new_head %x "
4282973Sgovinda 	    "rec2process %x\n", msiq_p->msiq_curr_head_index,
4292973Sgovinda 	    msiq_p->msiq_new_head_index, msiq_p->msiq_recs2process);
4302588Segillett 
4312973Sgovinda 	/* ino_claimed used just for debugging purpose */
4322973Sgovinda 	if (ret)
4332973Sgovinda 		ino_p->ino_claimed |= (1 << pil);
4342973Sgovinda 
4352973Sgovinda intr_done:
4362973Sgovinda 	/* Interrupt can only be cleared after all pil levels are handled */
43710596SDaniel.Ice@Sun.COM 	if (--ino_p->ino_ipil_cntr != 0)
4382973Sgovinda 		return (DDI_INTR_CLAIMED);
4392973Sgovinda 
4402973Sgovinda 	if (msiq_p->msiq_new_head_index <= msiq_p->msiq_curr_head_index)  {
4412973Sgovinda 		if (px_unclaimed_intr_block)
4422973Sgovinda 			return (px_spurintr(ipil_p));
4432588Segillett 	}
4440Sstevel@tonic-gate 
4450Sstevel@tonic-gate 	/*  Update MSIQ head index with no of MSIQ records processed */
4462973Sgovinda 	if (msiq_p->msiq_new_head_index >= msiq_state_p->msiq_rec_cnt)
4472973Sgovinda 		msiq_p->msiq_new_head_index -= msiq_state_p->msiq_rec_cnt;
4480Sstevel@tonic-gate 
4492973Sgovinda 	msiq_p->msiq_curr_head_index = msiq_p->msiq_new_head_index;
4502973Sgovinda 	px_lib_msiq_sethead(dip, msiq_p->msiq_id, msiq_p->msiq_new_head_index);
4512973Sgovinda 
4522973Sgovinda 	msiq_p->msiq_new_head_index = 0;
4532973Sgovinda 	msiq_p->msiq_recs2process = 0;
4542973Sgovinda 	ino_p->ino_claimed = 0;
4550Sstevel@tonic-gate 
4560Sstevel@tonic-gate 	/* Clear the pending state */
4570Sstevel@tonic-gate 	if (px_lib_intr_setstate(dip, ino_p->ino_sysino,
4580Sstevel@tonic-gate 	    INTR_IDLE_STATE) != DDI_SUCCESS)
4590Sstevel@tonic-gate 		return (DDI_INTR_UNCLAIMED);
4600Sstevel@tonic-gate 
4610Sstevel@tonic-gate 	return (DDI_INTR_CLAIMED);
4620Sstevel@tonic-gate }
4630Sstevel@tonic-gate 
4640Sstevel@tonic-gate dev_info_t *
px_get_my_childs_dip(dev_info_t * dip,dev_info_t * rdip)4650Sstevel@tonic-gate px_get_my_childs_dip(dev_info_t *dip, dev_info_t *rdip)
4660Sstevel@tonic-gate {
4670Sstevel@tonic-gate 	dev_info_t	*cdip = rdip;
4680Sstevel@tonic-gate 
4690Sstevel@tonic-gate 	for (; ddi_get_parent(cdip) != dip; cdip = ddi_get_parent(cdip))
4700Sstevel@tonic-gate 		;
4710Sstevel@tonic-gate 
4720Sstevel@tonic-gate 	return (cdip);
4730Sstevel@tonic-gate }
4740Sstevel@tonic-gate 
4750Sstevel@tonic-gate /* ARGSUSED */
4760Sstevel@tonic-gate int
px_intx_ops(dev_info_t * dip,dev_info_t * rdip,ddi_intr_op_t intr_op,ddi_intr_handle_impl_t * hdlp,void * result)4770Sstevel@tonic-gate px_intx_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op,
4780Sstevel@tonic-gate     ddi_intr_handle_impl_t *hdlp, void *result)
4790Sstevel@tonic-gate {
480693Sgovinda 	px_t	*px_p = DIP_TO_STATE(dip);
481693Sgovinda 	int	ret = DDI_SUCCESS;
4820Sstevel@tonic-gate 
4830Sstevel@tonic-gate 	DBG(DBG_INTROPS, dip, "px_intx_ops: dip=%x rdip=%x intr_op=%x "
4840Sstevel@tonic-gate 	    "handle=%p\n", dip, rdip, intr_op, hdlp);
4850Sstevel@tonic-gate 
4860Sstevel@tonic-gate 	switch (intr_op) {
4870Sstevel@tonic-gate 	case DDI_INTROP_GETCAP:
4880Sstevel@tonic-gate 		ret = pci_intx_get_cap(rdip, (int *)result);
4890Sstevel@tonic-gate 		break;
4900Sstevel@tonic-gate 	case DDI_INTROP_SETCAP:
4910Sstevel@tonic-gate 		DBG(DBG_INTROPS, dip, "px_intx_ops: SetCap is not supported\n");
4920Sstevel@tonic-gate 		ret = DDI_ENOTSUP;
4930Sstevel@tonic-gate 		break;
4940Sstevel@tonic-gate 	case DDI_INTROP_ALLOC:
4950Sstevel@tonic-gate 		*(int *)result = hdlp->ih_scratch1;
4960Sstevel@tonic-gate 		break;
4970Sstevel@tonic-gate 	case DDI_INTROP_FREE:
4980Sstevel@tonic-gate 		break;
4990Sstevel@tonic-gate 	case DDI_INTROP_GETPRI:
500693Sgovinda 		*(int *)result = hdlp->ih_pri ?
5018535Sevan.yan@sun.com 		    hdlp->ih_pri : pci_class_to_pil(rdip);
5020Sstevel@tonic-gate 		break;
5030Sstevel@tonic-gate 	case DDI_INTROP_SETPRI:
5040Sstevel@tonic-gate 		break;
5050Sstevel@tonic-gate 	case DDI_INTROP_ADDISR:
5060Sstevel@tonic-gate 		ret = px_add_intx_intr(dip, rdip, hdlp);
5070Sstevel@tonic-gate 		break;
5080Sstevel@tonic-gate 	case DDI_INTROP_REMISR:
5090Sstevel@tonic-gate 		ret = px_rem_intx_intr(dip, rdip, hdlp);
5100Sstevel@tonic-gate 		break;
51110053SEvan.Yan@Sun.COM 	case DDI_INTROP_GETTARGET:
51210053SEvan.Yan@Sun.COM 		ret = px_ib_get_intr_target(px_p, hdlp->ih_vector,
51310053SEvan.Yan@Sun.COM 		    (cpuid_t *)result);
51410053SEvan.Yan@Sun.COM 		break;
51510053SEvan.Yan@Sun.COM 	case DDI_INTROP_SETTARGET:
51610053SEvan.Yan@Sun.COM 		ret = DDI_ENOTSUP;
51710053SEvan.Yan@Sun.COM 		break;
5180Sstevel@tonic-gate 	case DDI_INTROP_ENABLE:
5190Sstevel@tonic-gate 		ret = px_ib_update_intr_state(px_p, rdip, hdlp->ih_inum,
5202973Sgovinda 		    hdlp->ih_vector, hdlp->ih_pri, PX_INTR_STATE_ENABLE, 0, 0);
5210Sstevel@tonic-gate 		break;
5220Sstevel@tonic-gate 	case DDI_INTROP_DISABLE:
5230Sstevel@tonic-gate 		ret = px_ib_update_intr_state(px_p, rdip, hdlp->ih_inum,
5242973Sgovinda 		    hdlp->ih_vector, hdlp->ih_pri, PX_INTR_STATE_DISABLE, 0, 0);
5250Sstevel@tonic-gate 		break;
5260Sstevel@tonic-gate 	case DDI_INTROP_SETMASK:
5270Sstevel@tonic-gate 		ret = pci_intx_set_mask(rdip);
5280Sstevel@tonic-gate 		break;
5290Sstevel@tonic-gate 	case DDI_INTROP_CLRMASK:
5300Sstevel@tonic-gate 		ret = pci_intx_clr_mask(rdip);
5310Sstevel@tonic-gate 		break;
5320Sstevel@tonic-gate 	case DDI_INTROP_GETPENDING:
5330Sstevel@tonic-gate 		ret = pci_intx_get_pending(rdip, (int *)result);
5340Sstevel@tonic-gate 		break;
5350Sstevel@tonic-gate 	case DDI_INTROP_NINTRS:
5360Sstevel@tonic-gate 	case DDI_INTROP_NAVAIL:
5372580Sanish 		*(int *)result = i_ddi_get_intx_nintrs(rdip);
5380Sstevel@tonic-gate 		break;
5390Sstevel@tonic-gate 	default:
5400Sstevel@tonic-gate 		ret = DDI_ENOTSUP;
5410Sstevel@tonic-gate 		break;
5420Sstevel@tonic-gate 	}
5430Sstevel@tonic-gate 
5440Sstevel@tonic-gate 	return (ret);
5450Sstevel@tonic-gate }
5460Sstevel@tonic-gate 
5470Sstevel@tonic-gate /* ARGSUSED */
5480Sstevel@tonic-gate int
px_msix_ops(dev_info_t * dip,dev_info_t * rdip,ddi_intr_op_t intr_op,ddi_intr_handle_impl_t * hdlp,void * result)5490Sstevel@tonic-gate px_msix_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op,
5500Sstevel@tonic-gate     ddi_intr_handle_impl_t *hdlp, void *result)
5510Sstevel@tonic-gate {
5520Sstevel@tonic-gate 	px_t			*px_p = DIP_TO_STATE(dip);
5530Sstevel@tonic-gate 	px_msi_state_t		*msi_state_p = &px_p->px_ib_p->ib_msi_state;
554965Sgovinda 	msiq_rec_type_t		msiq_rec_type;
555965Sgovinda 	msi_type_t		msi_type;
556965Sgovinda 	uint64_t		msi_addr;
5570Sstevel@tonic-gate 	msinum_t		msi_num;
5580Sstevel@tonic-gate 	msiqid_t		msiq_id;
5590Sstevel@tonic-gate 	uint_t			nintrs;
56010053SEvan.Yan@Sun.COM 	int			ret = DDI_SUCCESS;
5610Sstevel@tonic-gate 
5620Sstevel@tonic-gate 	DBG(DBG_INTROPS, dip, "px_msix_ops: dip=%x rdip=%x intr_op=%x "
5630Sstevel@tonic-gate 	    "handle=%p\n", dip, rdip, intr_op, hdlp);
5640Sstevel@tonic-gate 
565965Sgovinda 	/* Check for MSI64 support */
5661653Sgovinda 	if ((hdlp->ih_cap & DDI_INTR_FLAG_MSI64) && msi_state_p->msi_addr64) {
567965Sgovinda 		msiq_rec_type = MSI64_REC;
568965Sgovinda 		msi_type = MSI64_TYPE;
5691653Sgovinda 		msi_addr = msi_state_p->msi_addr64;
570965Sgovinda 	} else {
571965Sgovinda 		msiq_rec_type = MSI32_REC;
572965Sgovinda 		msi_type = MSI32_TYPE;
573965Sgovinda 		msi_addr = msi_state_p->msi_addr32;
574965Sgovinda 	}
575965Sgovinda 
57610053SEvan.Yan@Sun.COM 	(void) px_msi_get_msinum(px_p, hdlp->ih_dip,
57710053SEvan.Yan@Sun.COM 	    (hdlp->ih_flags & DDI_INTR_MSIX_DUP) ? hdlp->ih_main->ih_inum :
57810053SEvan.Yan@Sun.COM 	    hdlp->ih_inum, &msi_num);
57910053SEvan.Yan@Sun.COM 
5800Sstevel@tonic-gate 	switch (intr_op) {
5810Sstevel@tonic-gate 	case DDI_INTROP_GETCAP:
5820Sstevel@tonic-gate 		ret = pci_msi_get_cap(rdip, hdlp->ih_type, (int *)result);
5830Sstevel@tonic-gate 		break;
5840Sstevel@tonic-gate 	case DDI_INTROP_SETCAP:
5850Sstevel@tonic-gate 		DBG(DBG_INTROPS, dip, "px_msix_ops: SetCap is not supported\n");
5860Sstevel@tonic-gate 		ret = DDI_ENOTSUP;
5870Sstevel@tonic-gate 		break;
5880Sstevel@tonic-gate 	case DDI_INTROP_ALLOC:
5890Sstevel@tonic-gate 		/*
5900Sstevel@tonic-gate 		 * We need to restrict this allocation in future
5910Sstevel@tonic-gate 		 * based on Resource Management policies.
5920Sstevel@tonic-gate 		 */
5938561SScott.Carter@Sun.COM 		if ((ret = px_msi_alloc(px_p, rdip, hdlp->ih_type,
5948561SScott.Carter@Sun.COM 		    hdlp->ih_inum, hdlp->ih_scratch1,
5958561SScott.Carter@Sun.COM 		    (uintptr_t)hdlp->ih_scratch2,
5961725Segillett 		    (int *)result)) != DDI_SUCCESS) {
5971725Segillett 			DBG(DBG_INTROPS, dip, "px_msix_ops: allocation "
5981725Segillett 			    "failed, rdip 0x%p type 0x%d inum 0x%x "
5991725Segillett 			    "count 0x%x\n", rdip, hdlp->ih_type, hdlp->ih_inum,
6001725Segillett 			    hdlp->ih_scratch1);
6010Sstevel@tonic-gate 
6020Sstevel@tonic-gate 			return (ret);
6030Sstevel@tonic-gate 		}
6040Sstevel@tonic-gate 
6051725Segillett 		if ((hdlp->ih_type == DDI_INTR_TYPE_MSIX) &&
6061725Segillett 		    (i_ddi_get_msix(rdip) == NULL)) {
6071725Segillett 			ddi_intr_msix_t		*msix_p;
6081725Segillett 
6091725Segillett 			if (msix_p = pci_msix_init(rdip)) {
6101725Segillett 				i_ddi_set_msix(rdip, msix_p);
6111725Segillett 				break;
6121725Segillett 			}
6131725Segillett 
6141725Segillett 			DBG(DBG_INTROPS, dip, "px_msix_ops: MSI-X allocation "
6151725Segillett 			    "failed, rdip 0x%p inum 0x%x\n", rdip,
6161725Segillett 			    hdlp->ih_inum);
6171725Segillett 
6181725Segillett 			(void) px_msi_free(px_p, rdip, hdlp->ih_inum,
6191725Segillett 			    hdlp->ih_scratch1);
6201725Segillett 
6211725Segillett 			return (DDI_FAILURE);
6221725Segillett 		}
6231725Segillett 
6240Sstevel@tonic-gate 		break;
6250Sstevel@tonic-gate 	case DDI_INTROP_FREE:
6260Sstevel@tonic-gate 		(void) pci_msi_unconfigure(rdip, hdlp->ih_type, hdlp->ih_inum);
6271725Segillett 
6281725Segillett 		if (hdlp->ih_type == DDI_INTR_TYPE_MSI)
6291725Segillett 			goto msi_free;
6301725Segillett 
6311725Segillett 		if (hdlp->ih_flags & DDI_INTR_MSIX_DUP)
6321725Segillett 			break;
6331725Segillett 
6341725Segillett 		if (((i_ddi_intr_get_current_nintrs(hdlp->ih_dip) - 1) == 0) &&
6351725Segillett 		    (i_ddi_get_msix(rdip))) {
6361725Segillett 			pci_msix_fini(i_ddi_get_msix(rdip));
6371725Segillett 			i_ddi_set_msix(rdip, NULL);
6381725Segillett 		}
6391725Segillett msi_free:
6400Sstevel@tonic-gate 		(void) px_msi_free(px_p, rdip, hdlp->ih_inum,
6410Sstevel@tonic-gate 		    hdlp->ih_scratch1);
6420Sstevel@tonic-gate 		break;
6430Sstevel@tonic-gate 	case DDI_INTROP_GETPRI:
6440Sstevel@tonic-gate 		*(int *)result = hdlp->ih_pri ?
6458535Sevan.yan@sun.com 		    hdlp->ih_pri : pci_class_to_pil(rdip);
6460Sstevel@tonic-gate 		break;
6470Sstevel@tonic-gate 	case DDI_INTROP_SETPRI:
6480Sstevel@tonic-gate 		break;
6490Sstevel@tonic-gate 	case DDI_INTROP_ADDISR:
6500Sstevel@tonic-gate 		if ((ret = px_add_msiq_intr(dip, rdip, hdlp,
65110053SEvan.Yan@Sun.COM 		    msiq_rec_type, msi_num, -1, &msiq_id)) != DDI_SUCCESS) {
6520Sstevel@tonic-gate 			DBG(DBG_INTROPS, dip, "px_msix_ops: Add MSI handler "
6530Sstevel@tonic-gate 			    "failed, rdip 0x%p msi 0x%x\n", rdip, msi_num);
6540Sstevel@tonic-gate 			return (ret);
6550Sstevel@tonic-gate 		}
6560Sstevel@tonic-gate 
6570Sstevel@tonic-gate 		DBG(DBG_INTROPS, dip, "px_msix_ops: msiq used 0x%x\n", msiq_id);
6580Sstevel@tonic-gate 
6590Sstevel@tonic-gate 		if ((ret = px_lib_msi_setmsiq(dip, msi_num,
660965Sgovinda 		    msiq_id, msi_type)) != DDI_SUCCESS) {
6610Sstevel@tonic-gate 			(void) px_rem_msiq_intr(dip, rdip,
662965Sgovinda 			    hdlp, msiq_rec_type, msi_num, msiq_id);
6630Sstevel@tonic-gate 			return (ret);
6640Sstevel@tonic-gate 		}
6650Sstevel@tonic-gate 
6660Sstevel@tonic-gate 		if ((ret = px_lib_msi_setstate(dip, msi_num,
6670Sstevel@tonic-gate 		    PCI_MSI_STATE_IDLE)) != DDI_SUCCESS) {
6680Sstevel@tonic-gate 			(void) px_rem_msiq_intr(dip, rdip,
669965Sgovinda 			    hdlp, msiq_rec_type, msi_num, msiq_id);
6700Sstevel@tonic-gate 			return (ret);
6710Sstevel@tonic-gate 		}
6720Sstevel@tonic-gate 
67310053SEvan.Yan@Sun.COM 		if ((ret = px_lib_msi_setvalid(dip, msi_num,
67410053SEvan.Yan@Sun.COM 		    PCI_MSI_VALID)) != DDI_SUCCESS)
67510053SEvan.Yan@Sun.COM 			return (ret);
67610053SEvan.Yan@Sun.COM 
67710053SEvan.Yan@Sun.COM 		ret = px_ib_update_intr_state(px_p, rdip, hdlp->ih_inum,
67810053SEvan.Yan@Sun.COM 		    px_msiqid_to_devino(px_p, msiq_id), hdlp->ih_pri,
67910053SEvan.Yan@Sun.COM 		    PX_INTR_STATE_ENABLE, msiq_rec_type, msi_num);
68010053SEvan.Yan@Sun.COM 
6810Sstevel@tonic-gate 		break;
6820Sstevel@tonic-gate 	case DDI_INTROP_DUPVEC:
6831725Segillett 		DBG(DBG_INTROPS, dip, "px_msix_ops: dupisr - inum: %x, "
6841725Segillett 		    "new_vector: %x\n", hdlp->ih_inum, hdlp->ih_scratch1);
6851725Segillett 
6861725Segillett 		ret = pci_msix_dup(hdlp->ih_dip, hdlp->ih_inum,
6871725Segillett 		    hdlp->ih_scratch1);
6880Sstevel@tonic-gate 		break;
6890Sstevel@tonic-gate 	case DDI_INTROP_REMISR:
6900Sstevel@tonic-gate 		if ((ret = px_lib_msi_getmsiq(dip, msi_num,
6910Sstevel@tonic-gate 		    &msiq_id)) != DDI_SUCCESS)
6920Sstevel@tonic-gate 			return (ret);
6930Sstevel@tonic-gate 
69410053SEvan.Yan@Sun.COM 		if ((ret = px_ib_update_intr_state(px_p, rdip,
69510053SEvan.Yan@Sun.COM 		    hdlp->ih_inum, px_msiqid_to_devino(px_p, msiq_id),
69610053SEvan.Yan@Sun.COM 		    hdlp->ih_pri, PX_INTR_STATE_DISABLE, msiq_rec_type,
69710053SEvan.Yan@Sun.COM 		    msi_num)) != DDI_SUCCESS)
69810053SEvan.Yan@Sun.COM 			return (ret);
69910053SEvan.Yan@Sun.COM 
70010053SEvan.Yan@Sun.COM 		if ((ret = px_lib_msi_setvalid(dip, msi_num,
70110053SEvan.Yan@Sun.COM 		    PCI_MSI_INVALID)) != DDI_SUCCESS)
70210053SEvan.Yan@Sun.COM 			return (ret);
70310053SEvan.Yan@Sun.COM 
7040Sstevel@tonic-gate 		if ((ret = px_lib_msi_setstate(dip, msi_num,
705965Sgovinda 		    PCI_MSI_STATE_IDLE)) != DDI_SUCCESS)
7060Sstevel@tonic-gate 			return (ret);
7070Sstevel@tonic-gate 
7080Sstevel@tonic-gate 		ret = px_rem_msiq_intr(dip, rdip,
709965Sgovinda 		    hdlp, msiq_rec_type, msi_num, msiq_id);
7100Sstevel@tonic-gate 
7110Sstevel@tonic-gate 		break;
71210053SEvan.Yan@Sun.COM 	case DDI_INTROP_GETTARGET:
71310053SEvan.Yan@Sun.COM 		if ((ret = px_lib_msi_getmsiq(dip, msi_num,
71410053SEvan.Yan@Sun.COM 		    &msiq_id)) != DDI_SUCCESS)
7150Sstevel@tonic-gate 			return (ret);
7160Sstevel@tonic-gate 
71710053SEvan.Yan@Sun.COM 		ret = px_ib_get_intr_target(px_p,
71810053SEvan.Yan@Sun.COM 		    px_msiqid_to_devino(px_p, msiq_id), (cpuid_t *)result);
71910053SEvan.Yan@Sun.COM 		break;
72010053SEvan.Yan@Sun.COM 	case DDI_INTROP_SETTARGET:
72110053SEvan.Yan@Sun.COM 		ret = px_ib_set_msix_target(px_p, hdlp, msi_num,
72210053SEvan.Yan@Sun.COM 		    *(cpuid_t *)result);
72310053SEvan.Yan@Sun.COM 		break;
72410053SEvan.Yan@Sun.COM 	case DDI_INTROP_ENABLE:
72510053SEvan.Yan@Sun.COM 		/*
72610115SGovinda.Tatti@Sun.COM 		 * For MSI, just clear the mask bit and return if curr_nenables
72710115SGovinda.Tatti@Sun.COM 		 * is > 1. For MSI-X, program MSI address and data for every
72810115SGovinda.Tatti@Sun.COM 		 * MSI-X vector including dup vectors irrespective of current
72910115SGovinda.Tatti@Sun.COM 		 * curr_nenables value.
73010053SEvan.Yan@Sun.COM 		 */
73110115SGovinda.Tatti@Sun.COM 		if ((pci_is_msi_enabled(rdip, hdlp->ih_type) != DDI_SUCCESS) ||
73210115SGovinda.Tatti@Sun.COM 		    (hdlp->ih_type == DDI_INTR_TYPE_MSIX)) {
73310115SGovinda.Tatti@Sun.COM 			nintrs = i_ddi_intr_get_current_nintrs(hdlp->ih_dip);
7340Sstevel@tonic-gate 
73510115SGovinda.Tatti@Sun.COM 			if ((ret = pci_msi_configure(rdip, hdlp->ih_type,
73610115SGovinda.Tatti@Sun.COM 			    nintrs, hdlp->ih_inum, msi_addr,
73710115SGovinda.Tatti@Sun.COM 			    hdlp->ih_type == DDI_INTR_TYPE_MSIX ?
73810115SGovinda.Tatti@Sun.COM 			    msi_num : msi_num & ~(nintrs - 1))) != DDI_SUCCESS)
73910115SGovinda.Tatti@Sun.COM 				return (ret);
7400Sstevel@tonic-gate 
74110115SGovinda.Tatti@Sun.COM 			if (i_ddi_intr_get_current_nenables(rdip) < 1) {
74210115SGovinda.Tatti@Sun.COM 				if ((ret = pci_msi_enable_mode(rdip,
74310115SGovinda.Tatti@Sun.COM 				    hdlp->ih_type)) != DDI_SUCCESS)
74410115SGovinda.Tatti@Sun.COM 					return (ret);
74510115SGovinda.Tatti@Sun.COM 			}
74610115SGovinda.Tatti@Sun.COM 		}
7470Sstevel@tonic-gate 
748909Segillett 		if ((ret = pci_msi_clr_mask(rdip, hdlp->ih_type,
749909Segillett 		    hdlp->ih_inum)) != DDI_SUCCESS)
750909Segillett 			return (ret);
751909Segillett 
7520Sstevel@tonic-gate 		break;
7530Sstevel@tonic-gate 	case DDI_INTROP_DISABLE:
7540Sstevel@tonic-gate 		if ((ret = pci_msi_set_mask(rdip, hdlp->ih_type,
7550Sstevel@tonic-gate 		    hdlp->ih_inum)) != DDI_SUCCESS)
7560Sstevel@tonic-gate 			return (ret);
7570Sstevel@tonic-gate 
75810053SEvan.Yan@Sun.COM 		/*
75910053SEvan.Yan@Sun.COM 		 * curr_nenables will be greater than 1 if rdip is using
76010053SEvan.Yan@Sun.COM 		 * MSI-X and also, if it is using DUP interface. If this
76110053SEvan.Yan@Sun.COM 		 * curr_enables is > 1, return after setting the mask bit.
76210053SEvan.Yan@Sun.COM 		 */
76310053SEvan.Yan@Sun.COM 		if (i_ddi_intr_get_current_nenables(rdip) > 1)
76410053SEvan.Yan@Sun.COM 			return (DDI_SUCCESS);
7651725Segillett 
76610053SEvan.Yan@Sun.COM 		if ((ret = pci_msi_disable_mode(rdip, hdlp->ih_type))
76710053SEvan.Yan@Sun.COM 		    != DDI_SUCCESS)
768909Segillett 			return (ret);
769909Segillett 
7700Sstevel@tonic-gate 		break;
7710Sstevel@tonic-gate 	case DDI_INTROP_BLOCKENABLE:
7720Sstevel@tonic-gate 		nintrs = i_ddi_intr_get_current_nintrs(hdlp->ih_dip);
7730Sstevel@tonic-gate 
7740Sstevel@tonic-gate 		if ((ret = pci_msi_configure(rdip, hdlp->ih_type,
775965Sgovinda 		    nintrs, hdlp->ih_inum, msi_addr,
7760Sstevel@tonic-gate 		    msi_num & ~(nintrs - 1))) != DDI_SUCCESS)
7770Sstevel@tonic-gate 			return (ret);
7780Sstevel@tonic-gate 
7792755Segillett 		ret = pci_msi_enable_mode(rdip, hdlp->ih_type);
7800Sstevel@tonic-gate 		break;
7810Sstevel@tonic-gate 	case DDI_INTROP_BLOCKDISABLE:
78210053SEvan.Yan@Sun.COM 		ret = pci_msi_disable_mode(rdip, hdlp->ih_type);
7830Sstevel@tonic-gate 		break;
7840Sstevel@tonic-gate 	case DDI_INTROP_SETMASK:
7850Sstevel@tonic-gate 		ret = pci_msi_set_mask(rdip, hdlp->ih_type, hdlp->ih_inum);
7860Sstevel@tonic-gate 		break;
7870Sstevel@tonic-gate 	case DDI_INTROP_CLRMASK:
7880Sstevel@tonic-gate 		ret = pci_msi_clr_mask(rdip, hdlp->ih_type, hdlp->ih_inum);
7890Sstevel@tonic-gate 		break;
7900Sstevel@tonic-gate 	case DDI_INTROP_GETPENDING:
7910Sstevel@tonic-gate 		ret = pci_msi_get_pending(rdip, hdlp->ih_type,
7920Sstevel@tonic-gate 		    hdlp->ih_inum, (int *)result);
7930Sstevel@tonic-gate 		break;
7940Sstevel@tonic-gate 	case DDI_INTROP_NINTRS:
7950Sstevel@tonic-gate 		ret = pci_msi_get_nintrs(rdip, hdlp->ih_type, (int *)result);
7960Sstevel@tonic-gate 		break;
7970Sstevel@tonic-gate 	case DDI_INTROP_NAVAIL:
7980Sstevel@tonic-gate 		/* XXX - a new interface may be needed */
7990Sstevel@tonic-gate 		ret = pci_msi_get_nintrs(rdip, hdlp->ih_type, (int *)result);
8000Sstevel@tonic-gate 		break;
8018561SScott.Carter@Sun.COM 	case DDI_INTROP_GETPOOL:
8028561SScott.Carter@Sun.COM 		if (msi_state_p->msi_pool_p == NULL) {
8038561SScott.Carter@Sun.COM 			*(ddi_irm_pool_t **)result = NULL;
8048561SScott.Carter@Sun.COM 			return (DDI_ENOTSUP);
8058561SScott.Carter@Sun.COM 		}
8068561SScott.Carter@Sun.COM 		*(ddi_irm_pool_t **)result = msi_state_p->msi_pool_p;
8078561SScott.Carter@Sun.COM 		ret = DDI_SUCCESS;
8088561SScott.Carter@Sun.COM 		break;
8090Sstevel@tonic-gate 	default:
8100Sstevel@tonic-gate 		ret = DDI_ENOTSUP;
8110Sstevel@tonic-gate 		break;
8120Sstevel@tonic-gate 	}
8130Sstevel@tonic-gate 
8140Sstevel@tonic-gate 	return (ret);
8150Sstevel@tonic-gate }
8160Sstevel@tonic-gate 
81766Sesolom static struct {
81866Sesolom 	kstat_named_t pxintr_ks_name;
81966Sesolom 	kstat_named_t pxintr_ks_type;
82066Sesolom 	kstat_named_t pxintr_ks_cpu;
82166Sesolom 	kstat_named_t pxintr_ks_pil;
82266Sesolom 	kstat_named_t pxintr_ks_time;
82366Sesolom 	kstat_named_t pxintr_ks_ino;
82466Sesolom 	kstat_named_t pxintr_ks_cookie;
82566Sesolom 	kstat_named_t pxintr_ks_devpath;
82666Sesolom 	kstat_named_t pxintr_ks_buspath;
82766Sesolom } pxintr_ks_template = {
82866Sesolom 	{ "name",	KSTAT_DATA_CHAR },
82966Sesolom 	{ "type",	KSTAT_DATA_CHAR },
83066Sesolom 	{ "cpu",	KSTAT_DATA_UINT64 },
83166Sesolom 	{ "pil",	KSTAT_DATA_UINT64 },
83266Sesolom 	{ "time",	KSTAT_DATA_UINT64 },
83366Sesolom 	{ "ino",	KSTAT_DATA_UINT64 },
83466Sesolom 	{ "cookie",	KSTAT_DATA_UINT64 },
83566Sesolom 	{ "devpath",	KSTAT_DATA_STRING },
83666Sesolom 	{ "buspath",	KSTAT_DATA_STRING },
83766Sesolom };
83866Sesolom 
83966Sesolom static uint32_t pxintr_ks_instance;
8401811Sesolom static char ih_devpath[MAXPATHLEN];
8411811Sesolom static char ih_buspath[MAXPATHLEN];
84266Sesolom kmutex_t pxintr_ks_template_lock;
84366Sesolom 
84466Sesolom int
px_ks_update(kstat_t * ksp,int rw)84566Sesolom px_ks_update(kstat_t *ksp, int rw)
84666Sesolom {
84766Sesolom 	px_ih_t *ih_p = ksp->ks_private;
84866Sesolom 	int maxlen = sizeof (pxintr_ks_template.pxintr_ks_name.value.c);
8492973Sgovinda 	px_ino_pil_t *ipil_p = ih_p->ih_ipil_p;
8502973Sgovinda 	px_ino_t *ino_p = ipil_p->ipil_ino_p;
8512973Sgovinda 	px_t *px_p = ino_p->ino_ib_p->ib_px_p;
85266Sesolom 	devino_t ino;
85366Sesolom 	sysino_t sysino;
85466Sesolom 
8552973Sgovinda 	ino = ino_p->ino_ino;
8567124Sanbui 	if (px_lib_intr_devino_to_sysino(px_p->px_dip, ino, &sysino) !=
8577124Sanbui 	    DDI_SUCCESS) {
8587124Sanbui 		cmn_err(CE_WARN, "px_ks_update: px_lib_intr_devino_to_sysino "
8597124Sanbui 		    "failed");
8607124Sanbui 	}
86166Sesolom 
86266Sesolom 	(void) snprintf(pxintr_ks_template.pxintr_ks_name.value.c, maxlen,
86366Sesolom 	    "%s%d", ddi_driver_name(ih_p->ih_dip),
86466Sesolom 	    ddi_get_instance(ih_p->ih_dip));
86566Sesolom 
86666Sesolom 	(void) ddi_pathname(ih_p->ih_dip, ih_devpath);
86766Sesolom 	(void) ddi_pathname(px_p->px_dip, ih_buspath);
86866Sesolom 	kstat_named_setstr(&pxintr_ks_template.pxintr_ks_devpath, ih_devpath);
86966Sesolom 	kstat_named_setstr(&pxintr_ks_template.pxintr_ks_buspath, ih_buspath);
87066Sesolom 
8711087Sschwartz 	if (ih_p->ih_intr_state == PX_INTR_STATE_ENABLE) {
8721087Sschwartz 
8734397Sschwartz 		switch (i_ddi_intr_get_current_type(ih_p->ih_dip)) {
8744397Sschwartz 		case DDI_INTR_TYPE_MSI:
8754397Sschwartz 			(void) strcpy(pxintr_ks_template.pxintr_ks_type.value.c,
8764397Sschwartz 			    "msi");
8774397Sschwartz 			break;
8784397Sschwartz 		case DDI_INTR_TYPE_MSIX:
8794397Sschwartz 			(void) strcpy(pxintr_ks_template.pxintr_ks_type.value.c,
8804397Sschwartz 			    "msix");
8814397Sschwartz 			break;
8824397Sschwartz 		default:
8834397Sschwartz 			(void) strcpy(pxintr_ks_template.pxintr_ks_type.value.c,
8844397Sschwartz 			    "fixed");
8854397Sschwartz 			break;
8864397Sschwartz 		}
8874397Sschwartz 
8882973Sgovinda 		pxintr_ks_template.pxintr_ks_cpu.value.ui64 = ino_p->ino_cpuid;
8892973Sgovinda 		pxintr_ks_template.pxintr_ks_pil.value.ui64 = ipil_p->ipil_pil;
8901087Sschwartz 		pxintr_ks_template.pxintr_ks_time.value.ui64 = ih_p->ih_nsec +
8911087Sschwartz 		    (uint64_t)tick2ns((hrtime_t)ih_p->ih_ticks,
8922973Sgovinda 		    ino_p->ino_cpuid);
8931087Sschwartz 		pxintr_ks_template.pxintr_ks_ino.value.ui64 = ino;
8941087Sschwartz 		pxintr_ks_template.pxintr_ks_cookie.value.ui64 = sysino;
8951087Sschwartz 	} else {
8961087Sschwartz 		(void) strcpy(pxintr_ks_template.pxintr_ks_type.value.c,
8971087Sschwartz 		    "disabled");
8981087Sschwartz 		pxintr_ks_template.pxintr_ks_cpu.value.ui64 = 0;
8991087Sschwartz 		pxintr_ks_template.pxintr_ks_pil.value.ui64 = 0;
9001087Sschwartz 		pxintr_ks_template.pxintr_ks_time.value.ui64 = 0;
9011087Sschwartz 		pxintr_ks_template.pxintr_ks_ino.value.ui64 = 0;
9021087Sschwartz 		pxintr_ks_template.pxintr_ks_cookie.value.ui64 = 0;
9031087Sschwartz 	}
90466Sesolom 	return (0);
90566Sesolom }
90666Sesolom 
90766Sesolom void
px_create_intr_kstats(px_ih_t * ih_p)90866Sesolom px_create_intr_kstats(px_ih_t *ih_p)
90966Sesolom {
91066Sesolom 	msiq_rec_type_t rec_type = ih_p->ih_rec_type;
91166Sesolom 
91266Sesolom 	ASSERT(ih_p->ih_ksp == NULL);
91366Sesolom 
91466Sesolom 	/*
91566Sesolom 	 * Create pci_intrs::: kstats for all ih types except messages,
91666Sesolom 	 * which represent unusual conditions and don't need to be tracked.
91766Sesolom 	 */
91866Sesolom 	if (rec_type == 0 || rec_type == MSI32_REC || rec_type == MSI64_REC) {
91966Sesolom 		ih_p->ih_ksp = kstat_create("pci_intrs",
92066Sesolom 		    atomic_inc_32_nv(&pxintr_ks_instance), "config",
92166Sesolom 		    "interrupts", KSTAT_TYPE_NAMED,
92266Sesolom 		    sizeof (pxintr_ks_template) / sizeof (kstat_named_t),
92366Sesolom 		    KSTAT_FLAG_VIRTUAL);
92466Sesolom 	}
92566Sesolom 	if (ih_p->ih_ksp != NULL) {
92666Sesolom 		ih_p->ih_ksp->ks_data_size += MAXPATHLEN * 2;
92766Sesolom 		ih_p->ih_ksp->ks_lock = &pxintr_ks_template_lock;
92866Sesolom 		ih_p->ih_ksp->ks_data = &pxintr_ks_template;
92966Sesolom 		ih_p->ih_ksp->ks_private = ih_p;
93066Sesolom 		ih_p->ih_ksp->ks_update = px_ks_update;
93166Sesolom 	}
93266Sesolom }
93366Sesolom 
934693Sgovinda /*
935693Sgovinda  * px_add_intx_intr:
936693Sgovinda  *
937693Sgovinda  * This function is called to register INTx and legacy hardware
938693Sgovinda  * interrupt pins interrupts.
939693Sgovinda  */
9400Sstevel@tonic-gate int
px_add_intx_intr(dev_info_t * dip,dev_info_t * rdip,ddi_intr_handle_impl_t * hdlp)9410Sstevel@tonic-gate px_add_intx_intr(dev_info_t *dip, dev_info_t *rdip,
9420Sstevel@tonic-gate     ddi_intr_handle_impl_t *hdlp)
9430Sstevel@tonic-gate {
9440Sstevel@tonic-gate 	px_t		*px_p = INST_TO_STATE(ddi_get_instance(dip));
9450Sstevel@tonic-gate 	px_ib_t		*ib_p = px_p->px_ib_p;
9460Sstevel@tonic-gate 	devino_t	ino;
9470Sstevel@tonic-gate 	px_ih_t		*ih_p;
9482973Sgovinda 	px_ino_t	*ino_p;
9492973Sgovinda 	px_ino_pil_t	*ipil_p, *ipil_list;
9500Sstevel@tonic-gate 	int32_t		weight;
9510Sstevel@tonic-gate 	int		ret = DDI_SUCCESS;
95211836SDaniel.Ice@Sun.COM 	cpuid_t		curr_cpu;
9530Sstevel@tonic-gate 
9540Sstevel@tonic-gate 	ino = hdlp->ih_vector;
9550Sstevel@tonic-gate 
9560Sstevel@tonic-gate 	DBG(DBG_A_INTX, dip, "px_add_intx_intr: rdip=%s%d ino=%x "
9570Sstevel@tonic-gate 	    "handler=%x arg1=%x arg2=%x\n", ddi_driver_name(rdip),
9580Sstevel@tonic-gate 	    ddi_get_instance(rdip), ino, hdlp->ih_cb_func,
9590Sstevel@tonic-gate 	    hdlp->ih_cb_arg1, hdlp->ih_cb_arg2);
9600Sstevel@tonic-gate 
9610Sstevel@tonic-gate 	ih_p = px_ib_alloc_ih(rdip, hdlp->ih_inum,
9620Sstevel@tonic-gate 	    hdlp->ih_cb_func, hdlp->ih_cb_arg1, hdlp->ih_cb_arg2, 0, 0);
9630Sstevel@tonic-gate 
9640Sstevel@tonic-gate 	mutex_enter(&ib_p->ib_ino_lst_mutex);
9650Sstevel@tonic-gate 
9662973Sgovinda 	ino_p = px_ib_locate_ino(ib_p, ino);
9672973Sgovinda 	ipil_list = ino_p ? ino_p->ino_ipil_p : NULL;
9682973Sgovinda 
969*12603SDavid.Major@Oracle.COM 	if (hdlp->ih_pri == 0)
970*12603SDavid.Major@Oracle.COM 		hdlp->ih_pri = pci_class_to_pil(rdip);
971*12603SDavid.Major@Oracle.COM 
97211836SDaniel.Ice@Sun.COM 	/* Sharing the INO using a PIL that already exists */
9732973Sgovinda 	if (ino_p && (ipil_p = px_ib_ino_locate_ipil(ino_p, hdlp->ih_pri))) {
9742973Sgovinda 		if (px_ib_intr_locate_ih(ipil_p, rdip, hdlp->ih_inum, 0, 0)) {
9750Sstevel@tonic-gate 			DBG(DBG_A_INTX, dip, "px_add_intx_intr: "
9762973Sgovinda 			    "dup intr #%d\n", hdlp->ih_inum);
9770Sstevel@tonic-gate 
9780Sstevel@tonic-gate 			ret = DDI_FAILURE;
9790Sstevel@tonic-gate 			goto fail1;
9800Sstevel@tonic-gate 		}
9810Sstevel@tonic-gate 
9820Sstevel@tonic-gate 		/* Save mondo value in hdlp */
9830Sstevel@tonic-gate 		hdlp->ih_vector = ino_p->ino_sysino;
9840Sstevel@tonic-gate 
9852973Sgovinda 		if ((ret = px_ib_ino_add_intr(px_p, ipil_p,
9862973Sgovinda 		    ih_p)) != DDI_SUCCESS)
9870Sstevel@tonic-gate 			goto fail1;
9882973Sgovinda 
9892973Sgovinda 		goto ino_done;
9902973Sgovinda 	}
9910Sstevel@tonic-gate 
99211836SDaniel.Ice@Sun.COM 	/* Sharing the INO using a new PIL */
99311836SDaniel.Ice@Sun.COM 	if (ipil_list != NULL) {
99411836SDaniel.Ice@Sun.COM 		/*
99511836SDaniel.Ice@Sun.COM 		 * disable INO to avoid lopil race condition with
99611836SDaniel.Ice@Sun.COM 		 * px_intx_intr
99711836SDaniel.Ice@Sun.COM 		 */
99811836SDaniel.Ice@Sun.COM 
99911836SDaniel.Ice@Sun.COM 		if ((ret = px_lib_intr_gettarget(dip, ino_p->ino_sysino,
100011836SDaniel.Ice@Sun.COM 		    &curr_cpu)) != DDI_SUCCESS) {
100111836SDaniel.Ice@Sun.COM 			DBG(DBG_IB, dip,
100211836SDaniel.Ice@Sun.COM 			    "px_add_intx_intr px_intr_gettarget() failed\n");
100311836SDaniel.Ice@Sun.COM 
100411836SDaniel.Ice@Sun.COM 			goto fail1;
100511836SDaniel.Ice@Sun.COM 		}
100611836SDaniel.Ice@Sun.COM 
100712589SDavid.Major@Oracle.COM 		/* Wait on pending interrupt */
100812589SDavid.Major@Oracle.COM 		if ((ret = px_ib_intr_pend(dip, ino_p->ino_sysino)) !=
100912589SDavid.Major@Oracle.COM 		    DDI_SUCCESS) {
101012589SDavid.Major@Oracle.COM 			cmn_err(CE_WARN, "%s%d: px_add_intx_intr: "
101112589SDavid.Major@Oracle.COM 			    "pending sysino 0x%lx(ino 0x%x) timeout",
101212589SDavid.Major@Oracle.COM 			    ddi_driver_name(dip), ddi_get_instance(dip),
101312589SDavid.Major@Oracle.COM 			    ino_p->ino_sysino, ino_p->ino_ino);
101412589SDavid.Major@Oracle.COM 			goto fail1;
101511836SDaniel.Ice@Sun.COM 		}
101611836SDaniel.Ice@Sun.COM 	}
101711836SDaniel.Ice@Sun.COM 
10182973Sgovinda 	ipil_p = px_ib_new_ino_pil(ib_p, ino, hdlp->ih_pri, ih_p);
10192973Sgovinda 	ino_p = ipil_p->ipil_ino_p;
10200Sstevel@tonic-gate 
10212973Sgovinda 	/* Save mondo value in hdlp */
10222973Sgovinda 	hdlp->ih_vector = ino_p->ino_sysino;
10230Sstevel@tonic-gate 
10242973Sgovinda 	DBG(DBG_A_INTX, dip, "px_add_intx_intr: pil=0x%x mondo=0x%x\n",
10252973Sgovinda 	    hdlp->ih_pri, hdlp->ih_vector);
10260Sstevel@tonic-gate 
10272973Sgovinda 	DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp,
10282973Sgovinda 	    (ddi_intr_handler_t *)px_intx_intr, (caddr_t)ipil_p, NULL);
10290Sstevel@tonic-gate 
10302973Sgovinda 	ret = i_ddi_add_ivintr(hdlp);
10310Sstevel@tonic-gate 
10322973Sgovinda 	/*
10332973Sgovinda 	 * Restore original interrupt handler
10342973Sgovinda 	 * and arguments in interrupt handle.
10352973Sgovinda 	 */
10362973Sgovinda 	DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp, ih_p->ih_handler,
10372973Sgovinda 	    ih_p->ih_handler_arg1, ih_p->ih_handler_arg2);
10380Sstevel@tonic-gate 
10392973Sgovinda 	if (ret != DDI_SUCCESS)
10402973Sgovinda 		goto fail2;
10410Sstevel@tonic-gate 
10422973Sgovinda 	/* Save the pil for this ino */
10432973Sgovinda 	ipil_p->ipil_pil = hdlp->ih_pri;
10440Sstevel@tonic-gate 
10452973Sgovinda 	/* Select cpu, saving it for sharing and removal */
10462973Sgovinda 	if (ipil_list == NULL) {
104710053SEvan.Yan@Sun.COM 		if (ino_p->ino_cpuid == -1)
104810053SEvan.Yan@Sun.COM 			ino_p->ino_cpuid = intr_dist_cpuid();
10490Sstevel@tonic-gate 
10500Sstevel@tonic-gate 		/* Enable interrupt */
10510Sstevel@tonic-gate 		px_ib_intr_enable(px_p, ino_p->ino_cpuid, ino);
105211836SDaniel.Ice@Sun.COM 	} else {
105311836SDaniel.Ice@Sun.COM 		/* Re-enable interrupt */
105411836SDaniel.Ice@Sun.COM 		PX_INTR_ENABLE(dip, ino_p->ino_sysino, curr_cpu);
10550Sstevel@tonic-gate 	}
10560Sstevel@tonic-gate 
10572973Sgovinda ino_done:
105810053SEvan.Yan@Sun.COM 	hdlp->ih_target = ino_p->ino_cpuid;
105910053SEvan.Yan@Sun.COM 
10602973Sgovinda 	/* Add weight to the cpu that we are already targeting */
10618535Sevan.yan@sun.com 	weight = pci_class_to_intr_weight(rdip);
10620Sstevel@tonic-gate 	intr_dist_cpuid_add_device_weight(ino_p->ino_cpuid, rdip, weight);
10630Sstevel@tonic-gate 
10642973Sgovinda 	ih_p->ih_ipil_p = ipil_p;
106566Sesolom 	px_create_intr_kstats(ih_p);
10660Sstevel@tonic-gate 	if (ih_p->ih_ksp)
10670Sstevel@tonic-gate 		kstat_install(ih_p->ih_ksp);
10680Sstevel@tonic-gate 	mutex_exit(&ib_p->ib_ino_lst_mutex);
10690Sstevel@tonic-gate 
10700Sstevel@tonic-gate 	DBG(DBG_A_INTX, dip, "px_add_intx_intr: done! Interrupt 0x%x pil=%x\n",
10710Sstevel@tonic-gate 	    ino_p->ino_sysino, hdlp->ih_pri);
10720Sstevel@tonic-gate 
10730Sstevel@tonic-gate 	return (ret);
10740Sstevel@tonic-gate fail2:
10752973Sgovinda 	px_ib_delete_ino_pil(ib_p, ipil_p);
10760Sstevel@tonic-gate fail1:
10770Sstevel@tonic-gate 	if (ih_p->ih_config_handle)
10780Sstevel@tonic-gate 		pci_config_teardown(&ih_p->ih_config_handle);
10790Sstevel@tonic-gate 
10800Sstevel@tonic-gate 	mutex_exit(&ib_p->ib_ino_lst_mutex);
10810Sstevel@tonic-gate 	kmem_free(ih_p, sizeof (px_ih_t));
10820Sstevel@tonic-gate 
10830Sstevel@tonic-gate 	DBG(DBG_A_INTX, dip, "px_add_intx_intr: Failed! Interrupt 0x%x "
10840Sstevel@tonic-gate 	    "pil=%x\n", ino_p->ino_sysino, hdlp->ih_pri);
10850Sstevel@tonic-gate 
10860Sstevel@tonic-gate 	return (ret);
10870Sstevel@tonic-gate }
10880Sstevel@tonic-gate 
1089693Sgovinda /*
1090693Sgovinda  * px_rem_intx_intr:
1091693Sgovinda  *
1092693Sgovinda  * This function is called to unregister INTx and legacy hardware
1093693Sgovinda  * interrupt pins interrupts.
1094693Sgovinda  */
10950Sstevel@tonic-gate int
px_rem_intx_intr(dev_info_t * dip,dev_info_t * rdip,ddi_intr_handle_impl_t * hdlp)10960Sstevel@tonic-gate px_rem_intx_intr(dev_info_t *dip, dev_info_t *rdip,
10970Sstevel@tonic-gate     ddi_intr_handle_impl_t *hdlp)
10980Sstevel@tonic-gate {
10990Sstevel@tonic-gate 	px_t		*px_p = INST_TO_STATE(ddi_get_instance(dip));
11000Sstevel@tonic-gate 	px_ib_t		*ib_p = px_p->px_ib_p;
11010Sstevel@tonic-gate 	devino_t	ino;
11020Sstevel@tonic-gate 	cpuid_t		curr_cpu;
11032973Sgovinda 	px_ino_t	*ino_p;
11042973Sgovinda 	px_ino_pil_t	*ipil_p;
11050Sstevel@tonic-gate 	px_ih_t		*ih_p;
11060Sstevel@tonic-gate 	int		ret = DDI_SUCCESS;
11070Sstevel@tonic-gate 
11080Sstevel@tonic-gate 	ino = hdlp->ih_vector;
11090Sstevel@tonic-gate 
11100Sstevel@tonic-gate 	DBG(DBG_R_INTX, dip, "px_rem_intx_intr: rdip=%s%d ino=%x\n",
11110Sstevel@tonic-gate 	    ddi_driver_name(rdip), ddi_get_instance(rdip), ino);
11120Sstevel@tonic-gate 
11130Sstevel@tonic-gate 	mutex_enter(&ib_p->ib_ino_lst_mutex);
11140Sstevel@tonic-gate 
11150Sstevel@tonic-gate 	ino_p = px_ib_locate_ino(ib_p, ino);
11162973Sgovinda 	ipil_p = px_ib_ino_locate_ipil(ino_p, hdlp->ih_pri);
11172973Sgovinda 	ih_p = px_ib_intr_locate_ih(ipil_p, rdip, hdlp->ih_inum, 0, 0);
11180Sstevel@tonic-gate 
11190Sstevel@tonic-gate 	/* Get the current cpu */
11200Sstevel@tonic-gate 	if ((ret = px_lib_intr_gettarget(px_p->px_dip, ino_p->ino_sysino,
11210Sstevel@tonic-gate 	    &curr_cpu)) != DDI_SUCCESS)
11220Sstevel@tonic-gate 		goto fail;
11230Sstevel@tonic-gate 
11242973Sgovinda 	if ((ret = px_ib_ino_rem_intr(px_p, ipil_p, ih_p)) != DDI_SUCCESS)
11250Sstevel@tonic-gate 		goto fail;
11260Sstevel@tonic-gate 
11270Sstevel@tonic-gate 	intr_dist_cpuid_rem_device_weight(ino_p->ino_cpuid, rdip);
11280Sstevel@tonic-gate 
11292973Sgovinda 	if (ipil_p->ipil_ih_size == 0) {
11300Sstevel@tonic-gate 		hdlp->ih_vector = ino_p->ino_sysino;
11310Sstevel@tonic-gate 		i_ddi_rem_ivintr(hdlp);
11320Sstevel@tonic-gate 
11332973Sgovinda 		px_ib_delete_ino_pil(ib_p, ipil_p);
11342973Sgovinda 	}
11352973Sgovinda 
11362973Sgovinda 	if (ino_p->ino_ipil_size == 0) {
11372973Sgovinda 		kmem_free(ino_p, sizeof (px_ino_t));
11380Sstevel@tonic-gate 	} else {
11393780Segillett 		/* Re-enable interrupt only if mapping register still shared */
11403780Segillett 		PX_INTR_ENABLE(px_p->px_dip, ino_p->ino_sysino, curr_cpu);
11410Sstevel@tonic-gate 	}
11420Sstevel@tonic-gate 
11430Sstevel@tonic-gate fail:
11440Sstevel@tonic-gate 	mutex_exit(&ib_p->ib_ino_lst_mutex);
11450Sstevel@tonic-gate 	return (ret);
11460Sstevel@tonic-gate }
11470Sstevel@tonic-gate 
1148693Sgovinda /*
1149693Sgovinda  * px_add_msiq_intr:
1150693Sgovinda  *
1151693Sgovinda  * This function is called to register MSI/Xs and PCIe message interrupts.
1152693Sgovinda  */
11530Sstevel@tonic-gate int
px_add_msiq_intr(dev_info_t * dip,dev_info_t * rdip,ddi_intr_handle_impl_t * hdlp,msiq_rec_type_t rec_type,msgcode_t msg_code,cpuid_t cpu_id,msiqid_t * msiq_id_p)11540Sstevel@tonic-gate px_add_msiq_intr(dev_info_t *dip, dev_info_t *rdip,
11550Sstevel@tonic-gate     ddi_intr_handle_impl_t *hdlp, msiq_rec_type_t rec_type,
115610053SEvan.Yan@Sun.COM     msgcode_t msg_code, cpuid_t cpu_id, msiqid_t *msiq_id_p)
11570Sstevel@tonic-gate {
11580Sstevel@tonic-gate 	px_t		*px_p = INST_TO_STATE(ddi_get_instance(dip));
11590Sstevel@tonic-gate 	px_ib_t		*ib_p = px_p->px_ib_p;
11600Sstevel@tonic-gate 	px_msiq_state_t	*msiq_state_p = &ib_p->ib_msiq_state;
11610Sstevel@tonic-gate 	devino_t	ino;
11620Sstevel@tonic-gate 	px_ih_t		*ih_p;
11632973Sgovinda 	px_ino_t	*ino_p;
11642973Sgovinda 	px_ino_pil_t	*ipil_p, *ipil_list;
11650Sstevel@tonic-gate 	int32_t		weight;
11660Sstevel@tonic-gate 	int		ret = DDI_SUCCESS;
11670Sstevel@tonic-gate 
116810053SEvan.Yan@Sun.COM 	DBG(DBG_MSIQ, dip, "px_add_msiq_intr: rdip=%s%d handler=0x%x "
116910053SEvan.Yan@Sun.COM 	    "arg1=0x%x arg2=0x%x cpu=0x%x\n", ddi_driver_name(rdip),
117010053SEvan.Yan@Sun.COM 	    ddi_get_instance(rdip), hdlp->ih_cb_func, hdlp->ih_cb_arg1,
117110053SEvan.Yan@Sun.COM 	    hdlp->ih_cb_arg2, cpu_id);
11720Sstevel@tonic-gate 
11730Sstevel@tonic-gate 	ih_p = px_ib_alloc_ih(rdip, hdlp->ih_inum, hdlp->ih_cb_func,
11740Sstevel@tonic-gate 	    hdlp->ih_cb_arg1, hdlp->ih_cb_arg2, rec_type, msg_code);
11750Sstevel@tonic-gate 
11760Sstevel@tonic-gate 	mutex_enter(&ib_p->ib_ino_lst_mutex);
11770Sstevel@tonic-gate 
117810841SAlan.Adamson@Sun.COM 	ret = (cpu_id == -1) ? px_msiq_alloc(px_p, rec_type, msg_code,
117910841SAlan.Adamson@Sun.COM 	    msiq_id_p) : px_msiq_alloc_based_on_cpuid(px_p, rec_type,
118010841SAlan.Adamson@Sun.COM 	    cpu_id, msiq_id_p);
118110053SEvan.Yan@Sun.COM 
118210053SEvan.Yan@Sun.COM 	if (ret != DDI_SUCCESS) {
118310053SEvan.Yan@Sun.COM 		DBG(DBG_MSIQ, dip, "px_add_msiq_intr: "
118410053SEvan.Yan@Sun.COM 		    "msiq allocation failed\n");
118510053SEvan.Yan@Sun.COM 		goto fail;
118610053SEvan.Yan@Sun.COM 	}
118710053SEvan.Yan@Sun.COM 
118810053SEvan.Yan@Sun.COM 	ino = px_msiqid_to_devino(px_p, *msiq_id_p);
118910053SEvan.Yan@Sun.COM 
11902973Sgovinda 	ino_p = px_ib_locate_ino(ib_p, ino);
11912973Sgovinda 	ipil_list = ino_p ? ino_p->ino_ipil_p : NULL;
11922973Sgovinda 
1193*12603SDavid.Major@Oracle.COM 	if (hdlp->ih_pri == 0)
1194*12603SDavid.Major@Oracle.COM 		hdlp->ih_pri = pci_class_to_pil(rdip);
1195*12603SDavid.Major@Oracle.COM 
11962973Sgovinda 	/* Sharing ino */
11972973Sgovinda 	if (ino_p && (ipil_p = px_ib_ino_locate_ipil(ino_p, hdlp->ih_pri))) {
11982973Sgovinda 		if (px_ib_intr_locate_ih(ipil_p, rdip,
11992973Sgovinda 		    hdlp->ih_inum, rec_type, msg_code)) {
12000Sstevel@tonic-gate 			DBG(DBG_MSIQ, dip, "px_add_msiq_intr: "
12012973Sgovinda 			    "dup intr #%d\n", hdlp->ih_inum);
12020Sstevel@tonic-gate 
12030Sstevel@tonic-gate 			ret = DDI_FAILURE;
12040Sstevel@tonic-gate 			goto fail1;
12050Sstevel@tonic-gate 		}
12060Sstevel@tonic-gate 
12070Sstevel@tonic-gate 		/* Save mondo value in hdlp */
12080Sstevel@tonic-gate 		hdlp->ih_vector = ino_p->ino_sysino;
12090Sstevel@tonic-gate 
12102973Sgovinda 		if ((ret = px_ib_ino_add_intr(px_p, ipil_p,
12112973Sgovinda 		    ih_p)) != DDI_SUCCESS)
12122973Sgovinda 			goto fail1;
12132973Sgovinda 
12142973Sgovinda 		goto ino_done;
12152973Sgovinda 	}
12162973Sgovinda 
12172973Sgovinda 	ipil_p = px_ib_new_ino_pil(ib_p, ino, hdlp->ih_pri, ih_p);
12182973Sgovinda 	ino_p = ipil_p->ipil_ino_p;
12192973Sgovinda 
12202973Sgovinda 	ino_p->ino_msiq_p = msiq_state_p->msiq_p +
12212973Sgovinda 	    (*msiq_id_p - msiq_state_p->msiq_1st_msiq_id);
12220Sstevel@tonic-gate 
12232973Sgovinda 	/* Save mondo value in hdlp */
12242973Sgovinda 	hdlp->ih_vector = ino_p->ino_sysino;
12252973Sgovinda 
12262973Sgovinda 	DBG(DBG_MSIQ, dip, "px_add_msiq_intr: pil=0x%x mondo=0x%x\n",
12272973Sgovinda 	    hdlp->ih_pri, hdlp->ih_vector);
12280Sstevel@tonic-gate 
12292973Sgovinda 	DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp,
12302973Sgovinda 	    (ddi_intr_handler_t *)px_msiq_intr, (caddr_t)ipil_p, NULL);
12312973Sgovinda 
12322973Sgovinda 	ret = i_ddi_add_ivintr(hdlp);
12330Sstevel@tonic-gate 
12342973Sgovinda 	/*
12352973Sgovinda 	 * Restore original interrupt handler
12362973Sgovinda 	 * and arguments in interrupt handle.
12372973Sgovinda 	 */
12382973Sgovinda 	DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp, ih_p->ih_handler,
12392973Sgovinda 	    ih_p->ih_handler_arg1, ih_p->ih_handler_arg2);
12400Sstevel@tonic-gate 
12412973Sgovinda 	if (ret != DDI_SUCCESS)
12422973Sgovinda 		goto fail2;
12432973Sgovinda 
12442973Sgovinda 	/* Save the pil for this ino */
12452973Sgovinda 	ipil_p->ipil_pil = hdlp->ih_pri;
12462973Sgovinda 
12472973Sgovinda 	/* Select cpu, saving it for sharing and removal */
12482973Sgovinda 	if (ipil_list == NULL) {
12490Sstevel@tonic-gate 		/* Enable MSIQ */
12500Sstevel@tonic-gate 		px_lib_msiq_setstate(dip, *msiq_id_p, PCI_MSIQ_STATE_IDLE);
12510Sstevel@tonic-gate 		px_lib_msiq_setvalid(dip, *msiq_id_p, PCI_MSIQ_VALID);
12520Sstevel@tonic-gate 
125310053SEvan.Yan@Sun.COM 		if (ino_p->ino_cpuid == -1)
125410053SEvan.Yan@Sun.COM 			ino_p->ino_cpuid = intr_dist_cpuid();
125510053SEvan.Yan@Sun.COM 
12560Sstevel@tonic-gate 		/* Enable interrupt */
12572973Sgovinda 		px_ib_intr_enable(px_p, ino_p->ino_cpuid, ino);
12580Sstevel@tonic-gate 	}
12590Sstevel@tonic-gate 
12602973Sgovinda ino_done:
126110053SEvan.Yan@Sun.COM 	hdlp->ih_target = ino_p->ino_cpuid;
126210053SEvan.Yan@Sun.COM 
12632973Sgovinda 	/* Add weight to the cpu that we are already targeting */
12648535Sevan.yan@sun.com 	weight = pci_class_to_intr_weight(rdip);
12650Sstevel@tonic-gate 	intr_dist_cpuid_add_device_weight(ino_p->ino_cpuid, rdip, weight);
12660Sstevel@tonic-gate 
12672973Sgovinda 	ih_p->ih_ipil_p = ipil_p;
126866Sesolom 	px_create_intr_kstats(ih_p);
12690Sstevel@tonic-gate 	if (ih_p->ih_ksp)
12700Sstevel@tonic-gate 		kstat_install(ih_p->ih_ksp);
12710Sstevel@tonic-gate 	mutex_exit(&ib_p->ib_ino_lst_mutex);
12720Sstevel@tonic-gate 
12730Sstevel@tonic-gate 	DBG(DBG_MSIQ, dip, "px_add_msiq_intr: done! Interrupt 0x%x pil=%x\n",
12740Sstevel@tonic-gate 	    ino_p->ino_sysino, hdlp->ih_pri);
12750Sstevel@tonic-gate 
12760Sstevel@tonic-gate 	return (ret);
12770Sstevel@tonic-gate fail2:
12782973Sgovinda 	px_ib_delete_ino_pil(ib_p, ipil_p);
12790Sstevel@tonic-gate fail1:
128010053SEvan.Yan@Sun.COM 	(void) px_msiq_free(px_p, *msiq_id_p);
128110053SEvan.Yan@Sun.COM fail:
12820Sstevel@tonic-gate 	if (ih_p->ih_config_handle)
12830Sstevel@tonic-gate 		pci_config_teardown(&ih_p->ih_config_handle);
12840Sstevel@tonic-gate 
12850Sstevel@tonic-gate 	mutex_exit(&ib_p->ib_ino_lst_mutex);
12860Sstevel@tonic-gate 	kmem_free(ih_p, sizeof (px_ih_t));
12870Sstevel@tonic-gate 
12880Sstevel@tonic-gate 	DBG(DBG_MSIQ, dip, "px_add_msiq_intr: Failed! Interrupt 0x%x pil=%x\n",
12890Sstevel@tonic-gate 	    ino_p->ino_sysino, hdlp->ih_pri);
12900Sstevel@tonic-gate 
12910Sstevel@tonic-gate 	return (ret);
12920Sstevel@tonic-gate }
12930Sstevel@tonic-gate 
1294693Sgovinda /*
1295693Sgovinda  * px_rem_msiq_intr:
1296693Sgovinda  *
1297693Sgovinda  * This function is called to unregister MSI/Xs and PCIe message interrupts.
1298693Sgovinda  */
12990Sstevel@tonic-gate int
px_rem_msiq_intr(dev_info_t * dip,dev_info_t * rdip,ddi_intr_handle_impl_t * hdlp,msiq_rec_type_t rec_type,msgcode_t msg_code,msiqid_t msiq_id)13000Sstevel@tonic-gate px_rem_msiq_intr(dev_info_t *dip, dev_info_t *rdip,
13010Sstevel@tonic-gate     ddi_intr_handle_impl_t *hdlp, msiq_rec_type_t rec_type,
13020Sstevel@tonic-gate     msgcode_t msg_code, msiqid_t msiq_id)
13030Sstevel@tonic-gate {
13040Sstevel@tonic-gate 	px_t		*px_p = INST_TO_STATE(ddi_get_instance(dip));
13050Sstevel@tonic-gate 	px_ib_t		*ib_p = px_p->px_ib_p;
13060Sstevel@tonic-gate 	devino_t	ino = px_msiqid_to_devino(px_p, msiq_id);
13070Sstevel@tonic-gate 	cpuid_t		curr_cpu;
13082973Sgovinda 	px_ino_t	*ino_p;
13092973Sgovinda 	px_ino_pil_t	*ipil_p;
13100Sstevel@tonic-gate 	px_ih_t		*ih_p;
13110Sstevel@tonic-gate 	int		ret = DDI_SUCCESS;
13120Sstevel@tonic-gate 
13130Sstevel@tonic-gate 	DBG(DBG_MSIQ, dip, "px_rem_msiq_intr: rdip=%s%d msiq_id=%x ino=%x\n",
13140Sstevel@tonic-gate 	    ddi_driver_name(rdip), ddi_get_instance(rdip), msiq_id, ino);
13150Sstevel@tonic-gate 
13160Sstevel@tonic-gate 	mutex_enter(&ib_p->ib_ino_lst_mutex);
13170Sstevel@tonic-gate 
13180Sstevel@tonic-gate 	ino_p = px_ib_locate_ino(ib_p, ino);
13192973Sgovinda 	ipil_p = px_ib_ino_locate_ipil(ino_p, hdlp->ih_pri);
13202973Sgovinda 	ih_p = px_ib_intr_locate_ih(ipil_p, rdip, hdlp->ih_inum, rec_type,
13212973Sgovinda 	    msg_code);
13220Sstevel@tonic-gate 
13230Sstevel@tonic-gate 	/* Get the current cpu */
13240Sstevel@tonic-gate 	if ((ret = px_lib_intr_gettarget(px_p->px_dip, ino_p->ino_sysino,
13250Sstevel@tonic-gate 	    &curr_cpu)) != DDI_SUCCESS)
13260Sstevel@tonic-gate 		goto fail;
13270Sstevel@tonic-gate 
13282973Sgovinda 	if ((ret = px_ib_ino_rem_intr(px_p, ipil_p, ih_p)) != DDI_SUCCESS)
13290Sstevel@tonic-gate 		goto fail;
13300Sstevel@tonic-gate 
13310Sstevel@tonic-gate 	intr_dist_cpuid_rem_device_weight(ino_p->ino_cpuid, rdip);
13320Sstevel@tonic-gate 
13332973Sgovinda 	if (ipil_p->ipil_ih_size == 0) {
13340Sstevel@tonic-gate 		hdlp->ih_vector = ino_p->ino_sysino;
13350Sstevel@tonic-gate 		i_ddi_rem_ivintr(hdlp);
13360Sstevel@tonic-gate 
13372973Sgovinda 		px_ib_delete_ino_pil(ib_p, ipil_p);
13382973Sgovinda 
13392973Sgovinda 		if (ino_p->ino_ipil_size == 0)
13402973Sgovinda 			px_lib_msiq_setvalid(dip,
13412973Sgovinda 			    px_devino_to_msiqid(px_p, ino), PCI_MSIQ_INVALID);
13422973Sgovinda 	}
13432973Sgovinda 
134410053SEvan.Yan@Sun.COM 	(void) px_msiq_free(px_p, msiq_id);
134510053SEvan.Yan@Sun.COM 
134610053SEvan.Yan@Sun.COM 	if (ino_p->ino_ipil_size) {
13473780Segillett 		/* Re-enable interrupt only if mapping register still shared */
13483780Segillett 		PX_INTR_ENABLE(px_p->px_dip, ino_p->ino_sysino, curr_cpu);
13490Sstevel@tonic-gate 	}
13500Sstevel@tonic-gate 
13510Sstevel@tonic-gate fail:
13520Sstevel@tonic-gate 	mutex_exit(&ib_p->ib_ino_lst_mutex);
13530Sstevel@tonic-gate 	return (ret);
13540Sstevel@tonic-gate }
1355