-static inline int
-mptsas_is_end_device(struct mptsas_devinfo * attached)
-{
- if ((attached->sas_address) &&
- (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;
-}
-
-/* no mutex */
-static void
-mptsas_port_delete(struct mptsas_portinfo_details * port_details)
-{
- struct mptsas_portinfo *port_info;
- struct mptsas_phyinfo *phy_info;
- u8 i;
-
- if (!port_details)
- return;
-
- port_info = port_details->port_info;
- phy_info = port_info->phy_info;
-
- dsaswideprintk((KERN_DEBUG "%s: [%p]: num_phys=%02d "
- "bitmask=0x%016llX\n",
- __FUNCTION__, port_details, port_details->num_phys,
- port_details->phy_bitmask));
-
- for (i = 0; i < port_info->num_phys; i++, phy_info++) {
- if(phy_info->port_details != port_details)
- continue;
- memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
- phy_info->port_details = NULL;
- }
- kfree(port_details);
-}
-
-static inline struct sas_rphy *
-mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
-{
- if (phy_info->port_details)
- return phy_info->port_details->rphy;
- else
- return NULL;
-}
-
-static inline void
-mptsas_set_rphy(struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
-{
- if (phy_info->port_details) {
- phy_info->port_details->rphy = rphy;
- dsaswideprintk((KERN_DEBUG "sas_rphy_add: rphy=%p\n", rphy));
- }
-
-#ifdef MPT_DEBUG_SAS_WIDE
- if (rphy) {
- dev_printk(KERN_DEBUG, &rphy->dev, "add:");
- printk("rphy=%p release=%p\n",
- rphy, rphy->dev.release);
- }
-#endif
-}
-
-static inline struct sas_port *
-mptsas_get_port(struct mptsas_phyinfo *phy_info)
-{
- if (phy_info->port_details)
- return phy_info->port_details->port;
- else
- return NULL;
-}
-
-static inline void
-mptsas_set_port(struct mptsas_phyinfo *phy_info, struct sas_port *port)
-{
- if (phy_info->port_details)
- phy_info->port_details->port = port;
-
-#ifdef MPT_DEBUG_SAS_WIDE
- if (port) {
- dev_printk(KERN_DEBUG, &port->dev, "add: ");
- printk("port=%p release=%p\n",
- port, port->dev.release);
- }
-#endif
-}
-
-static inline struct scsi_target *
-mptsas_get_starget(struct mptsas_phyinfo *phy_info)
-{
- if (phy_info->port_details)
- return phy_info->port_details->starget;
- else
- return NULL;
-}
-
-static inline void
-mptsas_set_starget(struct mptsas_phyinfo *phy_info, struct scsi_target *
-starget)
-{
- if (phy_info->port_details)
- phy_info->port_details->starget = starget;
-}
-
-
-/*
- * mptsas_setup_wide_ports
- *
- * Updates for new and existing narrow/wide port configuration
- * in the sas_topology
- */
-static void
-mptsas_setup_wide_ports(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
-{
- struct mptsas_portinfo_details * port_details;
- struct mptsas_phyinfo *phy_info, *phy_info_cmp;
- u64 sas_address;
- int i, j;
-
- mutex_lock(&ioc->sas_topology_mutex);
-
- phy_info = port_info->phy_info;
- for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
- if (phy_info->attached.handle)
- continue;
- port_details = phy_info->port_details;
- if (!port_details)
- continue;
- if (port_details->num_phys < 2)
- continue;
- /*
- * Removing a phy from a port, letting the last
- * phy be removed by firmware events.
- */
- dsaswideprintk((KERN_DEBUG
- "%s: [%p]: deleting phy = %d\n",
- __FUNCTION__, port_details, i));
- port_details->num_phys--;
- port_details->phy_bitmask &= ~ (1 << phy_info->phy_id);
- memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
- sas_port_delete_phy(port_details->port, phy_info->phy);
- phy_info->port_details = NULL;
- }
-
- /*
- * Populate and refresh the tree
- */
- phy_info = port_info->phy_info;
- for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
- sas_address = phy_info->attached.sas_address;
- dsaswideprintk((KERN_DEBUG "phy_id=%d sas_address=0x%018llX\n",
- i, sas_address));
- if (!sas_address)
- continue;
- port_details = phy_info->port_details;
- /*
- * Forming a port
- */
- if (!port_details) {
- port_details = kzalloc(sizeof(*port_details),
- GFP_KERNEL);
- if (!port_details)
- goto out;
- port_details->num_phys = 1;
- port_details->port_info = port_info;
- if (phy_info->phy_id < 64 )
- port_details->phy_bitmask |=
- (1 << phy_info->phy_id);
- phy_info->sas_port_add_phy=1;
- dsaswideprintk((KERN_DEBUG "\t\tForming port\n\t\t"
- "phy_id=%d sas_address=0x%018llX\n",
- i, sas_address));
- phy_info->port_details = port_details;
- }
-
- if (i == port_info->num_phys - 1)
- continue;
- phy_info_cmp = &port_info->phy_info[i + 1];
- for (j = i + 1 ; j < port_info->num_phys ; j++,
- phy_info_cmp++) {
- if (!phy_info_cmp->attached.sas_address)
- continue;
- if (sas_address != phy_info_cmp->attached.sas_address)
- continue;
- if (phy_info_cmp->port_details == port_details )
- continue;
- dsaswideprintk((KERN_DEBUG
- "\t\tphy_id=%d sas_address=0x%018llX\n",
- j, phy_info_cmp->attached.sas_address));
- if (phy_info_cmp->port_details) {
- port_details->rphy =
- mptsas_get_rphy(phy_info_cmp);
- port_details->port =
- mptsas_get_port(phy_info_cmp);
- port_details->starget =
- mptsas_get_starget(phy_info_cmp);
- port_details->num_phys =
- phy_info_cmp->port_details->num_phys;
- if (!phy_info_cmp->port_details->num_phys)
- kfree(phy_info_cmp->port_details);
- } else
- phy_info_cmp->sas_port_add_phy=1;
- /*
- * Adding a phy to a port
- */
- phy_info_cmp->port_details = port_details;
- if (phy_info_cmp->phy_id < 64 )
- port_details->phy_bitmask |=
- (1 << phy_info_cmp->phy_id);
- port_details->num_phys++;
- }
- }
-
- out:
-
-#ifdef MPT_DEBUG_SAS_WIDE
- for (i = 0; i < port_info->num_phys; i++) {
- port_details = port_info->phy_info[i].port_details;
- if (!port_details)
- continue;
- dsaswideprintk((KERN_DEBUG
- "%s: [%p]: phy_id=%02d num_phys=%02d "
- "bitmask=0x%016llX\n",
- __FUNCTION__,
- port_details, i, port_details->num_phys,
- port_details->phy_bitmask));
- dsaswideprintk((KERN_DEBUG"\t\tport = %p rphy=%p\n",
- port_details->port, port_details->rphy));
- }
- dsaswideprintk((KERN_DEBUG"\n"));
-#endif
- mutex_unlock(&ioc->sas_topology_mutex);
-}
-
-static void
-mptsas_target_reset(MPT_ADAPTER *ioc, VirtTarget * vtarget)
-{
- MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)ioc->sh->hostdata;
-
- if (mptscsih_TMHandler(hd,
- MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET,
- vtarget->bus_id, vtarget->target_id, 0, 0, 5) < 0) {
- hd->tmPending = 0;
- hd->tmState = TM_STATE_NONE;
- printk(MYIOC_s_WARN_FMT
- "Error processing TaskMgmt id=%d TARGET_RESET\n",
- ioc->name, vtarget->target_id);
- }
-}
-
-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)
-{
-
- if (sdev->channel == MPTSAS_RAID_CHANNEL)
- goto out;
-
- sas_read_port_mode_page(sdev);
-
- out:
- return mptscsih_slave_configure(sdev);
-}
-
-static int
-mptsas_target_alloc(struct scsi_target *starget)
-{
- struct Scsi_Host *host = dev_to_shost(&starget->dev);
- MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
- VirtTarget *vtarget;
- u32 target_id;
- u32 channel;
- struct sas_rphy *rphy;
- struct mptsas_portinfo *p;
- int i;
-
- vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL);
- if (!vtarget)
- return -ENOMEM;
-
- vtarget->starget = starget;
- vtarget->ioc_id = hd->ioc->id;
- vtarget->tflags = MPT_TARGET_FLAGS_Q_YES|MPT_TARGET_FLAGS_VALID_INQUIRY;
-
- target_id = starget->id;
- channel = 0;
-
- hd->Targets[target_id] = vtarget;
-
- if (starget->channel == MPTSAS_RAID_CHANNEL)
- goto out;
-
- rphy = dev_to_rphy(starget->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)
- continue;
- target_id = p->phy_info[i].attached.id;
- channel = p->phy_info[i].attached.channel;
- mptsas_set_starget(&p->phy_info[i], starget);
-
- /*
- * Exposing hidden raid components
- */
- if (mptscsih_is_phys_disk(hd->ioc, target_id)) {
- target_id = mptscsih_raid_id_to_num(hd,
- target_id);
- vtarget->tflags |=
- MPT_TARGET_FLAGS_RAID_COMPONENT;
- }
- mutex_unlock(&hd->ioc->sas_topology_mutex);
- goto out;
- }
- }
- mutex_unlock(&hd->ioc->sas_topology_mutex);
-
- kfree(vtarget);
- return -ENXIO;
-
- out:
- vtarget->target_id = target_id;
- vtarget->bus_id = channel;
- starget->hostdata = vtarget;
- return 0;
-}
-
-static void
-mptsas_target_destroy(struct scsi_target *starget)
-{
- struct Scsi_Host *host = dev_to_shost(&starget->dev);
- MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
- struct sas_rphy *rphy;
- struct mptsas_portinfo *p;
- int i;
-
- if (!starget->hostdata)
- return;
-
- if (starget->channel == MPTSAS_RAID_CHANNEL)
- goto out;
-
- rphy = dev_to_rphy(starget->dev.parent);
- 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)
- continue;
- mptsas_set_starget(&p->phy_info[i], NULL);
- goto out;
- }
- }
-
- out:
- kfree(starget->hostdata);
- starget->hostdata = NULL;
-}
-
-