linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / drivers / message / fusion / mptsas.c
index af6ec55..2512d0e 100644 (file)
@@ -91,7 +91,6 @@ enum mptsas_hotplug_action {
        MPTSAS_DEL_DEVICE,
        MPTSAS_ADD_RAID,
        MPTSAS_DEL_RAID,
-       MPTSAS_IGNORE_EVENT,
 };
 
 struct mptsas_hotplug_event {
@@ -105,13 +104,6 @@ struct mptsas_hotplug_event {
        u16                     handle;
        u16                     parent_handle;
        u8                      phy_id;
-       u8                      phys_disk_num;
-       u8                      phys_disk_num_valid;
-};
-
-struct mptsas_discovery_event {
-       struct work_struct      work;
-       MPT_ADAPTER             *ioc;
 };
 
 /*
@@ -125,8 +117,6 @@ struct mptsas_discovery_event {
 struct mptsas_devinfo {
        u16     handle;         /* unique id to address this device */
        u16     handle_parent;  /* unique id to address parent device */
-       u16     handle_enclosure; /* enclosure identifier of the enclosure */
-       u16     slot;           /* physical slot in enclosure */
        u8      phy_id;         /* phy number of parent device */
        u8      port_id;        /* sas physical port this device
                                   is assoc'd with */
@@ -147,7 +137,6 @@ struct mptsas_phyinfo {
        struct mptsas_devinfo attached; /* point to attached device info */
        struct sas_phy *phy;
        struct sas_rphy *rphy;
-       struct scsi_target *starget;
 };
 
 struct mptsas_portinfo {
@@ -157,17 +146,6 @@ struct mptsas_portinfo {
        struct mptsas_phyinfo *phy_info;
 };
 
-struct mptsas_enclosure {
-       u64     enclosure_logical_id;   /* The WWN for the enclosure */
-       u16     enclosure_handle;       /* unique id to address this */
-       u16     flags;                  /* details enclosure management */
-       u16     num_slot;               /* num slots */
-       u16     start_slot;             /* first slot */
-       u8      start_id;               /* starting logical target id */
-       u8      start_channel;          /* starting logical channel id */
-       u8      sep_id;                 /* SEP device logical target id */
-       u8      sep_channel;            /* SEP channel logical channel id */
-};
 
 #ifdef SASDEBUG
 static void mptsas_print_phy_data(MPI_SAS_IO_UNIT0_PHY_DATA *phy_data)
@@ -227,7 +205,6 @@ static void mptsas_print_device_pg0(SasDevicePage0_t *pg0)
 
        printk("---- SAS DEVICE PAGE 0 ---------\n");
        printk("Handle=0x%X\n" ,le16_to_cpu(pg0->DevHandle));
-       printk("Parent Handle=0x%X\n" ,le16_to_cpu(pg0->ParentDevHandle));
        printk("Enclosure Handle=0x%X\n", le16_to_cpu(pg0->EnclosureHandle));
        printk("Slot=0x%X\n", le16_to_cpu(pg0->Slot));
        printk("SAS Address=0x%llX\n", le64_to_cpu(sas_address));
@@ -266,139 +243,6 @@ static void mptsas_print_expander_pg1(SasExpanderPage1_t *pg1)
 #define mptsas_print_expander_pg1(pg1)         do { } while (0)
 #endif
 
-static inline MPT_ADAPTER *phy_to_ioc(struct sas_phy *phy)
-{
-       struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
-       return ((MPT_SCSI_HOST *)shost->hostdata)->ioc;
-}
-
-static inline MPT_ADAPTER *rphy_to_ioc(struct sas_rphy *rphy)
-{
-       struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent);
-       return ((MPT_SCSI_HOST *)shost->hostdata)->ioc;
-}
-
-/*
- * mptsas_find_portinfo_by_handle
- *
- * This function should be called with the sas_topology_mutex already held
- */
-static struct mptsas_portinfo *
-mptsas_find_portinfo_by_handle(MPT_ADAPTER *ioc, u16 handle)
-{
-       struct mptsas_portinfo *port_info, *rc=NULL;
-       int i;
-
-       list_for_each_entry(port_info, &ioc->sas_topology, list)
-               for (i = 0; i < port_info->num_phys; i++)
-                       if (port_info->phy_info[i].identify.handle == handle) {
-                               rc = port_info;
-                               goto out;
-                       }
- out:
-       return rc;
-}
-
-/*
- * Returns true if there is a scsi end device
- */
-static inline int
-mptsas_is_end_device(struct mptsas_devinfo * attached)
-{
-       if ((attached->handle) &&
-           (attached->device_info &
-           MPI_SAS_DEVICE_INFO_END_DEVICE) &&
-           ((attached->device_info &
-           MPI_SAS_DEVICE_INFO_SSP_TARGET) |
-           (attached->device_info &
-           MPI_SAS_DEVICE_INFO_STP_TARGET) |
-           (attached->device_info &
-           MPI_SAS_DEVICE_INFO_SATA_DEVICE)))
-               return 1;
-       else
-               return 0;
-}
-
-static int
-mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc, struct mptsas_enclosure *enclosure,
-               u32 form, u32 form_specific)
-{
-       ConfigExtendedPageHeader_t hdr;
-       CONFIGPARMS cfg;
-       SasEnclosurePage0_t *buffer;
-       dma_addr_t dma_handle;
-       int error;
-       __le64 le_identifier;
-
-       memset(&hdr, 0, sizeof(hdr));
-       hdr.PageVersion = MPI_SASENCLOSURE0_PAGEVERSION;
-       hdr.PageNumber = 0;
-       hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
-       hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_ENCLOSURE;
-
-       cfg.cfghdr.ehdr = &hdr;
-       cfg.physAddr = -1;
-       cfg.pageAddr = form + form_specific;
-       cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
-       cfg.dir = 0;    /* read */
-       cfg.timeout = 10;
-
-       error = mpt_config(ioc, &cfg);
-       if (error)
-               goto out;
-       if (!hdr.ExtPageLength) {
-               error = -ENXIO;
-               goto out;
-       }
-
-       buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
-                       &dma_handle);
-       if (!buffer) {
-               error = -ENOMEM;
-               goto out;
-       }
-
-       cfg.physAddr = dma_handle;
-       cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
-
-       error = mpt_config(ioc, &cfg);
-       if (error)
-               goto out_free_consistent;
-
-       /* save config data */
-       memcpy(&le_identifier, &buffer->EnclosureLogicalID, sizeof(__le64));
-       enclosure->enclosure_logical_id = le64_to_cpu(le_identifier);
-       enclosure->enclosure_handle = le16_to_cpu(buffer->EnclosureHandle);
-       enclosure->flags = le16_to_cpu(buffer->Flags);
-       enclosure->num_slot = le16_to_cpu(buffer->NumSlots);
-       enclosure->start_slot = le16_to_cpu(buffer->StartSlot);
-       enclosure->start_id = buffer->StartTargetID;
-       enclosure->start_channel = buffer->StartBus;
-       enclosure->sep_id = buffer->SEPTargetID;
-       enclosure->sep_channel = buffer->SEPBus;
-
- out_free_consistent:
-       pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
-                           buffer, dma_handle);
- out:
-       return error;
-}
-
-static int
-mptsas_slave_configure(struct scsi_device *sdev)
-{
-       struct Scsi_Host        *host = sdev->host;
-       MPT_SCSI_HOST           *hd = (MPT_SCSI_HOST *)host->hostdata;
-
-       /*
-        * RAID volumes placed beyond the last expected port.
-        * Ignore sending sas mode pages in that case..
-        */
-       if (sdev->channel < hd->ioc->num_ports)
-               sas_read_port_mode_page(sdev);
-
-       return mptscsih_slave_configure(sdev);
-}
 
 /*
  * This is pretty ugly.  We will be able to seriously clean it up
@@ -415,7 +259,6 @@ mptsas_slave_alloc(struct scsi_device *sdev)
        VirtTarget              *vtarget;
        VirtDevice              *vdev;
        struct scsi_target      *starget;
-       u32                     target_id;
        int i;
 
        vdev = kzalloc(sizeof(VirtDevice), GFP_KERNEL);
@@ -424,10 +267,10 @@ mptsas_slave_alloc(struct scsi_device *sdev)
                                hd->ioc->name, sizeof(VirtDevice));
                return -ENOMEM;
        }
+       vdev->ioc_id = hd->ioc->id;
        sdev->hostdata = vdev;
        starget = scsi_target(sdev);
        vtarget = starget->hostdata;
-       vtarget->ioc_id = hd->ioc->id;
        vdev->vtarget = vtarget;
        if (vtarget->num_luns == 0) {
                vtarget->tflags = MPT_TARGET_FLAGS_Q_YES|MPT_TARGET_FLAGS_VALID_INQUIRY;
@@ -438,8 +281,8 @@ mptsas_slave_alloc(struct scsi_device *sdev)
          RAID volumes placed beyond the last expected port.
        */
        if (sdev->channel == hd->ioc->num_ports) {
-               target_id = sdev->id;
-               vtarget->bus_id = 0;
+               vdev->target_id = sdev->id;
+               vdev->bus_id = 0;
                vdev->lun = 0;
                goto out;
        }
