xref: /onnv-gate/usr/src/uts/sun4/io/px/px_pec.c (revision 10923:df470fd79c3c)
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
51725Segillett  * Common Development and Distribution License (the "License").
61725Segillett  * 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 /*
2210053SEvan.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 Express PEC implementation:
280Sstevel@tonic-gate  *	initialization
290Sstevel@tonic-gate  *	Bus error interrupt handler
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/spl.h>
350Sstevel@tonic-gate #include <sys/sysmacros.h>
360Sstevel@tonic-gate #include <sys/sunddi.h>
370Sstevel@tonic-gate #include <sys/machsystm.h>	/* ldphysio() */
380Sstevel@tonic-gate #include <sys/async.h>
390Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
400Sstevel@tonic-gate #include <sys/ontrap.h>
410Sstevel@tonic-gate #include <sys/membar.h>
420Sstevel@tonic-gate #include "px_obj.h"
430Sstevel@tonic-gate 
440Sstevel@tonic-gate /*LINTLIBRARY*/
450Sstevel@tonic-gate 
460Sstevel@tonic-gate extern uint_t px_ranges_phi_mask;
470Sstevel@tonic-gate 
4827Sjchu static uint_t px_pec_error_intr(caddr_t a);
490Sstevel@tonic-gate static int    px_pec_msg_add_intr(px_t *px_p);
500Sstevel@tonic-gate static void   px_pec_msg_rem_intr(px_t *px_p);
510Sstevel@tonic-gate 
520Sstevel@tonic-gate int
530Sstevel@tonic-gate px_pec_attach(px_t *px_p)
540Sstevel@tonic-gate {
550Sstevel@tonic-gate 	px_pec_t *pec_p;
560Sstevel@tonic-gate 	int i, len;
57*10923SEvan.Yan@Sun.COM 	int nrange = px_p->px_ranges_length / sizeof (pci_ranges_t);
580Sstevel@tonic-gate 	dev_info_t *dip = px_p->px_dip;
59*10923SEvan.Yan@Sun.COM 	pci_ranges_t *rangep = px_p->px_ranges_p;
600Sstevel@tonic-gate 	int ret;
610Sstevel@tonic-gate 
620Sstevel@tonic-gate 	/*
630Sstevel@tonic-gate 	 * Allocate a state structure for the PEC and cross-link it
640Sstevel@tonic-gate 	 * to its per px node state structure.
650Sstevel@tonic-gate 	 */
660Sstevel@tonic-gate 	pec_p = kmem_zalloc(sizeof (px_pec_t), KM_SLEEP);
670Sstevel@tonic-gate 	px_p->px_pec_p = pec_p;
680Sstevel@tonic-gate 	pec_p->pec_px_p = px_p;
690Sstevel@tonic-gate 
700Sstevel@tonic-gate 	len = snprintf(pec_p->pec_nameinst_str,
715132Srameshc 	    sizeof (pec_p->pec_nameinst_str),
725132Srameshc 	    "%s%d", NAMEINST(dip));
730Sstevel@tonic-gate 	pec_p->pec_nameaddr_str = pec_p->pec_nameinst_str + ++len;
740Sstevel@tonic-gate 	(void) snprintf(pec_p->pec_nameaddr_str,
755132Srameshc 	    sizeof (pec_p->pec_nameinst_str) - len,
765132Srameshc 	    "%s@%s", NAMEADDR(dip));
770Sstevel@tonic-gate 
780Sstevel@tonic-gate 	/*
790Sstevel@tonic-gate 	 * Add interrupt handlers to process correctable/fatal/non fatal
800Sstevel@tonic-gate 	 * PCIE messages.
810Sstevel@tonic-gate 	 */
820Sstevel@tonic-gate 	if ((ret = px_pec_msg_add_intr(px_p)) != DDI_SUCCESS) {
830Sstevel@tonic-gate 		px_pec_msg_rem_intr(px_p);
840Sstevel@tonic-gate 		return (ret);
850Sstevel@tonic-gate 	}
860Sstevel@tonic-gate 
870Sstevel@tonic-gate 	/*
880Sstevel@tonic-gate 	 * Get this pec's mem32 and mem64 segments to determine whether
890Sstevel@tonic-gate 	 * a dma object originates from ths pec. i.e. dev to dev dma
900Sstevel@tonic-gate 	 */
910Sstevel@tonic-gate 	for (i = 0; i < nrange; i++, rangep++) {
920Sstevel@tonic-gate 		uint64_t rng_addr, rng_size, *pfnbp, *pfnlp;
930Sstevel@tonic-gate 		uint32_t rng_type = rangep->child_high & PCI_ADDR_MASK;
940Sstevel@tonic-gate 
950Sstevel@tonic-gate 		switch (rng_type) {
960Sstevel@tonic-gate 			case PCI_ADDR_MEM32:
970Sstevel@tonic-gate 				pfnbp = &pec_p->pec_base32_pfn;
980Sstevel@tonic-gate 				pfnlp = &pec_p->pec_last32_pfn;
990Sstevel@tonic-gate 				break;
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate 			case PCI_ADDR_MEM64:
1020Sstevel@tonic-gate 				pfnbp = &pec_p->pec_base64_pfn;
1030Sstevel@tonic-gate 				pfnlp = &pec_p->pec_last64_pfn;
1040Sstevel@tonic-gate 				break;
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate 			case PCI_ADDR_CONFIG:
1070Sstevel@tonic-gate 			case PCI_ADDR_IO:
1080Sstevel@tonic-gate 			default:
1090Sstevel@tonic-gate 				continue;
1100Sstevel@tonic-gate 		}
1110Sstevel@tonic-gate 		rng_addr = (uint64_t)(rangep->parent_high &
1125132Srameshc 		    px_ranges_phi_mask) << 32;
1130Sstevel@tonic-gate 		rng_addr |= (uint64_t)rangep->parent_low;
1140Sstevel@tonic-gate 		rng_size = (uint64_t)rangep->size_high << 32;
1150Sstevel@tonic-gate 		rng_size |= (uint64_t)rangep->size_low;
1160Sstevel@tonic-gate 
1170Sstevel@tonic-gate 		*pfnbp = mmu_btop(rng_addr);
1180Sstevel@tonic-gate 		*pfnlp = mmu_btop(rng_addr + rng_size);
1190Sstevel@tonic-gate 	}
1200Sstevel@tonic-gate 
1215132Srameshc 	/*
1225132Srameshc 	 * This lock is for serializing safe acc calls. It is not associated
1235132Srameshc 	 * with an iblock cookie.
1245132Srameshc 	 */
1255132Srameshc 	mutex_init(&pec_p->pec_pokefault_mutex, NULL, MUTEX_DRIVER, NULL);
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate 	return (DDI_SUCCESS);
1280Sstevel@tonic-gate }
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate void
1310Sstevel@tonic-gate px_pec_detach(px_t *px_p)
1320Sstevel@tonic-gate {
1330Sstevel@tonic-gate 	dev_info_t *dip = px_p->px_dip;
1340Sstevel@tonic-gate 	px_pec_t *pec_p = px_p->px_pec_p;
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate 	/*
1370Sstevel@tonic-gate 	 * Free the pokefault mutex.
1380Sstevel@tonic-gate 	 */
1390Sstevel@tonic-gate 	DBG(DBG_DETACH, dip, "px_pec_detach:\n");
1400Sstevel@tonic-gate 	mutex_destroy(&pec_p->pec_pokefault_mutex);
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate 	/*
1430Sstevel@tonic-gate 	 * Remove interrupt handlers to process correctable/fatal/non fatal
1440Sstevel@tonic-gate 	 * PCIE messages.
1450Sstevel@tonic-gate 	 */
1460Sstevel@tonic-gate 	px_pec_msg_rem_intr(px_p);
1470Sstevel@tonic-gate 
1480Sstevel@tonic-gate 	/*
1490Sstevel@tonic-gate 	 * Free the pec state structure.
1500Sstevel@tonic-gate 	 */
1510Sstevel@tonic-gate 	kmem_free(pec_p, sizeof (px_pec_t));
1520Sstevel@tonic-gate 	px_p->px_pec_p = NULL;
1530Sstevel@tonic-gate }
1540Sstevel@tonic-gate 
1550Sstevel@tonic-gate /*
1560Sstevel@tonic-gate  * pec_msg_add_intr:
1570Sstevel@tonic-gate  *
1580Sstevel@tonic-gate  * Add interrupt handlers to process correctable/fatal/non fatal
1590Sstevel@tonic-gate  * PCIE messages.
1600Sstevel@tonic-gate  */
1610Sstevel@tonic-gate static int
1620Sstevel@tonic-gate px_pec_msg_add_intr(px_t *px_p)
1630Sstevel@tonic-gate {
1640Sstevel@tonic-gate 	dev_info_t		*dip = px_p->px_dip;
1650Sstevel@tonic-gate 	px_pec_t		*pec_p = px_p->px_pec_p;
1660Sstevel@tonic-gate 	ddi_intr_handle_impl_t	hdl;
1670Sstevel@tonic-gate 	int			ret = DDI_SUCCESS;
1680Sstevel@tonic-gate 
1690Sstevel@tonic-gate 	DBG(DBG_MSG, px_p->px_dip, "px_pec_msg_add_intr\n");
1700Sstevel@tonic-gate 
1711725Segillett 	/* Initialize handle */
1721725Segillett 	bzero(&hdl, sizeof (ddi_intr_handle_impl_t));
17327Sjchu 	hdl.ih_cb_func = (ddi_intr_handler_t *)px_err_fabric_intr;
1740Sstevel@tonic-gate 	hdl.ih_ver = DDI_INTR_VERSION;
1750Sstevel@tonic-gate 	hdl.ih_state = DDI_IHDL_STATE_ALLOC;
1760Sstevel@tonic-gate 	hdl.ih_dip = dip;
1770Sstevel@tonic-gate 
1780Sstevel@tonic-gate 	/* Add correctable error message handler */
17927Sjchu 	hdl.ih_pri = PX_ERR_LOW_PIL;
1800Sstevel@tonic-gate 
1810Sstevel@tonic-gate 	if ((ret = px_add_msiq_intr(dip, dip, &hdl,
18210053SEvan.Yan@Sun.COM 	    MSG_REC, (msgcode_t)PCIE_CORR_MSG, -1,
1830Sstevel@tonic-gate 	    &pec_p->pec_corr_msg_msiq_id)) != DDI_SUCCESS) {
1840Sstevel@tonic-gate 		DBG(DBG_MSG, px_p->px_dip,
1850Sstevel@tonic-gate 		    "PCIE_CORR_MSG registration failed\n");
1860Sstevel@tonic-gate 		return (DDI_FAILURE);
1870Sstevel@tonic-gate 	}
1880Sstevel@tonic-gate 
1890Sstevel@tonic-gate 	px_lib_msg_setmsiq(dip, PCIE_CORR_MSG, pec_p->pec_corr_msg_msiq_id);
1900Sstevel@tonic-gate 	px_lib_msg_setvalid(dip, PCIE_CORR_MSG, PCIE_MSG_VALID);
1910Sstevel@tonic-gate 
1922973Sgovinda 	if ((ret = px_ib_update_intr_state(px_p, px_p->px_dip, hdl.ih_inum,
1932973Sgovinda 	    px_msiqid_to_devino(px_p, pec_p->pec_corr_msg_msiq_id),
1942973Sgovinda 	    PX_ERR_LOW_PIL, PX_INTR_STATE_ENABLE, MSG_REC,
1952973Sgovinda 	    PCIE_CORR_MSG)) != DDI_SUCCESS) {
196909Segillett 		DBG(DBG_MSG, px_p->px_dip,
197909Segillett 		    "PCIE_CORR_MSG update interrupt state failed\n");
198909Segillett 		return (DDI_FAILURE);
199909Segillett 	}
200909Segillett 
2010Sstevel@tonic-gate 	/* Add non-fatal error message handler */
20227Sjchu 	hdl.ih_pri = PX_ERR_PIL;
2030Sstevel@tonic-gate 
2040Sstevel@tonic-gate 	if ((ret = px_add_msiq_intr(dip, dip, &hdl,
20510053SEvan.Yan@Sun.COM 	    MSG_REC, (msgcode_t)PCIE_NONFATAL_MSG, -1,
2060Sstevel@tonic-gate 	    &pec_p->pec_non_fatal_msg_msiq_id)) != DDI_SUCCESS) {
2070Sstevel@tonic-gate 		DBG(DBG_MSG, px_p->px_dip,
2080Sstevel@tonic-gate 		    "PCIE_NONFATAL_MSG registration failed\n");
2090Sstevel@tonic-gate 		return (DDI_FAILURE);
2100Sstevel@tonic-gate 	}
2110Sstevel@tonic-gate 
2120Sstevel@tonic-gate 	px_lib_msg_setmsiq(dip, PCIE_NONFATAL_MSG,
2130Sstevel@tonic-gate 	    pec_p->pec_non_fatal_msg_msiq_id);
2140Sstevel@tonic-gate 	px_lib_msg_setvalid(dip, PCIE_NONFATAL_MSG, PCIE_MSG_VALID);
2150Sstevel@tonic-gate 
2162973Sgovinda 	if ((ret = px_ib_update_intr_state(px_p, px_p->px_dip, hdl.ih_inum,
2172973Sgovinda 	    px_msiqid_to_devino(px_p, pec_p->pec_non_fatal_msg_msiq_id),
2182973Sgovinda 	    PX_ERR_PIL, PX_INTR_STATE_ENABLE, MSG_REC,
219909Segillett 	    PCIE_NONFATAL_MSG)) != DDI_SUCCESS) {
220909Segillett 		DBG(DBG_MSG, px_p->px_dip,
221909Segillett 		    "PCIE_NONFATAL_MSG update interrupt state failed\n");
222909Segillett 		return (DDI_FAILURE);
223909Segillett 	}
224909Segillett 
2250Sstevel@tonic-gate 	/* Add fatal error message handler */
22627Sjchu 	hdl.ih_pri = PX_ERR_PIL;
2270Sstevel@tonic-gate 
2280Sstevel@tonic-gate 	if ((ret = px_add_msiq_intr(dip, dip, &hdl,
22910053SEvan.Yan@Sun.COM 	    MSG_REC, (msgcode_t)PCIE_FATAL_MSG, -1,
2300Sstevel@tonic-gate 	    &pec_p->pec_fatal_msg_msiq_id)) != DDI_SUCCESS) {
2310Sstevel@tonic-gate 		DBG(DBG_MSG, px_p->px_dip,
2320Sstevel@tonic-gate 		    "PCIE_FATAL_MSG registration failed\n");
2330Sstevel@tonic-gate 		return (DDI_FAILURE);
2340Sstevel@tonic-gate 	}
2350Sstevel@tonic-gate 
2360Sstevel@tonic-gate 	px_lib_msg_setmsiq(dip, PCIE_FATAL_MSG, pec_p->pec_fatal_msg_msiq_id);
2370Sstevel@tonic-gate 	px_lib_msg_setvalid(dip, PCIE_FATAL_MSG, PCIE_MSG_VALID);
2380Sstevel@tonic-gate 
2392973Sgovinda 	if ((ret = px_ib_update_intr_state(px_p, px_p->px_dip, hdl.ih_inum,
2402973Sgovinda 	    px_msiqid_to_devino(px_p, pec_p->pec_fatal_msg_msiq_id), PX_ERR_PIL,
2412973Sgovinda 	    PX_INTR_STATE_ENABLE, MSG_REC, PCIE_FATAL_MSG)) != DDI_SUCCESS) {
242909Segillett 		DBG(DBG_MSG, px_p->px_dip,
243909Segillett 		    "PCIE_FATAL_MSG update interrupt state failed\n");
244909Segillett 		return (DDI_FAILURE);
245909Segillett 	}
246909Segillett 
2470Sstevel@tonic-gate 	return (ret);
2480Sstevel@tonic-gate }
2490Sstevel@tonic-gate 
2500Sstevel@tonic-gate /*
2510Sstevel@tonic-gate  * px_pec_msg_rem_intr:
2520Sstevel@tonic-gate  *
2530Sstevel@tonic-gate  * Remove interrupt handlers to process correctable/fatal/non fatal
2540Sstevel@tonic-gate  * PCIE messages. For now, all these PCIe messages are mapped to
2550Sstevel@tonic-gate  * same MSIQ.
2560Sstevel@tonic-gate  */
2570Sstevel@tonic-gate static void
2580Sstevel@tonic-gate px_pec_msg_rem_intr(px_t *px_p)
2590Sstevel@tonic-gate {
2600Sstevel@tonic-gate 	dev_info_t		*dip = px_p->px_dip;
2610Sstevel@tonic-gate 	px_pec_t		*pec_p = px_p->px_pec_p;
2620Sstevel@tonic-gate 	ddi_intr_handle_impl_t	hdl;
2630Sstevel@tonic-gate 
2640Sstevel@tonic-gate 	DBG(DBG_MSG, px_p->px_dip, "px_pec_msg_rem_intr: dip 0x%p\n", dip);
2650Sstevel@tonic-gate 
2661725Segillett 	/* Initialize handle */
2671725Segillett 	bzero(&hdl, sizeof (ddi_intr_handle_impl_t));
2680Sstevel@tonic-gate 	hdl.ih_ver = DDI_INTR_VERSION;
2690Sstevel@tonic-gate 	hdl.ih_state = DDI_IHDL_STATE_ALLOC;
2700Sstevel@tonic-gate 	hdl.ih_dip = dip;
2710Sstevel@tonic-gate 
2723162Sgovinda 	/* Remove correctable error message handler */
2730Sstevel@tonic-gate 	if (pec_p->pec_corr_msg_msiq_id >= 0) {
2740Sstevel@tonic-gate 		px_lib_msg_setvalid(dip, PCIE_CORR_MSG, PCIE_MSG_INVALID);
2750Sstevel@tonic-gate 
2763162Sgovinda 		hdl.ih_pri = PX_ERR_LOW_PIL;
2770Sstevel@tonic-gate 		(void) px_rem_msiq_intr(dip, dip, &hdl, MSG_REC,
2780Sstevel@tonic-gate 		    PCIE_CORR_MSG, pec_p->pec_corr_msg_msiq_id);
279909Segillett 
2802973Sgovinda 		(void) px_ib_update_intr_state(px_p, px_p->px_dip, hdl.ih_inum,
2812973Sgovinda 		    px_msiqid_to_devino(px_p, pec_p->pec_corr_msg_msiq_id),
2822973Sgovinda 		    PX_ERR_LOW_PIL, PX_INTR_STATE_DISABLE, MSG_REC,
2832973Sgovinda 		    PCIE_CORR_MSG);
284909Segillett 
2852840Scarlsonj 		pec_p->pec_corr_msg_msiq_id = (msiqid_t)-1;
2860Sstevel@tonic-gate 	}
2870Sstevel@tonic-gate 
2883162Sgovinda 	/* Remove non-fatal error message handler */
2890Sstevel@tonic-gate 	if (pec_p->pec_non_fatal_msg_msiq_id >= 0) {
2900Sstevel@tonic-gate 		px_lib_msg_setvalid(dip, PCIE_NONFATAL_MSG,
2910Sstevel@tonic-gate 		    PCIE_MSG_INVALID);
2920Sstevel@tonic-gate 
2933162Sgovinda 		hdl.ih_pri = PX_ERR_PIL;
2940Sstevel@tonic-gate 		(void) px_rem_msiq_intr(dip, dip, &hdl, MSG_REC,
2950Sstevel@tonic-gate 		    PCIE_NONFATAL_MSG, pec_p->pec_non_fatal_msg_msiq_id);
2960Sstevel@tonic-gate 
2972973Sgovinda 		(void) px_ib_update_intr_state(px_p, px_p->px_dip, hdl.ih_inum,
2982973Sgovinda 		    px_msiqid_to_devino(px_p, pec_p->pec_non_fatal_msg_msiq_id),
2992973Sgovinda 		    PX_ERR_PIL, PX_INTR_STATE_DISABLE, MSG_REC,
3002973Sgovinda 		    PCIE_NONFATAL_MSG);
301909Segillett 
3022840Scarlsonj 		pec_p->pec_non_fatal_msg_msiq_id = (msiqid_t)-1;
3030Sstevel@tonic-gate 	}
3040Sstevel@tonic-gate 
3053162Sgovinda 	/* Remove fatal error message handler */
3060Sstevel@tonic-gate 	if (pec_p->pec_fatal_msg_msiq_id >= 0) {
3070Sstevel@tonic-gate 		px_lib_msg_setvalid(dip, PCIE_FATAL_MSG, PCIE_MSG_INVALID);
3080Sstevel@tonic-gate 
3093162Sgovinda 		hdl.ih_pri = PX_ERR_PIL;
3100Sstevel@tonic-gate 		(void) px_rem_msiq_intr(dip, dip, &hdl, MSG_REC,
3110Sstevel@tonic-gate 		    PCIE_FATAL_MSG, pec_p->pec_fatal_msg_msiq_id);
3120Sstevel@tonic-gate 
3132973Sgovinda 		(void) px_ib_update_intr_state(px_p, px_p->px_dip, hdl.ih_inum,
3142973Sgovinda 		    px_msiqid_to_devino(px_p, pec_p->pec_fatal_msg_msiq_id),
3152973Sgovinda 		    PX_ERR_PIL, PX_INTR_STATE_DISABLE, MSG_REC, PCIE_FATAL_MSG);
316909Segillett 
3172840Scarlsonj 		pec_p->pec_fatal_msg_msiq_id = (msiqid_t)-1;
3180Sstevel@tonic-gate 	}
3190Sstevel@tonic-gate }
320