1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2015, Nexenta Systems, Inc. All rights reserved.
  24  * Copyright (c) 2012, Alexey Zaytsev <alexey.zaytsev@gmail.com>
  25  */
  26 
  27 
  28 #include <sys/modctl.h>
  29 #include <sys/blkdev.h>
  30 #include <sys/types.h>
  31 #include <sys/errno.h>
  32 #include <sys/param.h>
  33 #include <sys/stropts.h>
  34 #include <sys/stream.h>
  35 #include <sys/strsubr.h>
  36 #include <sys/kmem.h>
  37 #include <sys/conf.h>
  38 #include <sys/devops.h>
  39 #include <sys/ksynch.h>
  40 #include <sys/stat.h>
  41 #include <sys/modctl.h>
  42 #include <sys/debug.h>
  43 #include <sys/pci.h>
  44 #include <sys/sysmacros.h>
  45 #include "virtiovar.h"
  46 #include "virtioreg.h"
 
 
 812 }
 813 
 814 static int
 815 vioblk_attach(dev_info_t *devinfo, ddi_attach_cmd_t cmd)
 816 {
 817         int ret = DDI_SUCCESS;
 818         int instance;
 819         struct vioblk_softc *sc;
 820         struct virtio_softc *vsc;
 821         struct vioblk_stats *ks_data;
 822 
 823         instance = ddi_get_instance(devinfo);
 824 
 825         switch (cmd) {
 826         case DDI_ATTACH:
 827                 break;
 828 
 829         case DDI_RESUME:
 830         case DDI_PM_RESUME:
 831                 dev_err(devinfo, CE_WARN, "resume not supported yet");
 832                 ret = DDI_FAILURE;
 833                 goto exit;
 834 
 835         default:
 836                 dev_err(devinfo, CE_WARN, "cmd 0x%x not recognized", cmd);
 837                 ret = DDI_FAILURE;
 838                 goto exit;
 839         }
 840 
 841         sc = kmem_zalloc(sizeof (struct vioblk_softc), KM_SLEEP);
 842         ddi_set_driver_private(devinfo, sc);
 843 
 844         vsc = &sc->sc_virtio;
 845 
 846         /* Duplicate for faster access / less typing */
 847         sc->sc_dev = devinfo;
 848         vsc->sc_dev = devinfo;
 849 
 850         cv_init(&sc->cv_devid, NULL, CV_DRIVER, NULL);
 851         mutex_init(&sc->lock_devid, NULL, MUTEX_DRIVER, NULL);
 852 
 853         /*
 854          * Initialize interrupt kstat.  This should not normally fail, since
 855          * we don't use a persistent stat.  We do it this way to avoid having
 856          * to test for it at run time on the hot path.
 857          */
 858         sc->sc_intrstat = kstat_create("vioblk", instance,
 
1012          * If they ever get split, don't forget to add a call here.
1013          */
1014 exit_enable_ints:
1015         virtio_stop_vq_intr(sc->sc_vq);
1016         bd_free_handle(sc->bd_h);
1017         vioblk_free_reqs(sc);
1018 exit_alloc2:
1019         virtio_free_vq(sc->sc_vq);
1020 exit_alloc1:
1021 exit_features:
1022         virtio_release_ints(&sc->sc_virtio);
1023 exit_int:
1024         virtio_set_status(&sc->sc_virtio, VIRTIO_CONFIG_DEVICE_STATUS_FAILED);
1025         ddi_regs_map_free(&sc->sc_virtio.sc_ioh);
1026 exit_map:
1027         kstat_delete(sc->sc_intrstat);
1028 exit_intrstat:
1029         mutex_destroy(&sc->lock_devid);
1030         cv_destroy(&sc->cv_devid);
1031         kmem_free(sc, sizeof (struct vioblk_softc));
1032 exit:
1033         return (ret);
1034 }
1035 
1036 static int
1037 vioblk_detach(dev_info_t *devinfo, ddi_detach_cmd_t cmd)
1038 {
1039         struct vioblk_softc *sc = ddi_get_driver_private(devinfo);
1040 
1041         switch (cmd) {
1042         case DDI_DETACH:
1043                 break;
1044 
1045         case DDI_PM_SUSPEND:
1046                 cmn_err(CE_WARN, "suspend not supported yet");
1047                 return (DDI_FAILURE);
1048 
1049         default:
1050                 cmn_err(CE_WARN, "cmd 0x%x unrecognized", cmd);
1051                 return (DDI_FAILURE);
1052         }
1053 
 
 | 
   1 /*
   2  * This file and its contents are supplied under the terms of the
   3  * Common Development and Distribution License ("CDDL"), version 1.0.
   4  * You may only use this file in accordance with the terms of version
   5  * 1.0 of the CDDL.
   6  *
   7  * A full copy of the text of the CDDL should have accompanied this
   8  * source.  A copy of the CDDL is also available via the Internet at
   9  * http://www.illumos.org/license/CDDL.
  10  */
  11 
  12 /*
  13  * Copyright (c) 2015, Nexenta Systems, Inc. All rights reserved.
  14  * Copyright (c) 2012, Alexey Zaytsev <alexey.zaytsev@gmail.com>
  15  * Copyright 2017, Joyent Inc.
  16  */
  17 
  18 /*
  19  * VirtIO block device driver
  20  */
  21 
  22 #include <sys/modctl.h>
  23 #include <sys/blkdev.h>
  24 #include <sys/types.h>
  25 #include <sys/errno.h>
  26 #include <sys/param.h>
  27 #include <sys/stropts.h>
  28 #include <sys/stream.h>
  29 #include <sys/strsubr.h>
  30 #include <sys/kmem.h>
  31 #include <sys/conf.h>
  32 #include <sys/devops.h>
  33 #include <sys/ksynch.h>
  34 #include <sys/stat.h>
  35 #include <sys/modctl.h>
  36 #include <sys/debug.h>
  37 #include <sys/pci.h>
  38 #include <sys/sysmacros.h>
  39 #include "virtiovar.h"
  40 #include "virtioreg.h"
 
 806 }
 807 
 808 static int
 809 vioblk_attach(dev_info_t *devinfo, ddi_attach_cmd_t cmd)
 810 {
 811         int ret = DDI_SUCCESS;
 812         int instance;
 813         struct vioblk_softc *sc;
 814         struct virtio_softc *vsc;
 815         struct vioblk_stats *ks_data;
 816 
 817         instance = ddi_get_instance(devinfo);
 818 
 819         switch (cmd) {
 820         case DDI_ATTACH:
 821                 break;
 822 
 823         case DDI_RESUME:
 824         case DDI_PM_RESUME:
 825                 dev_err(devinfo, CE_WARN, "resume not supported yet");
 826                 return (DDI_FAILURE);
 827 
 828         default:
 829                 dev_err(devinfo, CE_WARN, "cmd 0x%x not recognized", cmd);
 830                 return (DDI_FAILURE);
 831         }
 832 
 833         sc = kmem_zalloc(sizeof (struct vioblk_softc), KM_SLEEP);
 834         ddi_set_driver_private(devinfo, sc);
 835 
 836         vsc = &sc->sc_virtio;
 837 
 838         /* Duplicate for faster access / less typing */
 839         sc->sc_dev = devinfo;
 840         vsc->sc_dev = devinfo;
 841 
 842         cv_init(&sc->cv_devid, NULL, CV_DRIVER, NULL);
 843         mutex_init(&sc->lock_devid, NULL, MUTEX_DRIVER, NULL);
 844 
 845         /*
 846          * Initialize interrupt kstat.  This should not normally fail, since
 847          * we don't use a persistent stat.  We do it this way to avoid having
 848          * to test for it at run time on the hot path.
 849          */
 850         sc->sc_intrstat = kstat_create("vioblk", instance,
 
1004          * If they ever get split, don't forget to add a call here.
1005          */
1006 exit_enable_ints:
1007         virtio_stop_vq_intr(sc->sc_vq);
1008         bd_free_handle(sc->bd_h);
1009         vioblk_free_reqs(sc);
1010 exit_alloc2:
1011         virtio_free_vq(sc->sc_vq);
1012 exit_alloc1:
1013 exit_features:
1014         virtio_release_ints(&sc->sc_virtio);
1015 exit_int:
1016         virtio_set_status(&sc->sc_virtio, VIRTIO_CONFIG_DEVICE_STATUS_FAILED);
1017         ddi_regs_map_free(&sc->sc_virtio.sc_ioh);
1018 exit_map:
1019         kstat_delete(sc->sc_intrstat);
1020 exit_intrstat:
1021         mutex_destroy(&sc->lock_devid);
1022         cv_destroy(&sc->cv_devid);
1023         kmem_free(sc, sizeof (struct vioblk_softc));
1024         return (DDI_FAILURE);
1025 }
1026 
1027 static int
1028 vioblk_detach(dev_info_t *devinfo, ddi_detach_cmd_t cmd)
1029 {
1030         struct vioblk_softc *sc = ddi_get_driver_private(devinfo);
1031 
1032         switch (cmd) {
1033         case DDI_DETACH:
1034                 break;
1035 
1036         case DDI_PM_SUSPEND:
1037                 cmn_err(CE_WARN, "suspend not supported yet");
1038                 return (DDI_FAILURE);
1039 
1040         default:
1041                 cmn_err(CE_WARN, "cmd 0x%x unrecognized", cmd);
1042                 return (DDI_FAILURE);
1043         }
1044 
 
 |