@@ -450,21 +293,11 @@ mptsas_slave_alloc(struct scsi_device *sdev)
                for (i = 0; i < p->num_phys; i++) {
                        if (p->phy_info[i].attached.sas_address ==
                                        rphy->identify.sas_address) {
-                               target_id = p->phy_info[i].attached.id;
-                               vtarget->bus_id = p->phy_info[i].attached.channel;
+                               vdev->target_id =
+                                       p->phy_info[i].attached.id;
+                               vdev->bus_id = p->phy_info[i].attached.channel;
                                vdev->lun = sdev->lun;
-                               p->phy_info[i].starget = sdev->sdev_target;
-                               /*
-                                * Exposing hidden disk (RAID)
-                                */
-                               if (mptscsih_is_phys_disk(hd->ioc, target_id)) {
-                                       target_id = mptscsih_raid_id_to_num(hd,
-                                                       target_id);
-                                       vdev->vtarget->tflags |=
-                                           MPT_TARGET_FLAGS_RAID_COMPONENT;
-                                       sdev->no_uld_attach = 1;
-                               }
-                               mutex_unlock(&hd->ioc->sas_topology_mutex);
+       mutex_unlock(&hd->ioc->sas_topology_mutex);
                                goto out;
                        }
                }
@@ -475,7 +308,9 @@ mptsas_slave_alloc(struct scsi_device *sdev)
        return -ENXIO;
 
  out:
-       vtarget->target_id = target_id;
+       vtarget->ioc_id = vdev->ioc_id;
+       vtarget->target_id = vdev->target_id;
+       vtarget->bus_id = vdev->bus_id;
        vtarget->num_luns++;
        return 0;
 }
