Print this page
OS-1996 mpt_sas: allow physical topology enumeration in libtopo
Reviewed by: Keith Wesolowski <keith.wesolowski@joyent.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/io/scsi/adapters/mpt_sas/mptsas.c
          +++ new/usr/src/uts/common/io/scsi/adapters/mpt_sas/mptsas.c
↓ open down ↓ 14 lines elided ↑ open up ↑
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  24   24   * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
       25 + * Copyright (c) 2013, Joyent, Inc. All rights reserved.
  25   26   */
  26   27  
  27   28  /*
  28   29   * Copyright (c) 2000 to 2010, LSI Corporation.
  29   30   * All rights reserved.
  30   31   *
  31   32   * Redistribution and use in source and binary forms of all code within
  32   33   * this file that is exclusively owned by LSI, with or without
  33   34   * modification, is permitted provided that, in addition to the CDDL 1.0
  34   35   * License requirements, the following conditions are met:
↓ open down ↓ 27 lines elided ↑ open up ↑
  62   63  
  63   64  /*
  64   65   * standard header files.
  65   66   */
  66   67  #include <sys/note.h>
  67   68  #include <sys/scsi/scsi.h>
  68   69  #include <sys/pci.h>
  69   70  #include <sys/file.h>
  70   71  #include <sys/cpuvar.h>
  71   72  #include <sys/policy.h>
       73 +#include <sys/model.h>
  72   74  #include <sys/sysevent.h>
  73   75  #include <sys/sysevent/eventdefs.h>
  74   76  #include <sys/sysevent/dr.h>
  75   77  #include <sys/sata/sata_defs.h>
  76   78  #include <sys/scsi/generic/sas.h>
  77   79  #include <sys/scsi/impl/scsi_sas.h>
  78   80  
  79   81  #pragma pack(1)
  80   82  #include <sys/scsi/adapters/mpt_sas/mpi/mpi2_type.h>
  81   83  #include <sys/scsi/adapters/mpt_sas/mpi/mpi2.h>
