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
52973Sgovinda * Common Development and Distribution License (the "License").
62973Sgovinda * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*10053SEvan.Yan@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate /*
270Sstevel@tonic-gate * PCI Interrupt Block (RISCx) implementation
280Sstevel@tonic-gate * initialization
290Sstevel@tonic-gate * interrupt enable/disable/clear and mapping register manipulation
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/systm.h> /* panicstr */
360Sstevel@tonic-gate #include <sys/spl.h>
370Sstevel@tonic-gate #include <sys/sunddi.h>
380Sstevel@tonic-gate #include <sys/machsystm.h> /* intr_dist_add */
390Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
400Sstevel@tonic-gate #include <sys/clock.h>
410Sstevel@tonic-gate #include <sys/cpuvar.h>
420Sstevel@tonic-gate #include <sys/pci/pci_obj.h>
430Sstevel@tonic-gate
440Sstevel@tonic-gate #ifdef _STARFIRE
450Sstevel@tonic-gate #include <sys/starfire.h>
460Sstevel@tonic-gate #endif /* _STARFIRE */
470Sstevel@tonic-gate
480Sstevel@tonic-gate /*LINTLIBRARY*/
490Sstevel@tonic-gate static uint_t ib_intr_reset(void *arg);
500Sstevel@tonic-gate
510Sstevel@tonic-gate void
ib_create(pci_t * pci_p)520Sstevel@tonic-gate ib_create(pci_t *pci_p)
530Sstevel@tonic-gate {
540Sstevel@tonic-gate dev_info_t *dip = pci_p->pci_dip;
550Sstevel@tonic-gate ib_t *ib_p;
560Sstevel@tonic-gate uintptr_t a;
570Sstevel@tonic-gate int i;
580Sstevel@tonic-gate
590Sstevel@tonic-gate /*
600Sstevel@tonic-gate * Allocate interrupt block state structure and link it to
610Sstevel@tonic-gate * the pci state structure.
620Sstevel@tonic-gate */
630Sstevel@tonic-gate ib_p = kmem_zalloc(sizeof (ib_t), KM_SLEEP);
640Sstevel@tonic-gate pci_p->pci_ib_p = ib_p;
650Sstevel@tonic-gate ib_p->ib_pci_p = pci_p;
660Sstevel@tonic-gate
670Sstevel@tonic-gate a = pci_ib_setup(ib_p);
680Sstevel@tonic-gate
690Sstevel@tonic-gate /*
700Sstevel@tonic-gate * Determine virtual addresses of interrupt mapping, clear and diag
710Sstevel@tonic-gate * registers that have common offsets.
720Sstevel@tonic-gate */
730Sstevel@tonic-gate ib_p->ib_slot_clear_intr_regs =
745635Srameshc a + COMMON_IB_SLOT_CLEAR_INTR_REG_OFFSET;
750Sstevel@tonic-gate ib_p->ib_intr_retry_timer_reg =
765635Srameshc (uint64_t *)(a + COMMON_IB_INTR_RETRY_TIMER_OFFSET);
770Sstevel@tonic-gate ib_p->ib_slot_intr_state_diag_reg =
785635Srameshc (uint64_t *)(a + COMMON_IB_SLOT_INTR_STATE_DIAG_REG);
790Sstevel@tonic-gate ib_p->ib_obio_intr_state_diag_reg =
805635Srameshc (uint64_t *)(a + COMMON_IB_OBIO_INTR_STATE_DIAG_REG);
810Sstevel@tonic-gate
820Sstevel@tonic-gate if (CHIP_TYPE(pci_p) != PCI_CHIP_XMITS) {
830Sstevel@tonic-gate ib_p->ib_upa_imr[0] = (volatile uint64_t *)
845635Srameshc (a + COMMON_IB_UPA0_INTR_MAP_REG_OFFSET);
850Sstevel@tonic-gate ib_p->ib_upa_imr[1] = (volatile uint64_t *)
865635Srameshc (a + COMMON_IB_UPA1_INTR_MAP_REG_OFFSET);
870Sstevel@tonic-gate }
880Sstevel@tonic-gate
890Sstevel@tonic-gate DEBUG2(DBG_ATTACH, dip, "ib_create: slot_imr=%x, slot_cir=%x\n",
905635Srameshc ib_p->ib_slot_intr_map_regs, ib_p->ib_obio_intr_map_regs);
910Sstevel@tonic-gate DEBUG2(DBG_ATTACH, dip, "ib_create: obio_imr=%x, obio_cir=%x\n",
925635Srameshc ib_p->ib_slot_clear_intr_regs, ib_p->ib_obio_clear_intr_regs);
930Sstevel@tonic-gate DEBUG2(DBG_ATTACH, dip, "ib_create: upa0_imr=%x, upa1_imr=%x\n",
945635Srameshc ib_p->ib_upa_imr[0], ib_p->ib_upa_imr[1]);
950Sstevel@tonic-gate DEBUG3(DBG_ATTACH, dip,
965635Srameshc "ib_create: retry_timer=%x, obio_diag=%x slot_diag=%x\n",
975635Srameshc ib_p->ib_intr_retry_timer_reg,
985635Srameshc ib_p->ib_obio_intr_state_diag_reg,
995635Srameshc ib_p->ib_slot_intr_state_diag_reg);
1000Sstevel@tonic-gate
1010Sstevel@tonic-gate ib_p->ib_ino_lst = (ib_ino_info_t *)NULL;
1020Sstevel@tonic-gate mutex_init(&ib_p->ib_intr_lock, NULL, MUTEX_DRIVER, NULL);
1030Sstevel@tonic-gate mutex_init(&ib_p->ib_ino_lst_mutex, NULL, MUTEX_DRIVER, NULL);
1040Sstevel@tonic-gate
1050Sstevel@tonic-gate DEBUG1(DBG_ATTACH, dip, "ib_create: numproxy=%x\n",
1065635Srameshc pci_p->pci_numproxy);
1070Sstevel@tonic-gate for (i = 1; i <= pci_p->pci_numproxy; i++) {
1080Sstevel@tonic-gate set_intr_mapping_reg(pci_p->pci_id,
1095635Srameshc (uint64_t *)ib_p->ib_upa_imr[i - 1], i);
1100Sstevel@tonic-gate }
1110Sstevel@tonic-gate
1120Sstevel@tonic-gate ib_configure(ib_p);
1130Sstevel@tonic-gate bus_func_register(BF_TYPE_RESINTR, ib_intr_reset, ib_p);
1140Sstevel@tonic-gate }
1150Sstevel@tonic-gate
1160Sstevel@tonic-gate void
ib_destroy(pci_t * pci_p)1170Sstevel@tonic-gate ib_destroy(pci_t *pci_p)
1180Sstevel@tonic-gate {
1190Sstevel@tonic-gate ib_t *ib_p = pci_p->pci_ib_p;
1200Sstevel@tonic-gate dev_info_t *dip = pci_p->pci_dip;
1210Sstevel@tonic-gate
1220Sstevel@tonic-gate DEBUG0(DBG_IB, dip, "ib_destroy\n");
1230Sstevel@tonic-gate bus_func_unregister(BF_TYPE_RESINTR, ib_intr_reset, ib_p);
1240Sstevel@tonic-gate
1250Sstevel@tonic-gate intr_dist_rem_weighted(ib_intr_dist_all, ib_p);
1260Sstevel@tonic-gate mutex_destroy(&ib_p->ib_ino_lst_mutex);
1270Sstevel@tonic-gate mutex_destroy(&ib_p->ib_intr_lock);
1280Sstevel@tonic-gate
1290Sstevel@tonic-gate ib_free_ino_all(ib_p);
1300Sstevel@tonic-gate
1310Sstevel@tonic-gate kmem_free(ib_p, sizeof (ib_t));
1320Sstevel@tonic-gate pci_p->pci_ib_p = NULL;
1330Sstevel@tonic-gate }
1340Sstevel@tonic-gate
1350Sstevel@tonic-gate void
ib_configure(ib_t * ib_p)1360Sstevel@tonic-gate ib_configure(ib_t *ib_p)
1370Sstevel@tonic-gate {
1380Sstevel@tonic-gate /* XXX could be different between psycho and schizo */
1390Sstevel@tonic-gate *ib_p->ib_intr_retry_timer_reg = pci_intr_retry_intv;
1400Sstevel@tonic-gate }
1410Sstevel@tonic-gate
1420Sstevel@tonic-gate /*
1430Sstevel@tonic-gate * can only used for psycho internal interrupts thermal, power,
1440Sstevel@tonic-gate * ue, ce, pbm
1450Sstevel@tonic-gate */
1460Sstevel@tonic-gate void
ib_intr_enable(pci_t * pci_p,ib_ino_t ino)1470Sstevel@tonic-gate ib_intr_enable(pci_t *pci_p, ib_ino_t ino)
1480Sstevel@tonic-gate {
1490Sstevel@tonic-gate ib_t *ib_p = pci_p->pci_ib_p;
1500Sstevel@tonic-gate ib_mondo_t mondo = IB_INO_TO_MONDO(ib_p, ino);
1510Sstevel@tonic-gate volatile uint64_t *imr_p = ib_intr_map_reg_addr(ib_p, ino);
1520Sstevel@tonic-gate uint_t cpu_id;
1530Sstevel@tonic-gate
1540Sstevel@tonic-gate /*
1550Sstevel@tonic-gate * Determine the cpu for the interrupt.
1560Sstevel@tonic-gate */
1570Sstevel@tonic-gate mutex_enter(&ib_p->ib_intr_lock);
1580Sstevel@tonic-gate cpu_id = intr_dist_cpuid();
1590Sstevel@tonic-gate #ifdef _STARFIRE
1600Sstevel@tonic-gate cpu_id = pc_translate_tgtid(IB2CB(ib_p)->cb_ittrans_cookie, cpu_id,
1615635Srameshc IB_GET_MAPREG_INO(ino));
1620Sstevel@tonic-gate #endif /* _STARFIRE */
1630Sstevel@tonic-gate DEBUG2(DBG_IB, pci_p->pci_dip,
1645635Srameshc "ib_intr_enable: ino=%x cpu_id=%x\n", ino, cpu_id);
1650Sstevel@tonic-gate
1660Sstevel@tonic-gate *imr_p = ib_get_map_reg(mondo, cpu_id);
1670Sstevel@tonic-gate IB_INO_INTR_CLEAR(ib_clear_intr_reg_addr(ib_p, ino));
1680Sstevel@tonic-gate mutex_exit(&ib_p->ib_intr_lock);
1690Sstevel@tonic-gate }
1700Sstevel@tonic-gate
1710Sstevel@tonic-gate /*
1720Sstevel@tonic-gate * Disable the interrupt via its interrupt mapping register.
1730Sstevel@tonic-gate * Can only be used for internal interrupts: thermal, power, ue, ce, pbm.
1740Sstevel@tonic-gate * If called under interrupt context, wait should be set to 0
1750Sstevel@tonic-gate */
1760Sstevel@tonic-gate void
ib_intr_disable(ib_t * ib_p,ib_ino_t ino,int wait)1770Sstevel@tonic-gate ib_intr_disable(ib_t *ib_p, ib_ino_t ino, int wait)
1780Sstevel@tonic-gate {
1790Sstevel@tonic-gate volatile uint64_t *imr_p = ib_intr_map_reg_addr(ib_p, ino);
1800Sstevel@tonic-gate volatile uint64_t *state_reg_p = IB_INO_INTR_STATE_REG(ib_p, ino);
1810Sstevel@tonic-gate hrtime_t start_time;
1820Sstevel@tonic-gate
1830Sstevel@tonic-gate /* disable the interrupt */
1840Sstevel@tonic-gate mutex_enter(&ib_p->ib_intr_lock);
1850Sstevel@tonic-gate IB_INO_INTR_OFF(imr_p);
1860Sstevel@tonic-gate *imr_p; /* flush previous write */
1870Sstevel@tonic-gate mutex_exit(&ib_p->ib_intr_lock);
1880Sstevel@tonic-gate
1890Sstevel@tonic-gate if (!wait)
1900Sstevel@tonic-gate goto wait_done;
1910Sstevel@tonic-gate
1920Sstevel@tonic-gate start_time = gethrtime();
1930Sstevel@tonic-gate /* busy wait if there is interrupt being processed */
1940Sstevel@tonic-gate while (IB_INO_INTR_PENDING(state_reg_p, ino) && !panicstr) {
1950Sstevel@tonic-gate if (gethrtime() - start_time > pci_intrpend_timeout) {
1960Sstevel@tonic-gate pbm_t *pbm_p = ib_p->ib_pci_p->pci_pbm_p;
1970Sstevel@tonic-gate cmn_err(CE_WARN, "%s:%s: ib_intr_disable timeout %x",
1985635Srameshc pbm_p->pbm_nameinst_str,
1995635Srameshc pbm_p->pbm_nameaddr_str, ino);
2000Sstevel@tonic-gate break;
2010Sstevel@tonic-gate }
2020Sstevel@tonic-gate }
2030Sstevel@tonic-gate wait_done:
2040Sstevel@tonic-gate IB_INO_INTR_PEND(ib_clear_intr_reg_addr(ib_p, ino));
2050Sstevel@tonic-gate #ifdef _STARFIRE
2060Sstevel@tonic-gate pc_ittrans_cleanup(IB2CB(ib_p)->cb_ittrans_cookie,
207946Smathue (volatile uint64_t *)(uintptr_t)ino);
2080Sstevel@tonic-gate #endif /* _STARFIRE */
2090Sstevel@tonic-gate }
2100Sstevel@tonic-gate
2110Sstevel@tonic-gate /* can only used for psycho internal interrupts thermal, power, ue, ce, pbm */
2120Sstevel@tonic-gate void
ib_nintr_clear(ib_t * ib_p,ib_ino_t ino)2130Sstevel@tonic-gate ib_nintr_clear(ib_t *ib_p, ib_ino_t ino)
2140Sstevel@tonic-gate {
2150Sstevel@tonic-gate uint64_t *clr_reg = ib_clear_intr_reg_addr(ib_p, ino);
2160Sstevel@tonic-gate IB_INO_INTR_CLEAR(clr_reg);
2170Sstevel@tonic-gate }
2180Sstevel@tonic-gate
2190Sstevel@tonic-gate /*
2200Sstevel@tonic-gate * distribute PBM and UPA interrupts. ino is set to 0 by caller if we
2210Sstevel@tonic-gate * are dealing with UPA interrupts (without inos).
2220Sstevel@tonic-gate */
2230Sstevel@tonic-gate void
ib_intr_dist_nintr(ib_t * ib_p,ib_ino_t ino,volatile uint64_t * imr_p)2240Sstevel@tonic-gate ib_intr_dist_nintr(ib_t *ib_p, ib_ino_t ino, volatile uint64_t *imr_p)
2250Sstevel@tonic-gate {
2260Sstevel@tonic-gate volatile uint64_t imr = *imr_p;
2270Sstevel@tonic-gate uint32_t cpu_id;
2280Sstevel@tonic-gate
2290Sstevel@tonic-gate if (!IB_INO_INTR_ISON(imr))
2300Sstevel@tonic-gate return;
2310Sstevel@tonic-gate
2320Sstevel@tonic-gate cpu_id = intr_dist_cpuid();
2330Sstevel@tonic-gate
2340Sstevel@tonic-gate #ifdef _STARFIRE
2350Sstevel@tonic-gate if (ino) {
2360Sstevel@tonic-gate cpu_id = pc_translate_tgtid(IB2CB(ib_p)->cb_ittrans_cookie,
2375635Srameshc cpu_id, IB_GET_MAPREG_INO(ino));
2380Sstevel@tonic-gate }
2390Sstevel@tonic-gate #else /* _STARFIRE */
2400Sstevel@tonic-gate if (ib_map_reg_get_cpu(*imr_p) == cpu_id)
2410Sstevel@tonic-gate return;
2420Sstevel@tonic-gate #endif /* _STARFIRE */
2430Sstevel@tonic-gate
2440Sstevel@tonic-gate *imr_p = ib_get_map_reg(IB_IMR2MONDO(imr), cpu_id);
2450Sstevel@tonic-gate imr = *imr_p; /* flush previous write */
2460Sstevel@tonic-gate }
2470Sstevel@tonic-gate
248117Sschwartz /*
249117Sschwartz * Converts into nsec, ticks logged with a given CPU. Adds nsec to ih.
250117Sschwartz */
251117Sschwartz /*ARGSUSED*/
252117Sschwartz void
ib_cpu_ticks_to_ih_nsec(ib_t * ib_p,ih_t * ih_p,uint32_t cpu_id)253117Sschwartz ib_cpu_ticks_to_ih_nsec(ib_t *ib_p, ih_t *ih_p, uint32_t cpu_id)
254117Sschwartz {
255117Sschwartz extern kmutex_t pciintr_ks_template_lock;
256117Sschwartz hrtime_t ticks;
257117Sschwartz
258117Sschwartz /*
259117Sschwartz * Because we are updating two fields in ih_t we must lock
260117Sschwartz * pciintr_ks_template_lock to prevent someone from reading the
261117Sschwartz * kstats after we set ih_ticks to 0 and before we increment
262117Sschwartz * ih_nsec to compensate.
263117Sschwartz *
264117Sschwartz * We must also protect against the interrupt arriving and incrementing
265117Sschwartz * ih_ticks between the time we read it and when we reset it to 0.
266117Sschwartz * To do this we use atomic_swap.
267117Sschwartz */
268117Sschwartz
269117Sschwartz ASSERT(MUTEX_HELD(&ib_p->ib_ino_lst_mutex));
270117Sschwartz
271117Sschwartz mutex_enter(&pciintr_ks_template_lock);
272117Sschwartz ticks = atomic_swap_64(&ih_p->ih_ticks, 0);
273117Sschwartz ih_p->ih_nsec += (uint64_t)tick2ns(ticks, cpu_id);
274117Sschwartz mutex_exit(&pciintr_ks_template_lock);
275117Sschwartz }
276117Sschwartz
2770Sstevel@tonic-gate static void
ib_intr_dist(ib_t * ib_p,ib_ino_info_t * ino_p)2780Sstevel@tonic-gate ib_intr_dist(ib_t *ib_p, ib_ino_info_t *ino_p)
2790Sstevel@tonic-gate {
2800Sstevel@tonic-gate uint32_t cpu_id = ino_p->ino_cpuid;
2810Sstevel@tonic-gate ib_ino_t ino = ino_p->ino_ino;
2820Sstevel@tonic-gate volatile uint64_t imr, *imr_p, *state_reg;
2830Sstevel@tonic-gate hrtime_t start_time;
2840Sstevel@tonic-gate
2850Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ib_p->ib_ino_lst_mutex));
2860Sstevel@tonic-gate imr_p = ib_intr_map_reg_addr(ib_p, ino);
2870Sstevel@tonic-gate state_reg = IB_INO_INTR_STATE_REG(ib_p, ino);
2880Sstevel@tonic-gate
2890Sstevel@tonic-gate #ifdef _STARFIRE
2900Sstevel@tonic-gate /*
2910Sstevel@tonic-gate * For Starfire it is a pain to check the current target for
2920Sstevel@tonic-gate * the mondo since we have to read the PC asics ITTR slot
2930Sstevel@tonic-gate * assigned to this mondo. It will be much easier to assume
2940Sstevel@tonic-gate * the current target is always different and do the target
2950Sstevel@tonic-gate * reprogram all the time.
2960Sstevel@tonic-gate */
2970Sstevel@tonic-gate cpu_id = pc_translate_tgtid(IB2CB(ib_p)->cb_ittrans_cookie, cpu_id,
2985635Srameshc IB_GET_MAPREG_INO(ino));
2990Sstevel@tonic-gate #else
3000Sstevel@tonic-gate if (ib_map_reg_get_cpu(*imr_p) == cpu_id) /* same cpu, no reprog */
3010Sstevel@tonic-gate return;
3020Sstevel@tonic-gate #endif /* _STARFIRE */
3030Sstevel@tonic-gate
3040Sstevel@tonic-gate /* disable interrupt, this could disrupt devices sharing our slot */
3050Sstevel@tonic-gate IB_INO_INTR_OFF(imr_p);
3060Sstevel@tonic-gate imr = *imr_p; /* flush previous write */
3070Sstevel@tonic-gate
3080Sstevel@tonic-gate /* busy wait if there is interrupt being processed */
3090Sstevel@tonic-gate start_time = gethrtime();
3100Sstevel@tonic-gate while (IB_INO_INTR_PENDING(state_reg, ino) && !panicstr) {
3110Sstevel@tonic-gate if (gethrtime() - start_time > pci_intrpend_timeout) {
3120Sstevel@tonic-gate pbm_t *pbm_p = ib_p->ib_pci_p->pci_pbm_p;
3130Sstevel@tonic-gate cmn_err(CE_WARN, "%s:%s: ib_intr_dist(%p,%x) timeout",
3145635Srameshc pbm_p->pbm_nameinst_str,
3155635Srameshc pbm_p->pbm_nameaddr_str,
3165635Srameshc imr_p, IB_INO_TO_MONDO(ib_p, ino));
3170Sstevel@tonic-gate break;
3180Sstevel@tonic-gate }
3190Sstevel@tonic-gate }
3200Sstevel@tonic-gate *imr_p = ib_get_map_reg(IB_IMR2MONDO(imr), cpu_id);
3210Sstevel@tonic-gate imr = *imr_p; /* flush previous write */
3220Sstevel@tonic-gate }
3230Sstevel@tonic-gate
3240Sstevel@tonic-gate /*
3250Sstevel@tonic-gate * Redistribute interrupts of the specified weight. The first call has a weight
3260Sstevel@tonic-gate * of weight_max, which can be used to trigger initialization for
3270Sstevel@tonic-gate * redistribution. The inos with weight [weight_max, inf.) should be processed
3280Sstevel@tonic-gate * on the "weight == weight_max" call. This first call is followed by calls
3290Sstevel@tonic-gate * of decreasing weights, inos of that weight should be processed. The final
3300Sstevel@tonic-gate * call specifies a weight of zero, this can be used to trigger processing of
3310Sstevel@tonic-gate * stragglers.
3320Sstevel@tonic-gate */
3330Sstevel@tonic-gate void
ib_intr_dist_all(void * arg,int32_t weight_max,int32_t weight)3340Sstevel@tonic-gate ib_intr_dist_all(void *arg, int32_t weight_max, int32_t weight)
3350Sstevel@tonic-gate {
3360Sstevel@tonic-gate ib_t *ib_p = (ib_t *)arg;
3370Sstevel@tonic-gate pci_t *pci_p = ib_p->ib_pci_p;
3380Sstevel@tonic-gate ib_ino_info_t *ino_p;
3392973Sgovinda ib_ino_pil_t *ipil_p;
3400Sstevel@tonic-gate ih_t *ih_lst;
3410Sstevel@tonic-gate int32_t dweight;
3420Sstevel@tonic-gate int i;
3430Sstevel@tonic-gate
3440Sstevel@tonic-gate if (weight == 0) {
3450Sstevel@tonic-gate mutex_enter(&ib_p->ib_intr_lock);
3460Sstevel@tonic-gate if (CHIP_TYPE(pci_p) != PCI_CHIP_XMITS) {
3470Sstevel@tonic-gate for (i = 0; i < 2; i++)
3480Sstevel@tonic-gate ib_intr_dist_nintr(ib_p, 0,
3490Sstevel@tonic-gate ib_p->ib_upa_imr[i]);
3500Sstevel@tonic-gate }
3510Sstevel@tonic-gate mutex_exit(&ib_p->ib_intr_lock);
3520Sstevel@tonic-gate }
3530Sstevel@tonic-gate
3540Sstevel@tonic-gate mutex_enter(&ib_p->ib_ino_lst_mutex);
3550Sstevel@tonic-gate
3560Sstevel@tonic-gate /* Perform special processing for first call of a redistribution. */
3570Sstevel@tonic-gate if (weight == weight_max) {
3582973Sgovinda for (ino_p = ib_p->ib_ino_lst; ino_p;
3592973Sgovinda ino_p = ino_p->ino_next_p) {
3600Sstevel@tonic-gate
3610Sstevel@tonic-gate /*
3620Sstevel@tonic-gate * Clear ino_established of each ino on first call.
3630Sstevel@tonic-gate * The ino_established field may be used by a pci
3640Sstevel@tonic-gate * nexus driver's pci_intr_dist_cpuid implementation
3650Sstevel@tonic-gate * when detection of established pci slot-cpu binding
3660Sstevel@tonic-gate * for multi function pci cards.
3670Sstevel@tonic-gate */
3680Sstevel@tonic-gate ino_p->ino_established = 0;
3690Sstevel@tonic-gate
3700Sstevel@tonic-gate /*
3710Sstevel@tonic-gate * recompute the ino_intr_weight based on the device
3720Sstevel@tonic-gate * weight of all devinfo nodes sharing the ino (this
3730Sstevel@tonic-gate * will allow us to pick up new weights established by
3740Sstevel@tonic-gate * i_ddi_set_intr_weight()).
3750Sstevel@tonic-gate */
3760Sstevel@tonic-gate ino_p->ino_intr_weight = 0;
3772973Sgovinda
3782973Sgovinda for (ipil_p = ino_p->ino_ipil_p; ipil_p;
3792973Sgovinda ipil_p = ipil_p->ipil_next_p) {
3802973Sgovinda for (i = 0, ih_lst = ipil_p->ipil_ih_head;
3812973Sgovinda i < ipil_p->ipil_ih_size; i++,
3822973Sgovinda ih_lst = ih_lst->ih_next) {
3832973Sgovinda dweight = i_ddi_get_intr_weight
3842973Sgovinda (ih_lst->ih_dip);
3852973Sgovinda if (dweight > 0)
3862973Sgovinda ino_p->ino_intr_weight +=
3872973Sgovinda dweight;
3882973Sgovinda }
3890Sstevel@tonic-gate }
3900Sstevel@tonic-gate }
3910Sstevel@tonic-gate }
3920Sstevel@tonic-gate
3932973Sgovinda for (ino_p = ib_p->ib_ino_lst; ino_p; ino_p = ino_p->ino_next_p) {
3940Sstevel@tonic-gate uint32_t orig_cpuid;
3950Sstevel@tonic-gate
3960Sstevel@tonic-gate /*
3970Sstevel@tonic-gate * Get the weight of the ino and determine if we are going to
3980Sstevel@tonic-gate * process call. We wait until an ib_intr_dist_all call of
3990Sstevel@tonic-gate * the proper weight occurs to support redistribution of all
4000Sstevel@tonic-gate * heavy weighted interrupts first (across all nexus driver
4010Sstevel@tonic-gate * instances). This is done to ensure optimal
4020Sstevel@tonic-gate * INTR_WEIGHTED_DIST behavior.
4030Sstevel@tonic-gate */
4040Sstevel@tonic-gate if ((weight == ino_p->ino_intr_weight) ||
4050Sstevel@tonic-gate ((weight >= weight_max) &&
4060Sstevel@tonic-gate (ino_p->ino_intr_weight >= weight_max))) {
4070Sstevel@tonic-gate /* select cpuid to target and mark ino established */
4080Sstevel@tonic-gate orig_cpuid = ino_p->ino_cpuid;
4090Sstevel@tonic-gate if (cpu[orig_cpuid] == NULL)
4100Sstevel@tonic-gate orig_cpuid = CPU->cpu_id;
4110Sstevel@tonic-gate ino_p->ino_cpuid = pci_intr_dist_cpuid(ib_p, ino_p);
4120Sstevel@tonic-gate ino_p->ino_established = 1;
4130Sstevel@tonic-gate
4140Sstevel@tonic-gate /* Add device weight of ino devinfos to targeted cpu. */
4152973Sgovinda for (ipil_p = ino_p->ino_ipil_p; ipil_p;
4162973Sgovinda ipil_p = ipil_p->ipil_next_p) {
4172973Sgovinda for (i = 0, ih_lst = ipil_p->ipil_ih_head;
4182973Sgovinda i < ipil_p->ipil_ih_size; i++,
4192973Sgovinda ih_lst = ih_lst->ih_next) {
4200Sstevel@tonic-gate
4212973Sgovinda dweight = i_ddi_get_intr_weight(
4222973Sgovinda ih_lst->ih_dip);
4232973Sgovinda intr_dist_cpuid_add_device_weight(
4242973Sgovinda ino_p->ino_cpuid, ih_lst->ih_dip,
4252973Sgovinda dweight);
4260Sstevel@tonic-gate
4272973Sgovinda /*
4282973Sgovinda * Different cpus may have different
4292973Sgovinda * clock speeds. to account for this,
4302973Sgovinda * whenever an interrupt is moved to a
4312973Sgovinda * new CPU, we convert the accumulated
4322973Sgovinda * ticks into nsec, based upon the clock
4332973Sgovinda * rate of the prior CPU.
4342973Sgovinda *
4352973Sgovinda * It is possible that the prior CPU no
4362973Sgovinda * longer exists. In this case, fall
4372973Sgovinda * back to using this CPU's clock rate.
4382973Sgovinda *
4392973Sgovinda * Note that the value in ih_ticks has
4402973Sgovinda * already been corrected for any power
4412973Sgovinda * savings mode which might have been
4422973Sgovinda * in effect.
4432973Sgovinda */
4442973Sgovinda ib_cpu_ticks_to_ih_nsec(ib_p, ih_lst,
4452973Sgovinda orig_cpuid);
4462973Sgovinda }
4470Sstevel@tonic-gate }
4480Sstevel@tonic-gate
4490Sstevel@tonic-gate /* program the hardware */
4500Sstevel@tonic-gate ib_intr_dist(ib_p, ino_p);
4510Sstevel@tonic-gate }
4520Sstevel@tonic-gate }
4530Sstevel@tonic-gate mutex_exit(&ib_p->ib_ino_lst_mutex);
4540Sstevel@tonic-gate }
4550Sstevel@tonic-gate
4560Sstevel@tonic-gate /*
4570Sstevel@tonic-gate * Reset interrupts to IDLE. This function is called during
4580Sstevel@tonic-gate * panic handling after redistributing interrupts; it's needed to
4590Sstevel@tonic-gate * support dumping to network devices after 'sync' from OBP.
4600Sstevel@tonic-gate *
4610Sstevel@tonic-gate * N.B. This routine runs in a context where all other threads
4620Sstevel@tonic-gate * are permanently suspended.
4630Sstevel@tonic-gate */
4640Sstevel@tonic-gate static uint_t
ib_intr_reset(void * arg)4650Sstevel@tonic-gate ib_intr_reset(void *arg)
4660Sstevel@tonic-gate {
4670Sstevel@tonic-gate ib_t *ib_p = (ib_t *)arg;
4680Sstevel@tonic-gate ib_ino_t ino;
4690Sstevel@tonic-gate uint64_t *clr_reg;
4700Sstevel@tonic-gate
4710Sstevel@tonic-gate /*
4720Sstevel@tonic-gate * Note that we only actually care about interrupts that are
4730Sstevel@tonic-gate * potentially from network devices.
4740Sstevel@tonic-gate */
4750Sstevel@tonic-gate for (ino = 0; ino <= ib_p->ib_max_ino; ino++) {
4760Sstevel@tonic-gate clr_reg = ib_clear_intr_reg_addr(ib_p, ino);
4770Sstevel@tonic-gate IB_INO_INTR_CLEAR(clr_reg);
4780Sstevel@tonic-gate }
4790Sstevel@tonic-gate
4800Sstevel@tonic-gate return (BF_NONE);
4810Sstevel@tonic-gate }
4820Sstevel@tonic-gate
4830Sstevel@tonic-gate void
ib_suspend(ib_t * ib_p)4840Sstevel@tonic-gate ib_suspend(ib_t *ib_p)
4850Sstevel@tonic-gate {
4860Sstevel@tonic-gate ib_ino_info_t *ip;
4870Sstevel@tonic-gate pci_t *pci_p = ib_p->ib_pci_p;
4880Sstevel@tonic-gate
4890Sstevel@tonic-gate /* save ino_lst interrupts' mapping registers content */
4900Sstevel@tonic-gate mutex_enter(&ib_p->ib_ino_lst_mutex);
4912973Sgovinda for (ip = ib_p->ib_ino_lst; ip; ip = ip->ino_next_p)
4920Sstevel@tonic-gate ip->ino_map_reg_save = *ip->ino_map_reg;
4930Sstevel@tonic-gate mutex_exit(&ib_p->ib_ino_lst_mutex);
4940Sstevel@tonic-gate
4950Sstevel@tonic-gate if (CHIP_TYPE(pci_p) != PCI_CHIP_XMITS) {
4960Sstevel@tonic-gate ib_p->ib_upa_imr_state[0] = *ib_p->ib_upa_imr[0];
4970Sstevel@tonic-gate ib_p->ib_upa_imr_state[1] = *ib_p->ib_upa_imr[1];
4980Sstevel@tonic-gate }
4990Sstevel@tonic-gate }
5000Sstevel@tonic-gate
5010Sstevel@tonic-gate void
ib_resume(ib_t * ib_p)5020Sstevel@tonic-gate ib_resume(ib_t *ib_p)
5030Sstevel@tonic-gate {
5040Sstevel@tonic-gate ib_ino_info_t *ip;
5050Sstevel@tonic-gate pci_t *pci_p = ib_p->ib_pci_p;
5060Sstevel@tonic-gate
5070Sstevel@tonic-gate /* restore ino_lst interrupts' mapping registers content */
5080Sstevel@tonic-gate mutex_enter(&ib_p->ib_ino_lst_mutex);
5092973Sgovinda for (ip = ib_p->ib_ino_lst; ip; ip = ip->ino_next_p) {
5100Sstevel@tonic-gate IB_INO_INTR_CLEAR(ip->ino_clr_reg); /* set intr to idle */
5110Sstevel@tonic-gate *ip->ino_map_reg = ip->ino_map_reg_save; /* restore IMR */
5120Sstevel@tonic-gate }
5130Sstevel@tonic-gate mutex_exit(&ib_p->ib_ino_lst_mutex);
5140Sstevel@tonic-gate
5150Sstevel@tonic-gate if (CHIP_TYPE(pci_p) != PCI_CHIP_XMITS) {
5160Sstevel@tonic-gate *ib_p->ib_upa_imr[0] = ib_p->ib_upa_imr_state[0];
5170Sstevel@tonic-gate *ib_p->ib_upa_imr[1] = ib_p->ib_upa_imr_state[1];
5180Sstevel@tonic-gate }
5190Sstevel@tonic-gate }
5200Sstevel@tonic-gate
5210Sstevel@tonic-gate /*
5220Sstevel@tonic-gate * locate ino_info structure on ib_p->ib_ino_lst according to ino#
5230Sstevel@tonic-gate * returns NULL if not found.
5240Sstevel@tonic-gate */
5250Sstevel@tonic-gate ib_ino_info_t *
ib_locate_ino(ib_t * ib_p,ib_ino_t ino_num)5260Sstevel@tonic-gate ib_locate_ino(ib_t *ib_p, ib_ino_t ino_num)
5270Sstevel@tonic-gate {
5280Sstevel@tonic-gate ib_ino_info_t *ino_p = ib_p->ib_ino_lst;
5290Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ib_p->ib_ino_lst_mutex));
5300Sstevel@tonic-gate
5315635Srameshc for (; ino_p && ino_p->ino_ino != ino_num; ino_p = ino_p->ino_next_p)
5325635Srameshc ;
5330Sstevel@tonic-gate return (ino_p);
5340Sstevel@tonic-gate }
5350Sstevel@tonic-gate
5360Sstevel@tonic-gate #define IB_INO_TO_SLOT(ino) (IB_IS_OBIO_INO(ino) ? 0xff : ((ino) & 0x1f) >> 2)
5370Sstevel@tonic-gate
5382973Sgovinda ib_ino_pil_t *
ib_new_ino_pil(ib_t * ib_p,ib_ino_t ino_num,uint_t pil,ih_t * ih_p)5392973Sgovinda ib_new_ino_pil(ib_t *ib_p, ib_ino_t ino_num, uint_t pil, ih_t *ih_p)
5400Sstevel@tonic-gate {
5412973Sgovinda ib_ino_pil_t *ipil_p = kmem_zalloc(sizeof (ib_ino_pil_t), KM_SLEEP);
5422973Sgovinda ib_ino_info_t *ino_p;
5432973Sgovinda
5442973Sgovinda if ((ino_p = ib_locate_ino(ib_p, ino_num)) == NULL) {
5452973Sgovinda ino_p = kmem_zalloc(sizeof (ib_ino_info_t), KM_SLEEP);
5462973Sgovinda
5472973Sgovinda ino_p->ino_next_p = ib_p->ib_ino_lst;
5482973Sgovinda ib_p->ib_ino_lst = ino_p;
5490Sstevel@tonic-gate
5502973Sgovinda ino_p->ino_ino = ino_num;
5512973Sgovinda ino_p->ino_slot_no = IB_INO_TO_SLOT(ino_num);
5522973Sgovinda ino_p->ino_ib_p = ib_p;
5532973Sgovinda ino_p->ino_clr_reg = ib_clear_intr_reg_addr(ib_p, ino_num);
5542973Sgovinda ino_p->ino_map_reg = ib_intr_map_reg_addr(ib_p, ino_num);
5552973Sgovinda ino_p->ino_unclaimed_intrs = 0;
5562973Sgovinda ino_p->ino_lopil = pil;
5572973Sgovinda }
5580Sstevel@tonic-gate
5590Sstevel@tonic-gate ih_p->ih_next = ih_p;
5602973Sgovinda ipil_p->ipil_pil = pil;
5612973Sgovinda ipil_p->ipil_ih_head = ih_p;
5622973Sgovinda ipil_p->ipil_ih_tail = ih_p;
5632973Sgovinda ipil_p->ipil_ih_start = ih_p;
5642973Sgovinda ipil_p->ipil_ih_size = 1;
5652973Sgovinda ipil_p->ipil_ino_p = ino_p;
5660Sstevel@tonic-gate
5672973Sgovinda ipil_p->ipil_next_p = ino_p->ino_ipil_p;
5682973Sgovinda ino_p->ino_ipil_p = ipil_p;
5692973Sgovinda ino_p->ino_ipil_size++;
5702973Sgovinda
5712973Sgovinda if (ino_p->ino_lopil > pil)
5722973Sgovinda ino_p->ino_lopil = pil;
5732973Sgovinda
5742973Sgovinda return (ipil_p);
5750Sstevel@tonic-gate }
5760Sstevel@tonic-gate
5770Sstevel@tonic-gate void
ib_delete_ino_pil(ib_t * ib_p,ib_ino_pil_t * ipil_p)5782973Sgovinda ib_delete_ino_pil(ib_t *ib_p, ib_ino_pil_t *ipil_p)
5790Sstevel@tonic-gate {
5802973Sgovinda ib_ino_info_t *ino_p = ipil_p->ipil_ino_p;
5812973Sgovinda ib_ino_pil_t *prev, *next;
5822973Sgovinda ushort_t pil = ipil_p->ipil_pil;
5832973Sgovinda
5840Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ib_p->ib_ino_lst_mutex));
5852973Sgovinda
5862973Sgovinda if (ino_p->ino_ipil_p == ipil_p)
5872973Sgovinda ino_p->ino_ipil_p = ipil_p->ipil_next_p;
5880Sstevel@tonic-gate else {
5892973Sgovinda for (prev = next = ino_p->ino_ipil_p; next != ipil_p;
5905635Srameshc prev = next, next = next->ipil_next_p)
5915635Srameshc ;
5922973Sgovinda
5932973Sgovinda if (prev)
5942973Sgovinda prev->ipil_next_p = ipil_p->ipil_next_p;
5952973Sgovinda }
5962973Sgovinda
5972973Sgovinda kmem_free(ipil_p, sizeof (ib_ino_pil_t));
5982973Sgovinda
5995962Srameshc if ((--ino_p->ino_ipil_size) && (ino_p->ino_lopil == pil)) {
6005962Srameshc for (next = ino_p->ino_ipil_p, pil = next->ipil_pil;
6015962Srameshc next; next = next->ipil_next_p) {
6025962Srameshc
6032973Sgovinda if (pil > next->ipil_pil)
6042973Sgovinda pil = next->ipil_pil;
6052973Sgovinda }
6065962Srameshc /*
6075962Srameshc * Value stored in pil should be the lowest pil.
6085962Srameshc */
6092973Sgovinda ino_p->ino_lopil = pil;
6102973Sgovinda }
6112973Sgovinda
6125962Srameshc if (ino_p->ino_ipil_size)
6132973Sgovinda return;
6142973Sgovinda
6152973Sgovinda if (ib_p->ib_ino_lst == ino_p)
6162973Sgovinda ib_p->ib_ino_lst = ino_p->ino_next_p;
6172973Sgovinda else {
6182973Sgovinda ib_ino_info_t *list = ib_p->ib_ino_lst;
6192973Sgovinda
6205635Srameshc for (; list->ino_next_p != ino_p; list = list->ino_next_p)
6215635Srameshc ;
6222973Sgovinda list->ino_next_p = ino_p->ino_next_p;
6230Sstevel@tonic-gate }
6240Sstevel@tonic-gate }
6250Sstevel@tonic-gate
6260Sstevel@tonic-gate /* free all ino when we are detaching */
6270Sstevel@tonic-gate void
ib_free_ino_all(ib_t * ib_p)6280Sstevel@tonic-gate ib_free_ino_all(ib_t *ib_p)
6290Sstevel@tonic-gate {
6302973Sgovinda ib_ino_info_t *ino_p = ib_p->ib_ino_lst;
6310Sstevel@tonic-gate ib_ino_info_t *next = NULL;
6322973Sgovinda
6332973Sgovinda while (ino_p) {
6342973Sgovinda next = ino_p->ino_next_p;
6352973Sgovinda kmem_free(ino_p, sizeof (ib_ino_info_t));
6362973Sgovinda ino_p = next;
6370Sstevel@tonic-gate }
6380Sstevel@tonic-gate }
6390Sstevel@tonic-gate
6402973Sgovinda /*
6412973Sgovinda * Locate ib_ino_pil_t structure on ino_p->ino_ipil_p according to ino#
6422973Sgovinda * returns NULL if not found.
6432973Sgovinda */
6442973Sgovinda ib_ino_pil_t *
ib_ino_locate_ipil(ib_ino_info_t * ino_p,uint_t pil)6452973Sgovinda ib_ino_locate_ipil(ib_ino_info_t *ino_p, uint_t pil)
6462973Sgovinda {
6472973Sgovinda ib_ino_pil_t *ipil_p = ino_p->ino_ipil_p;
6482973Sgovinda
6495635Srameshc for (; ipil_p && ipil_p->ipil_pil != pil; ipil_p = ipil_p->ipil_next_p)
6505635Srameshc ;
6512973Sgovinda
6522973Sgovinda return (ipil_p);
6532973Sgovinda }
6542973Sgovinda
6550Sstevel@tonic-gate void
ib_ino_add_intr(pci_t * pci_p,ib_ino_pil_t * ipil_p,ih_t * ih_p)6562973Sgovinda ib_ino_add_intr(pci_t *pci_p, ib_ino_pil_t *ipil_p, ih_t *ih_p)
6570Sstevel@tonic-gate {
6582973Sgovinda ib_ino_info_t *ino_p = ipil_p->ipil_ino_p;
6590Sstevel@tonic-gate ib_ino_t ino = ino_p->ino_ino;
6600Sstevel@tonic-gate ib_t *ib_p = ino_p->ino_ib_p;
6610Sstevel@tonic-gate volatile uint64_t *state_reg = IB_INO_INTR_STATE_REG(ib_p, ino);
6620Sstevel@tonic-gate hrtime_t start_time;
6630Sstevel@tonic-gate
6640Sstevel@tonic-gate ASSERT(ib_p == pci_p->pci_ib_p);
6650Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ib_p->ib_ino_lst_mutex));
6660Sstevel@tonic-gate
6670Sstevel@tonic-gate /* disable interrupt, this could disrupt devices sharing our slot */
6680Sstevel@tonic-gate IB_INO_INTR_OFF(ino_p->ino_map_reg);
6690Sstevel@tonic-gate *ino_p->ino_map_reg;
6700Sstevel@tonic-gate
6710Sstevel@tonic-gate /* do NOT modify the link list until after the busy wait */
6720Sstevel@tonic-gate
6730Sstevel@tonic-gate /*
6740Sstevel@tonic-gate * busy wait if there is interrupt being processed.
6750Sstevel@tonic-gate * either the pending state will be cleared by the interrupt wrapper
6760Sstevel@tonic-gate * or the interrupt will be marked as blocked indicating that it was
6770Sstevel@tonic-gate * jabbering.
6780Sstevel@tonic-gate */
6790Sstevel@tonic-gate start_time = gethrtime();
6802973Sgovinda while ((ino_p->ino_unclaimed_intrs <= pci_unclaimed_intr_max) &&
6815635Srameshc IB_INO_INTR_PENDING(state_reg, ino) && !panicstr) {
6820Sstevel@tonic-gate if (gethrtime() - start_time > pci_intrpend_timeout) {
6830Sstevel@tonic-gate pbm_t *pbm_p = pci_p->pci_pbm_p;
6840Sstevel@tonic-gate cmn_err(CE_WARN, "%s:%s: ib_ino_add_intr %x timeout",
6855635Srameshc pbm_p->pbm_nameinst_str,
6865635Srameshc pbm_p->pbm_nameaddr_str, ino);
6870Sstevel@tonic-gate break;
6880Sstevel@tonic-gate }
6890Sstevel@tonic-gate }
6900Sstevel@tonic-gate
6912973Sgovinda /* link up ih_t */
6922973Sgovinda ih_p->ih_next = ipil_p->ipil_ih_head;
6932973Sgovinda ipil_p->ipil_ih_tail->ih_next = ih_p;
6942973Sgovinda ipil_p->ipil_ih_tail = ih_p;
6950Sstevel@tonic-gate
6962973Sgovinda ipil_p->ipil_ih_start = ipil_p->ipil_ih_head;
6972973Sgovinda ipil_p->ipil_ih_size++;
6980Sstevel@tonic-gate
6990Sstevel@tonic-gate /*
7000Sstevel@tonic-gate * if the interrupt was previously blocked (left in pending state)
7010Sstevel@tonic-gate * because of jabber we need to clear the pending state in case the
7020Sstevel@tonic-gate * jabber has gone away.
7030Sstevel@tonic-gate */
7042973Sgovinda if (ino_p->ino_unclaimed_intrs > pci_unclaimed_intr_max) {
7050Sstevel@tonic-gate cmn_err(CE_WARN,
7060Sstevel@tonic-gate "%s%d: ib_ino_add_intr: ino 0x%x has been unblocked",
7070Sstevel@tonic-gate ddi_driver_name(pci_p->pci_dip),
7080Sstevel@tonic-gate ddi_get_instance(pci_p->pci_dip),
7090Sstevel@tonic-gate ino_p->ino_ino);
7102973Sgovinda ino_p->ino_unclaimed_intrs = 0;
7110Sstevel@tonic-gate IB_INO_INTR_CLEAR(ino_p->ino_clr_reg);
7120Sstevel@tonic-gate }
7130Sstevel@tonic-gate
7140Sstevel@tonic-gate /* re-enable interrupt */
7150Sstevel@tonic-gate IB_INO_INTR_ON(ino_p->ino_map_reg);
7160Sstevel@tonic-gate *ino_p->ino_map_reg;
7170Sstevel@tonic-gate }
7180Sstevel@tonic-gate
7190Sstevel@tonic-gate /*
7200Sstevel@tonic-gate * removes pci_ispec_t from the ino's link list.
7210Sstevel@tonic-gate * uses hardware mutex to lock out interrupt threads.
7220Sstevel@tonic-gate * Side effects: interrupt belongs to that ino is turned off on return.
7230Sstevel@tonic-gate * if we are sharing PCI slot with other inos, the caller needs
7240Sstevel@tonic-gate * to turn it back on.
7250Sstevel@tonic-gate */
7260Sstevel@tonic-gate void
ib_ino_rem_intr(pci_t * pci_p,ib_ino_pil_t * ipil_p,ih_t * ih_p)7272973Sgovinda ib_ino_rem_intr(pci_t *pci_p, ib_ino_pil_t *ipil_p, ih_t *ih_p)
7280Sstevel@tonic-gate {
7292973Sgovinda ib_ino_info_t *ino_p = ipil_p->ipil_ino_p;
7300Sstevel@tonic-gate int i;
7310Sstevel@tonic-gate ib_ino_t ino = ino_p->ino_ino;
7322973Sgovinda ih_t *ih_lst = ipil_p->ipil_ih_head;
7330Sstevel@tonic-gate volatile uint64_t *state_reg =
7345635Srameshc IB_INO_INTR_STATE_REG(ino_p->ino_ib_p, ino);
7350Sstevel@tonic-gate hrtime_t start_time;
7360Sstevel@tonic-gate
7370Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ino_p->ino_ib_p->ib_ino_lst_mutex));
7380Sstevel@tonic-gate /* disable interrupt, this could disrupt devices sharing our slot */
7390Sstevel@tonic-gate IB_INO_INTR_OFF(ino_p->ino_map_reg);
7400Sstevel@tonic-gate *ino_p->ino_map_reg;
7410Sstevel@tonic-gate
7420Sstevel@tonic-gate /* do NOT modify the link list until after the busy wait */
7430Sstevel@tonic-gate
7440Sstevel@tonic-gate /*
7450Sstevel@tonic-gate * busy wait if there is interrupt being processed.
7460Sstevel@tonic-gate * either the pending state will be cleared by the interrupt wrapper
7470Sstevel@tonic-gate * or the interrupt will be marked as blocked indicating that it was
7480Sstevel@tonic-gate * jabbering.
7490Sstevel@tonic-gate */
7500Sstevel@tonic-gate start_time = gethrtime();
7512973Sgovinda while ((ino_p->ino_unclaimed_intrs <= pci_unclaimed_intr_max) &&
7525635Srameshc IB_INO_INTR_PENDING(state_reg, ino) && !panicstr) {
7530Sstevel@tonic-gate if (gethrtime() - start_time > pci_intrpend_timeout) {
7540Sstevel@tonic-gate pbm_t *pbm_p = pci_p->pci_pbm_p;
7550Sstevel@tonic-gate cmn_err(CE_WARN, "%s:%s: ib_ino_rem_intr %x timeout",
7565635Srameshc pbm_p->pbm_nameinst_str,
7575635Srameshc pbm_p->pbm_nameaddr_str, ino);
7580Sstevel@tonic-gate break;
7590Sstevel@tonic-gate }
7600Sstevel@tonic-gate }
7610Sstevel@tonic-gate
7622973Sgovinda if (ipil_p->ipil_ih_size == 1) {
7630Sstevel@tonic-gate if (ih_lst != ih_p)
7640Sstevel@tonic-gate goto not_found;
7650Sstevel@tonic-gate /* no need to set head/tail as ino_p will be freed */
7660Sstevel@tonic-gate goto reset;
7670Sstevel@tonic-gate }
7680Sstevel@tonic-gate
7690Sstevel@tonic-gate /*
7700Sstevel@tonic-gate * if the interrupt was previously blocked (left in pending state)
7710Sstevel@tonic-gate * because of jabber we need to clear the pending state in case the
7720Sstevel@tonic-gate * jabber has gone away.
7730Sstevel@tonic-gate */
7742973Sgovinda if (ino_p->ino_unclaimed_intrs > pci_unclaimed_intr_max) {
7750Sstevel@tonic-gate cmn_err(CE_WARN,
7760Sstevel@tonic-gate "%s%d: ib_ino_rem_intr: ino 0x%x has been unblocked",
7770Sstevel@tonic-gate ddi_driver_name(pci_p->pci_dip),
7780Sstevel@tonic-gate ddi_get_instance(pci_p->pci_dip),
7790Sstevel@tonic-gate ino_p->ino_ino);
7802973Sgovinda ino_p->ino_unclaimed_intrs = 0;
7810Sstevel@tonic-gate IB_INO_INTR_CLEAR(ino_p->ino_clr_reg);
7820Sstevel@tonic-gate }
7830Sstevel@tonic-gate
7840Sstevel@tonic-gate /* search the link list for ih_p */
7850Sstevel@tonic-gate for (i = 0;
7865635Srameshc (i < ipil_p->ipil_ih_size) && (ih_lst->ih_next != ih_p);
7875635Srameshc i++, ih_lst = ih_lst->ih_next)
7885635Srameshc ;
7890Sstevel@tonic-gate if (ih_lst->ih_next != ih_p)
7900Sstevel@tonic-gate goto not_found;
7910Sstevel@tonic-gate
7920Sstevel@tonic-gate /* remove ih_p from the link list and maintain the head/tail */
7930Sstevel@tonic-gate ih_lst->ih_next = ih_p->ih_next;
7942973Sgovinda if (ipil_p->ipil_ih_head == ih_p)
7952973Sgovinda ipil_p->ipil_ih_head = ih_p->ih_next;
7962973Sgovinda if (ipil_p->ipil_ih_tail == ih_p)
7972973Sgovinda ipil_p->ipil_ih_tail = ih_lst;
7982973Sgovinda ipil_p->ipil_ih_start = ipil_p->ipil_ih_head;
7990Sstevel@tonic-gate reset:
8000Sstevel@tonic-gate if (ih_p->ih_config_handle)
8010Sstevel@tonic-gate pci_config_teardown(&ih_p->ih_config_handle);
8020Sstevel@tonic-gate if (ih_p->ih_ksp != NULL)
8030Sstevel@tonic-gate kstat_delete(ih_p->ih_ksp);
8040Sstevel@tonic-gate kmem_free(ih_p, sizeof (ih_t));
8052973Sgovinda ipil_p->ipil_ih_size--;
8060Sstevel@tonic-gate
8070Sstevel@tonic-gate return;
8080Sstevel@tonic-gate not_found:
8090Sstevel@tonic-gate DEBUG2(DBG_R_INTX, ino_p->ino_ib_p->ib_pci_p->pci_dip,
8105635Srameshc "ino_p=%x does not have ih_p=%x\n", ino_p, ih_p);
8110Sstevel@tonic-gate }
8120Sstevel@tonic-gate
8130Sstevel@tonic-gate ih_t *
ib_intr_locate_ih(ib_ino_pil_t * ipil_p,dev_info_t * rdip,uint32_t inum)8142973Sgovinda ib_intr_locate_ih(ib_ino_pil_t *ipil_p, dev_info_t *rdip, uint32_t inum)
8150Sstevel@tonic-gate {
8162973Sgovinda ih_t *ih_p = ipil_p->ipil_ih_head;
8170Sstevel@tonic-gate int i;
8182973Sgovinda
8192973Sgovinda for (i = 0; i < ipil_p->ipil_ih_size; i++, ih_p = ih_p->ih_next) {
8202973Sgovinda if (ih_p->ih_dip == rdip && ih_p->ih_inum == inum)
8212973Sgovinda return (ih_p);
8220Sstevel@tonic-gate }
8232973Sgovinda
8240Sstevel@tonic-gate return ((ih_t *)NULL);
8250Sstevel@tonic-gate }
8260Sstevel@tonic-gate
8270Sstevel@tonic-gate ih_t *
ib_alloc_ih(dev_info_t * rdip,uint32_t inum,uint_t (* int_handler)(caddr_t int_handler_arg1,caddr_t int_handler_arg2),caddr_t int_handler_arg1,caddr_t int_handler_arg2)8280Sstevel@tonic-gate ib_alloc_ih(dev_info_t *rdip, uint32_t inum,
829117Sschwartz uint_t (*int_handler)(caddr_t int_handler_arg1,
830117Sschwartz caddr_t int_handler_arg2),
831117Sschwartz caddr_t int_handler_arg1,
832117Sschwartz caddr_t int_handler_arg2)
8330Sstevel@tonic-gate {
8340Sstevel@tonic-gate ih_t *ih_p;
8350Sstevel@tonic-gate
8360Sstevel@tonic-gate ih_p = kmem_alloc(sizeof (ih_t), KM_SLEEP);
8370Sstevel@tonic-gate ih_p->ih_dip = rdip;
8380Sstevel@tonic-gate ih_p->ih_inum = inum;
8390Sstevel@tonic-gate ih_p->ih_intr_state = PCI_INTR_STATE_DISABLE;
8400Sstevel@tonic-gate ih_p->ih_handler = int_handler;
8410Sstevel@tonic-gate ih_p->ih_handler_arg1 = int_handler_arg1;
8420Sstevel@tonic-gate ih_p->ih_handler_arg2 = int_handler_arg2;
8430Sstevel@tonic-gate ih_p->ih_config_handle = NULL;
8440Sstevel@tonic-gate ih_p->ih_nsec = 0;
8450Sstevel@tonic-gate ih_p->ih_ticks = 0;
84666Sesolom ih_p->ih_ksp = NULL;
8470Sstevel@tonic-gate
8480Sstevel@tonic-gate return (ih_p);
8490Sstevel@tonic-gate }
8500Sstevel@tonic-gate
8510Sstevel@tonic-gate int
ib_update_intr_state(pci_t * pci_p,dev_info_t * rdip,ddi_intr_handle_impl_t * hdlp,uint_t new_intr_state)8520Sstevel@tonic-gate ib_update_intr_state(pci_t *pci_p, dev_info_t *rdip,
853117Sschwartz ddi_intr_handle_impl_t *hdlp, uint_t new_intr_state)
8540Sstevel@tonic-gate {
8550Sstevel@tonic-gate ib_t *ib_p = pci_p->pci_ib_p;
8560Sstevel@tonic-gate ib_ino_info_t *ino_p;
8572973Sgovinda ib_ino_pil_t *ipil_p;
8580Sstevel@tonic-gate ib_mondo_t mondo;
8590Sstevel@tonic-gate ih_t *ih_p;
8600Sstevel@tonic-gate int ret = DDI_FAILURE;
8610Sstevel@tonic-gate
8621252Sgovinda /*
8631252Sgovinda * For PULSE interrupts, pci driver don't allocate
8641252Sgovinda * ib_ino_info_t and ih_t data structures and also,
8651252Sgovinda * not maintains any interrupt state information.
8661252Sgovinda * So, just return success from here.
8671252Sgovinda */
8681252Sgovinda if (hdlp->ih_vector & PCI_PULSE_INO) {
8691252Sgovinda DEBUG0(DBG_IB, ib_p->ib_pci_p->pci_dip,
8701252Sgovinda "ib_update_intr_state: PULSE interrupt, return success\n");
8711252Sgovinda
8721252Sgovinda return (DDI_SUCCESS);
8731252Sgovinda }
8741252Sgovinda
8750Sstevel@tonic-gate mutex_enter(&ib_p->ib_ino_lst_mutex);
8760Sstevel@tonic-gate
8770Sstevel@tonic-gate if ((mondo = pci_xlate_intr(pci_p->pci_dip, rdip, pci_p->pci_ib_p,
878693Sgovinda IB_MONDO_TO_INO(hdlp->ih_vector))) == 0) {
8790Sstevel@tonic-gate mutex_exit(&ib_p->ib_ino_lst_mutex);
8800Sstevel@tonic-gate return (ret);
8810Sstevel@tonic-gate }
8820Sstevel@tonic-gate
8832973Sgovinda ino_p = ib_locate_ino(ib_p, IB_MONDO_TO_INO(mondo));
8842973Sgovinda if (ino_p && (ipil_p = ib_ino_locate_ipil(ino_p, hdlp->ih_pri))) {
8852973Sgovinda if (ih_p = ib_intr_locate_ih(ipil_p, rdip, hdlp->ih_inum)) {
8860Sstevel@tonic-gate ih_p->ih_intr_state = new_intr_state;
8870Sstevel@tonic-gate ret = DDI_SUCCESS;
8880Sstevel@tonic-gate }
8890Sstevel@tonic-gate }
8900Sstevel@tonic-gate
8910Sstevel@tonic-gate mutex_exit(&ib_p->ib_ino_lst_mutex);
8920Sstevel@tonic-gate return (ret);
8930Sstevel@tonic-gate }
894117Sschwartz
895117Sschwartz /*
896*10053SEvan.Yan@Sun.COM * Get interrupt CPU for a given ino.
897*10053SEvan.Yan@Sun.COM * Return info only for inos which are already mapped to devices.
898*10053SEvan.Yan@Sun.COM */
899*10053SEvan.Yan@Sun.COM /*ARGSUSED*/
900*10053SEvan.Yan@Sun.COM int
ib_get_intr_target(pci_t * pci_p,ib_ino_t ino,int * cpu_id_p)901*10053SEvan.Yan@Sun.COM ib_get_intr_target(pci_t *pci_p, ib_ino_t ino, int *cpu_id_p)
902*10053SEvan.Yan@Sun.COM {
903*10053SEvan.Yan@Sun.COM dev_info_t *dip = pci_p->pci_dip;
904*10053SEvan.Yan@Sun.COM ib_t *ib_p = pci_p->pci_ib_p;
905*10053SEvan.Yan@Sun.COM volatile uint64_t *imregp;
906*10053SEvan.Yan@Sun.COM uint64_t imregval;
907*10053SEvan.Yan@Sun.COM
908*10053SEvan.Yan@Sun.COM DEBUG1(DBG_IB, dip, "ib_get_intr_target: ino %x\n", ino);
909*10053SEvan.Yan@Sun.COM
910*10053SEvan.Yan@Sun.COM imregp = ib_intr_map_reg_addr(ib_p, ino);
911*10053SEvan.Yan@Sun.COM imregval = *imregp;
912*10053SEvan.Yan@Sun.COM
913*10053SEvan.Yan@Sun.COM *cpu_id_p = ib_map_reg_get_cpu(imregval);
914*10053SEvan.Yan@Sun.COM
915*10053SEvan.Yan@Sun.COM DEBUG1(DBG_IB, dip, "ib_get_intr_target: cpu_id %x\n", *cpu_id_p);
916*10053SEvan.Yan@Sun.COM
917*10053SEvan.Yan@Sun.COM return (DDI_SUCCESS);
918*10053SEvan.Yan@Sun.COM }
919*10053SEvan.Yan@Sun.COM
920*10053SEvan.Yan@Sun.COM /*
921*10053SEvan.Yan@Sun.COM * Associate a new CPU with a given ino.
922*10053SEvan.Yan@Sun.COM * Operate only on inos which are already mapped to devices.
923*10053SEvan.Yan@Sun.COM */
924*10053SEvan.Yan@Sun.COM int
ib_set_intr_target(pci_t * pci_p,ib_ino_t ino,int cpu_id)925*10053SEvan.Yan@Sun.COM ib_set_intr_target(pci_t *pci_p, ib_ino_t ino, int cpu_id)
926*10053SEvan.Yan@Sun.COM {
927*10053SEvan.Yan@Sun.COM dev_info_t *dip = pci_p->pci_dip;
928*10053SEvan.Yan@Sun.COM ib_t *ib_p = pci_p->pci_ib_p;
929*10053SEvan.Yan@Sun.COM int ret = DDI_SUCCESS;
930*10053SEvan.Yan@Sun.COM uint32_t old_cpu_id;
931*10053SEvan.Yan@Sun.COM hrtime_t start_time;
932*10053SEvan.Yan@Sun.COM uint64_t imregval;
933*10053SEvan.Yan@Sun.COM uint64_t new_imregval;
934*10053SEvan.Yan@Sun.COM volatile uint64_t *imregp;
935*10053SEvan.Yan@Sun.COM volatile uint64_t *idregp;
936*10053SEvan.Yan@Sun.COM extern const int _ncpu;
937*10053SEvan.Yan@Sun.COM extern cpu_t *cpu[];
938*10053SEvan.Yan@Sun.COM
939*10053SEvan.Yan@Sun.COM DEBUG2(DBG_IB, dip, "ib_set_intr_target: ino %x cpu_id %x\n",
940*10053SEvan.Yan@Sun.COM ino, cpu_id);
941*10053SEvan.Yan@Sun.COM
942*10053SEvan.Yan@Sun.COM imregp = (uint64_t *)ib_intr_map_reg_addr(ib_p, ino);
943*10053SEvan.Yan@Sun.COM idregp = IB_INO_INTR_STATE_REG(ib_p, ino);
944*10053SEvan.Yan@Sun.COM
945*10053SEvan.Yan@Sun.COM /* Save original mapreg value. */
946*10053SEvan.Yan@Sun.COM imregval = *imregp;
947*10053SEvan.Yan@Sun.COM DEBUG1(DBG_IB, dip, "ib_set_intr_target: orig mapreg value: 0x%llx\n",
948*10053SEvan.Yan@Sun.COM imregval);
949*10053SEvan.Yan@Sun.COM
950*10053SEvan.Yan@Sun.COM /* Operate only on inos which are already enabled. */
951*10053SEvan.Yan@Sun.COM if (!(imregval & COMMON_INTR_MAP_REG_VALID))
952*10053SEvan.Yan@Sun.COM return (DDI_FAILURE);
953*10053SEvan.Yan@Sun.COM
954*10053SEvan.Yan@Sun.COM /* Is this request a noop? */
955*10053SEvan.Yan@Sun.COM if ((old_cpu_id = ib_map_reg_get_cpu(imregval)) == cpu_id)
956*10053SEvan.Yan@Sun.COM return (DDI_SUCCESS);
957*10053SEvan.Yan@Sun.COM
958*10053SEvan.Yan@Sun.COM /* Clear the interrupt valid/enable bit for particular ino. */
959*10053SEvan.Yan@Sun.COM DEBUG0(DBG_IB, dip, "Clearing intr_enabled...\n");
960*10053SEvan.Yan@Sun.COM *imregp = imregval & ~COMMON_INTR_MAP_REG_VALID;
961*10053SEvan.Yan@Sun.COM
962*10053SEvan.Yan@Sun.COM /* Wait until there are no more pending interrupts. */
963*10053SEvan.Yan@Sun.COM start_time = gethrtime();
964*10053SEvan.Yan@Sun.COM
965*10053SEvan.Yan@Sun.COM DEBUG0(DBG_IB, dip, "About to check for pending interrupts...\n");
966*10053SEvan.Yan@Sun.COM
967*10053SEvan.Yan@Sun.COM while (IB_INO_INTR_PENDING(idregp, ino)) {
968*10053SEvan.Yan@Sun.COM DEBUG0(DBG_IB, dip, "Waiting for pending ints to clear\n");
969*10053SEvan.Yan@Sun.COM if ((gethrtime() - start_time) < pci_intrpend_timeout) {
970*10053SEvan.Yan@Sun.COM continue;
971*10053SEvan.Yan@Sun.COM } else { /* Timed out waiting. */
972*10053SEvan.Yan@Sun.COM DEBUG0(DBG_IB, dip, "Timed out waiting \n");
973*10053SEvan.Yan@Sun.COM return (DDI_EPENDING);
974*10053SEvan.Yan@Sun.COM }
975*10053SEvan.Yan@Sun.COM }
976*10053SEvan.Yan@Sun.COM
977*10053SEvan.Yan@Sun.COM new_imregval = *imregp;
978*10053SEvan.Yan@Sun.COM
979*10053SEvan.Yan@Sun.COM DEBUG1(DBG_IB, dip,
980*10053SEvan.Yan@Sun.COM "after disabling intr, mapreg value: 0x%llx\n", new_imregval);
981*10053SEvan.Yan@Sun.COM
982*10053SEvan.Yan@Sun.COM /*
983*10053SEvan.Yan@Sun.COM * Get lock, validate cpu and write new mapreg value.
984*10053SEvan.Yan@Sun.COM */
985*10053SEvan.Yan@Sun.COM mutex_enter(&cpu_lock);
986*10053SEvan.Yan@Sun.COM if ((cpu_id < _ncpu) && (cpu[cpu_id] && cpu_is_online(cpu[cpu_id]))) {
987*10053SEvan.Yan@Sun.COM /* Prepare new mapreg value with intr enabled and new cpu_id. */
988*10053SEvan.Yan@Sun.COM new_imregval &=
989*10053SEvan.Yan@Sun.COM COMMON_INTR_MAP_REG_IGN | COMMON_INTR_MAP_REG_INO;
990*10053SEvan.Yan@Sun.COM new_imregval = ib_get_map_reg(new_imregval, cpu_id);
991*10053SEvan.Yan@Sun.COM
992*10053SEvan.Yan@Sun.COM DEBUG1(DBG_IB, dip, "Writing new mapreg value:0x%llx\n",
993*10053SEvan.Yan@Sun.COM new_imregval);
994*10053SEvan.Yan@Sun.COM
995*10053SEvan.Yan@Sun.COM *imregp = new_imregval;
996*10053SEvan.Yan@Sun.COM
997*10053SEvan.Yan@Sun.COM ib_log_new_cpu(ib_p, old_cpu_id, cpu_id, ino);
998*10053SEvan.Yan@Sun.COM } else { /* Invalid cpu. Restore original register image. */
999*10053SEvan.Yan@Sun.COM DEBUG0(DBG_IB, dip,
1000*10053SEvan.Yan@Sun.COM "Invalid cpuid: writing orig mapreg value\n");
1001*10053SEvan.Yan@Sun.COM
1002*10053SEvan.Yan@Sun.COM *imregp = imregval;
1003*10053SEvan.Yan@Sun.COM ret = DDI_EINVAL;
1004*10053SEvan.Yan@Sun.COM }
1005*10053SEvan.Yan@Sun.COM mutex_exit(&cpu_lock);
1006*10053SEvan.Yan@Sun.COM
1007*10053SEvan.Yan@Sun.COM return (ret);
1008*10053SEvan.Yan@Sun.COM }
1009*10053SEvan.Yan@Sun.COM
1010*10053SEvan.Yan@Sun.COM
1011*10053SEvan.Yan@Sun.COM /*
1012117Sschwartz * Return the dips or number of dips associated with a given interrupt block.
1013117Sschwartz * Size of dips array arg is passed in as dips_ret arg.
1014117Sschwartz * Number of dips returned is returned in dips_ret arg.
1015117Sschwartz * Array of dips gets returned in the dips argument.
1016117Sschwartz * Function returns number of dips existing for the given interrupt block.
1017117Sschwartz *
1018117Sschwartz */
1019117Sschwartz uint8_t
ib_get_ino_devs(ib_t * ib_p,uint32_t ino,uint8_t * devs_ret,pcitool_intr_dev_t * devs)1020117Sschwartz ib_get_ino_devs(
1021117Sschwartz ib_t *ib_p, uint32_t ino, uint8_t *devs_ret, pcitool_intr_dev_t *devs)
1022117Sschwartz {
10232973Sgovinda ib_ino_info_t *ino_p;
10242973Sgovinda ib_ino_pil_t *ipil_p;
10252973Sgovinda ih_t *ih_p;
10262973Sgovinda uint32_t num_devs = 0;
10272973Sgovinda int i, j;
1028117Sschwartz
1029117Sschwartz mutex_enter(&ib_p->ib_ino_lst_mutex);
1030117Sschwartz ino_p = ib_locate_ino(ib_p, ino);
1031117Sschwartz if (ino_p != NULL) {
10322973Sgovinda for (j = 0, ipil_p = ino_p->ino_ipil_p; ipil_p;
10332973Sgovinda ipil_p = ipil_p->ipil_next_p) {
10342973Sgovinda num_devs += ipil_p->ipil_ih_size;
10352973Sgovinda
10362973Sgovinda for (i = 0, ih_p = ipil_p->ipil_ih_head;
10372973Sgovinda ((i < ipil_p->ipil_ih_size) && (i < *devs_ret));
10382973Sgovinda i++, j++, ih_p = ih_p->ih_next) {
10392973Sgovinda (void) strncpy(devs[i].driver_name,
10402973Sgovinda ddi_driver_name(ih_p->ih_dip),
10412973Sgovinda MAXMODCONFNAME-1);
10422973Sgovinda devs[i].driver_name[MAXMODCONFNAME] = '\0';
10432973Sgovinda (void) ddi_pathname(ih_p->ih_dip, devs[i].path);
10442973Sgovinda devs[i].dev_inst =
10452973Sgovinda ddi_get_instance(ih_p->ih_dip);
10462973Sgovinda }
1047117Sschwartz }
10482973Sgovinda *devs_ret = j;
1049117Sschwartz }
1050117Sschwartz
1051117Sschwartz mutex_exit(&ib_p->ib_ino_lst_mutex);
1052117Sschwartz
1053117Sschwartz return (num_devs);
1054117Sschwartz }
1055117Sschwartz
ib_log_new_cpu(ib_t * ib_p,uint32_t old_cpu_id,uint32_t new_cpu_id,uint32_t ino)1056117Sschwartz void ib_log_new_cpu(ib_t *ib_p, uint32_t old_cpu_id, uint32_t new_cpu_id,
1057117Sschwartz uint32_t ino)
1058117Sschwartz {
10592973Sgovinda ib_ino_info_t *ino_p;
10602973Sgovinda ib_ino_pil_t *ipil_p;
10612973Sgovinda ih_t *ih_p;
10622973Sgovinda int i;
1063117Sschwartz
1064117Sschwartz mutex_enter(&ib_p->ib_ino_lst_mutex);
1065117Sschwartz
1066117Sschwartz /* Log in OS data structures the new CPU. */
1067117Sschwartz ino_p = ib_locate_ino(ib_p, ino);
1068117Sschwartz if (ino_p != NULL) {
1069117Sschwartz
1070117Sschwartz /* Log in OS data structures the new CPU. */
1071117Sschwartz ino_p->ino_cpuid = new_cpu_id;
1072117Sschwartz
10732973Sgovinda for (ipil_p = ino_p->ino_ipil_p; ipil_p;
10742973Sgovinda ipil_p = ipil_p->ipil_next_p) {
10752973Sgovinda for (i = 0, ih_p = ipil_p->ipil_ih_head;
10762973Sgovinda (i < ipil_p->ipil_ih_size);
10772973Sgovinda i++, ih_p = ih_p->ih_next) {
10782973Sgovinda /*
10792973Sgovinda * Account for any residual time
10802973Sgovinda * to be logged for old cpu.
10812973Sgovinda */
10822973Sgovinda ib_cpu_ticks_to_ih_nsec(ib_p,
10832973Sgovinda ipil_p->ipil_ih_head, old_cpu_id);
10842973Sgovinda }
10852973Sgovinda }
1086117Sschwartz }
1087117Sschwartz
1088117Sschwartz mutex_exit(&ib_p->ib_ino_lst_mutex);
1089117Sschwartz }
1090