14d0e5007SSukumar Swaminathan /*
24d0e5007SSukumar Swaminathan * CDDL HEADER START
34d0e5007SSukumar Swaminathan *
44d0e5007SSukumar Swaminathan * The contents of this file are subject to the terms of the
54d0e5007SSukumar Swaminathan * Common Development and Distribution License (the "License").
64d0e5007SSukumar Swaminathan * You may not use this file except in compliance with the License.
74d0e5007SSukumar Swaminathan *
84d0e5007SSukumar Swaminathan * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
94d0e5007SSukumar Swaminathan * or http://www.opensolaris.org/os/licensing.
104d0e5007SSukumar Swaminathan * See the License for the specific language governing permissions
114d0e5007SSukumar Swaminathan * and limitations under the License.
124d0e5007SSukumar Swaminathan *
134d0e5007SSukumar Swaminathan * When distributing Covered Code, include this CDDL HEADER in each
144d0e5007SSukumar Swaminathan * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
154d0e5007SSukumar Swaminathan * If applicable, add the following below this CDDL HEADER, with the
164d0e5007SSukumar Swaminathan * fields enclosed by brackets "[]" replaced with your own identifying
174d0e5007SSukumar Swaminathan * information: Portions Copyright [yyyy] [name of copyright owner]
184d0e5007SSukumar Swaminathan *
194d0e5007SSukumar Swaminathan * CDDL HEADER END
204d0e5007SSukumar Swaminathan */
214d0e5007SSukumar Swaminathan
22*3abb112fSGarrett D'Amore /* Copyright © 2003-2011 Emulex. All rights reserved. */
234d0e5007SSukumar Swaminathan
244d0e5007SSukumar Swaminathan /*
254d0e5007SSukumar Swaminathan * Source file containing the implementation of fma support in driver
264d0e5007SSukumar Swaminathan *
274d0e5007SSukumar Swaminathan */
284d0e5007SSukumar Swaminathan
294d0e5007SSukumar Swaminathan #include <oce_impl.h>
304d0e5007SSukumar Swaminathan
314d0e5007SSukumar Swaminathan static int oce_fm_error_cb(dev_info_t *dip, ddi_fm_error_t *err,
324d0e5007SSukumar Swaminathan const void *impl_data);
334d0e5007SSukumar Swaminathan
344d0e5007SSukumar Swaminathan /*
354d0e5007SSukumar Swaminathan * function to initialize driver fma support
364d0e5007SSukumar Swaminathan *
374d0e5007SSukumar Swaminathan * dev - software handle to the device
384d0e5007SSukumar Swaminathan *
394d0e5007SSukumar Swaminathan * return none
404d0e5007SSukumar Swaminathan */
414d0e5007SSukumar Swaminathan
424d0e5007SSukumar Swaminathan void
oce_fm_init(struct oce_dev * dev)434d0e5007SSukumar Swaminathan oce_fm_init(struct oce_dev *dev)
444d0e5007SSukumar Swaminathan {
454d0e5007SSukumar Swaminathan ddi_iblock_cookie_t ibc;
464d0e5007SSukumar Swaminathan
474d0e5007SSukumar Swaminathan if (dev->fm_caps == DDI_FM_NOT_CAPABLE) {
484d0e5007SSukumar Swaminathan return;
494d0e5007SSukumar Swaminathan }
504d0e5007SSukumar Swaminathan
514d0e5007SSukumar Swaminathan oce_set_dma_fma_flags(dev->fm_caps);
524d0e5007SSukumar Swaminathan oce_set_reg_fma_flags(dev->fm_caps);
534d0e5007SSukumar Swaminathan
544d0e5007SSukumar Swaminathan (void) ddi_fm_init(dev->dip, &dev->fm_caps, &ibc);
554d0e5007SSukumar Swaminathan if (DDI_FM_EREPORT_CAP(dev->fm_caps) ||
564d0e5007SSukumar Swaminathan DDI_FM_ERRCB_CAP(dev->fm_caps)) {
574d0e5007SSukumar Swaminathan pci_ereport_setup(dev->dip);
584d0e5007SSukumar Swaminathan }
594d0e5007SSukumar Swaminathan if (DDI_FM_ERRCB_CAP(dev->fm_caps)) {
604d0e5007SSukumar Swaminathan ddi_fm_handler_register(dev->dip, oce_fm_error_cb,
614d0e5007SSukumar Swaminathan (void *)dev);
624d0e5007SSukumar Swaminathan }
634d0e5007SSukumar Swaminathan } /* oce_fm_init */
644d0e5007SSukumar Swaminathan
654d0e5007SSukumar Swaminathan /*
664d0e5007SSukumar Swaminathan * function to deinitialize driver fma support
674d0e5007SSukumar Swaminathan *
684d0e5007SSukumar Swaminathan * dev - software handle to the device
694d0e5007SSukumar Swaminathan *
704d0e5007SSukumar Swaminathan * return none
714d0e5007SSukumar Swaminathan */
724d0e5007SSukumar Swaminathan void
oce_fm_fini(struct oce_dev * dev)734d0e5007SSukumar Swaminathan oce_fm_fini(struct oce_dev *dev)
744d0e5007SSukumar Swaminathan {
754d0e5007SSukumar Swaminathan if (dev->fm_caps == DDI_FM_NOT_CAPABLE) {
764d0e5007SSukumar Swaminathan return;
774d0e5007SSukumar Swaminathan }
784d0e5007SSukumar Swaminathan if (DDI_FM_ERRCB_CAP(dev->fm_caps)) {
794d0e5007SSukumar Swaminathan ddi_fm_handler_unregister(dev->dip);
804d0e5007SSukumar Swaminathan }
814d0e5007SSukumar Swaminathan if (DDI_FM_EREPORT_CAP(dev->fm_caps) ||
824d0e5007SSukumar Swaminathan DDI_FM_ERRCB_CAP(dev->fm_caps)) {
834d0e5007SSukumar Swaminathan pci_ereport_teardown(dev->dip);
844d0e5007SSukumar Swaminathan }
854d0e5007SSukumar Swaminathan (void) ddi_fm_fini(dev->dip);
864d0e5007SSukumar Swaminathan } /* oce_fm_fini */
874d0e5007SSukumar Swaminathan
884d0e5007SSukumar Swaminathan /*
894d0e5007SSukumar Swaminathan * function to check the access handle
904d0e5007SSukumar Swaminathan *
914d0e5007SSukumar Swaminathan * dev - software handle to the device
924d0e5007SSukumar Swaminathan * acc_handle - access handle
934d0e5007SSukumar Swaminathan *
944d0e5007SSukumar Swaminathan * return fm error status
954d0e5007SSukumar Swaminathan */
964d0e5007SSukumar Swaminathan int
oce_fm_check_acc_handle(struct oce_dev * dev,ddi_acc_handle_t acc_handle)974d0e5007SSukumar Swaminathan oce_fm_check_acc_handle(struct oce_dev *dev, ddi_acc_handle_t acc_handle)
984d0e5007SSukumar Swaminathan {
994d0e5007SSukumar Swaminathan ddi_fm_error_t fme;
1004d0e5007SSukumar Swaminathan
101*3abb112fSGarrett D'Amore
1024d0e5007SSukumar Swaminathan if (!DDI_FM_ACC_ERR_CAP(dev->fm_caps)) {
1034d0e5007SSukumar Swaminathan return (DDI_FM_OK);
1044d0e5007SSukumar Swaminathan }
1054d0e5007SSukumar Swaminathan (void) ddi_fm_acc_err_get(acc_handle, &fme, DDI_FME_VERSION);
1064d0e5007SSukumar Swaminathan (void) ddi_fm_acc_err_clear(acc_handle, DDI_FME_VERSION);
1074d0e5007SSukumar Swaminathan
1084d0e5007SSukumar Swaminathan return (fme.fme_status);
1094d0e5007SSukumar Swaminathan } /* oce_fm_chk_ach */
1104d0e5007SSukumar Swaminathan
1114d0e5007SSukumar Swaminathan /*
1124d0e5007SSukumar Swaminathan * function to check error updates associated with a dma handle
1134d0e5007SSukumar Swaminathan *
1144d0e5007SSukumar Swaminathan * dev - software handle to the device
1154d0e5007SSukumar Swaminathan * dma_handle - dma handle to the resources on which to check for errors
1164d0e5007SSukumar Swaminathan *
1174d0e5007SSukumar Swaminathan * return error code. DDI_FM_OK => no error
1184d0e5007SSukumar Swaminathan */
1194d0e5007SSukumar Swaminathan int
oce_fm_check_dma_handle(struct oce_dev * dev,ddi_dma_handle_t dma_handle)1204d0e5007SSukumar Swaminathan oce_fm_check_dma_handle(struct oce_dev *dev, ddi_dma_handle_t dma_handle)
1214d0e5007SSukumar Swaminathan {
1224d0e5007SSukumar Swaminathan ddi_fm_error_t fme;
1234d0e5007SSukumar Swaminathan
1244d0e5007SSukumar Swaminathan if (!DDI_FM_DMA_ERR_CAP(dev->fm_caps)) {
1254d0e5007SSukumar Swaminathan return (DDI_FM_OK);
1264d0e5007SSukumar Swaminathan }
1274d0e5007SSukumar Swaminathan
1284d0e5007SSukumar Swaminathan (void) ddi_fm_dma_err_get(dma_handle, &fme, DDI_FME_VERSION);
1294d0e5007SSukumar Swaminathan return (fme.fme_status);
1304d0e5007SSukumar Swaminathan } /* oce_fm_chk_dh */
1314d0e5007SSukumar Swaminathan
1324d0e5007SSukumar Swaminathan /*
1334d0e5007SSukumar Swaminathan * function to report an error to the FMA framework
1344d0e5007SSukumar Swaminathan *
1354d0e5007SSukumar Swaminathan * dev - software handle to the device
1364d0e5007SSukumar Swaminathan * detail - OS defined string that provides the kind of error to report
1374d0e5007SSukumar Swaminathan */
1384d0e5007SSukumar Swaminathan void
oce_fm_ereport(struct oce_dev * dev,char * detail)1394d0e5007SSukumar Swaminathan oce_fm_ereport(struct oce_dev *dev, char *detail)
1404d0e5007SSukumar Swaminathan {
1414d0e5007SSukumar Swaminathan uint64_t ena;
1424d0e5007SSukumar Swaminathan char buf[FM_MAX_CLASS];
1434d0e5007SSukumar Swaminathan
1444d0e5007SSukumar Swaminathan if (!DDI_FM_EREPORT_CAP(dev->fm_caps) || detail == NULL) {
1454d0e5007SSukumar Swaminathan return;
1464d0e5007SSukumar Swaminathan }
1474d0e5007SSukumar Swaminathan (void) snprintf(buf, FM_MAX_CLASS, "%s.%s", DDI_FM_DEVICE, detail);
1484d0e5007SSukumar Swaminathan ena = fm_ena_generate(0, FM_ENA_FMT1);
1494d0e5007SSukumar Swaminathan if (DDI_FM_EREPORT_CAP(dev->fm_caps)) {
1504d0e5007SSukumar Swaminathan ddi_fm_ereport_post(dev->dip, buf, ena, DDI_NOSLEEP,
1514d0e5007SSukumar Swaminathan FM_VERSION, DATA_TYPE_UINT8, FM_EREPORT_VERS0, NULL);
1524d0e5007SSukumar Swaminathan }
1534d0e5007SSukumar Swaminathan } /* oce_fm_ereport */
1544d0e5007SSukumar Swaminathan
1554d0e5007SSukumar Swaminathan /*
1564d0e5007SSukumar Swaminathan * callback function registered with the FMA infrastructure. This callback is
1574d0e5007SSukumar Swaminathan * called by the nexux driver if there is an error with the device
1584d0e5007SSukumar Swaminathan *
1594d0e5007SSukumar Swaminathan * dip - dev_info_t structure for this device
1604d0e5007SSukumar Swaminathan * err - error information provided by the nexus
1614d0e5007SSukumar Swaminathan * impl_data - callback data
1624d0e5007SSukumar Swaminathan *
1634d0e5007SSukumar Swaminathan * return error code. DDI_FM_OK => no error
1644d0e5007SSukumar Swaminathan */
1654d0e5007SSukumar Swaminathan static int
oce_fm_error_cb(dev_info_t * dip,ddi_fm_error_t * err,const void * impl_data)1664d0e5007SSukumar Swaminathan oce_fm_error_cb(dev_info_t *dip, ddi_fm_error_t *err, const void *impl_data)
1674d0e5007SSukumar Swaminathan {
1684d0e5007SSukumar Swaminathan _NOTE(ARGUNUSED(impl_data));
1694d0e5007SSukumar Swaminathan /* Driver must handle the dma/access error */
1704d0e5007SSukumar Swaminathan pci_ereport_post(dip, err, NULL);
1714d0e5007SSukumar Swaminathan return (err->fme_status);
1724d0e5007SSukumar Swaminathan }
173