Message ID | 20220804131226.16653-12-sreekanth.reddy@broadcom.com (mailing list archive) |
---|---|
State | Accepted |
Headers | show |
Series | mpi3mr: Added Support for SAS Transport | expand |
> On Aug 4, 2022, at 6:12 AM, Sreekanth Reddy <sreekanth.reddy@broadcom.com> wrote: > > Register/unregister the SAS, SATA devices to > SCSI Transport Layer(STL) whenever the corresponding device > is added/removed from topology. > > Reported-by: kernel test robot <lkp@intel.com> > Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com> > --- > drivers/scsi/mpi3mr/mpi3mr.h | 10 ++ > drivers/scsi/mpi3mr/mpi3mr_os.c | 84 ++++++++++--- > drivers/scsi/mpi3mr/mpi3mr_transport.c | 158 +++++++++++++++++++++++++ > 3 files changed, 235 insertions(+), 17 deletions(-) > > diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h > index a91a57b..21ea021 100644 > --- a/drivers/scsi/mpi3mr/mpi3mr.h > +++ b/drivers/scsi/mpi3mr/mpi3mr.h > @@ -569,7 +569,10 @@ struct mpi3mr_enclosure_node { > * information cached from firmware given data > * > * @sas_address: World wide unique SAS address > + * @sas_address_parent: Sas address of parent expander or host > * @dev_info: Device information bits > + * @phy_id: Phy identifier provided in device page 0 > + * @attached_phy_id: Attached phy identifier provided in device page 0 > * @sas_transport_attached: Is this device exposed to transport > * @pend_sas_rphy_add: Flag to check device is in process of add > * @hba_port: HBA port entry > @@ -577,7 +580,10 @@ struct mpi3mr_enclosure_node { > */ > struct tgt_dev_sas_sata { > u64 sas_address; > + u64 sas_address_parent; > u16 dev_info; > + u8 phy_id; > + u8 attached_phy_id; > u8 sas_transport_attached; > u8 pend_sas_rphy_add; > struct mpi3mr_hba_port *hba_port; > @@ -1357,6 +1363,10 @@ void mpi3mr_update_links(struct mpi3mr_ioc *mrioc, > struct mpi3mr_hba_port *hba_port); > void mpi3mr_remove_tgtdev_from_host(struct mpi3mr_ioc *mrioc, > struct mpi3mr_tgt_dev *tgtdev); > +int mpi3mr_report_tgtdev_to_sas_transport(struct mpi3mr_ioc *mrioc, > + struct mpi3mr_tgt_dev *tgtdev); > +void mpi3mr_remove_tgtdev_from_sas_transport(struct mpi3mr_ioc *mrioc, > + struct mpi3mr_tgt_dev *tgtdev); > struct mpi3mr_tgt_dev *__mpi3mr_get_tgtdev_by_addr_and_rphy( > struct mpi3mr_ioc *mrioc, u64 sas_address, struct sas_rphy *rphy); > void mpi3mr_print_device_event_notice(struct mpi3mr_ioc *mrioc, > diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c > index aed9b60..8b1b912 100644 > --- a/drivers/scsi/mpi3mr/mpi3mr_os.c > +++ b/drivers/scsi/mpi3mr/mpi3mr_os.c > @@ -836,19 +836,25 @@ void mpi3mr_remove_tgtdev_from_host(struct mpi3mr_ioc *mrioc, > tgt_priv->dev_handle = MPI3MR_INVALID_DEV_HANDLE; > } > > - if (tgtdev->starget) { > - if (mrioc->current_event) > - mrioc->current_event->pending_at_sml = 1; > - scsi_remove_target(&tgtdev->starget->dev); > - tgtdev->host_exposed = 0; > - if (mrioc->current_event) { > - mrioc->current_event->pending_at_sml = 0; > - if (mrioc->current_event->discard) { > - mpi3mr_print_device_event_notice(mrioc, false); > - return; > + if (!mrioc->sas_transport_enabled || (tgtdev->dev_type != > + MPI3_DEVICE_DEVFORM_SAS_SATA) || tgtdev->non_stl) { > + if (tgtdev->starget) { > + if (mrioc->current_event) > + mrioc->current_event->pending_at_sml = 1; > + scsi_remove_target(&tgtdev->starget->dev); > + tgtdev->host_exposed = 0; > + if (mrioc->current_event) { > + mrioc->current_event->pending_at_sml = 0; > + if (mrioc->current_event->discard) { > + mpi3mr_print_device_event_notice(mrioc, > + false); > + return; > + } > } > } > - } > + } else > + mpi3mr_remove_tgtdev_from_sas_transport(mrioc, tgtdev); > + > ioc_info(mrioc, "%s :Removed handle(0x%04x), wwid(0x%016llx)\n", > __func__, tgtdev->dev_handle, (unsigned long long)tgtdev->wwid); > } > @@ -870,21 +876,25 @@ static int mpi3mr_report_tgtdev_to_host(struct mpi3mr_ioc *mrioc, > int retval = 0; > struct mpi3mr_tgt_dev *tgtdev; > > + if (mrioc->reset_in_progress) > + return -1; > + > tgtdev = mpi3mr_get_tgtdev_by_perst_id(mrioc, perst_id); > if (!tgtdev) { > retval = -1; > goto out; > } > - if (tgtdev->is_hidden) { > + if (tgtdev->is_hidden || tgtdev->host_exposed) { > retval = -1; > goto out; > } > - if (!tgtdev->host_exposed && !mrioc->reset_in_progress) { > + if (!mrioc->sas_transport_enabled || (tgtdev->dev_type != > + MPI3_DEVICE_DEVFORM_SAS_SATA) || tgtdev->non_stl){ > tgtdev->host_exposed = 1; > if (mrioc->current_event) > mrioc->current_event->pending_at_sml = 1; > - scsi_scan_target(&mrioc->shost->shost_gendev, 0, > - tgtdev->perst_id, > + scsi_scan_target(&mrioc->shost->shost_gendev, > + mrioc->scsi_device_channel, tgtdev->perst_id, > SCAN_WILD_CARD, SCSI_SCAN_INITIAL); > if (!tgtdev->starget) > tgtdev->host_exposed = 0; > @@ -895,7 +905,8 @@ static int mpi3mr_report_tgtdev_to_host(struct mpi3mr_ioc *mrioc, > goto out; > } > } > - } > + } else > + mpi3mr_report_tgtdev_to_sas_transport(mrioc, tgtdev); > out: > if (tgtdev) > mpi3mr_tgtdev_put(tgtdev); > @@ -1087,6 +1098,9 @@ static void mpi3mr_update_tgtdev(struct mpi3mr_ioc *mrioc, > tgtdev->dev_spec.sas_sata_inf.dev_info = dev_info; > tgtdev->dev_spec.sas_sata_inf.sas_address = > le64_to_cpu(sasinf->sas_address); > + tgtdev->dev_spec.sas_sata_inf.phy_id = sasinf->phy_num; > + tgtdev->dev_spec.sas_sata_inf.attached_phy_id = > + sasinf->attached_phy_identifier; > if ((dev_info & MPI3_SAS_DEVICE_INFO_DEVICE_TYPE_MASK) != > MPI3_SAS_DEVICE_INFO_DEVICE_TYPE_END_DEVICE) > tgtdev->is_hidden = 1; > @@ -1494,12 +1508,30 @@ static void mpi3mr_sastopochg_evt_bh(struct mpi3mr_ioc *mrioc, > int i; > u16 handle; > u8 reason_code; > - u64 exp_sas_address = 0; > + u64 exp_sas_address = 0, parent_sas_address = 0; > struct mpi3mr_hba_port *hba_port = NULL; > struct mpi3mr_tgt_dev *tgtdev = NULL; > struct mpi3mr_sas_node *sas_expander = NULL; > + unsigned long flags; > + u8 link_rate, prev_link_rate, parent_phy_number; > > mpi3mr_sastopochg_evt_debug(mrioc, event_data); > + if (mrioc->sas_transport_enabled) { > + hba_port = mpi3mr_get_hba_port_by_id(mrioc, > + event_data->io_unit_port); > + if (le16_to_cpu(event_data->expander_dev_handle)) { > + spin_lock_irqsave(&mrioc->sas_node_lock, flags); > + sas_expander = __mpi3mr_expander_find_by_handle(mrioc, > + le16_to_cpu(event_data->expander_dev_handle)); > + if (sas_expander) { > + exp_sas_address = sas_expander->sas_address; > + hba_port = sas_expander->hba_port; > + } > + spin_unlock_irqrestore(&mrioc->sas_node_lock, flags); > + parent_sas_address = exp_sas_address; > + } else > + parent_sas_address = mrioc->sas_hba.sas_address; > + } > > for (i = 0; i < event_data->num_entries; i++) { > if (fwevt->discard) > @@ -1521,6 +1553,24 @@ static void mpi3mr_sastopochg_evt_bh(struct mpi3mr_ioc *mrioc, > mpi3mr_tgtdev_del_from_list(mrioc, tgtdev); > mpi3mr_tgtdev_put(tgtdev); > break; > + case MPI3_EVENT_SAS_TOPO_PHY_RC_RESPONDING: > + case MPI3_EVENT_SAS_TOPO_PHY_RC_PHY_CHANGED: > + case MPI3_EVENT_SAS_TOPO_PHY_RC_NO_CHANGE: > + { > + if (!mrioc->sas_transport_enabled || tgtdev->non_stl > + || tgtdev->is_hidden) > + break; > + link_rate = event_data->phy_entry[i].link_rate >> 4; > + prev_link_rate = event_data->phy_entry[i].link_rate & 0xF; > + if (link_rate == prev_link_rate) > + break; > + if (!parent_sas_address) > + break; > + parent_phy_number = event_data->start_phy_num + i; > + mpi3mr_update_links(mrioc, parent_sas_address, handle, > + parent_phy_number, link_rate, hba_port); > + break; > + } > default: > break; > } > diff --git a/drivers/scsi/mpi3mr/mpi3mr_transport.c b/drivers/scsi/mpi3mr/mpi3mr_transport.c > index 48cee03..706c6e6 100644 > --- a/drivers/scsi/mpi3mr/mpi3mr_transport.c > +++ b/drivers/scsi/mpi3mr/mpi3mr_transport.c > @@ -1652,3 +1652,161 @@ void mpi3mr_expander_remove(struct mpi3mr_ioc *mrioc, u64 sas_address, > mpi3mr_expander_node_remove(mrioc, sas_expander); > > } > + > +/** > + * mpi3mr_get_sas_negotiated_logical_linkrate - get linkrate > + * @mrioc: Adapter instance reference > + * @tgtdev: Target device > + * > + * This function identifies whether the target device is > + * attached directly or through expander and issues sas phy > + * page0 or expander phy page1 and gets the link rate, if there > + * is any failure in reading the pages then this returns link > + * rate of 1.5. > + * > + * Return: logical link rate. > + */ > +static u8 mpi3mr_get_sas_negotiated_logical_linkrate(struct mpi3mr_ioc *mrioc, > + struct mpi3mr_tgt_dev *tgtdev) > +{ > + u8 link_rate = MPI3_SAS_NEG_LINK_RATE_1_5, phy_number; > + struct mpi3_sas_expander_page1 expander_pg1; > + struct mpi3_sas_phy_page0 phy_pg0; > + u32 phynum_handle; > + u16 ioc_status; > + > + phy_number = tgtdev->dev_spec.sas_sata_inf.phy_id; > + if (!(tgtdev->devpg0_flag & MPI3_DEVICE0_FLAGS_ATT_METHOD_DIR_ATTACHED)) { > + phynum_handle = ((phy_number<<MPI3_SAS_EXPAND_PGAD_PHYNUM_SHIFT) > + | tgtdev->parent_handle); > + if (mpi3mr_cfg_get_sas_exp_pg1(mrioc, &ioc_status, > + &expander_pg1, sizeof(expander_pg1), > + MPI3_SAS_EXPAND_PGAD_FORM_HANDLE_PHY_NUM, > + phynum_handle)) { > + ioc_err(mrioc, "failure at %s:%d/%s()!\n", > + __FILE__, __LINE__, __func__); > + goto out; > + } > + if (ioc_status != MPI3_IOCSTATUS_SUCCESS) { > + ioc_err(mrioc, "failure at %s:%d/%s()!\n", > + __FILE__, __LINE__, __func__); > + goto out; > + } > + link_rate = (expander_pg1.negotiated_link_rate & > + MPI3_SAS_NEG_LINK_RATE_LOGICAL_MASK) >> > + MPI3_SAS_NEG_LINK_RATE_LOGICAL_SHIFT; > + goto out; > + } > + if (mpi3mr_cfg_get_sas_phy_pg0(mrioc, &ioc_status, &phy_pg0, > + sizeof(struct mpi3_sas_phy_page0), > + MPI3_SAS_PHY_PGAD_FORM_PHY_NUMBER, phy_number)) { > + ioc_err(mrioc, "failure at %s:%d/%s()!\n", > + __FILE__, __LINE__, __func__); > + goto out; > + } > + if (ioc_status != MPI3_IOCSTATUS_SUCCESS) { > + ioc_err(mrioc, "failure at %s:%d/%s()!\n", > + __FILE__, __LINE__, __func__); > + goto out; > + } > + link_rate = (phy_pg0.negotiated_link_rate & > + MPI3_SAS_NEG_LINK_RATE_LOGICAL_MASK) >> > + MPI3_SAS_NEG_LINK_RATE_LOGICAL_SHIFT; > +out: > + return link_rate; > +} > + > +/** > + * mpi3mr_report_tgtdev_to_sas_transport - expose dev to SAS TL > + * @mrioc: Adapter instance reference > + * @tgtdev: Target device > + * > + * This function exposes the target device after > + * preparing host_phy, setting up link rate etc. > + * > + * Return: 0 on success, non-zero for failure. > + */ > +int mpi3mr_report_tgtdev_to_sas_transport(struct mpi3mr_ioc *mrioc, > + struct mpi3mr_tgt_dev *tgtdev) > +{ > + int retval = 0; > + u8 link_rate, parent_phy_number; > + u64 sas_address_parent, sas_address; > + struct mpi3mr_hba_port *hba_port; > + u8 port_id; > + > + if ((tgtdev->dev_type != MPI3_DEVICE_DEVFORM_SAS_SATA) || > + !mrioc->sas_transport_enabled) > + return -1; > + > + sas_address = tgtdev->dev_spec.sas_sata_inf.sas_address; > + if (!mrioc->sas_hba.num_phys) > + mpi3mr_sas_host_add(mrioc); > + else > + mpi3mr_sas_host_refresh(mrioc); > + > + if (mpi3mr_get_sas_address(mrioc, tgtdev->parent_handle, > + &sas_address_parent) != 0) { > + ioc_err(mrioc, "failure at %s:%d/%s()!\n", > + __FILE__, __LINE__, __func__); > + return -1; > + } > + tgtdev->dev_spec.sas_sata_inf.sas_address_parent = sas_address_parent; > + > + parent_phy_number = tgtdev->dev_spec.sas_sata_inf.phy_id; > + port_id = tgtdev->io_unit_port; > + > + hba_port = mpi3mr_get_hba_port_by_id(mrioc, port_id); > + if (!hba_port) { > + ioc_err(mrioc, "failure at %s:%d/%s()!\n", > + __FILE__, __LINE__, __func__); > + return -1; > + } > + tgtdev->dev_spec.sas_sata_inf.hba_port = hba_port; > + > + link_rate = mpi3mr_get_sas_negotiated_logical_linkrate(mrioc, tgtdev); > + > + mpi3mr_update_links(mrioc, sas_address_parent, tgtdev->dev_handle, > + parent_phy_number, link_rate, hba_port); > + > + tgtdev->host_exposed = 1; > + if (!mpi3mr_sas_port_add(mrioc, tgtdev->dev_handle, > + sas_address_parent, hba_port)) { > + tgtdev->host_exposed = 0; > + retval = -1; > + } else if ((!tgtdev->starget)) { > + if (!mrioc->is_driver_loading) > + mpi3mr_sas_port_remove(mrioc, sas_address, > + sas_address_parent, hba_port); > + tgtdev->host_exposed = 0; > + retval = -1; > + } > + return retval; > +} > + > +/** > + * mpi3mr_remove_tgtdev_from_sas_transport - remove from SAS TL > + * @mrioc: Adapter instance reference > + * @tgtdev: Target device > + * > + * This function removes the target device > + * > + * Return: None. > + */ > +void mpi3mr_remove_tgtdev_from_sas_transport(struct mpi3mr_ioc *mrioc, > + struct mpi3mr_tgt_dev *tgtdev) > +{ > + u64 sas_address_parent, sas_address; > + struct mpi3mr_hba_port *hba_port; > + > + if ((tgtdev->dev_type != MPI3_DEVICE_DEVFORM_SAS_SATA) || > + !mrioc->sas_transport_enabled) > + return; > + > + hba_port = tgtdev->dev_spec.sas_sata_inf.hba_port; > + sas_address = tgtdev->dev_spec.sas_sata_inf.sas_address; > + sas_address_parent = tgtdev->dev_spec.sas_sata_inf.sas_address_parent; > + mpi3mr_sas_port_remove(mrioc, sas_address, sas_address_parent, > + hba_port); > + tgtdev->host_exposed = 0; > +} > -- > 2.27.0 > Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com> — Himanshu Madhani Oracle Linux Engineering
diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h index a91a57b..21ea021 100644 --- a/drivers/scsi/mpi3mr/mpi3mr.h +++ b/drivers/scsi/mpi3mr/mpi3mr.h @@ -569,7 +569,10 @@ struct mpi3mr_enclosure_node { * information cached from firmware given data * * @sas_address: World wide unique SAS address + * @sas_address_parent: Sas address of parent expander or host * @dev_info: Device information bits + * @phy_id: Phy identifier provided in device page 0 + * @attached_phy_id: Attached phy identifier provided in device page 0 * @sas_transport_attached: Is this device exposed to transport * @pend_sas_rphy_add: Flag to check device is in process of add * @hba_port: HBA port entry @@ -577,7 +580,10 @@ struct mpi3mr_enclosure_node { */ struct tgt_dev_sas_sata { u64 sas_address; + u64 sas_address_parent; u16 dev_info; + u8 phy_id; + u8 attached_phy_id; u8 sas_transport_attached; u8 pend_sas_rphy_add; struct mpi3mr_hba_port *hba_port; @@ -1357,6 +1363,10 @@ void mpi3mr_update_links(struct mpi3mr_ioc *mrioc, struct mpi3mr_hba_port *hba_port); void mpi3mr_remove_tgtdev_from_host(struct mpi3mr_ioc *mrioc, struct mpi3mr_tgt_dev *tgtdev); +int mpi3mr_report_tgtdev_to_sas_transport(struct mpi3mr_ioc *mrioc, + struct mpi3mr_tgt_dev *tgtdev); +void mpi3mr_remove_tgtdev_from_sas_transport(struct mpi3mr_ioc *mrioc, + struct mpi3mr_tgt_dev *tgtdev); struct mpi3mr_tgt_dev *__mpi3mr_get_tgtdev_by_addr_and_rphy( struct mpi3mr_ioc *mrioc, u64 sas_address, struct sas_rphy *rphy); void mpi3mr_print_device_event_notice(struct mpi3mr_ioc *mrioc, diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c index aed9b60..8b1b912 100644 --- a/drivers/scsi/mpi3mr/mpi3mr_os.c +++ b/drivers/scsi/mpi3mr/mpi3mr_os.c @@ -836,19 +836,25 @@ void mpi3mr_remove_tgtdev_from_host(struct mpi3mr_ioc *mrioc, tgt_priv->dev_handle = MPI3MR_INVALID_DEV_HANDLE; } - if (tgtdev->starget) { - if (mrioc->current_event) - mrioc->current_event->pending_at_sml = 1; - scsi_remove_target(&tgtdev->starget->dev); - tgtdev->host_exposed = 0; - if (mrioc->current_event) { - mrioc->current_event->pending_at_sml = 0; - if (mrioc->current_event->discard) { - mpi3mr_print_device_event_notice(mrioc, false); - return; + if (!mrioc->sas_transport_enabled || (tgtdev->dev_type != + MPI3_DEVICE_DEVFORM_SAS_SATA) || tgtdev->non_stl) { + if (tgtdev->starget) { + if (mrioc->current_event) + mrioc->current_event->pending_at_sml = 1; + scsi_remove_target(&tgtdev->starget->dev); + tgtdev->host_exposed = 0; + if (mrioc->current_event) { + mrioc->current_event->pending_at_sml = 0; + if (mrioc->current_event->discard) { + mpi3mr_print_device_event_notice(mrioc, + false); + return; + } } } - } + } else + mpi3mr_remove_tgtdev_from_sas_transport(mrioc, tgtdev); + ioc_info(mrioc, "%s :Removed handle(0x%04x), wwid(0x%016llx)\n", __func__, tgtdev->dev_handle, (unsigned long long)tgtdev->wwid); } @@ -870,21 +876,25 @@ static int mpi3mr_report_tgtdev_to_host(struct mpi3mr_ioc *mrioc, int retval = 0; struct mpi3mr_tgt_dev *tgtdev; + if (mrioc->reset_in_progress) + return -1; + tgtdev = mpi3mr_get_tgtdev_by_perst_id(mrioc, perst_id); if (!tgtdev) { retval = -1; goto out; } - if (tgtdev->is_hidden) { + if (tgtdev->is_hidden || tgtdev->host_exposed) { retval = -1; goto out; } - if (!tgtdev->host_exposed && !mrioc->reset_in_progress) { + if (!mrioc->sas_transport_enabled || (tgtdev->dev_type != + MPI3_DEVICE_DEVFORM_SAS_SATA) || tgtdev->non_stl){ tgtdev->host_exposed = 1; if (mrioc->current_event) mrioc->current_event->pending_at_sml = 1; - scsi_scan_target(&mrioc->shost->shost_gendev, 0, - tgtdev->perst_id, + scsi_scan_target(&mrioc->shost->shost_gendev, + mrioc->scsi_device_channel, tgtdev->perst_id, SCAN_WILD_CARD, SCSI_SCAN_INITIAL); if (!tgtdev->starget) tgtdev->host_exposed = 0; @@ -895,7 +905,8 @@ static int mpi3mr_report_tgtdev_to_host(struct mpi3mr_ioc *mrioc, goto out; } } - } + } else + mpi3mr_report_tgtdev_to_sas_transport(mrioc, tgtdev); out: if (tgtdev) mpi3mr_tgtdev_put(tgtdev); @@ -1087,6 +1098,9 @@ static void mpi3mr_update_tgtdev(struct mpi3mr_ioc *mrioc, tgtdev->dev_spec.sas_sata_inf.dev_info = dev_info; tgtdev->dev_spec.sas_sata_inf.sas_address = le64_to_cpu(sasinf->sas_address); + tgtdev->dev_spec.sas_sata_inf.phy_id = sasinf->phy_num; + tgtdev->dev_spec.sas_sata_inf.attached_phy_id = + sasinf->attached_phy_identifier; if ((dev_info & MPI3_SAS_DEVICE_INFO_DEVICE_TYPE_MASK) != MPI3_SAS_DEVICE_INFO_DEVICE_TYPE_END_DEVICE) tgtdev->is_hidden = 1; @@ -1494,12 +1508,30 @@ static void mpi3mr_sastopochg_evt_bh(struct mpi3mr_ioc *mrioc, int i; u16 handle; u8 reason_code; - u64 exp_sas_address = 0; + u64 exp_sas_address = 0, parent_sas_address = 0; struct mpi3mr_hba_port *hba_port = NULL; struct mpi3mr_tgt_dev *tgtdev = NULL; struct mpi3mr_sas_node *sas_expander = NULL; + unsigned long flags; + u8 link_rate, prev_link_rate, parent_phy_number; mpi3mr_sastopochg_evt_debug(mrioc, event_data); + if (mrioc->sas_transport_enabled) { + hba_port = mpi3mr_get_hba_port_by_id(mrioc, + event_data->io_unit_port); + if (le16_to_cpu(event_data->expander_dev_handle)) { + spin_lock_irqsave(&mrioc->sas_node_lock, flags); + sas_expander = __mpi3mr_expander_find_by_handle(mrioc, + le16_to_cpu(event_data->expander_dev_handle)); + if (sas_expander) { + exp_sas_address = sas_expander->sas_address; + hba_port = sas_expander->hba_port; + } + spin_unlock_irqrestore(&mrioc->sas_node_lock, flags); + parent_sas_address = exp_sas_address; + } else + parent_sas_address = mrioc->sas_hba.sas_address; + } for (i = 0; i < event_data->num_entries; i++) { if (fwevt->discard) @@ -1521,6 +1553,24 @@ static void mpi3mr_sastopochg_evt_bh(struct mpi3mr_ioc *mrioc, mpi3mr_tgtdev_del_from_list(mrioc, tgtdev); mpi3mr_tgtdev_put(tgtdev); break; + case MPI3_EVENT_SAS_TOPO_PHY_RC_RESPONDING: + case MPI3_EVENT_SAS_TOPO_PHY_RC_PHY_CHANGED: + case MPI3_EVENT_SAS_TOPO_PHY_RC_NO_CHANGE: + { + if (!mrioc->sas_transport_enabled || tgtdev->non_stl + || tgtdev->is_hidden) + break; + link_rate = event_data->phy_entry[i].link_rate >> 4; + prev_link_rate = event_data->phy_entry[i].link_rate & 0xF; + if (link_rate == prev_link_rate) + break; + if (!parent_sas_address) + break; + parent_phy_number = event_data->start_phy_num + i; + mpi3mr_update_links(mrioc, parent_sas_address, handle, + parent_phy_number, link_rate, hba_port); + break; + } default: break; } diff --git a/drivers/scsi/mpi3mr/mpi3mr_transport.c b/drivers/scsi/mpi3mr/mpi3mr_transport.c index 48cee03..706c6e6 100644 --- a/drivers/scsi/mpi3mr/mpi3mr_transport.c +++ b/drivers/scsi/mpi3mr/mpi3mr_transport.c @@ -1652,3 +1652,161 @@ void mpi3mr_expander_remove(struct mpi3mr_ioc *mrioc, u64 sas_address, mpi3mr_expander_node_remove(mrioc, sas_expander); } + +/** + * mpi3mr_get_sas_negotiated_logical_linkrate - get linkrate + * @mrioc: Adapter instance reference + * @tgtdev: Target device + * + * This function identifies whether the target device is + * attached directly or through expander and issues sas phy + * page0 or expander phy page1 and gets the link rate, if there + * is any failure in reading the pages then this returns link + * rate of 1.5. + * + * Return: logical link rate. + */ +static u8 mpi3mr_get_sas_negotiated_logical_linkrate(struct mpi3mr_ioc *mrioc, + struct mpi3mr_tgt_dev *tgtdev) +{ + u8 link_rate = MPI3_SAS_NEG_LINK_RATE_1_5, phy_number; + struct mpi3_sas_expander_page1 expander_pg1; + struct mpi3_sas_phy_page0 phy_pg0; + u32 phynum_handle; + u16 ioc_status; + + phy_number = tgtdev->dev_spec.sas_sata_inf.phy_id; + if (!(tgtdev->devpg0_flag & MPI3_DEVICE0_FLAGS_ATT_METHOD_DIR_ATTACHED)) { + phynum_handle = ((phy_number<<MPI3_SAS_EXPAND_PGAD_PHYNUM_SHIFT) + | tgtdev->parent_handle); + if (mpi3mr_cfg_get_sas_exp_pg1(mrioc, &ioc_status, + &expander_pg1, sizeof(expander_pg1), + MPI3_SAS_EXPAND_PGAD_FORM_HANDLE_PHY_NUM, + phynum_handle)) { + ioc_err(mrioc, "failure at %s:%d/%s()!\n", + __FILE__, __LINE__, __func__); + goto out; + } + if (ioc_status != MPI3_IOCSTATUS_SUCCESS) { + ioc_err(mrioc, "failure at %s:%d/%s()!\n", + __FILE__, __LINE__, __func__); + goto out; + } + link_rate = (expander_pg1.negotiated_link_rate & + MPI3_SAS_NEG_LINK_RATE_LOGICAL_MASK) >> + MPI3_SAS_NEG_LINK_RATE_LOGICAL_SHIFT; + goto out; + } + if (mpi3mr_cfg_get_sas_phy_pg0(mrioc, &ioc_status, &phy_pg0, + sizeof(struct mpi3_sas_phy_page0), + MPI3_SAS_PHY_PGAD_FORM_PHY_NUMBER, phy_number)) { + ioc_err(mrioc, "failure at %s:%d/%s()!\n", + __FILE__, __LINE__, __func__); + goto out; + } + if (ioc_status != MPI3_IOCSTATUS_SUCCESS) { + ioc_err(mrioc, "failure at %s:%d/%s()!\n", + __FILE__, __LINE__, __func__); + goto out; + } + link_rate = (phy_pg0.negotiated_link_rate & + MPI3_SAS_NEG_LINK_RATE_LOGICAL_MASK) >> + MPI3_SAS_NEG_LINK_RATE_LOGICAL_SHIFT; +out: + return link_rate; +} + +/** + * mpi3mr_report_tgtdev_to_sas_transport - expose dev to SAS TL + * @mrioc: Adapter instance reference + * @tgtdev: Target device + * + * This function exposes the target device after + * preparing host_phy, setting up link rate etc. + * + * Return: 0 on success, non-zero for failure. + */ +int mpi3mr_report_tgtdev_to_sas_transport(struct mpi3mr_ioc *mrioc, + struct mpi3mr_tgt_dev *tgtdev) +{ + int retval = 0; + u8 link_rate, parent_phy_number; + u64 sas_address_parent, sas_address; + struct mpi3mr_hba_port *hba_port; + u8 port_id; + + if ((tgtdev->dev_type != MPI3_DEVICE_DEVFORM_SAS_SATA) || + !mrioc->sas_transport_enabled) + return -1; + + sas_address = tgtdev->dev_spec.sas_sata_inf.sas_address; + if (!mrioc->sas_hba.num_phys) + mpi3mr_sas_host_add(mrioc); + else + mpi3mr_sas_host_refresh(mrioc); + + if (mpi3mr_get_sas_address(mrioc, tgtdev->parent_handle, + &sas_address_parent) != 0) { + ioc_err(mrioc, "failure at %s:%d/%s()!\n", + __FILE__, __LINE__, __func__); + return -1; + } + tgtdev->dev_spec.sas_sata_inf.sas_address_parent = sas_address_parent; + + parent_phy_number = tgtdev->dev_spec.sas_sata_inf.phy_id; + port_id = tgtdev->io_unit_port; + + hba_port = mpi3mr_get_hba_port_by_id(mrioc, port_id); + if (!hba_port) { + ioc_err(mrioc, "failure at %s:%d/%s()!\n", + __FILE__, __LINE__, __func__); + return -1; + } + tgtdev->dev_spec.sas_sata_inf.hba_port = hba_port; + + link_rate = mpi3mr_get_sas_negotiated_logical_linkrate(mrioc, tgtdev); + + mpi3mr_update_links(mrioc, sas_address_parent, tgtdev->dev_handle, + parent_phy_number, link_rate, hba_port); + + tgtdev->host_exposed = 1; + if (!mpi3mr_sas_port_add(mrioc, tgtdev->dev_handle, + sas_address_parent, hba_port)) { + tgtdev->host_exposed = 0; + retval = -1; + } else if ((!tgtdev->starget)) { + if (!mrioc->is_driver_loading) + mpi3mr_sas_port_remove(mrioc, sas_address, + sas_address_parent, hba_port); + tgtdev->host_exposed = 0; + retval = -1; + } + return retval; +} + +/** + * mpi3mr_remove_tgtdev_from_sas_transport - remove from SAS TL + * @mrioc: Adapter instance reference + * @tgtdev: Target device + * + * This function removes the target device + * + * Return: None. + */ +void mpi3mr_remove_tgtdev_from_sas_transport(struct mpi3mr_ioc *mrioc, + struct mpi3mr_tgt_dev *tgtdev) +{ + u64 sas_address_parent, sas_address; + struct mpi3mr_hba_port *hba_port; + + if ((tgtdev->dev_type != MPI3_DEVICE_DEVFORM_SAS_SATA) || + !mrioc->sas_transport_enabled) + return; + + hba_port = tgtdev->dev_spec.sas_sata_inf.hba_port; + sas_address = tgtdev->dev_spec.sas_sata_inf.sas_address; + sas_address_parent = tgtdev->dev_spec.sas_sata_inf.sas_address_parent; + mpi3mr_sas_port_remove(mrioc, sas_address, sas_address_parent, + hba_port); + tgtdev->host_exposed = 0; +}
Register/unregister the SAS, SATA devices to SCSI Transport Layer(STL) whenever the corresponding device is added/removed from topology. Reported-by: kernel test robot <lkp@intel.com> Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com> --- drivers/scsi/mpi3mr/mpi3mr.h | 10 ++ drivers/scsi/mpi3mr/mpi3mr_os.c | 84 ++++++++++--- drivers/scsi/mpi3mr/mpi3mr_transport.c | 158 +++++++++++++++++++++++++ 3 files changed, 235 insertions(+), 17 deletions(-)