@@ -485,8 +320,32 @@ mptsas_slave_destroy(struct scsi_device *sdev)
 {
        struct Scsi_Host *host = sdev->host;
        MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
+       struct sas_rphy *rphy;
+       struct mptsas_portinfo *p;
+       int i;
        VirtDevice *vdev;
 
+       /*
+        * Handle hotplug removal case.
+        * We need to clear out attached data structure.
+        */
+       rphy = dev_to_rphy(sdev->sdev_target->dev.parent);
+
+       mutex_lock(&hd->ioc->sas_topology_mutex);
+       list_for_each_entry(p, &hd->ioc->sas_topology, list) {
+               for (i = 0; i < p->num_phys; i++) {
+                       if (p->phy_info[i].attached.sas_address ==
+                                       rphy->identify.sas_address) {
+                               memset(&p->phy_info[i].attached, 0,
+                                   sizeof(struct mptsas_devinfo));
+                               p->phy_info[i].rphy = NULL;
+                               goto out;
+                       }
+               }
+       }
+
+ out:
+       mutex_unlock(&hd->ioc->sas_topology_mutex);
        /*
         * Issue target reset to flush firmware outstanding commands.
         */
@@ -494,8 +353,8 @@ mptsas_slave_destroy(struct scsi_device *sdev)
        if (vdev->configured_lun){
                if (mptscsih_TMHandler(hd,
                     MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET,
-                    vdev->vtarget->bus_id,
-                    vdev->vtarget->target_id,
+                    vdev->bus_id,
+                    vdev->target_id,
                     0, 0, 5 /* 5 second timeout */)
                     < 0){
 
@@ -505,7 +364,7 @@ mptsas_slave_destroy(struct scsi_device *sdev)
                        printk(MYIOC_s_WARN_FMT
                       "Error processing TaskMgmt id=%d TARGET_RESET\n",
                                hd->ioc->name,
-                               vdev->vtarget->target_id);
+                               vdev->target_id);
 
                        hd->tmPending = 0;
                        hd->tmState = TM_STATE_NONE;
@@ -523,7 +382,7 @@ static struct scsi_host_template mptsas_driver_template = {
        .queuecommand                   = mptscsih_qcmd,
        .target_alloc                   = mptscsih_target_alloc,
        .slave_alloc                    = mptsas_slave_alloc,
-       .slave_configure                = mptsas_slave_configure,
+       .slave_configure                = mptscsih_slave_configure,
        .target_destroy                 = mptscsih_target_destroy,
        .slave_destroy                  = mptsas_slave_destroy,
        .change_queue_depth             = mptscsih_change_queue_depth,
@@ -540,6 +399,12 @@ static struct scsi_host_template mptsas_driver_template = {
        .use_clustering                 = ENABLE_CLUSTERING,
 };
 
+static inline MPT_ADAPTER *phy_to_ioc(struct sas_phy *phy)
+{
+       struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
+       return ((MPT_SCSI_HOST *)shost->hostdata)->ioc;
+}
+
 static int mptsas_get_linkerrors(struct sas_phy *phy)
 {
        MPT_ADAPTER *ioc = phy_to_ioc(phy);
@@ -681,67 +546,8 @@ static int mptsas_phy_reset(struct sas_phy *phy, int hard_reset)
        return error;
 }
 
-static int
-mptsas_get_enclosure_identifier(struct sas_rphy *rphy, u64 *identifier)
-{
-       MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
-       int i, error;
-       struct mptsas_portinfo *p;
-       struct mptsas_enclosure enclosure_info;
-       u64 enclosure_handle;
-
-       mutex_lock(&ioc->sas_topology_mutex);
-       list_for_each_entry(p, &ioc->sas_topology, list) {
-               for (i = 0; i < p->num_phys; i++) {
-                       if (p->phy_info[i].attached.sas_address ==
-                           rphy->identify.sas_address) {
-                               enclosure_handle = p->phy_info[i].
-                                       attached.handle_enclosure;
-                               goto found_info;
-                       }
-               }
-       }
-       mutex_unlock(&ioc->sas_topology_mutex);
-       return -ENXIO;
-
- found_info:
-       mutex_unlock(&ioc->sas_topology_mutex);
-       memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));
-       error = mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
-                       (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
-                        MPI_SAS_ENCLOS_PGAD_FORM_SHIFT), enclosure_handle);
-       if (!error)
-               *identifier = enclosure_info.enclosure_logical_id;
-       return error;
-}
-
-static int
-mptsas_get_bay_identifier(struct sas_rphy *rphy)
-{
-       MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
-       struct mptsas_portinfo *p;
-       int i, rc;
-
-       mutex_lock(&ioc->sas_topology_mutex);
-       list_for_each_entry(p, &ioc->sas_topology, list) {
-               for (i = 0; i < p->num_phys; i++) {
-                       if (p->phy_info[i].attached.sas_address ==
-                           rphy->identify.sas_address) {
-                               rc = p->phy_info[i].attached.slot;
-                               goto out;
-                       }
-               }
-       }
-       rc = -ENXIO;
- out:
-       mutex_unlock(&ioc->sas_topology_mutex);
-       return rc;
-}
-
 static struct sas_function_template mptsas_transport_functions = {
        .get_linkerrors         = mptsas_get_linkerrors,
-       .get_enclosure_identifier = mptsas_get_enclosure_identifier,
-       .get_bay_identifier     = mptsas_get_bay_identifier,
        .phy_reset              = mptsas_phy_reset,
 };
 
@@ -801,9 +607,6 @@ mptsas_sas_io_unit_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
                goto out_free_consistent;
        }
 
