17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 500d0963fSdilpreet * Common Development and Distribution License (the "License"). 600d0963fSdilpreet * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22eae2e508Skrishnae * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate /* 297c478bd9Sstevel@tonic-gate * Fault Management for Device Drivers 307c478bd9Sstevel@tonic-gate * 317c478bd9Sstevel@tonic-gate * Device drivers wishing to participate in fault management may do so by 327c478bd9Sstevel@tonic-gate * first initializing their fault management state and capabilties via 337c478bd9Sstevel@tonic-gate * ddi_fm_init(). If the system supports the requested FM capabilities, 347c478bd9Sstevel@tonic-gate * the IO framework will intialize FM state and return a bit mask of the 357c478bd9Sstevel@tonic-gate * requested capabilities. 367c478bd9Sstevel@tonic-gate * 377c478bd9Sstevel@tonic-gate * If the system does not support the requested FM capabilities, 387c478bd9Sstevel@tonic-gate * the device driver must behave in accordance with the programming semantics 397c478bd9Sstevel@tonic-gate * defined below for the capabilities returned from ddi_fm_init(). 407c478bd9Sstevel@tonic-gate * ddi_fm_init() must be called at attach(9E) time and ddi_fm_fini() must be 417c478bd9Sstevel@tonic-gate * called from detach(9E) to perform FM clean-up. 427c478bd9Sstevel@tonic-gate * 437c478bd9Sstevel@tonic-gate * Driver Fault Management Capabilities 447c478bd9Sstevel@tonic-gate * 457c478bd9Sstevel@tonic-gate * DDI_FM_NOT_CAPABLE 467c478bd9Sstevel@tonic-gate * 477c478bd9Sstevel@tonic-gate * This is the default fault management capability for drivers. Drivers 487c478bd9Sstevel@tonic-gate * that implement no fault management capabilites or do not participate 497c478bd9Sstevel@tonic-gate * in fault management activities have their FM capability bitmask set 507c478bd9Sstevel@tonic-gate * to 0. 517c478bd9Sstevel@tonic-gate * 527c478bd9Sstevel@tonic-gate * DDI_FM_EREPORT_CAPABLE 537c478bd9Sstevel@tonic-gate * 547c478bd9Sstevel@tonic-gate * When this capability bit is set, drivers are expected to generate error 557c478bd9Sstevel@tonic-gate * report events via ddi_ereport_post() for the associated faults 567c478bd9Sstevel@tonic-gate * that are diagnosed by the IO fault manager DE. ddi_ereport_post() 577c478bd9Sstevel@tonic-gate * may be called in any context subject to the constraints specified 587c478bd9Sstevel@tonic-gate * by the interrupt iblock cookie returned during initialization. 597c478bd9Sstevel@tonic-gate * 607c478bd9Sstevel@tonic-gate * Error reports resulting from hardware component specific and common IO 617c478bd9Sstevel@tonic-gate * fault and driver defects must be accompanied by an Eversholt fault 627c478bd9Sstevel@tonic-gate * tree (.eft) by the Solaris fault manager (fmd(1M)) for 637c478bd9Sstevel@tonic-gate * diagnosis. 647c478bd9Sstevel@tonic-gate * 657c478bd9Sstevel@tonic-gate * DDI_FM_ERRCB_CAPABLE 667c478bd9Sstevel@tonic-gate * 677c478bd9Sstevel@tonic-gate * Device drivers are expected to implement and register an error 687c478bd9Sstevel@tonic-gate * handler callback function. ddi_fm_handler_register() and 697c478bd9Sstevel@tonic-gate * ddi_fm_handler_unregister() must be 707c478bd9Sstevel@tonic-gate * called in passive kernel context, typically during an attach(9E) 717c478bd9Sstevel@tonic-gate * or detach(9E) operation. When called by the FM IO framework, 727c478bd9Sstevel@tonic-gate * the callback function should check for error conditions for the 737c478bd9Sstevel@tonic-gate * hardware and software under its control. All detected errors 747c478bd9Sstevel@tonic-gate * should have ereport events generated for them. 757c478bd9Sstevel@tonic-gate * 767c478bd9Sstevel@tonic-gate * Upon completion of the error handler callback, the driver should 777c478bd9Sstevel@tonic-gate * return one of the following values: 787c478bd9Sstevel@tonic-gate * 797c478bd9Sstevel@tonic-gate * #define DDI_FM_OK - no error was detected 807c478bd9Sstevel@tonic-gate * #define DDI_FM_FATAL - a fatal error was detected 817c478bd9Sstevel@tonic-gate * #define DDI_FM_NONFATAL - a non-fatal error was detected 827c478bd9Sstevel@tonic-gate * #define DDI_FM_UNKNOWN - the error status is unknown 837c478bd9Sstevel@tonic-gate * 847c478bd9Sstevel@tonic-gate * To insure single threaded access to error handling callbacks, 857c478bd9Sstevel@tonic-gate * the device driver may use i_ddi_fm_handler_enter() and 867c478bd9Sstevel@tonic-gate * i_ddi_fm_handler_exit() when entering and exiting the callback. 877c478bd9Sstevel@tonic-gate * 887c478bd9Sstevel@tonic-gate * DDI_FM_ACCCHK_CAPABLE/DDI_FM_DMACHK_CAPABLE 897c478bd9Sstevel@tonic-gate * 907c478bd9Sstevel@tonic-gate * Device drivers are expected to set-up access and DMA handles 917c478bd9Sstevel@tonic-gate * with FM-specific attributes designed to allow nexus parent 927c478bd9Sstevel@tonic-gate * drivers to flag any errors seen during subsequent IO transactions. 937c478bd9Sstevel@tonic-gate * Drivers must set the devacc_attr_acc_flag member of their 947c478bd9Sstevel@tonic-gate * ddi_device_acc_attr_t structures to DDI_FLAGERR_ACC or DDI_CAUTIOUS_ACC. 957c478bd9Sstevel@tonic-gate * For DMA transactions, driver must set the dma_attr_flags of 967c478bd9Sstevel@tonic-gate * their ddi_dma_attr_t structures to DDI_DMA_FLAGERR. 977c478bd9Sstevel@tonic-gate * 987c478bd9Sstevel@tonic-gate * Upon completion of an IO transaction, device drivers are expected 997c478bd9Sstevel@tonic-gate * to check the status of host-side hardware access and device-side 1007c478bd9Sstevel@tonic-gate * dma completions by calling ddi_acc_err_check() or ddi_dma_err_check() 1017c478bd9Sstevel@tonic-gate * respectively. If the handle is associated with an error detected by 1027c478bd9Sstevel@tonic-gate * the nexus parent or FM IO framework, ddi_fm_error_t data (status, ena 1037c478bd9Sstevel@tonic-gate * and error expectation) is returned. If status of DDI_FM_NONFATAL or 1047c478bd9Sstevel@tonic-gate * DDI_FM_FATAL is returned, the ena is valid and the expectation flag 1057c478bd9Sstevel@tonic-gate * will be set to 1 if the error was unexpected (i.e. not the result 1067c478bd9Sstevel@tonic-gate * of a peek or poke type operation). 1077c478bd9Sstevel@tonic-gate * 1087c478bd9Sstevel@tonic-gate * ddi_acc_err_check() and ddi_dma_err_check() may be called in any 1097c478bd9Sstevel@tonic-gate * context subject to the constraints specified by the interrupt 1107c478bd9Sstevel@tonic-gate * iblock cookie returned during initialization. 1117c478bd9Sstevel@tonic-gate * 1127c478bd9Sstevel@tonic-gate * Device drivers should generate an access (DDI_FM_IO_ACC) or dma 1137c478bd9Sstevel@tonic-gate * (DDI_FM_IO_DMA) data path error report if DDI_FM_NONFATAL or 1147c478bd9Sstevel@tonic-gate * DDI_FM_FATAL is returned. 1157c478bd9Sstevel@tonic-gate * 1167c478bd9Sstevel@tonic-gate */ 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate #include <sys/types.h> 1197c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 1207c478bd9Sstevel@tonic-gate #include <sys/sunndi.h> 1217c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 1227c478bd9Sstevel@tonic-gate #include <sys/nvpair.h> 1237c478bd9Sstevel@tonic-gate #include <sys/fm/protocol.h> 1247c478bd9Sstevel@tonic-gate #include <sys/ndifm.h> 1257c478bd9Sstevel@tonic-gate #include <sys/ddifm.h> 1267c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 1277c478bd9Sstevel@tonic-gate #include <sys/ddi_isa.h> 1287c478bd9Sstevel@tonic-gate #include <sys/spl.h> 1297c478bd9Sstevel@tonic-gate #include <sys/varargs.h> 1307c478bd9Sstevel@tonic-gate #include <sys/systm.h> 1317c478bd9Sstevel@tonic-gate #include <sys/disp.h> 1327c478bd9Sstevel@tonic-gate #include <sys/atomic.h> 1337c478bd9Sstevel@tonic-gate #include <sys/errorq_impl.h> 1347c478bd9Sstevel@tonic-gate #include <sys/kobj.h> 1357c478bd9Sstevel@tonic-gate #include <sys/fm/util.h> 1367c478bd9Sstevel@tonic-gate #include <sys/fm/io/ddi.h> 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate #define ERPT_CLASS_SZ sizeof (DDI_IO_CLASS) + sizeof (FM_EREPORT_CLASS) + \ 1397c478bd9Sstevel@tonic-gate DDI_MAX_ERPT_CLASS + 2 1407c478bd9Sstevel@tonic-gate /* Globals */ 1417c478bd9Sstevel@tonic-gate int default_dmacache_sz = DEFAULT_DMACACHE_SZ; 1427c478bd9Sstevel@tonic-gate int default_acccache_sz = DEFAULT_ACCCACHE_SZ; 1437c478bd9Sstevel@tonic-gate int ddi_system_fmcap = 0; 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate static struct i_ddi_fmkstat ddifm_kstat_template = { 1467c478bd9Sstevel@tonic-gate {"erpt_dropped", KSTAT_DATA_UINT64 }, 1477c478bd9Sstevel@tonic-gate {"fm_cache_full", KSTAT_DATA_UINT64 }, 1487c478bd9Sstevel@tonic-gate {"fm_cache_grew", KSTAT_DATA_UINT64 }, 1497c478bd9Sstevel@tonic-gate {"acc_err", KSTAT_DATA_UINT64 }, 1507c478bd9Sstevel@tonic-gate {"dma_err", KSTAT_DATA_UINT64 } 1517c478bd9Sstevel@tonic-gate }; 1527c478bd9Sstevel@tonic-gate 1537c478bd9Sstevel@tonic-gate /* 1547c478bd9Sstevel@tonic-gate * Update the service state following the detection of an 1557c478bd9Sstevel@tonic-gate * error. 1567c478bd9Sstevel@tonic-gate */ 1577c478bd9Sstevel@tonic-gate void 1587c478bd9Sstevel@tonic-gate ddi_fm_service_impact(dev_info_t *dip, int svc_impact) 1597c478bd9Sstevel@tonic-gate { 16000d0963fSdilpreet uint64_t ena; 16100d0963fSdilpreet char buf[FM_MAX_CLASS]; 16200d0963fSdilpreet 16300d0963fSdilpreet ena = fm_ena_generate(0, FM_ENA_FMT1); 1647c478bd9Sstevel@tonic-gate mutex_enter(&(DEVI(dip)->devi_lock)); 1657c478bd9Sstevel@tonic-gate if (!DEVI_IS_DEVICE_OFFLINE(dip)) { 1667c478bd9Sstevel@tonic-gate switch (svc_impact) { 1677c478bd9Sstevel@tonic-gate case DDI_SERVICE_LOST: 1687c478bd9Sstevel@tonic-gate DEVI_SET_DEVICE_DOWN(dip); 16900d0963fSdilpreet (void) snprintf(buf, FM_MAX_CLASS, "%s.%s", 17000d0963fSdilpreet DDI_FM_SERVICE_IMPACT, DDI_FM_SERVICE_LOST); 17100d0963fSdilpreet ddi_fm_ereport_post(dip, buf, ena, DDI_NOSLEEP, 17200d0963fSdilpreet FM_VERSION, DATA_TYPE_UINT8, FM_EREPORT_VERS0, 17300d0963fSdilpreet NULL); 1747c478bd9Sstevel@tonic-gate break; 1757c478bd9Sstevel@tonic-gate case DDI_SERVICE_DEGRADED: 1767c478bd9Sstevel@tonic-gate DEVI_SET_DEVICE_DEGRADED(dip); 17700d0963fSdilpreet if (DEVI_IS_DEVICE_DEGRADED(dip)) { 17800d0963fSdilpreet (void) snprintf(buf, FM_MAX_CLASS, "%s.%s", 17900d0963fSdilpreet DDI_FM_SERVICE_IMPACT, 18000d0963fSdilpreet DDI_FM_SERVICE_DEGRADED); 18100d0963fSdilpreet ddi_fm_ereport_post(dip, buf, ena, DDI_NOSLEEP, 18200d0963fSdilpreet FM_VERSION, DATA_TYPE_UINT8, 18300d0963fSdilpreet FM_EREPORT_VERS0, NULL); 18400d0963fSdilpreet } else if (DEVI_IS_DEVICE_DOWN(dip)) { 18500d0963fSdilpreet (void) snprintf(buf, FM_MAX_CLASS, "%s.%s", 18600d0963fSdilpreet DDI_FM_SERVICE_IMPACT, 18700d0963fSdilpreet DDI_FM_SERVICE_LOST); 18800d0963fSdilpreet ddi_fm_ereport_post(dip, buf, ena, DDI_NOSLEEP, 18900d0963fSdilpreet FM_VERSION, DATA_TYPE_UINT8, 19000d0963fSdilpreet FM_EREPORT_VERS0, NULL); 19100d0963fSdilpreet } 1927c478bd9Sstevel@tonic-gate break; 1937c478bd9Sstevel@tonic-gate case DDI_SERVICE_RESTORED: 1947c478bd9Sstevel@tonic-gate DEVI_SET_DEVICE_UP(dip); 19500d0963fSdilpreet (void) snprintf(buf, FM_MAX_CLASS, "%s.%s", 19600d0963fSdilpreet DDI_FM_SERVICE_IMPACT, DDI_FM_SERVICE_RESTORED); 19700d0963fSdilpreet ddi_fm_ereport_post(dip, buf, ena, DDI_NOSLEEP, 19800d0963fSdilpreet FM_VERSION, DATA_TYPE_UINT8, FM_EREPORT_VERS0, 19900d0963fSdilpreet NULL); 2007c478bd9Sstevel@tonic-gate break; 2017c478bd9Sstevel@tonic-gate case DDI_SERVICE_UNAFFECTED: 20200d0963fSdilpreet (void) snprintf(buf, FM_MAX_CLASS, "%s.%s", 20300d0963fSdilpreet DDI_FM_SERVICE_IMPACT, DDI_FM_SERVICE_UNAFFECTED); 20400d0963fSdilpreet ddi_fm_ereport_post(dip, buf, ena, DDI_NOSLEEP, 20500d0963fSdilpreet FM_VERSION, DATA_TYPE_UINT8, FM_EREPORT_VERS0, 20600d0963fSdilpreet NULL); 20700d0963fSdilpreet break; 2087c478bd9Sstevel@tonic-gate default: 2097c478bd9Sstevel@tonic-gate break; 2107c478bd9Sstevel@tonic-gate } 2117c478bd9Sstevel@tonic-gate } 2127c478bd9Sstevel@tonic-gate mutex_exit(&(DEVI(dip)->devi_lock)); 2137c478bd9Sstevel@tonic-gate } 2147c478bd9Sstevel@tonic-gate 2157c478bd9Sstevel@tonic-gate void 2167c478bd9Sstevel@tonic-gate i_ddi_drv_ereport_post(dev_info_t *dip, const char *error_class, 2177c478bd9Sstevel@tonic-gate nvlist_t *errp, int sflag) 2187c478bd9Sstevel@tonic-gate { 2197c478bd9Sstevel@tonic-gate int i; 2207c478bd9Sstevel@tonic-gate int depth; 2217c478bd9Sstevel@tonic-gate char classp[DDI_DVR_MAX_CLASS]; 2227c478bd9Sstevel@tonic-gate caddr_t stkp; 2237c478bd9Sstevel@tonic-gate char *buf; 2247c478bd9Sstevel@tonic-gate char **stkpp; 2257c478bd9Sstevel@tonic-gate char *sym; 2267c478bd9Sstevel@tonic-gate pc_t stack[DDI_FM_STKDEPTH]; 2277c478bd9Sstevel@tonic-gate ulong_t off; 2287c478bd9Sstevel@tonic-gate dev_info_t *root_dip = ddi_root_node(); 2297c478bd9Sstevel@tonic-gate 2307c478bd9Sstevel@tonic-gate if (!DDI_FM_EREPORT_CAP(ddi_fm_capable(root_dip))) 2317c478bd9Sstevel@tonic-gate return; 2327c478bd9Sstevel@tonic-gate 2337c478bd9Sstevel@tonic-gate (void) snprintf(classp, DDI_DVR_MAX_CLASS, "%s%s", DVR_ERPT, 2347c478bd9Sstevel@tonic-gate error_class); 2357c478bd9Sstevel@tonic-gate 2367c478bd9Sstevel@tonic-gate if (sflag == DDI_SLEEP) { 2377c478bd9Sstevel@tonic-gate depth = getpcstack(stack, DDI_FM_STKDEPTH); 2387c478bd9Sstevel@tonic-gate 2397c478bd9Sstevel@tonic-gate /* Allocate array of char * for nvlist payload */ 2407c478bd9Sstevel@tonic-gate stkpp = (char **)kmem_alloc(depth * sizeof (char *), KM_SLEEP); 2417c478bd9Sstevel@tonic-gate 2427c478bd9Sstevel@tonic-gate /* 2437c478bd9Sstevel@tonic-gate * Allocate temporary 64-bit aligned buffer for stack 2447c478bd9Sstevel@tonic-gate * symbol strings 2457c478bd9Sstevel@tonic-gate */ 2467c478bd9Sstevel@tonic-gate buf = kmem_alloc(depth * DDI_FM_SYM_SZ, KM_SLEEP); 2477c478bd9Sstevel@tonic-gate 2487c478bd9Sstevel@tonic-gate stkp = buf; 2497c478bd9Sstevel@tonic-gate for (i = 0; i < depth; ++i) { 2507c478bd9Sstevel@tonic-gate sym = kobj_getsymname(stack[i], &off); 2517c478bd9Sstevel@tonic-gate (void) snprintf(stkp, DDI_FM_SYM_SZ, 2527c478bd9Sstevel@tonic-gate "\t%s+%lx\n", sym ? sym : "?", off); 2537c478bd9Sstevel@tonic-gate stkpp[i] = stkp; 2547c478bd9Sstevel@tonic-gate stkp += DDI_FM_SYM_SZ; 2557c478bd9Sstevel@tonic-gate } 2567c478bd9Sstevel@tonic-gate 2577c478bd9Sstevel@tonic-gate if (errp) 2587c478bd9Sstevel@tonic-gate ddi_fm_ereport_post(root_dip, 2597c478bd9Sstevel@tonic-gate classp, fm_ena_generate(0, FM_ENA_FMT1), sflag, 2607c478bd9Sstevel@tonic-gate FM_VERSION, DATA_TYPE_UINT8, 0, 2617c478bd9Sstevel@tonic-gate DVR_NAME, DATA_TYPE_STRING, ddi_driver_name(dip), 2627c478bd9Sstevel@tonic-gate DVR_STACK_DEPTH, DATA_TYPE_UINT32, depth, 2637c478bd9Sstevel@tonic-gate DVR_STACK, DATA_TYPE_STRING_ARRAY, depth, stkpp, 2647c478bd9Sstevel@tonic-gate DVR_ERR_SPECIFIC, DATA_TYPE_NVLIST, errp, NULL); 2657c478bd9Sstevel@tonic-gate else 2667c478bd9Sstevel@tonic-gate ddi_fm_ereport_post(root_dip, 2677c478bd9Sstevel@tonic-gate classp, fm_ena_generate(0, FM_ENA_FMT1), sflag, 2687c478bd9Sstevel@tonic-gate FM_VERSION, DATA_TYPE_UINT8, 0, 2697c478bd9Sstevel@tonic-gate DVR_NAME, DATA_TYPE_STRING, ddi_driver_name(dip), 2707c478bd9Sstevel@tonic-gate DVR_STACK_DEPTH, DATA_TYPE_UINT32, depth, 2717c478bd9Sstevel@tonic-gate DVR_STACK, DATA_TYPE_STRING_ARRAY, depth, stkpp, 2727c478bd9Sstevel@tonic-gate NULL); 2737c478bd9Sstevel@tonic-gate 2747c478bd9Sstevel@tonic-gate kmem_free(stkpp, depth * sizeof (char *)); 2757c478bd9Sstevel@tonic-gate kmem_free(buf, depth * DDI_FM_SYM_SZ); 2767c478bd9Sstevel@tonic-gate 2777c478bd9Sstevel@tonic-gate } else { 2787c478bd9Sstevel@tonic-gate if (errp) 2797c478bd9Sstevel@tonic-gate ddi_fm_ereport_post(root_dip, 2807c478bd9Sstevel@tonic-gate classp, fm_ena_generate(0, FM_ENA_FMT1), sflag, 2817c478bd9Sstevel@tonic-gate FM_VERSION, DATA_TYPE_UINT8, 0, 2827c478bd9Sstevel@tonic-gate DVR_NAME, DATA_TYPE_STRING, ddi_driver_name(dip), 2837c478bd9Sstevel@tonic-gate DVR_ERR_SPECIFIC, DATA_TYPE_NVLIST, errp, NULL); 2847c478bd9Sstevel@tonic-gate else 2857c478bd9Sstevel@tonic-gate ddi_fm_ereport_post(root_dip, 2867c478bd9Sstevel@tonic-gate classp, fm_ena_generate(0, FM_ENA_FMT1), sflag, 2877c478bd9Sstevel@tonic-gate FM_VERSION, DATA_TYPE_UINT8, 0, 2887c478bd9Sstevel@tonic-gate DVR_NAME, DATA_TYPE_STRING, ddi_driver_name(dip), 2897c478bd9Sstevel@tonic-gate NULL); 2907c478bd9Sstevel@tonic-gate } 2917c478bd9Sstevel@tonic-gate } 2927c478bd9Sstevel@tonic-gate 2937c478bd9Sstevel@tonic-gate /* 294*602ca9eaScth * fm_dev_ereport_postv: Common consolidation private interface to 295*602ca9eaScth * post a device tree oriented dev_scheme ereport. The device tree is 296*602ca9eaScth * composed of the following entities: devinfo nodes, minor nodes, and 297*602ca9eaScth * pathinfo nodes. All entities are associated with some devinfo node, 298*602ca9eaScth * either directly or indirectly. The intended devinfo node association 299*602ca9eaScth * for the ereport is communicated by the 'dip' argument. A minor node, 300*602ca9eaScth * an entity below 'dip', is represented by a non-null 'minor_name' 301*602ca9eaScth * argument. An application specific caller, like scsi_fm_ereport_post, 302*602ca9eaScth * can override the devinfo path with a pathinfo path via a non-null 303*602ca9eaScth * 'devpath' argument - in this case 'dip' is the MPXIO client node and 304*602ca9eaScth * devpath should be the path through the pHCI devinfo node to the 305*602ca9eaScth * pathinfo node. 306*602ca9eaScth * 307*602ca9eaScth * This interface also allows the caller to decide if the error being 308*602ca9eaScth * reported is know to be associated with a specific device identity 309*602ca9eaScth * via the 'devid' argument. The caller needs to control wether the 310*602ca9eaScth * devid appears as an authority in the FMRI because for some types of 311*602ca9eaScth * errors, like transport errors, the identity of the device on the 312*602ca9eaScth * other end of the transport is not guaranteed to be the current 313*602ca9eaScth * identity of the dip. For transport errors the caller should specify 314*602ca9eaScth * a NULL devid, even when there is a valid devid associated with the dip. 315*602ca9eaScth * 316*602ca9eaScth * The ddi_fm_ereport_post() implementation calls this interface with 317*602ca9eaScth * just a dip: devpath, minor_name, and devid are all NULL. The 318*602ca9eaScth * scsi_fm_ereport_post() implementation may call this interface with 319*602ca9eaScth * non-null devpath, minor_name, and devid arguments depending on 320*602ca9eaScth * wether MPXIO is enabled, and wether a transport or non-transport 321*602ca9eaScth * error is being posted. 322*602ca9eaScth */ 323*602ca9eaScth void 324*602ca9eaScth fm_dev_ereport_postv(dev_info_t *dip, dev_info_t *eqdip, 325*602ca9eaScth const char *devpath, const char *minor_name, const char *devid, 326*602ca9eaScth const char *error_class, uint64_t ena, int sflag, va_list ap) 327*602ca9eaScth { 328*602ca9eaScth struct i_ddi_fmhdl *fmhdl; 329*602ca9eaScth errorq_elem_t *eqep; 330*602ca9eaScth nv_alloc_t *nva; 331*602ca9eaScth nvlist_t *ereport = NULL; 332*602ca9eaScth nvlist_t *detector = NULL; 333*602ca9eaScth char *name; 334*602ca9eaScth data_type_t type; 335*602ca9eaScth uint8_t version; 336*602ca9eaScth char class[ERPT_CLASS_SZ]; 337*602ca9eaScth char path[MAXPATHLEN]; 338*602ca9eaScth 339*602ca9eaScth ASSERT(dip && eqdip && error_class); 340*602ca9eaScth 341*602ca9eaScth /* 342*602ca9eaScth * This interface should be called with a fm_capable eqdip. The 343*602ca9eaScth * ddi_fm_ereport_post* interfaces call with eqdip == dip, 344*602ca9eaScth * ndi_fm_ereport_post* interfaces call with eqdip == ddi_parent(dip). 345*602ca9eaScth */ 346*602ca9eaScth if (!DDI_FM_EREPORT_CAP(ddi_fm_capable(eqdip))) 347*602ca9eaScth goto err; 348*602ca9eaScth 349*602ca9eaScth /* get ereport nvlist handle */ 350*602ca9eaScth if ((sflag == DDI_SLEEP) && !panicstr) { 351*602ca9eaScth /* 352*602ca9eaScth * Driver defect - should not call with DDI_SLEEP while in 353*602ca9eaScth * interrupt context. 354*602ca9eaScth */ 355*602ca9eaScth if (servicing_interrupt()) { 356*602ca9eaScth i_ddi_drv_ereport_post(dip, DVR_ECONTEXT, NULL, sflag); 357*602ca9eaScth goto err; 358*602ca9eaScth } 359*602ca9eaScth 360*602ca9eaScth /* Use normal interfaces to allocate memory. */ 361*602ca9eaScth if ((ereport = fm_nvlist_create(NULL)) == NULL) 362*602ca9eaScth goto err; 363*602ca9eaScth nva = NULL; 364*602ca9eaScth } else { 365*602ca9eaScth /* Use errorq interfaces to avoid memory allocation. */ 366*602ca9eaScth fmhdl = DEVI(eqdip)->devi_fmhdl; 367*602ca9eaScth ASSERT(fmhdl); 368*602ca9eaScth eqep = errorq_reserve(fmhdl->fh_errorq); 369*602ca9eaScth if (eqep == NULL) 370*602ca9eaScth goto err; 371*602ca9eaScth 372*602ca9eaScth ereport = errorq_elem_nvl(fmhdl->fh_errorq, eqep); 373*602ca9eaScth nva = errorq_elem_nva(fmhdl->fh_errorq, eqep); 374*602ca9eaScth ASSERT(nva); 375*602ca9eaScth } 376*602ca9eaScth ASSERT(ereport); 377*602ca9eaScth 378*602ca9eaScth /* 379*602ca9eaScth * Form parts of an ereport: 380*602ca9eaScth * A: version 381*602ca9eaScth * B: error_class 382*602ca9eaScth * C: ena 383*602ca9eaScth * D: detector (path and optional devid authority) 384*602ca9eaScth * E: payload 385*602ca9eaScth * 386*602ca9eaScth * A: ereport version: first payload tuple must be the version. 387*602ca9eaScth */ 388*602ca9eaScth name = va_arg(ap, char *); 389*602ca9eaScth type = va_arg(ap, data_type_t); 390*602ca9eaScth version = va_arg(ap, uint_t); 391*602ca9eaScth if ((strcmp(name, FM_VERSION) != 0) || (type != DATA_TYPE_UINT8)) { 392*602ca9eaScth i_ddi_drv_ereport_post(dip, DVR_EVER, NULL, sflag); 393*602ca9eaScth goto err; 394*602ca9eaScth } 395*602ca9eaScth 396*602ca9eaScth /* B: ereport error_class: add "io." prefix to class. */ 397*602ca9eaScth (void) snprintf(class, ERPT_CLASS_SZ, "%s.%s", 398*602ca9eaScth DDI_IO_CLASS, error_class); 399*602ca9eaScth 400*602ca9eaScth /* C: ereport ena: if not passed in, generate new ena. */ 401*602ca9eaScth if (ena == 0) 402*602ca9eaScth ena = fm_ena_generate(0, FM_ENA_FMT1); 403*602ca9eaScth 404*602ca9eaScth /* D: detector: form dev scheme fmri with path and devid. */ 405*602ca9eaScth if (devpath) { 406*602ca9eaScth (void) strlcpy(path, devpath, sizeof (path)); 407*602ca9eaScth } else { 408*602ca9eaScth /* derive devpath from dip */ 409*602ca9eaScth if (dip == ddi_root_node()) 410*602ca9eaScth (void) strcpy(path, "/"); 411*602ca9eaScth else 412*602ca9eaScth (void) ddi_pathname(dip, path); 413*602ca9eaScth } 414*602ca9eaScth if (minor_name) { 415*602ca9eaScth (void) strlcat(path, ":", sizeof (path)); 416*602ca9eaScth (void) strlcat(path, minor_name, sizeof (path)); 417*602ca9eaScth } 418*602ca9eaScth detector = fm_nvlist_create(nva); 419*602ca9eaScth fm_fmri_dev_set(detector, FM_DEV_SCHEME_VERSION, NULL, path, devid); 420*602ca9eaScth 421*602ca9eaScth /* Pull parts of ereport together into ereport. */ 422*602ca9eaScth fm_ereport_set(ereport, version, class, ena, detector, NULL); 423*602ca9eaScth 424*602ca9eaScth /* Add the payload to ereport. */ 425*602ca9eaScth name = va_arg(ap, char *); 426*602ca9eaScth (void) i_fm_payload_set(ereport, name, ap); 427*602ca9eaScth 428*602ca9eaScth /* Post the ereport. */ 429*602ca9eaScth if (nva) 430*602ca9eaScth errorq_commit(fmhdl->fh_errorq, eqep, ERRORQ_ASYNC); 431*602ca9eaScth else 432*602ca9eaScth fm_ereport_post(ereport, EVCH_SLEEP); 433*602ca9eaScth goto out; 434*602ca9eaScth 435*602ca9eaScth /* Count errors as drops. */ 436*602ca9eaScth err: if (fmhdl) 437*602ca9eaScth atomic_add_64(&fmhdl->fh_kstat.fek_erpt_dropped.value.ui64, 1); 438*602ca9eaScth 439*602ca9eaScth out: if (ereport && (nva == NULL)) 440*602ca9eaScth fm_nvlist_destroy(ereport, FM_NVA_FREE); 441*602ca9eaScth if (detector && (nva == NULL)) 442*602ca9eaScth fm_nvlist_destroy(detector, FM_NVA_FREE); 443*602ca9eaScth } 444*602ca9eaScth 445*602ca9eaScth /* 4467c478bd9Sstevel@tonic-gate * Generate an error report for consumption by the Solaris Fault Manager, 447*602ca9eaScth * fmd(1M). Valid ereport classes are defined in /usr/include/sys/fm/io. 448*602ca9eaScth * 449*602ca9eaScth * The ENA should be set if this error is a result of an error status 450*602ca9eaScth * returned from ddi_dma_err_check() or ddi_acc_err_check(). Otherwise, 451*602ca9eaScth * an ENA value of 0 is appropriate. 4527c478bd9Sstevel@tonic-gate * 4537c478bd9Sstevel@tonic-gate * If sflag == DDI_NOSLEEP, ddi_fm_ereport_post () may be called 4547c478bd9Sstevel@tonic-gate * from user, kernel, interrupt or high-interrupt context. Otherwise, 4557c478bd9Sstevel@tonic-gate * ddi_fm_ereport_post() must be called from user or kernel context. 456*602ca9eaScth * 457*602ca9eaScth * The ndi_interfaces are provided for use by nexus drivers to post 458*602ca9eaScth * ereports about children who may not themselves be fm_capable. 459*602ca9eaScth * 460*602ca9eaScth * All interfaces end up in the common fm_dev_ereport_postv code above. 4617c478bd9Sstevel@tonic-gate */ 4627c478bd9Sstevel@tonic-gate void 463*602ca9eaScth ddi_fm_ereport_post(dev_info_t *dip, 464*602ca9eaScth const char *error_class, uint64_t ena, int sflag, ...) 4657c478bd9Sstevel@tonic-gate { 4667c478bd9Sstevel@tonic-gate va_list ap; 4677c478bd9Sstevel@tonic-gate 468*602ca9eaScth ASSERT(dip && error_class); 4697c478bd9Sstevel@tonic-gate va_start(ap, sflag); 470*602ca9eaScth fm_dev_ereport_postv(dip, dip, NULL, NULL, NULL, 471*602ca9eaScth error_class, ena, sflag, ap); 4727c478bd9Sstevel@tonic-gate va_end(ap); 4737c478bd9Sstevel@tonic-gate } 4747c478bd9Sstevel@tonic-gate 475*602ca9eaScth void 476*602ca9eaScth ndi_fm_ereport_post(dev_info_t *dip, 477*602ca9eaScth const char *error_class, uint64_t ena, int sflag, ...) 478*602ca9eaScth { 479*602ca9eaScth va_list ap; 480*602ca9eaScth 481*602ca9eaScth ASSERT(dip && error_class && (sflag == DDI_SLEEP)); 482*602ca9eaScth va_start(ap, sflag); 483*602ca9eaScth fm_dev_ereport_postv(dip, ddi_get_parent(dip), NULL, NULL, NULL, 484*602ca9eaScth error_class, ena, sflag, ap); 4857c478bd9Sstevel@tonic-gate va_end(ap); 4867c478bd9Sstevel@tonic-gate } 4877c478bd9Sstevel@tonic-gate 4887c478bd9Sstevel@tonic-gate /* 4897c478bd9Sstevel@tonic-gate * Driver error handling entry. Prevents multiple simultaneous calls into 4907c478bd9Sstevel@tonic-gate * driver error handling callback. 4917c478bd9Sstevel@tonic-gate * 4927c478bd9Sstevel@tonic-gate * May be called from a context consistent with the iblock_cookie returned 4937c478bd9Sstevel@tonic-gate * in ddi_fm_init(). 4947c478bd9Sstevel@tonic-gate */ 4957c478bd9Sstevel@tonic-gate void 4967c478bd9Sstevel@tonic-gate i_ddi_fm_handler_enter(dev_info_t *dip) 4977c478bd9Sstevel@tonic-gate { 4987c478bd9Sstevel@tonic-gate struct i_ddi_fmhdl *hdl = DEVI(dip)->devi_fmhdl; 4997c478bd9Sstevel@tonic-gate 5007c478bd9Sstevel@tonic-gate mutex_enter(&hdl->fh_lock); 501eae2e508Skrishnae hdl->fh_lock_owner = curthread; 5027c478bd9Sstevel@tonic-gate } 5037c478bd9Sstevel@tonic-gate 5047c478bd9Sstevel@tonic-gate /* 5057c478bd9Sstevel@tonic-gate * Driver error handling exit. 5067c478bd9Sstevel@tonic-gate * 5077c478bd9Sstevel@tonic-gate * May be called from a context consistent with the iblock_cookie returned 5087c478bd9Sstevel@tonic-gate * in ddi_fm_init(). 5097c478bd9Sstevel@tonic-gate */ 5107c478bd9Sstevel@tonic-gate void 5117c478bd9Sstevel@tonic-gate i_ddi_fm_handler_exit(dev_info_t *dip) 5127c478bd9Sstevel@tonic-gate { 5137c478bd9Sstevel@tonic-gate struct i_ddi_fmhdl *hdl = DEVI(dip)->devi_fmhdl; 5147c478bd9Sstevel@tonic-gate 515eae2e508Skrishnae hdl->fh_lock_owner = NULL; 5167c478bd9Sstevel@tonic-gate mutex_exit(&hdl->fh_lock); 5177c478bd9Sstevel@tonic-gate } 5187c478bd9Sstevel@tonic-gate 519eae2e508Skrishnae boolean_t 520eae2e508Skrishnae i_ddi_fm_handler_owned(dev_info_t *dip) 521eae2e508Skrishnae { 522eae2e508Skrishnae struct i_ddi_fmhdl *hdl = DEVI(dip)->devi_fmhdl; 523eae2e508Skrishnae 524eae2e508Skrishnae return (hdl->fh_lock_owner == curthread); 525eae2e508Skrishnae } 526eae2e508Skrishnae 5277c478bd9Sstevel@tonic-gate /* 5287c478bd9Sstevel@tonic-gate * Register a fault manager error handler for this device instance 5297c478bd9Sstevel@tonic-gate * 5307c478bd9Sstevel@tonic-gate * This function must be called from a driver's attach(9E) routine. 5317c478bd9Sstevel@tonic-gate */ 5327c478bd9Sstevel@tonic-gate void 5337c478bd9Sstevel@tonic-gate ddi_fm_handler_register(dev_info_t *dip, ddi_err_func_t handler, 5347c478bd9Sstevel@tonic-gate void *impl_data) 5357c478bd9Sstevel@tonic-gate { 5367c478bd9Sstevel@tonic-gate dev_info_t *pdip; 5377c478bd9Sstevel@tonic-gate struct i_ddi_fmhdl *pfmhdl; 5387c478bd9Sstevel@tonic-gate struct i_ddi_errhdl *new_eh; 5397c478bd9Sstevel@tonic-gate struct i_ddi_fmtgt *tgt; 5407c478bd9Sstevel@tonic-gate 5417c478bd9Sstevel@tonic-gate /* 5427c478bd9Sstevel@tonic-gate * Check for proper calling context. 5437c478bd9Sstevel@tonic-gate * The DDI configuration framework does not support 5447c478bd9Sstevel@tonic-gate * DR states to allow checking for proper invocation 5457c478bd9Sstevel@tonic-gate * from a DDI_ATTACH or DDI_RESUME. This limits context checking 5467c478bd9Sstevel@tonic-gate * to interrupt only. 5477c478bd9Sstevel@tonic-gate */ 5487c478bd9Sstevel@tonic-gate if (servicing_interrupt()) { 5497c478bd9Sstevel@tonic-gate i_ddi_drv_ereport_post(dip, DVR_ECONTEXT, NULL, DDI_NOSLEEP); 5507c478bd9Sstevel@tonic-gate return; 5517c478bd9Sstevel@tonic-gate } 5527c478bd9Sstevel@tonic-gate 5537aec1d6eScindi if (dip == ddi_root_node()) 5547aec1d6eScindi pdip = dip; 5557aec1d6eScindi else 5567c478bd9Sstevel@tonic-gate pdip = (dev_info_t *)DEVI(dip)->devi_parent; 5577c478bd9Sstevel@tonic-gate 5587c478bd9Sstevel@tonic-gate ASSERT(pdip); 5597c478bd9Sstevel@tonic-gate 5607c478bd9Sstevel@tonic-gate if (!(DDI_FM_ERRCB_CAP(ddi_fm_capable(dip)) && 5617c478bd9Sstevel@tonic-gate DDI_FM_ERRCB_CAP(ddi_fm_capable(pdip)))) { 5627c478bd9Sstevel@tonic-gate i_ddi_drv_ereport_post(dip, DVR_EFMCAP, NULL, DDI_SLEEP); 5637c478bd9Sstevel@tonic-gate return; 5647c478bd9Sstevel@tonic-gate } 5657c478bd9Sstevel@tonic-gate 5667c478bd9Sstevel@tonic-gate new_eh = kmem_zalloc(sizeof (struct i_ddi_errhdl), KM_SLEEP); 5677c478bd9Sstevel@tonic-gate new_eh->eh_func = handler; 5687c478bd9Sstevel@tonic-gate new_eh->eh_impl = impl_data; 5697c478bd9Sstevel@tonic-gate 5707c478bd9Sstevel@tonic-gate /* Add dip to parent's target list of registered error handlers */ 5717c478bd9Sstevel@tonic-gate tgt = kmem_alloc(sizeof (struct i_ddi_fmtgt), KM_SLEEP); 5727c478bd9Sstevel@tonic-gate tgt->ft_dip = dip; 5737c478bd9Sstevel@tonic-gate tgt->ft_errhdl = new_eh; 5747c478bd9Sstevel@tonic-gate 5757c478bd9Sstevel@tonic-gate i_ddi_fm_handler_enter(pdip); 5767c478bd9Sstevel@tonic-gate pfmhdl = DEVI(pdip)->devi_fmhdl; 5777c478bd9Sstevel@tonic-gate ASSERT(pfmhdl); 5787c478bd9Sstevel@tonic-gate tgt->ft_next = pfmhdl->fh_tgts; 5797c478bd9Sstevel@tonic-gate pfmhdl->fh_tgts = tgt; 5807c478bd9Sstevel@tonic-gate i_ddi_fm_handler_exit(pdip); 5817c478bd9Sstevel@tonic-gate } 5827c478bd9Sstevel@tonic-gate 5837c478bd9Sstevel@tonic-gate /* 5847c478bd9Sstevel@tonic-gate * Unregister a fault manager error handler for this device instance 5857c478bd9Sstevel@tonic-gate * 5867c478bd9Sstevel@tonic-gate * This function must be called from a drivers attach(9E) or detach(9E) 5877c478bd9Sstevel@tonic-gate * routine. 5887c478bd9Sstevel@tonic-gate */ 5897c478bd9Sstevel@tonic-gate void 5907c478bd9Sstevel@tonic-gate ddi_fm_handler_unregister(dev_info_t *dip) 5917c478bd9Sstevel@tonic-gate { 5927c478bd9Sstevel@tonic-gate dev_info_t *pdip; 5937c478bd9Sstevel@tonic-gate struct i_ddi_fmhdl *pfmhdl; 5947c478bd9Sstevel@tonic-gate struct i_ddi_fmtgt *tgt, **ptgt; 5957c478bd9Sstevel@tonic-gate 5967c478bd9Sstevel@tonic-gate /* 5977c478bd9Sstevel@tonic-gate * Check for proper calling context. 5987c478bd9Sstevel@tonic-gate * The DDI configuration framework does not support 5997c478bd9Sstevel@tonic-gate * DR states to allow checking for proper invocation 6007c478bd9Sstevel@tonic-gate * from a DDI_DETACH or DDI_SUSPEND. This limits context checking 6017c478bd9Sstevel@tonic-gate * to interrupt only. 6027c478bd9Sstevel@tonic-gate */ 6037c478bd9Sstevel@tonic-gate if (servicing_interrupt()) { 6047c478bd9Sstevel@tonic-gate i_ddi_drv_ereport_post(dip, DVR_ECONTEXT, NULL, DDI_NOSLEEP); 6057c478bd9Sstevel@tonic-gate return; 6067c478bd9Sstevel@tonic-gate } 6077c478bd9Sstevel@tonic-gate 6087aec1d6eScindi if (dip == ddi_root_node()) 6097aec1d6eScindi pdip = dip; 6107aec1d6eScindi else 6117c478bd9Sstevel@tonic-gate pdip = (dev_info_t *)DEVI(dip)->devi_parent; 6127c478bd9Sstevel@tonic-gate 6137c478bd9Sstevel@tonic-gate ASSERT(pdip); 6147c478bd9Sstevel@tonic-gate 6157c478bd9Sstevel@tonic-gate if (!(DDI_FM_ERRCB_CAP(ddi_fm_capable(dip)) && 6167c478bd9Sstevel@tonic-gate DDI_FM_ERRCB_CAP(ddi_fm_capable(pdip)))) { 6177c478bd9Sstevel@tonic-gate i_ddi_drv_ereport_post(dip, DVR_EFMCAP, NULL, DDI_SLEEP); 6187c478bd9Sstevel@tonic-gate return; 6197c478bd9Sstevel@tonic-gate } 6207c478bd9Sstevel@tonic-gate 6217c478bd9Sstevel@tonic-gate i_ddi_fm_handler_enter(pdip); 6227c478bd9Sstevel@tonic-gate pfmhdl = DEVI(pdip)->devi_fmhdl; 6237c478bd9Sstevel@tonic-gate ASSERT(pfmhdl); 6247c478bd9Sstevel@tonic-gate ptgt = &pfmhdl->fh_tgts; 6257c478bd9Sstevel@tonic-gate for (tgt = pfmhdl->fh_tgts; tgt != NULL; tgt = tgt->ft_next) { 6267c478bd9Sstevel@tonic-gate if (dip == tgt->ft_dip) { 6277c478bd9Sstevel@tonic-gate *ptgt = tgt->ft_next; 6287c478bd9Sstevel@tonic-gate kmem_free(tgt->ft_errhdl, sizeof (struct i_ddi_errhdl)); 6297c478bd9Sstevel@tonic-gate kmem_free(tgt, sizeof (struct i_ddi_fmtgt)); 6307c478bd9Sstevel@tonic-gate break; 6317c478bd9Sstevel@tonic-gate } 6327c478bd9Sstevel@tonic-gate ptgt = &tgt->ft_next; 6337c478bd9Sstevel@tonic-gate } 6347c478bd9Sstevel@tonic-gate i_ddi_fm_handler_exit(pdip); 6357c478bd9Sstevel@tonic-gate 6367c478bd9Sstevel@tonic-gate 6377c478bd9Sstevel@tonic-gate } 6387c478bd9Sstevel@tonic-gate 6397c478bd9Sstevel@tonic-gate /* 6407c478bd9Sstevel@tonic-gate * Initialize Fault Management capabilities for this device instance (dip). 6417c478bd9Sstevel@tonic-gate * When called with the following capabilities, data structures neccessary 6427c478bd9Sstevel@tonic-gate * for fault management activities are allocated and initialized. 6437c478bd9Sstevel@tonic-gate * 6447c478bd9Sstevel@tonic-gate * DDI_FM_EREPORT_CAPABLE - initialize ereport errorq and ereport 6457c478bd9Sstevel@tonic-gate * capable driver property. 6467c478bd9Sstevel@tonic-gate * 6477c478bd9Sstevel@tonic-gate * DDI_FM_ERRCB_CAPABLE - check with parent for ability to register 6487c478bd9Sstevel@tonic-gate * an error handler. 6497c478bd9Sstevel@tonic-gate * 6507c478bd9Sstevel@tonic-gate * DDI_FM_ACCCHK_CAPABLE - initialize access handle cache and acc-chk 6517c478bd9Sstevel@tonic-gate * driver property 6527c478bd9Sstevel@tonic-gate * 6537c478bd9Sstevel@tonic-gate * DDI_FM_DMACHK_CAPABLE - initialize dma handle cache and dma-chk 6547c478bd9Sstevel@tonic-gate * driver property 6557c478bd9Sstevel@tonic-gate * 6567c478bd9Sstevel@tonic-gate * A driver's FM capability level may not exceed that of its parent or 6577c478bd9Sstevel@tonic-gate * system-wide FM capability. The available capability level for this 6587c478bd9Sstevel@tonic-gate * device instance is returned in *fmcap. 6597c478bd9Sstevel@tonic-gate * 6607c478bd9Sstevel@tonic-gate * This function must be called from a driver's attach(9E) entry point. 6617c478bd9Sstevel@tonic-gate */ 6627c478bd9Sstevel@tonic-gate void 6637aec1d6eScindi ddi_fm_init(dev_info_t *dip, int *fmcap, ddi_iblock_cookie_t *ibcp) 6647c478bd9Sstevel@tonic-gate { 6657c478bd9Sstevel@tonic-gate struct dev_info *devi = DEVI(dip); 6667c478bd9Sstevel@tonic-gate struct i_ddi_fmhdl *fmhdl; 6677aec1d6eScindi ddi_iblock_cookie_t ibc; 6687c478bd9Sstevel@tonic-gate int pcap, newcap = DDI_FM_NOT_CAPABLE; 6697c478bd9Sstevel@tonic-gate 6707c478bd9Sstevel@tonic-gate if (!DEVI_IS_ATTACHING(dip)) { 6717c478bd9Sstevel@tonic-gate i_ddi_drv_ereport_post(dip, DVR_ECONTEXT, NULL, DDI_NOSLEEP); 6727c478bd9Sstevel@tonic-gate *fmcap = DDI_FM_NOT_CAPABLE; 6737c478bd9Sstevel@tonic-gate return; 6747c478bd9Sstevel@tonic-gate } 6757c478bd9Sstevel@tonic-gate 6767c478bd9Sstevel@tonic-gate if (DDI_FM_DEFAULT_CAP(*fmcap)) 6777c478bd9Sstevel@tonic-gate return; 6787c478bd9Sstevel@tonic-gate 6797c478bd9Sstevel@tonic-gate /* 6807c478bd9Sstevel@tonic-gate * Check parent for supported FM level 6817c478bd9Sstevel@tonic-gate * and correct error handling PIL 6827c478bd9Sstevel@tonic-gate */ 6837c478bd9Sstevel@tonic-gate if (dip != ddi_root_node()) { 6847c478bd9Sstevel@tonic-gate 6857c478bd9Sstevel@tonic-gate /* 6867c478bd9Sstevel@tonic-gate * Initialize the default ibc. The parent may change it 6877c478bd9Sstevel@tonic-gate * depending upon its capabilities. 6887c478bd9Sstevel@tonic-gate */ 6897aec1d6eScindi ibc = (ddi_iblock_cookie_t)ipltospl(FM_ERR_PIL); 6907c478bd9Sstevel@tonic-gate 6917aec1d6eScindi pcap = i_ndi_busop_fm_init(dip, *fmcap, &ibc); 6927c478bd9Sstevel@tonic-gate } else { 6937c478bd9Sstevel@tonic-gate pcap = *fmcap; 6947aec1d6eScindi ibc = *ibcp; 6957c478bd9Sstevel@tonic-gate } 6967c478bd9Sstevel@tonic-gate 6977c478bd9Sstevel@tonic-gate /* Initialize the per-device instance FM handle */ 6987c478bd9Sstevel@tonic-gate fmhdl = kmem_zalloc(sizeof (struct i_ddi_fmhdl), KM_SLEEP); 6997c478bd9Sstevel@tonic-gate 7007c478bd9Sstevel@tonic-gate if ((fmhdl->fh_ksp = kstat_create((char *)ddi_driver_name(dip), 7017c478bd9Sstevel@tonic-gate ddi_get_instance(dip), "fm", "misc", 7027c478bd9Sstevel@tonic-gate KSTAT_TYPE_NAMED, sizeof (struct i_ddi_fmkstat) / 7037c478bd9Sstevel@tonic-gate sizeof (kstat_named_t), KSTAT_FLAG_VIRTUAL)) == NULL) { 7047c478bd9Sstevel@tonic-gate mutex_destroy(&fmhdl->fh_lock); 7057c478bd9Sstevel@tonic-gate kmem_free(fmhdl, sizeof (struct i_ddi_fmhdl)); 7067c478bd9Sstevel@tonic-gate *fmcap = DDI_FM_NOT_CAPABLE; 7077c478bd9Sstevel@tonic-gate return; 7087c478bd9Sstevel@tonic-gate } 7097c478bd9Sstevel@tonic-gate 7107c478bd9Sstevel@tonic-gate bcopy(&ddifm_kstat_template, &fmhdl->fh_kstat, 7117c478bd9Sstevel@tonic-gate sizeof (struct i_ddi_fmkstat)); 7127c478bd9Sstevel@tonic-gate fmhdl->fh_ksp->ks_data = &fmhdl->fh_kstat; 7137c478bd9Sstevel@tonic-gate fmhdl->fh_ksp->ks_private = fmhdl; 7147c478bd9Sstevel@tonic-gate kstat_install(fmhdl->fh_ksp); 7157c478bd9Sstevel@tonic-gate 7167c478bd9Sstevel@tonic-gate fmhdl->fh_dma_cache = NULL; 7177c478bd9Sstevel@tonic-gate fmhdl->fh_acc_cache = NULL; 7187c478bd9Sstevel@tonic-gate fmhdl->fh_tgts = NULL; 7197c478bd9Sstevel@tonic-gate fmhdl->fh_dip = dip; 7207aec1d6eScindi fmhdl->fh_ibc = ibc; 7217c478bd9Sstevel@tonic-gate mutex_init(&fmhdl->fh_lock, NULL, MUTEX_DRIVER, fmhdl->fh_ibc); 7227c478bd9Sstevel@tonic-gate devi->devi_fmhdl = fmhdl; 7237c478bd9Sstevel@tonic-gate 7247c478bd9Sstevel@tonic-gate /* 7257c478bd9Sstevel@tonic-gate * Initialize support for ereport generation 7267c478bd9Sstevel@tonic-gate */ 72700d0963fSdilpreet if (DDI_FM_EREPORT_CAP(*fmcap) && DDI_FM_EREPORT_CAP(pcap)) { 7287c478bd9Sstevel@tonic-gate fmhdl->fh_errorq = ereport_errorq; 72900d0963fSdilpreet if (ddi_getprop(DDI_DEV_T_NONE, dip, DDI_PROP_DONTPASS, 7307c478bd9Sstevel@tonic-gate "fm-ereport-capable", 0) == 0) 73100d0963fSdilpreet (void) ddi_prop_create(DDI_DEV_T_NONE, dip, 7327c478bd9Sstevel@tonic-gate DDI_PROP_CANSLEEP, "fm-ereport-capable", NULL, 0); 7337c478bd9Sstevel@tonic-gate 7347c478bd9Sstevel@tonic-gate newcap |= DDI_FM_EREPORT_CAPABLE; 7357c478bd9Sstevel@tonic-gate } 7367c478bd9Sstevel@tonic-gate 7377c478bd9Sstevel@tonic-gate /* 7387c478bd9Sstevel@tonic-gate * Need cooperation of the parent for error handling 7397c478bd9Sstevel@tonic-gate */ 7407c478bd9Sstevel@tonic-gate 7417c478bd9Sstevel@tonic-gate if (DDI_FM_ERRCB_CAP(*fmcap) && DDI_FM_ERRCB_CAP(pcap)) { 74200d0963fSdilpreet if (ddi_getprop(DDI_DEV_T_NONE, dip, DDI_PROP_DONTPASS, 7437c478bd9Sstevel@tonic-gate "fm-errcb-capable", 0) == 0) 74400d0963fSdilpreet (void) ddi_prop_create(DDI_DEV_T_NONE, dip, 7457c478bd9Sstevel@tonic-gate DDI_PROP_CANSLEEP, "fm-errcb-capable", NULL, 0); 7467c478bd9Sstevel@tonic-gate 7477c478bd9Sstevel@tonic-gate newcap |= DDI_FM_ERRCB_CAPABLE; 7487c478bd9Sstevel@tonic-gate } 7497c478bd9Sstevel@tonic-gate 7507c478bd9Sstevel@tonic-gate /* 7517c478bd9Sstevel@tonic-gate * Support for DMA and Access error handling 7527c478bd9Sstevel@tonic-gate */ 7537c478bd9Sstevel@tonic-gate 7547c478bd9Sstevel@tonic-gate if (DDI_FM_DMA_ERR_CAP(*fmcap) && DDI_FM_DMA_ERR_CAP(pcap)) { 7557aec1d6eScindi i_ndi_fmc_create(&fmhdl->fh_dma_cache, 2, ibc); 7567c478bd9Sstevel@tonic-gate 7577c478bd9Sstevel@tonic-gate /* Set-up dma chk capability prop */ 75800d0963fSdilpreet if (ddi_getprop(DDI_DEV_T_NONE, dip, DDI_PROP_DONTPASS, 7597c478bd9Sstevel@tonic-gate "fm-dmachk-capable", 0) == 0) 76000d0963fSdilpreet (void) ddi_prop_create(DDI_DEV_T_NONE, dip, 7617c478bd9Sstevel@tonic-gate DDI_PROP_CANSLEEP, "fm-dmachk-capable", NULL, 0); 7627c478bd9Sstevel@tonic-gate 7637c478bd9Sstevel@tonic-gate newcap |= DDI_FM_DMACHK_CAPABLE; 7647c478bd9Sstevel@tonic-gate } 7657c478bd9Sstevel@tonic-gate 7667c478bd9Sstevel@tonic-gate if (DDI_FM_ACC_ERR_CAP(*fmcap) && DDI_FM_ACC_ERR_CAP(pcap)) { 7677aec1d6eScindi i_ndi_fmc_create(&fmhdl->fh_acc_cache, 2, ibc); 7687c478bd9Sstevel@tonic-gate /* Set-up dma chk capability prop */ 76900d0963fSdilpreet if (ddi_getprop(DDI_DEV_T_NONE, dip, DDI_PROP_DONTPASS, 7707c478bd9Sstevel@tonic-gate "fm-accchk-capable", 0) == 0) 77100d0963fSdilpreet (void) ddi_prop_create(DDI_DEV_T_NONE, dip, 7727c478bd9Sstevel@tonic-gate DDI_PROP_CANSLEEP, "fm-accchk-capable", NULL, 0); 7737c478bd9Sstevel@tonic-gate 7747c478bd9Sstevel@tonic-gate newcap |= DDI_FM_ACCCHK_CAPABLE; 7757c478bd9Sstevel@tonic-gate } 7767c478bd9Sstevel@tonic-gate 7777c478bd9Sstevel@tonic-gate /* 7787c478bd9Sstevel@tonic-gate * Return the capability support available 7797c478bd9Sstevel@tonic-gate * to this driver instance 7807c478bd9Sstevel@tonic-gate */ 7817c478bd9Sstevel@tonic-gate fmhdl->fh_cap = newcap; 7827c478bd9Sstevel@tonic-gate *fmcap = newcap; 7837aec1d6eScindi 7847aec1d6eScindi if (ibcp != NULL) 7857aec1d6eScindi *ibcp = ibc; 7867c478bd9Sstevel@tonic-gate } 7877c478bd9Sstevel@tonic-gate 7887c478bd9Sstevel@tonic-gate /* 7897c478bd9Sstevel@tonic-gate * Finalize Fault Management activities for this device instance. 7907c478bd9Sstevel@tonic-gate * Outstanding IO transaction must be completed prior to calling 7917c478bd9Sstevel@tonic-gate * this routine. All previously allocated resources and error handler 7927c478bd9Sstevel@tonic-gate * registration are cleared and deallocated. 7937c478bd9Sstevel@tonic-gate * 7947c478bd9Sstevel@tonic-gate * This function must be called from a driver's detach(9E) entry point. 7957c478bd9Sstevel@tonic-gate */ 7967c478bd9Sstevel@tonic-gate void 7977c478bd9Sstevel@tonic-gate ddi_fm_fini(dev_info_t *dip) 7987c478bd9Sstevel@tonic-gate { 7997c478bd9Sstevel@tonic-gate struct i_ddi_fmhdl *fmhdl = DEVI(dip)->devi_fmhdl; 8007c478bd9Sstevel@tonic-gate 80100d0963fSdilpreet ASSERT(fmhdl); 80200d0963fSdilpreet 8037c478bd9Sstevel@tonic-gate if (!(DEVI_IS_DETACHING(dip) || DEVI_IS_ATTACHING(dip))) { 8047c478bd9Sstevel@tonic-gate i_ddi_drv_ereport_post(dip, DVR_ECONTEXT, NULL, DDI_NOSLEEP); 8057c478bd9Sstevel@tonic-gate return; 8067c478bd9Sstevel@tonic-gate } 8077c478bd9Sstevel@tonic-gate 8087c478bd9Sstevel@tonic-gate kstat_delete(fmhdl->fh_ksp); 8097c478bd9Sstevel@tonic-gate 8107c478bd9Sstevel@tonic-gate if (DDI_FM_EREPORT_CAP(fmhdl->fh_cap)) { 81100d0963fSdilpreet (void) ddi_prop_remove(DDI_DEV_T_NONE, dip, 8127c478bd9Sstevel@tonic-gate "fm-ereport-capable"); 8137c478bd9Sstevel@tonic-gate } 8147c478bd9Sstevel@tonic-gate 8157c478bd9Sstevel@tonic-gate if (dip != ddi_root_node()) { 816cecfa358Sstephh if (DDI_FM_ERRCB_CAP(fmhdl->fh_cap)) { 8177c478bd9Sstevel@tonic-gate ddi_fm_handler_unregister(dip); 818cecfa358Sstephh (void) ddi_prop_remove(DDI_DEV_T_NONE, dip, 819cecfa358Sstephh "fm-errcb-capable"); 820cecfa358Sstephh } 8217c478bd9Sstevel@tonic-gate 8227c478bd9Sstevel@tonic-gate if (DDI_FM_DMA_ERR_CAP(fmhdl->fh_cap) || 8237c478bd9Sstevel@tonic-gate DDI_FM_ACC_ERR_CAP(fmhdl->fh_cap)) { 8247c478bd9Sstevel@tonic-gate if (fmhdl->fh_dma_cache != NULL) { 8257c478bd9Sstevel@tonic-gate i_ndi_fmc_destroy(fmhdl->fh_dma_cache); 82600d0963fSdilpreet (void) ddi_prop_remove(DDI_DEV_T_NONE, dip, 8277c478bd9Sstevel@tonic-gate "fm-dmachk-capable"); 8287c478bd9Sstevel@tonic-gate } 8297c478bd9Sstevel@tonic-gate if (fmhdl->fh_acc_cache != NULL) { 8307c478bd9Sstevel@tonic-gate i_ndi_fmc_destroy(fmhdl->fh_acc_cache); 83100d0963fSdilpreet (void) ddi_prop_remove(DDI_DEV_T_NONE, dip, 8327c478bd9Sstevel@tonic-gate "fm-accachk-capable"); 8337c478bd9Sstevel@tonic-gate } 8347c478bd9Sstevel@tonic-gate } 8357c478bd9Sstevel@tonic-gate 8367c478bd9Sstevel@tonic-gate i_ndi_busop_fm_fini(dip); 8377c478bd9Sstevel@tonic-gate } 8387c478bd9Sstevel@tonic-gate 8397c478bd9Sstevel@tonic-gate kmem_free(fmhdl, sizeof (struct i_ddi_fmhdl)); 8407c478bd9Sstevel@tonic-gate DEVI(dip)->devi_fmhdl = NULL; 8417c478bd9Sstevel@tonic-gate } 8427c478bd9Sstevel@tonic-gate 8437c478bd9Sstevel@tonic-gate /* 8447c478bd9Sstevel@tonic-gate * Return the fault management capability level for this device instance. 8457c478bd9Sstevel@tonic-gate * 8467c478bd9Sstevel@tonic-gate * This function may be called from user, kernel, or interrupt context. 8477c478bd9Sstevel@tonic-gate */ 8487c478bd9Sstevel@tonic-gate int 8497c478bd9Sstevel@tonic-gate ddi_fm_capable(dev_info_t *dip) 8507c478bd9Sstevel@tonic-gate { 8517c478bd9Sstevel@tonic-gate struct i_ddi_fmhdl *fmhdl = DEVI(dip)->devi_fmhdl; 8527c478bd9Sstevel@tonic-gate 8537c478bd9Sstevel@tonic-gate if (fmhdl == NULL) 8547c478bd9Sstevel@tonic-gate return (DDI_FM_NOT_CAPABLE); 8557c478bd9Sstevel@tonic-gate 8567c478bd9Sstevel@tonic-gate return (fmhdl->fh_cap); 8577c478bd9Sstevel@tonic-gate } 8587c478bd9Sstevel@tonic-gate 8597c478bd9Sstevel@tonic-gate /* 8607c478bd9Sstevel@tonic-gate * Routines to set and get error information for/from an access or dma handle 8617c478bd9Sstevel@tonic-gate * 8627c478bd9Sstevel@tonic-gate * These routines may be called from user, kernel, and interrupt contexts. 8637c478bd9Sstevel@tonic-gate */ 8647c478bd9Sstevel@tonic-gate void 8657c478bd9Sstevel@tonic-gate ddi_fm_acc_err_get(ddi_acc_handle_t handle, ddi_fm_error_t *de, int version) 8667c478bd9Sstevel@tonic-gate { 86700d0963fSdilpreet ndi_err_t *errp; 86800d0963fSdilpreet 86900d0963fSdilpreet if (handle == NULL) 87000d0963fSdilpreet return; 8717c478bd9Sstevel@tonic-gate 8728aec9182Sstephh if (version != DDI_FME_VER0 && version != DDI_FME_VER1) { 8737c478bd9Sstevel@tonic-gate ddi_acc_hdl_t *hp = impl_acc_hdl_get(handle); 8747c478bd9Sstevel@tonic-gate 8757c478bd9Sstevel@tonic-gate i_ddi_drv_ereport_post(hp->ah_dip, DVR_EVER, NULL, DDI_NOSLEEP); 87600d0963fSdilpreet cmn_err(CE_PANIC, "ddi_fm_acc_err_get: " 8777c478bd9Sstevel@tonic-gate "Invalid driver version\n"); 8787c478bd9Sstevel@tonic-gate } 8797c478bd9Sstevel@tonic-gate 88000d0963fSdilpreet errp = ((ddi_acc_impl_t *)handle)->ahi_err; 8817c478bd9Sstevel@tonic-gate de->fme_status = errp->err_status; 8827c478bd9Sstevel@tonic-gate de->fme_ena = errp->err_ena; 8837c478bd9Sstevel@tonic-gate de->fme_flag = errp->err_expected; 8847c478bd9Sstevel@tonic-gate de->fme_acc_handle = handle; 8857c478bd9Sstevel@tonic-gate } 8867c478bd9Sstevel@tonic-gate 8877c478bd9Sstevel@tonic-gate void 8887c478bd9Sstevel@tonic-gate ddi_fm_dma_err_get(ddi_dma_handle_t handle, ddi_fm_error_t *de, int version) 8897c478bd9Sstevel@tonic-gate { 89000d0963fSdilpreet ndi_err_t *errp; 89100d0963fSdilpreet 89200d0963fSdilpreet if (handle == NULL) 89300d0963fSdilpreet return; 8947c478bd9Sstevel@tonic-gate 8958aec9182Sstephh if (version != DDI_FME_VER0 && version != DDI_FME_VER1) { 8967c478bd9Sstevel@tonic-gate i_ddi_drv_ereport_post(((ddi_dma_impl_t *)handle)->dmai_rdip, 8977c478bd9Sstevel@tonic-gate DVR_EVER, NULL, DDI_NOSLEEP); 8987c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "ddi_fm_dma_err_get: " 8997c478bd9Sstevel@tonic-gate "Invalid driver version\n"); 9007c478bd9Sstevel@tonic-gate } 9017c478bd9Sstevel@tonic-gate 90200d0963fSdilpreet errp = &((ddi_dma_impl_t *)handle)->dmai_error; 90300d0963fSdilpreet 9047c478bd9Sstevel@tonic-gate de->fme_status = errp->err_status; 9057c478bd9Sstevel@tonic-gate de->fme_ena = errp->err_ena; 9067c478bd9Sstevel@tonic-gate de->fme_flag = errp->err_expected; 9077c478bd9Sstevel@tonic-gate de->fme_dma_handle = handle; 9087c478bd9Sstevel@tonic-gate } 9097c478bd9Sstevel@tonic-gate 9107c478bd9Sstevel@tonic-gate void 91100d0963fSdilpreet ddi_fm_acc_err_clear(ddi_acc_handle_t handle, int version) 91200d0963fSdilpreet { 91300d0963fSdilpreet ndi_err_t *errp; 91400d0963fSdilpreet 91500d0963fSdilpreet if (handle == NULL) 91600d0963fSdilpreet return; 91700d0963fSdilpreet 9188aec9182Sstephh if (version != DDI_FME_VER0 && version != DDI_FME_VER1) { 91900d0963fSdilpreet ddi_acc_hdl_t *hp = impl_acc_hdl_get(handle); 92000d0963fSdilpreet 92100d0963fSdilpreet i_ddi_drv_ereport_post(hp->ah_dip, DVR_EVER, NULL, DDI_NOSLEEP); 92200d0963fSdilpreet cmn_err(CE_PANIC, "ddi_fm_acc_err_clear: " 92300d0963fSdilpreet "Invalid driver version\n"); 92400d0963fSdilpreet } 92500d0963fSdilpreet 92600d0963fSdilpreet errp = ((ddi_acc_impl_t *)handle)->ahi_err; 92700d0963fSdilpreet errp->err_status = DDI_FM_OK; 92800d0963fSdilpreet errp->err_ena = 0; 92900d0963fSdilpreet errp->err_expected = DDI_FM_ERR_UNEXPECTED; 93000d0963fSdilpreet } 93100d0963fSdilpreet 93200d0963fSdilpreet void 93300d0963fSdilpreet ddi_fm_dma_err_clear(ddi_dma_handle_t handle, int version) 93400d0963fSdilpreet { 93500d0963fSdilpreet ndi_err_t *errp; 93600d0963fSdilpreet 93700d0963fSdilpreet if (handle == NULL) 93800d0963fSdilpreet return; 93900d0963fSdilpreet 9408aec9182Sstephh if (version != DDI_FME_VER0 && version != DDI_FME_VER1) { 94100d0963fSdilpreet i_ddi_drv_ereport_post(((ddi_dma_impl_t *)handle)->dmai_rdip, 94200d0963fSdilpreet DVR_EVER, NULL, DDI_NOSLEEP); 94300d0963fSdilpreet cmn_err(CE_PANIC, "ddi_fm_dma_err_clear: " 94400d0963fSdilpreet "Invalid driver version\n"); 94500d0963fSdilpreet } 94600d0963fSdilpreet 94700d0963fSdilpreet errp = &((ddi_dma_impl_t *)handle)->dmai_error; 94800d0963fSdilpreet 94900d0963fSdilpreet errp->err_status = DDI_FM_OK; 95000d0963fSdilpreet errp->err_ena = 0; 95100d0963fSdilpreet errp->err_expected = DDI_FM_ERR_UNEXPECTED; 95200d0963fSdilpreet } 95300d0963fSdilpreet 95400d0963fSdilpreet void 9557c478bd9Sstevel@tonic-gate i_ddi_fm_acc_err_set(ddi_acc_handle_t handle, uint64_t ena, int status, 9567c478bd9Sstevel@tonic-gate int flag) 9577c478bd9Sstevel@tonic-gate { 9587c478bd9Sstevel@tonic-gate ddi_acc_hdl_t *hdlp = impl_acc_hdl_get(handle); 9597c478bd9Sstevel@tonic-gate ddi_acc_impl_t *i_hdlp = (ddi_acc_impl_t *)handle; 9607c478bd9Sstevel@tonic-gate struct i_ddi_fmhdl *fmhdl = DEVI(hdlp->ah_dip)->devi_fmhdl; 9617c478bd9Sstevel@tonic-gate 9627c478bd9Sstevel@tonic-gate i_hdlp->ahi_err->err_ena = ena; 9637c478bd9Sstevel@tonic-gate i_hdlp->ahi_err->err_status = status; 9647c478bd9Sstevel@tonic-gate i_hdlp->ahi_err->err_expected = flag; 9657c478bd9Sstevel@tonic-gate atomic_add_64(&fmhdl->fh_kstat.fek_acc_err.value.ui64, 1); 9667c478bd9Sstevel@tonic-gate } 9677c478bd9Sstevel@tonic-gate 9687c478bd9Sstevel@tonic-gate void 9697c478bd9Sstevel@tonic-gate i_ddi_fm_dma_err_set(ddi_dma_handle_t handle, uint64_t ena, int status, 9707c478bd9Sstevel@tonic-gate int flag) 9717c478bd9Sstevel@tonic-gate { 9727c478bd9Sstevel@tonic-gate ddi_dma_impl_t *hdlp = (ddi_dma_impl_t *)handle; 9737c478bd9Sstevel@tonic-gate struct i_ddi_fmhdl *fmhdl = DEVI(hdlp->dmai_rdip)->devi_fmhdl; 9747c478bd9Sstevel@tonic-gate 9757c478bd9Sstevel@tonic-gate hdlp->dmai_error.err_ena = ena; 9767c478bd9Sstevel@tonic-gate hdlp->dmai_error.err_status = status; 9777c478bd9Sstevel@tonic-gate hdlp->dmai_error.err_expected = flag; 9787c478bd9Sstevel@tonic-gate atomic_add_64(&fmhdl->fh_kstat.fek_dma_err.value.ui64, 1); 9797c478bd9Sstevel@tonic-gate } 98000d0963fSdilpreet 98100d0963fSdilpreet ddi_fmcompare_t 98200d0963fSdilpreet i_ddi_fm_acc_err_cf_get(ddi_acc_handle_t handle) 98300d0963fSdilpreet { 98400d0963fSdilpreet ddi_acc_impl_t *i_hdlp = (ddi_acc_impl_t *)handle; 98500d0963fSdilpreet 98600d0963fSdilpreet return (i_hdlp->ahi_err->err_cf); 98700d0963fSdilpreet } 98800d0963fSdilpreet 98900d0963fSdilpreet ddi_fmcompare_t 99000d0963fSdilpreet i_ddi_fm_dma_err_cf_get(ddi_dma_handle_t handle) 99100d0963fSdilpreet { 99200d0963fSdilpreet ddi_dma_impl_t *hdlp = (ddi_dma_impl_t *)handle; 99300d0963fSdilpreet 99400d0963fSdilpreet return (hdlp->dmai_error.err_cf); 99500d0963fSdilpreet } 996