↓ open down ↓ 11862 lines elided ↑ open up ↑
11944 11946                  }
11945 11947          } else {
11946 11948                  status = EFAULT;
11947 11949          }
11948 11950  
11949 11951          mutex_exit(&mpt->m_mutex);
11950 11952          return (status);
11951 11953  }
11952 11954  
11953 11955  static int
     11956 +get_disk_info(mptsas_t *mpt, intptr_t data, int mode)
     11957 +{
     11958 +        int i = 0;
     11959 +        int count = 0;
     11960 +        int ret = 0;
     11961 +        mptsas_target_t *ptgt;
     11962 +        mptsas_disk_info_t *di;
     11963 +        STRUCT_DECL(mptsas_get_disk_info, gdi);
     11964 +
     11965 +        STRUCT_INIT(gdi, get_udatamodel());
     11966 +
     11967 +        if (ddi_copyin((void *)data, STRUCT_BUF(gdi), STRUCT_SIZE(gdi),
     11968 +            mode) != 0) {
     11969 +                return (EFAULT);
     11970 +        }
     11971 +
     11972 +        /* Find out how many targets there are. */
     11973 +        mutex_enter(&mpt->m_mutex);
     11974 +        ptgt = (mptsas_target_t *)mptsas_hash_traverse(&mpt->m_active->m_tgttbl,
     11975 +            MPTSAS_HASH_FIRST);
     11976 +        while (ptgt != NULL) {
     11977 +                count++;
     11978 +                ptgt = (mptsas_target_t *)mptsas_hash_traverse(
     11979 +                    &mpt->m_active->m_tgttbl, MPTSAS_HASH_NEXT);
     11980 +        }
     11981 +        mutex_exit(&mpt->m_mutex);
     11982 +
     11983 +        /*
     11984 +         * If we haven't been asked to copy out information on each target,
     11985 +         * then just return the count.
     11986 +         */
     11987 +        STRUCT_FSET(gdi, DiskCount, count);
     11988 +        if (STRUCT_FGETP(gdi, PtrDiskInfoArray) == NULL)
     11989 +                goto copy_out;
     11990 +
     11991 +        /*
     11992 +         * If we haven't been given a large enough buffer to copy out into,
     11993 +         * let the caller know.
     11994 +         */
     11995 +        if (STRUCT_FGET(gdi, DiskInfoArraySize) <
     11996 +            count * sizeof (mptsas_disk_info_t)) {
     11997 +                ret = ENOSPC;
     11998 +                goto copy_out;
     11999 +        }
     12000 +
     12001 +        di = kmem_zalloc(count * sizeof (mptsas_disk_info_t), KM_SLEEP);
     12002 +
     12003 +        mutex_enter(&mpt->m_mutex);
     12004 +        ptgt = (mptsas_target_t *)mptsas_hash_traverse(&mpt->m_active->m_tgttbl,
     12005 +            MPTSAS_HASH_FIRST);
     12006 +        while (ptgt != NULL) {
     12007 +                if (i >= count) {
     12008 +                        /*
     12009 +                         * The number of targets changed while we weren't
     12010 +                         * looking, so give up.
     12011 +                         */
     12012 +                        mutex_exit(&mpt->m_mutex);
     12013 +                        kmem_free(di, count * sizeof (mptsas_disk_info_t));
     12014 +                        return (EAGAIN);
     12015 +                }
     12016 +                di[i].Instance = mpt->m_instance;
     12017 +                di[i].Enclosure = ptgt->m_enclosure;
     12018 +                di[i].Slot = ptgt->m_slot_num;
     12019 +                di[i].SasAddress = ptgt->m_sas_wwn;
     12020 +
     12021 +                ptgt = (mptsas_target_t *)mptsas_hash_traverse(
     12022 +                    &mpt->m_active->m_tgttbl, MPTSAS_HASH_NEXT);
     12023 +                i++;
     12024 +        }
     12025 +        mutex_exit(&mpt->m_mutex);
     12026 +        STRUCT_FSET(gdi, DiskCount, i);
     12027 +
     12028 +        /* Copy out the disk information to the caller. */
     12029 +        if (ddi_copyout((void *)di, STRUCT_FGETP(gdi, PtrDiskInfoArray),
     12030 +            i * sizeof (mptsas_disk_info_t), mode) != 0) {
     12031 +                ret = EFAULT;
     12032 +        }
     12033 +
     12034 +        kmem_free(di, count * sizeof (mptsas_disk_info_t));
     12035 +
     12036 +copy_out:
     12037 +        if (ddi_copyout(STRUCT_BUF(gdi), (void *)data, STRUCT_SIZE(gdi),
     12038 +            mode) != 0) {
     12039 +                ret = EFAULT;
     12040 +        }
     12041 +
     12042 +        return (ret);
     12043 +}
     12044 +
     12045 +static int
11954 12046  mptsas_ioctl(dev_t dev, int cmd, intptr_t data, int mode, cred_t *credp,
11955 12047      int *rval)
11956 12048  {
11957 12049          int                     status = 0;
11958 12050          mptsas_t                *mpt;
11959 12051          mptsas_update_flash_t   flashdata;
11960 12052          mptsas_pass_thru_t      passthru_data;
11961 12053          mptsas_adapter_data_t   adapter_data;
11962 12054          mptsas_pci_info_t       pci_info;
11963 12055          int                     copylen;
↓ open down ↓ 100 lines elided ↑ open up ↑
12064 12156                              DDI_SUCCESS) {
12065 12157                                  NDBG14(("mptsas_ioctl: set LED for tgt %s "
12066 12158                                      "failed %x", addr, slotstatus));
12067 12159                          }
12068 12160                          mutex_exit(&mpt->m_mutex);
12069 12161                          ndi_dc_freehdl(dcp);
12070 12162                  }
12071 12163                  goto out;
12072 12164          }
12073 12165          switch (cmd) {
     12166 +                case MPTIOCTL_GET_DISK_INFO:
     12167 +                        status = get_disk_info(mpt, data, mode);
     12168 +                        break;
12074 12169                  case MPTIOCTL_UPDATE_FLASH:
12075 12170                          if (ddi_copyin((void *)data, &flashdata,
12076 12171                                  sizeof (struct mptsas_update_flash), mode)) {
12077 12172                                  status = EFAULT;
12078 12173                                  break;
12079 12174                          }
12080 12175  
12081 12176                          mutex_enter(&mpt->m_mutex);
12082 12177                          if (mptsas_update_flash(mpt,
12083 12178                              (caddr_t)(long)flashdata.PtrBuffer,
↓ open down ↓ 4116 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX