-/* 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);
- }
-}
-