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 */
21*12458SErwin.Tsaur@Sun.COM
220Sstevel@tonic-gate /*
23*12458SErwin.Tsaur@Sun.COM * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
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
500Sstevel@tonic-gate int
px_pec_attach(px_t * px_p)510Sstevel@tonic-gate px_pec_attach(px_t *px_p)
520Sstevel@tonic-gate {
530Sstevel@tonic-gate px_pec_t *pec_p;
540Sstevel@tonic-gate int i, len;
5510923SEvan.Yan@Sun.COM int nrange = px_p->px_ranges_length / sizeof (pci_ranges_t);
560Sstevel@tonic-gate dev_info_t *dip = px_p->px_dip;
5710923SEvan.Yan@Sun.COM pci_ranges_t *rangep = px_p->px_ranges_p;
580Sstevel@tonic-gate
590Sstevel@tonic-gate /*
600Sstevel@tonic-gate * Allocate a state structure for the PEC and cross-link it
610Sstevel@tonic-gate * to its per px node state structure.
620Sstevel@tonic-gate */
630Sstevel@tonic-gate pec_p = kmem_zalloc(sizeof (px_pec_t), KM_SLEEP);
640Sstevel@tonic-gate px_p->px_pec_p = pec_p;
650Sstevel@tonic-gate pec_p->pec_px_p = px_p;
660Sstevel@tonic-gate
670Sstevel@tonic-gate len = snprintf(pec_p->pec_nameinst_str,
685132Srameshc sizeof (pec_p->pec_nameinst_str),
695132Srameshc "%s%d", NAMEINST(dip));
700Sstevel@tonic-gate pec_p->pec_nameaddr_str = pec_p->pec_nameinst_str + ++len;
710Sstevel@tonic-gate (void) snprintf(pec_p->pec_nameaddr_str,
725132Srameshc sizeof (pec_p->pec_nameinst_str) - len,
735132Srameshc "%s@%s", NAMEADDR(dip));
740Sstevel@tonic-gate
750Sstevel@tonic-gate /*
760Sstevel@tonic-gate * Get this pec's mem32 and mem64 segments to determine whether
770Sstevel@tonic-gate * a dma object originates from ths pec. i.e. dev to dev dma
780Sstevel@tonic-gate */
790Sstevel@tonic-gate for (i = 0; i < nrange; i++, rangep++) {
800Sstevel@tonic-gate uint64_t rng_addr, rng_size, *pfnbp, *pfnlp;
810Sstevel@tonic-gate uint32_t rng_type = rangep->child_high & PCI_ADDR_MASK;
820Sstevel@tonic-gate
830Sstevel@tonic-gate switch (rng_type) {
840Sstevel@tonic-gate case PCI_ADDR_MEM32:
850Sstevel@tonic-gate pfnbp = &pec_p->pec_base32_pfn;
860Sstevel@tonic-gate pfnlp = &pec_p->pec_last32_pfn;
870Sstevel@tonic-gate break;
880Sstevel@tonic-gate
890Sstevel@tonic-gate case PCI_ADDR_MEM64:
900Sstevel@tonic-gate pfnbp = &pec_p->pec_base64_pfn;
910Sstevel@tonic-gate pfnlp = &pec_p->pec_last64_pfn;
920Sstevel@tonic-gate break;
930Sstevel@tonic-gate
940Sstevel@tonic-gate case PCI_ADDR_CONFIG:
950Sstevel@tonic-gate case PCI_ADDR_IO:
960Sstevel@tonic-gate default:
970Sstevel@tonic-gate continue;
980Sstevel@tonic-gate }
990Sstevel@tonic-gate rng_addr = (uint64_t)(rangep->parent_high &
1005132Srameshc px_ranges_phi_mask) << 32;
1010Sstevel@tonic-gate rng_addr |= (uint64_t)rangep->parent_low;
1020Sstevel@tonic-gate rng_size = (uint64_t)rangep->size_high << 32;
1030Sstevel@tonic-gate rng_size |= (uint64_t)rangep->size_low;
1040Sstevel@tonic-gate
1050Sstevel@tonic-gate *pfnbp = mmu_btop(rng_addr);
1060Sstevel@tonic-gate *pfnlp = mmu_btop(rng_addr + rng_size);
1070Sstevel@tonic-gate }
1080Sstevel@tonic-gate
1095132Srameshc /*
1105132Srameshc * This lock is for serializing safe acc calls. It is not associated
1115132Srameshc * with an iblock cookie.
1125132Srameshc */
1135132Srameshc mutex_init(&pec_p->pec_pokefault_mutex, NULL, MUTEX_DRIVER, NULL);
1140Sstevel@tonic-gate
1150Sstevel@tonic-gate return (DDI_SUCCESS);
1160Sstevel@tonic-gate }
1170Sstevel@tonic-gate
1180Sstevel@tonic-gate void
px_pec_detach(px_t * px_p)1190Sstevel@tonic-gate px_pec_detach(px_t *px_p)
1200Sstevel@tonic-gate {
1210Sstevel@tonic-gate dev_info_t *dip = px_p->px_dip;
1220Sstevel@tonic-gate px_pec_t *pec_p = px_p->px_pec_p;
1230Sstevel@tonic-gate
1240Sstevel@tonic-gate /*
1250Sstevel@tonic-gate * Free the pokefault mutex.
1260Sstevel@tonic-gate */
1270Sstevel@tonic-gate DBG(DBG_DETACH, dip, "px_pec_detach:\n");
1280Sstevel@tonic-gate mutex_destroy(&pec_p->pec_pokefault_mutex);
1290Sstevel@tonic-gate
1300Sstevel@tonic-gate /*
1310Sstevel@tonic-gate * Free the pec state structure.
1320Sstevel@tonic-gate */
1330Sstevel@tonic-gate kmem_free(pec_p, sizeof (px_pec_t));
1340Sstevel@tonic-gate px_p->px_pec_p = NULL;
1350Sstevel@tonic-gate }
1360Sstevel@tonic-gate
1370Sstevel@tonic-gate /*
1380Sstevel@tonic-gate * pec_msg_add_intr:
1390Sstevel@tonic-gate *
1400Sstevel@tonic-gate * Add interrupt handlers to process correctable/fatal/non fatal
1410Sstevel@tonic-gate * PCIE messages.
1420Sstevel@tonic-gate */
143*12458SErwin.Tsaur@Sun.COM int
px_pec_msg_add_intr(px_t * px_p)1440Sstevel@tonic-gate px_pec_msg_add_intr(px_t *px_p)
1450Sstevel@tonic-gate {
1460Sstevel@tonic-gate dev_info_t *dip = px_p->px_dip;
1470Sstevel@tonic-gate px_pec_t *pec_p = px_p->px_pec_p;
1480Sstevel@tonic-gate ddi_intr_handle_impl_t hdl;
1490Sstevel@tonic-gate int ret = DDI_SUCCESS;
1500Sstevel@tonic-gate
1510Sstevel@tonic-gate DBG(DBG_MSG, px_p->px_dip, "px_pec_msg_add_intr\n");
1520Sstevel@tonic-gate
1531725Segillett /* Initialize handle */
1541725Segillett bzero(&hdl, sizeof (ddi_intr_handle_impl_t));
15527Sjchu hdl.ih_cb_func = (ddi_intr_handler_t *)px_err_fabric_intr;
1560Sstevel@tonic-gate hdl.ih_ver = DDI_INTR_VERSION;
1570Sstevel@tonic-gate hdl.ih_state = DDI_IHDL_STATE_ALLOC;
1580Sstevel@tonic-gate hdl.ih_dip = dip;
1590Sstevel@tonic-gate
1600Sstevel@tonic-gate /* Add correctable error message handler */
16127Sjchu hdl.ih_pri = PX_ERR_LOW_PIL;
1620Sstevel@tonic-gate
1630Sstevel@tonic-gate if ((ret = px_add_msiq_intr(dip, dip, &hdl,
16410053SEvan.Yan@Sun.COM MSG_REC, (msgcode_t)PCIE_CORR_MSG, -1,
1650Sstevel@tonic-gate &pec_p->pec_corr_msg_msiq_id)) != DDI_SUCCESS) {
1660Sstevel@tonic-gate DBG(DBG_MSG, px_p->px_dip,
1670Sstevel@tonic-gate "PCIE_CORR_MSG registration failed\n");
1680Sstevel@tonic-gate return (DDI_FAILURE);
1690Sstevel@tonic-gate }
1700Sstevel@tonic-gate
1710Sstevel@tonic-gate px_lib_msg_setmsiq(dip, PCIE_CORR_MSG, pec_p->pec_corr_msg_msiq_id);
1720Sstevel@tonic-gate px_lib_msg_setvalid(dip, PCIE_CORR_MSG, PCIE_MSG_VALID);
1730Sstevel@tonic-gate
1742973Sgovinda if ((ret = px_ib_update_intr_state(px_p, px_p->px_dip, hdl.ih_inum,
1752973Sgovinda px_msiqid_to_devino(px_p, pec_p->pec_corr_msg_msiq_id),
1762973Sgovinda PX_ERR_LOW_PIL, PX_INTR_STATE_ENABLE, MSG_REC,
1772973Sgovinda PCIE_CORR_MSG)) != DDI_SUCCESS) {
178909Segillett DBG(DBG_MSG, px_p->px_dip,
179909Segillett "PCIE_CORR_MSG update interrupt state failed\n");
180909Segillett return (DDI_FAILURE);
181909Segillett }
182909Segillett
1830Sstevel@tonic-gate /* Add non-fatal error message handler */
18427Sjchu hdl.ih_pri = PX_ERR_PIL;
1850Sstevel@tonic-gate
1860Sstevel@tonic-gate if ((ret = px_add_msiq_intr(dip, dip, &hdl,
18710053SEvan.Yan@Sun.COM MSG_REC, (msgcode_t)PCIE_NONFATAL_MSG, -1,
1880Sstevel@tonic-gate &pec_p->pec_non_fatal_msg_msiq_id)) != DDI_SUCCESS) {
1890Sstevel@tonic-gate DBG(DBG_MSG, px_p->px_dip,
1900Sstevel@tonic-gate "PCIE_NONFATAL_MSG registration failed\n");
1910Sstevel@tonic-gate return (DDI_FAILURE);
1920Sstevel@tonic-gate }
1930Sstevel@tonic-gate
1940Sstevel@tonic-gate px_lib_msg_setmsiq(dip, PCIE_NONFATAL_MSG,
1950Sstevel@tonic-gate pec_p->pec_non_fatal_msg_msiq_id);
1960Sstevel@tonic-gate px_lib_msg_setvalid(dip, PCIE_NONFATAL_MSG, PCIE_MSG_VALID);
1970Sstevel@tonic-gate
1982973Sgovinda if ((ret = px_ib_update_intr_state(px_p, px_p->px_dip, hdl.ih_inum,
1992973Sgovinda px_msiqid_to_devino(px_p, pec_p->pec_non_fatal_msg_msiq_id),
2002973Sgovinda PX_ERR_PIL, PX_INTR_STATE_ENABLE, MSG_REC,
201909Segillett PCIE_NONFATAL_MSG)) != DDI_SUCCESS) {
202909Segillett DBG(DBG_MSG, px_p->px_dip,
203909Segillett "PCIE_NONFATAL_MSG update interrupt state failed\n");
204909Segillett return (DDI_FAILURE);
205909Segillett }
206909Segillett
2070Sstevel@tonic-gate /* Add fatal error message handler */
20827Sjchu hdl.ih_pri = PX_ERR_PIL;
2090Sstevel@tonic-gate
2100Sstevel@tonic-gate if ((ret = px_add_msiq_intr(dip, dip, &hdl,
21110053SEvan.Yan@Sun.COM MSG_REC, (msgcode_t)PCIE_FATAL_MSG, -1,
2120Sstevel@tonic-gate &pec_p->pec_fatal_msg_msiq_id)) != DDI_SUCCESS) {
2130Sstevel@tonic-gate DBG(DBG_MSG, px_p->px_dip,
2140Sstevel@tonic-gate "PCIE_FATAL_MSG registration failed\n");
2150Sstevel@tonic-gate return (DDI_FAILURE);
2160Sstevel@tonic-gate }
2170Sstevel@tonic-gate
2180Sstevel@tonic-gate px_lib_msg_setmsiq(dip, PCIE_FATAL_MSG, pec_p->pec_fatal_msg_msiq_id);
2190Sstevel@tonic-gate px_lib_msg_setvalid(dip, PCIE_FATAL_MSG, PCIE_MSG_VALID);
2200Sstevel@tonic-gate
2212973Sgovinda if ((ret = px_ib_update_intr_state(px_p, px_p->px_dip, hdl.ih_inum,
2222973Sgovinda px_msiqid_to_devino(px_p, pec_p->pec_fatal_msg_msiq_id), PX_ERR_PIL,
2232973Sgovinda PX_INTR_STATE_ENABLE, MSG_REC, PCIE_FATAL_MSG)) != DDI_SUCCESS) {
224909Segillett DBG(DBG_MSG, px_p->px_dip,
225909Segillett "PCIE_FATAL_MSG update interrupt state failed\n");
226909Segillett return (DDI_FAILURE);
227909Segillett }
228909Segillett
2290Sstevel@tonic-gate return (ret);
2300Sstevel@tonic-gate }
2310Sstevel@tonic-gate
2320Sstevel@tonic-gate /*
2330Sstevel@tonic-gate * px_pec_msg_rem_intr:
2340Sstevel@tonic-gate *
2350Sstevel@tonic-gate * Remove interrupt handlers to process correctable/fatal/non fatal
2360Sstevel@tonic-gate * PCIE messages. For now, all these PCIe messages are mapped to
2370Sstevel@tonic-gate * same MSIQ.
2380Sstevel@tonic-gate */
239*12458SErwin.Tsaur@Sun.COM void
px_pec_msg_rem_intr(px_t * px_p)2400Sstevel@tonic-gate px_pec_msg_rem_intr(px_t *px_p)
2410Sstevel@tonic-gate {
2420Sstevel@tonic-gate dev_info_t *dip = px_p->px_dip;
2430Sstevel@tonic-gate px_pec_t *pec_p = px_p->px_pec_p;
2440Sstevel@tonic-gate ddi_intr_handle_impl_t hdl;
2450Sstevel@tonic-gate
2460Sstevel@tonic-gate DBG(DBG_MSG, px_p->px_dip, "px_pec_msg_rem_intr: dip 0x%p\n", dip);
2470Sstevel@tonic-gate
2481725Segillett /* Initialize handle */
2491725Segillett bzero(&hdl, sizeof (ddi_intr_handle_impl_t));
2500Sstevel@tonic-gate hdl.ih_ver = DDI_INTR_VERSION;
2510Sstevel@tonic-gate hdl.ih_state = DDI_IHDL_STATE_ALLOC;
2520Sstevel@tonic-gate hdl.ih_dip = dip;
2530Sstevel@tonic-gate
2543162Sgovinda /* Remove correctable error message handler */
2550Sstevel@tonic-gate if (pec_p->pec_corr_msg_msiq_id >= 0) {
2560Sstevel@tonic-gate px_lib_msg_setvalid(dip, PCIE_CORR_MSG, PCIE_MSG_INVALID);
2570Sstevel@tonic-gate
2583162Sgovinda hdl.ih_pri = PX_ERR_LOW_PIL;
2590Sstevel@tonic-gate (void) px_rem_msiq_intr(dip, dip, &hdl, MSG_REC,
2600Sstevel@tonic-gate PCIE_CORR_MSG, pec_p->pec_corr_msg_msiq_id);
261909Segillett
2622973Sgovinda (void) px_ib_update_intr_state(px_p, px_p->px_dip, hdl.ih_inum,
2632973Sgovinda px_msiqid_to_devino(px_p, pec_p->pec_corr_msg_msiq_id),
2642973Sgovinda PX_ERR_LOW_PIL, PX_INTR_STATE_DISABLE, MSG_REC,
2652973Sgovinda PCIE_CORR_MSG);
266909Segillett
2672840Scarlsonj pec_p->pec_corr_msg_msiq_id = (msiqid_t)-1;
2680Sstevel@tonic-gate }
2690Sstevel@tonic-gate
2703162Sgovinda /* Remove non-fatal error message handler */
2710Sstevel@tonic-gate if (pec_p->pec_non_fatal_msg_msiq_id >= 0) {
2720Sstevel@tonic-gate px_lib_msg_setvalid(dip, PCIE_NONFATAL_MSG,
2730Sstevel@tonic-gate PCIE_MSG_INVALID);
2740Sstevel@tonic-gate
2753162Sgovinda hdl.ih_pri = PX_ERR_PIL;
2760Sstevel@tonic-gate (void) px_rem_msiq_intr(dip, dip, &hdl, MSG_REC,
2770Sstevel@tonic-gate PCIE_NONFATAL_MSG, pec_p->pec_non_fatal_msg_msiq_id);
2780Sstevel@tonic-gate
2792973Sgovinda (void) px_ib_update_intr_state(px_p, px_p->px_dip, hdl.ih_inum,
2802973Sgovinda px_msiqid_to_devino(px_p, pec_p->pec_non_fatal_msg_msiq_id),
2812973Sgovinda PX_ERR_PIL, PX_INTR_STATE_DISABLE, MSG_REC,
2822973Sgovinda PCIE_NONFATAL_MSG);
283909Segillett
2842840Scarlsonj pec_p->pec_non_fatal_msg_msiq_id = (msiqid_t)-1;
2850Sstevel@tonic-gate }
2860Sstevel@tonic-gate
2873162Sgovinda /* Remove fatal error message handler */
2880Sstevel@tonic-gate if (pec_p->pec_fatal_msg_msiq_id >= 0) {
2890Sstevel@tonic-gate px_lib_msg_setvalid(dip, PCIE_FATAL_MSG, PCIE_MSG_INVALID);
2900Sstevel@tonic-gate
2913162Sgovinda hdl.ih_pri = PX_ERR_PIL;
2920Sstevel@tonic-gate (void) px_rem_msiq_intr(dip, dip, &hdl, MSG_REC,
2930Sstevel@tonic-gate PCIE_FATAL_MSG, pec_p->pec_fatal_msg_msiq_id);
2940Sstevel@tonic-gate
2952973Sgovinda (void) px_ib_update_intr_state(px_p, px_p->px_dip, hdl.ih_inum,
2962973Sgovinda px_msiqid_to_devino(px_p, pec_p->pec_fatal_msg_msiq_id),
2972973Sgovinda PX_ERR_PIL, PX_INTR_STATE_DISABLE, MSG_REC, PCIE_FATAL_MSG);
298909Segillett
2992840Scarlsonj pec_p->pec_fatal_msg_msiq_id = (msiqid_t)-1;
3000Sstevel@tonic-gate }
3010Sstevel@tonic-gate }
302