-       if (port_info->num_phys)
-               port_info->handle =
-                   le16_to_cpu(buffer->PhyData[0].ControllerDevHandle);
        for (i = 0; i < port_info->num_phys; i++) {
                mptsas_print_phy_data(&buffer->PhyData[i]);
                port_info->phy_info[i].phy_id = i;
@@ -893,11 +696,7 @@ mptsas_sas_device_pg0(MPT_ADAPTER *ioc, struct mptsas_devinfo *device_info,
        SasDevicePage0_t *buffer;
        dma_addr_t dma_handle;
        __le64 sas_address;
-       int error=0;
-
-       if (ioc->sas_discovery_runtime &&
-               mptsas_is_end_device(device_info))
-                       goto out;
+       int error;
 
        hdr.PageVersion = MPI_SASDEVICE0_PAGEVERSION;
        hdr.ExtPageLength = 0;
@@ -914,7 +713,6 @@ mptsas_sas_device_pg0(MPT_ADAPTER *ioc, struct mptsas_devinfo *device_info,
        cfg.dir = 0;    /* read */
        cfg.timeout = 10;
 
-       memset(device_info, 0, sizeof(struct mptsas_devinfo));
        error = mpt_config(ioc, &cfg);
        if (error)
                goto out;
@@ -941,9 +739,6 @@ mptsas_sas_device_pg0(MPT_ADAPTER *ioc, struct mptsas_devinfo *device_info,
 
        device_info->handle = le16_to_cpu(buffer->DevHandle);
        device_info->handle_parent = le16_to_cpu(buffer->ParentDevHandle);
-       device_info->handle_enclosure =
-           le16_to_cpu(buffer->EnclosureHandle);
-       device_info->slot = le16_to_cpu(buffer->Slot);
        device_info->phy_id = buffer->PhyNum;
        device_info->port_id = buffer->PhysicalPort;
        device_info->id = buffer->TargetID;
@@ -985,7 +780,6 @@ mptsas_sas_expander_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info,
        cfg.dir = 0;    /* read */
        cfg.timeout = 10;
 
-       memset(port_info, 0, sizeof(struct mptsas_portinfo));
        error = mpt_config(ioc, &cfg);
        if (error)
                goto out;
@@ -1034,11 +828,7 @@ mptsas_sas_expander_pg1(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,
        CONFIGPARMS cfg;
        SasExpanderPage1_t *buffer;
        dma_addr_t dma_handle;
-       int error=0;
-
-       if (ioc->sas_discovery_runtime &&
-               mptsas_is_end_device(&phy_info->attached))
-                       goto out;
+       int error;
 
        hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION;
        hdr.ExtPageLength = 0;
@@ -1090,6 +880,7 @@ mptsas_sas_expander_pg1(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,
        phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle);
        phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle);
 
+
  out_free_consistent:
        pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
                            buffer, dma_handle);
@@ -1097,6 +888,26 @@ mptsas_sas_expander_pg1(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,
        return error;
 }
 
+/*
+ * Returns true if there is a scsi end device
+ */
+static inline int
+mptsas_is_end_device(struct mptsas_devinfo * attached)
+{
+       if ((attached->handle) &&
+           (attached->device_info &
+           MPI_SAS_DEVICE_INFO_END_DEVICE) &&
+           ((attached->device_info &
+           MPI_SAS_DEVICE_INFO_SSP_TARGET) |
+           (attached->device_info &
+           MPI_SAS_DEVICE_INFO_STP_TARGET) |
+           (attached->device_info &
+           MPI_SAS_DEVICE_INFO_SATA_DEVICE)))
+               return 1;
+       else
+               return 0;
+}
+
 static void
 mptsas_parse_device_info(struct sas_identify *identify,
                struct mptsas_devinfo *device_info)
@@ -1159,19 +970,12 @@ mptsas_parse_device_info(struct sas_identify *identify,
 static int mptsas_probe_one_phy(struct device *dev,
                struct mptsas_phyinfo *phy_info, int index, int local)
 {
-       MPT_ADAPTER *ioc;
        struct sas_phy *phy;
        int error;
 
-       if (!dev)
-               return -ENODEV;
-
-       if (!phy_info->phy) {
-               phy = sas_phy_alloc(dev, index);
-               if (!phy)
-                       return -ENOMEM;
-       } else
-               phy = phy_info->phy;
+       phy = sas_phy_alloc(dev, index);
+       if (!phy)
+               return -ENOMEM;
 
        phy->port_identifier = phy_info->port_id;
        mptsas_parse_device_info(&phy->identify, &phy_info->identify);
@@ -1257,54 +1061,24 @@ static int mptsas_probe_one_phy(struct device *dev,
                break;
        }
 
-       if (!phy_info->phy) {
-
-               if (local)
-                       phy->local_attached = 1;
+       if (local)
+               phy->local_attached = 1;
 
-               error = sas_phy_add(phy);
-               if (error) {
-                       sas_phy_free(phy);
-                       return error;
-               }
-               phy_info->phy = phy;
+       error = sas_phy_add(phy);
+       if (error) {
+               sas_phy_free(phy);
+               return error;
        }
+       phy_info->phy = phy;
 
-       if ((phy_info->attached.handle) &&
-           (!phy_info->rphy)) {
-
+       if (phy_info->attached.handle) {
                struct sas_rphy *rphy;
-               struct sas_identify identify;
-
-               ioc = phy_to_ioc(phy_info->phy);
 
-               /*
-                * Let the hotplug_work thread handle processing
-                * the adding/removing of devices that occur
-                * after start of day.
-                */
-               if (ioc->sas_discovery_runtime &&
-                       mptsas_is_end_device(&phy_info->attached))
-                       return 0;
-
-               mptsas_parse_device_info(&identify, &phy_info->attached);
-               switch (identify.device_type) {
-               case SAS_END_DEVICE:
-                       rphy = sas_end_device_alloc(phy);
-                       break;
-               case SAS_EDGE_EXPANDER_DEVICE:
-               case SAS_FANOUT_EXPANDER_DEVICE:
-                       rphy = sas_expander_alloc(phy, identify.device_type);
-                       break;
-               default:
-                       rphy = NULL;
-                       break;
-               }
+               rphy = sas_rphy_alloc(phy);
                if (!rphy)
                        return 0; /* non-fatal: an rphy can be added later */
 
-               rphy->identify = identify;
-
+               mptsas_parse_device_info(&rphy->identify, &phy_info->attached);
                error = sas_rphy_add(rphy);
                if (error) {
                        sas_rphy_free(rphy);
@@ -1318,37 +1092,24 @@ static int mptsas_probe_one_phy(struct device *dev,
 }
 
 static int
-mptsas_probe_hba_phys(MPT_ADAPTER *ioc)
+mptsas_probe_hba_phys(MPT_ADAPTER *ioc, int *index)
 {
-       struct mptsas_portinfo *port_info, *hba;
+       struct mptsas_portinfo *port_info;
        u32 handle = 0xFFFF;
        int error = -ENOMEM, i;
 
-       hba = kzalloc(sizeof(*port_info), GFP_KERNEL);
-       if (! hba)
+       port_info = kzalloc(sizeof(*port_info), GFP_KERNEL);
+       if (!port_info)
                goto out;
 
-       error = mptsas_sas_io_unit_pg0(ioc, hba);
+       error = mptsas_sas_io_unit_pg0(ioc, port_info);
        if (error)
                goto out_free_port_info;
 
+       ioc->num_ports = port_info->num_phys;
        mutex_lock(&ioc->sas_topology_mutex);
-       port_info = mptsas_find_portinfo_by_handle(ioc, hba->handle);
-       if (!port_info) {
-               port_info = hba;
-               list_add_tail(&port_info->list, &ioc->sas_topology);
-       } else {
-               port_info->handle = hba->handle;
-               for (i = 0; i < hba->num_phys; i++)
-                       port_info->phy_info[i].negotiated_link_rate =
-                               hba->phy_info[i].negotiated_link_rate;
-               if (hba->phy_info)
-                       kfree(hba->phy_info);
-               kfree(hba);
-               hba = NULL;
-       }
+       list_add_tail(&port_info->list, &ioc->sas_topology);
        mutex_unlock(&ioc->sas_topology_mutex);
-       ioc->num_ports = port_info->num_phys;
 
        for (i = 0; i < port_info->num_phys; i++) {
                mptsas_sas_phy_pg0(ioc, &port_info->phy_info[i],
@@ -1371,49 +1132,38 @@ mptsas_probe_hba_phys(MPT_ADAPTER *ioc)
                }
 
                mptsas_probe_one_phy(&ioc->sh->shost_gendev,
-                   &port_info->phy_info[i], ioc->sas_index, 1);
-               ioc->sas_index++;
+                                    &port_info->phy_info[i], *index, 1);
+               (*index)++;
        }
 
        return 0;
 
  out_free_port_info:
-       if (hba)
-               kfree(hba);
+       kfree(port_info);
  out:
        return error;
 }
 
 static int
-mptsas_probe_expander_phys(MPT_ADAPTER *ioc, u32 *handle)
+mptsas_probe_expander_phys(MPT_ADAPTER *ioc, u32 *handle, int *index)
 {
-       struct mptsas_portinfo *port_info, *p, *ex;
+       struct mptsas_portinfo *port_info, *p;
        int error = -ENOMEM, i, j;
 
-       ex = kzalloc(sizeof(*port_info), GFP_KERNEL);
-       if (!ex)
+       port_info = kzalloc(sizeof(*port_info), GFP_KERNEL);
+       if (!port_info)
                goto out;
 
-       error = mptsas_sas_expander_pg0(ioc, ex,
+       error = mptsas_sas_expander_pg0(ioc, port_info,
                (MPI_SAS_EXPAND_PGAD_FORM_GET_NEXT_HANDLE <<
                 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), *handle);
        if (error)
                goto out_free_port_info;
 
-       *handle = ex->handle;
+       *handle = port_info->handle;
 
        mutex_lock(&ioc->sas_topology_mutex);
-       port_info = mptsas_find_portinfo_by_handle(ioc, *handle);
-       if (!port_info) {
-               port_info = ex;
-               list_add_tail(&port_info->list, &ioc->sas_topology);
-       } else {
-               port_info->handle = ex->handle;
-               if (ex->phy_info)
-                       kfree(ex->phy_info);
-               kfree(ex);
-               ex = NULL;
-       }
+       list_add_tail(&port_info->list, &ioc->sas_topology);
        mutex_unlock(&ioc->sas_topology_mutex);
 
        for (i = 0; i < port_info->num_phys; i++) {
@@ -1439,8 +1189,6 @@ mptsas_probe_expander_phys(MPT_ADAPTER *ioc, u32 *handle)
                                (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
                                 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
                                port_info->phy_info[i].attached.handle);
-                       port_info->phy_info[i].attached.phy_id =
-                           port_info->phy_info[i].phy_id;
                }
 
                /*
@@ -1460,137 +1208,27 @@ mptsas_probe_expander_phys(MPT_ADAPTER *ioc, u32 *handle)
                mutex_unlock(&ioc->sas_topology_mutex);
 
                mptsas_probe_one_phy(parent, &port_info->phy_info[i],
-                   ioc->sas_index, 0);
-               ioc->sas_index++;
+                                    *index, 0);
+               (*index)++;
        }
 
        return 0;
 
  out_free_port_info:
-       if (ex) {
-               if (ex->phy_info)
-                       kfree(ex->phy_info);
-               kfree(ex);
-       }
+       kfree(port_info);
  out:
        return error;
 }
 
-/*
- * mptsas_delete_expander_phys
- *
- *
- * This will traverse topology, and remove expanders
- * that are no longer present
- */
-static void
-mptsas_delete_expander_phys(MPT_ADAPTER *ioc)
-{
-       struct mptsas_portinfo buffer;
-       struct mptsas_portinfo *port_info, *n, *parent;
-       int i;
-
-       mutex_lock(&ioc->sas_topology_mutex);
-       list_for_each_entry_safe(port_info, n, &ioc->sas_topology, list) {
-
-               if (port_info->phy_info &&
-                   (!(port_info->phy_info[0].identify.device_info &
-                   MPI_SAS_DEVICE_INFO_SMP_TARGET)))
-                       continue;
-
-               if (mptsas_sas_expander_pg0(ioc, &buffer,
-                    (MPI_SAS_EXPAND_PGAD_FORM_HANDLE <<
-                    MPI_SAS_EXPAND_PGAD_FORM_SHIFT), port_info->handle)) {
-
-                       /*
-                        * Obtain the port_info instance to the parent port
-                        */
-                       parent = mptsas_find_portinfo_by_handle(ioc,
-                           port_info->phy_info[0].identify.handle_parent);
-
-                       if (!parent)
-                               goto next_port;
-
-                       /*
-                        * Delete rphys in the parent that point
-                        * to this expander.  The transport layer will
-                        * cleanup all the children.
-                        */
-                       for (i = 0; i < parent->num_phys; i++) {
-                               if ((!parent->phy_info[i].rphy) ||
-                                   (parent->phy_info[i].attached.sas_address !=
-                                  port_info->phy_info[i].identify.sas_address))
-                                       continue;
-                               sas_rphy_delete(parent->phy_info[i].rphy);
-                               memset(&parent->phy_info[i].attached, 0,
-                                   sizeof(struct mptsas_devinfo));
-                               parent->phy_info[i].rphy = NULL;
-                               parent->phy_info[i].starget = NULL;
-                       }
- next_port:
-                       list_del(&port_info->list);
-                       if (port_info->phy_info)
-                               kfree(port_info->phy_info);
-                       kfree(port_info);
-               }
-               /*
-               * Free this memory allocated from inside
-               * mptsas_sas_expander_pg0
-               */
-               if (buffer.phy_info)
-                       kfree(buffer.phy_info);
-       }
-       mutex_unlock(&ioc->sas_topology_mutex);
-}
-
-/*
- * Start of day discovery
- */
 static void
 mptsas_scan_sas_topology(MPT_ADAPTER *ioc)
 {
        u32 handle = 0xFFFF;
-       int i;
+       int index = 0;
 
-       mutex_lock(&ioc->sas_discovery_mutex);
-       mptsas_probe_hba_phys(ioc);
-       while (!mptsas_probe_expander_phys(ioc, &handle))
+       mptsas_probe_hba_phys(ioc, &index);
+       while (!mptsas_probe_expander_phys(ioc, &handle, &index))
                ;
-       /*
-         Reporting RAID volumes.
-       */
-       if (!ioc->raid_data.pIocPg2)
-               goto out;
-       if (!ioc->raid_data.pIocPg2->NumActiveVolumes)
-               goto out;
-       for (i=0; i<ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
-               scsi_add_device(ioc->sh, ioc->num_ports,
-                   ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0);
-       }
- out:
-       mutex_unlock(&ioc->sas_discovery_mutex);
-}
-
-/*
- * Work queue thread to handle Runtime discovery
- * Mere purpose is the hot add/delete of expanders
- */
-static void
-mptscsih_discovery_work(void * arg)
-{
-       struct mptsas_discovery_event *ev = arg;
-       MPT_ADAPTER *ioc = ev->ioc;
-       u32 handle = 0xFFFF;
-
-       mutex_lock(&ioc->sas_discovery_mutex);
-       ioc->sas_discovery_runtime=1;
-       mptsas_delete_expander_phys(ioc);
-       mptsas_probe_hba_phys(ioc);
-       while (!mptsas_probe_expander_phys(ioc, &handle))
-               ;
-       kfree(ev);
-       ioc->sas_discovery_runtime=0;
-       mutex_unlock(&ioc->sas_discovery_mutex);
 }
 
 static struct mptsas_phyinfo *
@@ -1608,8 +1246,10 @@ mptsas_find_phyinfo_by_parent(MPT_ADAPTER *ioc, u16 parent_handle, u8 phy_id)
                (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
                 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
                parent_handle);
-       if (error)
+       if (error) {
+               printk("mptsas: failed to retrieve device page\n");
                return NULL;
+       }
 
        /*
         * The phy_info structures are never deallocated during lifetime of
@@ -1656,35 +1296,6 @@ mptsas_find_phyinfo_by_target(MPT_ADAPTER *ioc, u32 id)
        return phy_info;
 }
 
-/*
- * Work queue thread to clear the persitency table
- */
-static void
-mptscsih_sas_persist_clear_table(void * arg)
-{
-       MPT_ADAPTER *ioc = (MPT_ADAPTER *)arg;
-
-       mptbase_sas_persist_operation(ioc, MPI_SAS_OP_CLEAR_NOT_PRESENT);
-}
-
-static void
-mptsas_reprobe_lun(struct scsi_device *sdev, void *data)
-{
-       sdev->no_uld_attach = data ? 1 : 0;
-       scsi_device_reprobe(sdev);
-}
-
-static void
-mptsas_reprobe_target(struct scsi_target *starget, int uld_attach)
-{
-       starget_for_each_device(starget, uld_attach ? (void *)1 : NULL,
-                       mptsas_reprobe_lun);
-}
-
-
-/*
- * Work queue thread to handle SAS hotplug events
- */
 static void
 mptsas_hotplug_work(void *arg)
 {
@@ -1693,39 +1304,16 @@ mptsas_hotplug_work(void *arg)
        struct mptsas_phyinfo *phy_info;
        struct sas_rphy *rphy;
        struct scsi_device *sdev;
-       struct sas_identify identify;
        char *ds = NULL;
        struct mptsas_devinfo sas_device;
-       VirtTarget *vtarget;
-
-       mutex_lock(&ioc->sas_discovery_mutex);
 
        switch (ev->event_type) {
        case MPTSAS_DEL_DEVICE:
 
                phy_info = mptsas_find_phyinfo_by_target(ioc, ev->id);
-
-               /*
-                * Sanity checks, for non-existing phys and remote rphys.
-                */
-               if (!phy_info)
-                       break;
-               if (!phy_info->rphy)
+               if (!phy_info) {
+                       printk("mptsas: remove event for non-existant PHY.\n");
                        break;
-               if (phy_info->starget) {
-                       vtarget = phy_info->starget->hostdata;
-
-                       if (!vtarget)
-                               break;
-                       /*
-                        * Handling  RAID components
-                        */
-                       if (ev->phys_disk_num_valid) {
-                               vtarget->target_id = ev->phys_disk_num;
-                               vtarget->tflags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
-                               mptsas_reprobe_target(vtarget->starget, 1);
-                               break;
-                       }
                }
 
                if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SSP_TARGET)
@@ -1739,77 +1327,55 @@ mptsas_hotplug_work(void *arg)
                       "removing %s device, channel %d, id %d, phy %d\n",
                       ioc->name, ds, ev->channel, ev->id, phy_info->phy_id);
 
-               sas_rphy_delete(phy_info->rphy);
-               memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
-               phy_info->rphy = NULL;
-               phy_info->starget = NULL;
+               if (phy_info->rphy) {
+                       sas_rphy_delete(phy_info->rphy);
+                       phy_info->rphy = NULL;
+               }
                break;
        case MPTSAS_ADD_DEVICE:
 
-               if (ev->phys_disk_num_valid)
-                       mpt_findImVolumes(ioc);
-
                /*
-                * Refresh sas device pg0 data
+                * When there is no sas address,
+                * RAID volumes are being deleted,
+                * and hidden phy disk are being added.
+                * We don't know the SAS data yet,
+                * so lookup sas device page to get
+                * pertaining info
                 */
-               if (mptsas_sas_device_pg0(ioc, &sas_device,
-                   (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
-                    MPI_SAS_DEVICE_PGAD_FORM_SHIFT), ev->id))
-                       break;
-
-               phy_info = mptsas_find_phyinfo_by_parent(ioc,
-                               sas_device.handle_parent, sas_device.phy_id);
-
-               if (!phy_info) {
-                       u32 handle = 0xFFFF;
-
-                       /*
-                       * Its possible when an expander has been hot added
-                       * containing attached devices, the sas firmware
-                       * may send a RC_ADDED event prior to the
-                       * DISCOVERY STOP event. If that occurs, our
-                       * view of the topology in the driver in respect to this
-                       * expander might of not been setup, and we hit this
-                       * condition.
-                       * Therefore, this code kicks off discovery to
-                       * refresh the data.
-                       * Then again, we check whether the parent phy has
-                       * been created.
-                       */
-                       ioc->sas_discovery_runtime=1;
-                       mptsas_delete_expander_phys(ioc);
-                       mptsas_probe_hba_phys(ioc);
-                       while (!mptsas_probe_expander_phys(ioc, &handle))
-                               ;
-                       ioc->sas_discovery_runtime=0;
-
-                       phy_info = mptsas_find_phyinfo_by_parent(ioc,
-                               sas_device.handle_parent, sas_device.phy_id);
-                       if (!phy_info)
+               if (!ev->sas_address) {
+                       if (mptsas_sas_device_pg0(ioc,
+                           &sas_device, ev->id,
+                           (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
+                            MPI_SAS_DEVICE_PGAD_FORM_SHIFT)))
                                break;
+                       ev->handle = sas_device.handle;
+                       ev->parent_handle = sas_device.handle_parent;
+                       ev->channel = sas_device.channel;
+                       ev->phy_id = sas_device.phy_id;
+                       ev->sas_address = sas_device.sas_address;
+                       ev->device_info = sas_device.device_info;
                }
 
-               if (phy_info->starget) {
-                       vtarget = phy_info->starget->hostdata;
-
-                       if (!vtarget)
-                               break;
-                       /*
-                        * Handling  RAID components
-                        */
-                       if (vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
-                               vtarget->tflags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT;
-                               vtarget->target_id = ev->id;
-                               mptsas_reprobe_target(phy_info->starget, 0);
-                       }
+               phy_info = mptsas_find_phyinfo_by_parent(ioc,
+                               ev->parent_handle, ev->phy_id);
+               if (!phy_info) {
+                       printk("mptsas: add event for non-existant PHY.\n");
                        break;
                }
 
-               if (phy_info->rphy)
+               if (phy_info->rphy) {
+                       printk("mptsas: trying to add existing device.\n");
                        break;
+               }
 
-               memcpy(&phy_info->attached, &sas_device,
-                   sizeof(struct mptsas_devinfo));
+               /* fill attached info */
+               phy_info->attached.handle = ev->handle;
+               phy_info->attached.phy_id = ev->phy_id;
+               phy_info->attached.port_id = phy_info->identify.port_id;
+               phy_info->attached.id = ev->id;
+               phy_info->attached.channel = ev->channel;
+               phy_info->attached.sas_address = ev->sas_address;
+               phy_info->attached.device_info = ev->device_info;
 
                if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SSP_TARGET)
                        ds = "ssp";
@@ -1822,23 +1388,13 @@ mptsas_hotplug_work(void *arg)
                       "attaching %s device, channel %d, id %d, phy %d\n",
                       ioc->name, ds, ev->channel, ev->id, ev->phy_id);
 
-               mptsas_parse_device_info(&identify, &phy_info->attached);
-               switch (identify.device_type) {
-               case SAS_END_DEVICE:
-                       rphy = sas_end_device_alloc(phy_info->phy);
-                       break;
-               case SAS_EDGE_EXPANDER_DEVICE:
-               case SAS_FANOUT_EXPANDER_DEVICE:
-                       rphy = sas_expander_alloc(phy_info->phy, identify.device_type);
-                       break;
-               default:
-                       rphy = NULL;
-                       break;
-               }
+
+               rphy = sas_rphy_alloc(phy_info->phy);
                if (!rphy)
                        break; /* non-fatal: an rphy can be added later */
 
-               rphy->identify = identify;
+               rphy->scsi_target_id = phy_info->attached.id;
+               mptsas_parse_device_info(&rphy->identify, &phy_info->attached);
                if (sas_rphy_add(rphy)) {
                        sas_rphy_free(rphy);
                        break;
@@ -1857,7 +1413,7 @@ mptsas_hotplug_work(void *arg)
                        break;
                }
                printk(MYIOC_s_INFO_FMT
-                      "attaching raid volume, channel %d, id %d\n",
+                      "attaching device, channel %d, id %d\n",
                       ioc->name, ioc->num_ports, ev->id);
                scsi_add_device(ioc->sh,
                        ioc->num_ports,
@@ -1874,19 +1430,15 @@ mptsas_hotplug_work(void *arg)
                if (!sdev)
                        break;
                printk(MYIOC_s_INFO_FMT
-                      "removing raid volume, channel %d, id %d\n",
+                      "removing device, channel %d, id %d\n",
                       ioc->name, ioc->num_ports, ev->id);
                scsi_remove_device(sdev);
                scsi_device_put(sdev);
                mpt_findImVolumes(ioc);
                break;
-       case MPTSAS_IGNORE_EVENT:
-       default:
-               break;
        }
 
        kfree(ev);
-       mutex_unlock(&ioc->sas_discovery_mutex);
 }
 
 static void
@@ -1903,51 +1455,35 @@ mptscsih_send_sas_event(MPT_ADAPTER *ioc,
              MPI_SAS_DEVICE_INFO_SATA_DEVICE )) == 0)
                return;
 
-       switch (sas_event_data->ReasonCode) {
-       case MPI_EVENT_SAS_DEV_STAT_RC_ADDED:
-       case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING:
-               ev = kmalloc(sizeof(*ev), GFP_ATOMIC);
-               if (!ev) {
-                       printk(KERN_WARNING "mptsas: lost hotplug event\n");
-                       break;
-               }
+       if ((sas_event_data->ReasonCode &
+            (MPI_EVENT_SAS_DEV_STAT_RC_ADDED |
+             MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING)) == 0)
+               return;
 
-               INIT_WORK(&ev->work, mptsas_hotplug_work, ev);
-               ev->ioc = ioc;
-               ev->handle = le16_to_cpu(sas_event_data->DevHandle);
-               ev->parent_handle =
-                   le16_to_cpu(sas_event_data->ParentDevHandle);
-               ev->channel = sas_event_data->Bus;
-               ev->id = sas_event_data->TargetID;
-               ev->phy_id = sas_event_data->PhyNum;
-               memcpy(&sas_address, &sas_event_data->SASAddress,
-                   sizeof(__le64));
-               ev->sas_address = le64_to_cpu(sas_address);
-               ev->device_info = device_info;
-
-               if (sas_event_data->ReasonCode &
-                   MPI_EVENT_SAS_DEV_STAT_RC_ADDED)
-                       ev->event_type = MPTSAS_ADD_DEVICE;
-               else
-                       ev->event_type = MPTSAS_DEL_DEVICE;
-               schedule_work(&ev->work);
-               break;
-       case MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED:
-       /*
-        * Persistent table is full.
-        */
-               INIT_WORK(&ioc->mptscsih_persistTask,
-                   mptscsih_sas_persist_clear_table,
-                   (void *)ioc);
-               schedule_work(&ioc->mptscsih_persistTask);
-               break;
-       case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
-       /* TODO */
-       case MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
-       /* TODO */
-       default:
-               break;
+       ev = kmalloc(sizeof(*ev), GFP_ATOMIC);
+       if (!ev) {
+               printk(KERN_WARNING "mptsas: lost hotplug event\n");
+               return;
        }
+
+
+       INIT_WORK(&ev->work, mptsas_hotplug_work, ev);
+       ev->ioc = ioc;
+       ev->handle = le16_to_cpu(sas_event_data->DevHandle);
+       ev->parent_handle = le16_to_cpu(sas_event_data->ParentDevHandle);
+       ev->channel = sas_event_data->Bus;
+       ev->id = sas_event_data->TargetID;
+       ev->phy_id = sas_event_data->PhyNum;
+       memcpy(&sas_address, &sas_event_data->SASAddress, sizeof(__le64));
+       ev->sas_address = le64_to_cpu(sas_address);
+       ev->device_info = device_info;
+
+       if (sas_event_data->ReasonCode & MPI_EVENT_SAS_DEV_STAT_RC_ADDED)
+               ev->event_type = MPTSAS_ADD_DEVICE;
+       else
+               ev->event_type = MPTSAS_DEL_DEVICE;
+
+       schedule_work(&ev->work);
 }
 
 static void
@@ -1955,8 +1491,7 @@ mptscsih_send_raid_event(MPT_ADAPTER *ioc,
                EVENT_DATA_RAID *raid_event_data)
 {
        struct mptsas_hotplug_event *ev;
-       int status = le32_to_cpu(raid_event_data->SettingsStatus);
-       int state = (status >> 8) & 0xff;
+       RAID_VOL0_STATUS * volumeStatus;
 
        if (ioc->bus_type != SAS)
                return;
@@ -1971,37 +1506,14 @@ mptscsih_send_raid_event(MPT_ADAPTER *ioc,
        INIT_WORK(&ev->work, mptsas_hotplug_work, ev);
        ev->ioc = ioc;
        ev->id = raid_event_data->VolumeID;
-       ev->event_type = MPTSAS_IGNORE_EVENT;
 
        switch (raid_event_data->ReasonCode) {
        case MPI_EVENT_RAID_RC_PHYSDISK_DELETED:
                ev->event_type = MPTSAS_ADD_DEVICE;
                break;
        case MPI_EVENT_RAID_RC_PHYSDISK_CREATED:
-               ioc->raid_data.isRaid = 1;
-               ev->phys_disk_num_valid = 1;
-               ev->phys_disk_num = raid_event_data->PhysDiskNum;
                ev->event_type = MPTSAS_DEL_DEVICE;
                break;
-       case MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED:
-               switch (state) {
-               case MPI_PD_STATE_ONLINE:
-                       ioc->raid_data.isRaid = 1;
-                       ev->phys_disk_num_valid = 1;
-                       ev->phys_disk_num = raid_event_data->PhysDiskNum;
-                       ev->event_type = MPTSAS_ADD_DEVICE;
-                       break;
-               case MPI_PD_STATE_MISSING:
-               case MPI_PD_STATE_NOT_COMPATIBLE:
-               case MPI_PD_STATE_OFFLINE_AT_HOST_REQUEST:
-               case MPI_PD_STATE_FAILED_AT_HOST_REQUEST:
-               case MPI_PD_STATE_OFFLINE_FOR_ANOTHER_REASON:
-                       ev->event_type = MPTSAS_DEL_DEVICE;
-                       break;
-               default:
-                       break;
-               }
-               break;
        case MPI_EVENT_RAID_RC_VOLUME_DELETED:
                ev->event_type = MPTSAS_DEL_RAID;
                break;
@@ -2009,18 +1521,11 @@ mptscsih_send_raid_event(MPT_ADAPTER *ioc,
                ev->event_type = MPTSAS_ADD_RAID;
                break;
        case MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED:
-               switch (state) {
-               case MPI_RAIDVOL0_STATUS_STATE_FAILED:
-               case MPI_RAIDVOL0_STATUS_STATE_MISSING:
-                       ev->event_type = MPTSAS_DEL_RAID;
-                       break;
-               case MPI_RAIDVOL0_STATUS_STATE_OPTIMAL:
-               case MPI_RAIDVOL0_STATUS_STATE_DEGRADED:
-                       ev->event_type = MPTSAS_ADD_RAID;
-                       break;
-               default:
-                       break;
-               }
+               volumeStatus = (RAID_VOL0_STATUS *) &
+                   raid_event_data->SettingsStatus;
+               ev->event_type = (volumeStatus->State ==
+                   MPI_RAIDVOL0_STATUS_STATE_FAILED) ?
+                   MPTSAS_DEL_RAID : MPTSAS_ADD_RAID;
                break;
        default:
                break;
@@ -2028,31 +1533,15 @@ mptscsih_send_raid_event(MPT_ADAPTER *ioc,
        schedule_work(&ev->work);
 }
 
+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+/* work queue thread to clear the persitency table */
 static void
-mptscsih_send_discovery(MPT_ADAPTER *ioc,
-       EVENT_DATA_SAS_DISCOVERY *discovery_data)
+mptscsih_sas_persist_clear_table(void * arg)
 {
-       struct mptsas_discovery_event *ev;
-
-       /*
-        * DiscoveryStatus
-        *
-        * This flag will be non-zero when firmware
-        * kicks off discovery, and return to zero
-        * once its completed.
-        */
-       if (discovery_data->DiscoveryStatus)
-               return;
-
-       ev = kmalloc(sizeof(*ev), GFP_ATOMIC);
-       if (!ev)
-               return;
-       memset(ev,0,sizeof(struct mptsas_discovery_event));
-       INIT_WORK(&ev->work, mptscsih_discovery_work, ev);
-       ev->ioc = ioc;
-       schedule_work(&ev->work);
-};
+       MPT_ADAPTER *ioc = (MPT_ADAPTER *)arg;
 
+       mptbase_sas_persist_operation(ioc, MPI_SAS_OP_CLEAR_NOT_PRESENT);
+}
 
 static int
 mptsas_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *reply)
@@ -2063,17 +1552,6 @@ mptsas_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *reply)
        if (!ioc->sh)
                goto out;
 
-       /*
-        * sas_discovery_ignore_events
-        *
-        * This flag is to prevent anymore processing of
-        * sas events once mptsas_remove function is called.
-        */
-       if (ioc->sas_discovery_ignore_events) {
-               rc = mptscsih_event_process(ioc, reply);
-               goto out;
-       }
-
        switch (event) {
        case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
                mptscsih_send_sas_event(ioc,
@@ -2089,10 +1567,6 @@ mptsas_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *reply)
                    (void *)ioc);
                schedule_work(&ioc->mptscsih_persistTask);
                break;
-        case MPI_EVENT_SAS_DISCOVERY:
-               mptscsih_send_discovery(ioc,
-                       (EVENT_DATA_SAS_DISCOVERY *)reply->Data);
-               break;
        default:
                rc = mptscsih_event_process(ioc, reply);
                break;
@@ -2194,7 +1668,7 @@ mptsas_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 
        INIT_LIST_HEAD(&ioc->sas_topology);
        mutex_init(&ioc->sas_topology_mutex);
-       mutex_init(&ioc->sas_discovery_mutex);
+
        mutex_init(&ioc->sas_mgmt.mutex);
        init_completion(&ioc->sas_mgmt.done);
 
@@ -2307,6 +1781,20 @@ mptsas_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 
        mptsas_scan_sas_topology(ioc);
 
+       /*
+         Reporting RAID volumes.
+       */
+       if (!ioc->raid_data.pIocPg2)
+               return 0;
+       if (!ioc->raid_data.pIocPg2->NumActiveVolumes)
+               return 0;
+       for (ii=0;ii<ioc->raid_data.pIocPg2->NumActiveVolumes;ii++) {
+               scsi_add_device(sh,
+                       ioc->num_ports,
+                       ioc->raid_data.pIocPg2->RaidVolume[ii].VolumeID,
+                       0);
+       }
+
        return 0;
 
 out_mptsas_probe:
@@ -2320,14 +1808,11 @@ static void __devexit mptsas_remove(struct pci_dev *pdev)
        MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
        struct mptsas_portinfo *p, *n;
 
-       ioc->sas_discovery_ignore_events=1;
        sas_remove_host(ioc->sh);
 
        mutex_lock(&ioc->sas_topology_mutex);
        list_for_each_entry_safe(p, n, &ioc->sas_topology, list) {
                list_del(&p->list);
-               if (p->phy_info)
-                       kfree(p->phy_info);
                kfree(p);
        }
        mutex_unlock(&ioc->sas_topology_mutex);
@@ -2382,7 +1867,7 @@ mptsas_init(void)
        mptsasMgmtCtx = mpt_register(mptsas_mgmt_done, MPTSAS_DRIVER);
 
        if (mpt_event_register(mptsasDoneCtx, mptsas_event_process) == 0) {
-               devtverboseprintk((KERN_INFO MYNAM
+               devtprintk((KERN_INFO MYNAM
                  ": Registered for IOC event notifications\n"));
        }