diff mbox series

[11/15] mpi3mr: Add SAS SATA end devices to STL

Message ID 20220729131627.15019-12-sreekanth.reddy@broadcom.com (mailing list archive)
State Superseded
Headers show
Series mpi3mr: Added Support for SAS Transport | expand

Commit Message

Sreekanth Reddy July 29, 2022, 1:16 p.m. UTC
Register/unregister the SAS, SATA devices to
SCSI Transport Layer(STL) whenever the corresponding device
is added/removed from topology.

Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
---
 drivers/scsi/mpi3mr/mpi3mr.h           |  10 ++
 drivers/scsi/mpi3mr/mpi3mr_os.c        |  83 ++++++++++---
 drivers/scsi/mpi3mr/mpi3mr_transport.c | 158 +++++++++++++++++++++++++
 3 files changed, 234 insertions(+), 17 deletions(-)

Comments

kernel test robot July 29, 2022, 5:32 p.m. UTC | #1
Hi Sreekanth,

I love your patch! Perhaps something to improve:

[auto build test WARNING on mkp-scsi/for-next]
[also build test WARNING on next-20220728]
[cannot apply to jejb-scsi/for-next linus/master v5.19-rc8]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Sreekanth-Reddy/mpi3mr-Added-Support-for-SAS-Transport/20220729-210902
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
config: i386-randconfig-a013 (https://download.01.org/0day-ci/archive/20220730/202207300127.y29B3Vbe-lkp@intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 8dfaecc4c24494337933aff9d9166486ca0949f1)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/e4b268bf60cc339de06db43ad3da7450cf59e9c2
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Sreekanth-Reddy/mpi3mr-Added-Support-for-SAS-Transport/20220729-210902
        git checkout e4b268bf60cc339de06db43ad3da7450cf59e9c2
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash drivers/scsi/mpi3mr/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/scsi/mpi3mr/mpi3mr_os.c:1573:3: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
                   default:
                   ^
   drivers/scsi/mpi3mr/mpi3mr_os.c:1573:3: note: insert 'break;' to avoid fall-through
                   default:
                   ^
                   break; 
   1 warning generated.


vim +1573 drivers/scsi/mpi3mr/mpi3mr_os.c

9fc4abfe5a5fc9f Kashyap Desai   2021-05-20  1491  
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1492  /**
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1493   * mpi3mr_sastopochg_evt_bh - SASTopologyChange evt bottomhalf
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1494   * @mrioc: Adapter instance reference
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1495   * @fwevt: Firmware event reference
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1496   *
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1497   * Prints information about the SAS topology change event and
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1498   * for "not responding" event code, removes the device from the
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1499   * upper layers.
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1500   *
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1501   * Return: Nothing.
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1502   */
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1503  static void mpi3mr_sastopochg_evt_bh(struct mpi3mr_ioc *mrioc,
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1504  	struct mpi3mr_fwevt *fwevt)
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1505  {
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1506  	struct mpi3_event_data_sas_topology_change_list *event_data =
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1507  	    (struct mpi3_event_data_sas_topology_change_list *)fwevt->event_data;
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1508  	int i;
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1509  	u16 handle;
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1510  	u8 reason_code;
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1511  	u64 exp_sas_address = 0, parent_sas_address = 0;
eaf398d9cf51b23 Sreekanth Reddy 2022-07-29  1512  	struct mpi3mr_hba_port *hba_port = NULL;
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1513  	struct mpi3mr_tgt_dev *tgtdev = NULL;
eaf398d9cf51b23 Sreekanth Reddy 2022-07-29  1514  	struct mpi3mr_sas_node *sas_expander = NULL;
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1515  	unsigned long flags;
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1516  	u8 link_rate, prev_link_rate, parent_phy_number;
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1517  
9fc4abfe5a5fc9f Kashyap Desai   2021-05-20  1518  	mpi3mr_sastopochg_evt_debug(mrioc, event_data);
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1519  	if (mrioc->sas_transport_enabled) {
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1520  		hba_port = mpi3mr_get_hba_port_by_id(mrioc,
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1521  		    event_data->io_unit_port);
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1522  		if (le16_to_cpu(event_data->expander_dev_handle)) {
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1523  			spin_lock_irqsave(&mrioc->sas_node_lock, flags);
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1524  			sas_expander = __mpi3mr_expander_find_by_handle(mrioc,
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1525  			    le16_to_cpu(event_data->expander_dev_handle));
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1526  			if (sas_expander) {
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1527  				exp_sas_address = sas_expander->sas_address;
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1528  				hba_port = sas_expander->hba_port;
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1529  			}
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1530  			spin_unlock_irqrestore(&mrioc->sas_node_lock, flags);
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1531  			parent_sas_address = exp_sas_address;
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1532  		} else
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1533  			parent_sas_address = mrioc->sas_hba.sas_address;
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1534  	}
9fc4abfe5a5fc9f Kashyap Desai   2021-05-20  1535  
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1536  	for (i = 0; i < event_data->num_entries; i++) {
580e6742205efe6 Sreekanth Reddy 2022-02-10  1537  		if (fwevt->discard)
580e6742205efe6 Sreekanth Reddy 2022-02-10  1538  			return;
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1539  		handle = le16_to_cpu(event_data->phy_entry[i].attached_dev_handle);
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1540  		if (!handle)
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1541  			continue;
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1542  		tgtdev = mpi3mr_get_tgtdev_by_handle(mrioc, handle);
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1543  		if (!tgtdev)
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1544  			continue;
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1545  
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1546  		reason_code = event_data->phy_entry[i].status &
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1547  		    MPI3_EVENT_SAS_TOPO_PHY_RC_MASK;
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1548  
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1549  		switch (reason_code) {
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1550  		case MPI3_EVENT_SAS_TOPO_PHY_RC_TARG_NOT_RESPONDING:
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1551  			if (tgtdev->host_exposed)
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1552  				mpi3mr_remove_tgtdev_from_host(mrioc, tgtdev);
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1553  			mpi3mr_tgtdev_del_from_list(mrioc, tgtdev);
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1554  			mpi3mr_tgtdev_put(tgtdev);
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1555  			break;
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1556  		case MPI3_EVENT_SAS_TOPO_PHY_RC_RESPONDING:
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1557  		case MPI3_EVENT_SAS_TOPO_PHY_RC_PHY_CHANGED:
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1558  		case MPI3_EVENT_SAS_TOPO_PHY_RC_NO_CHANGE:
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1559  		{
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1560  			if (!mrioc->sas_transport_enabled || tgtdev->non_stl
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1561  			    || tgtdev->is_hidden)
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1562  				break;
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1563  			link_rate = event_data->phy_entry[i].link_rate >> 4;
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1564  			prev_link_rate = event_data->phy_entry[i].link_rate & 0xF;
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1565  			if (link_rate == prev_link_rate)
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1566  				break;
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1567  			if (!parent_sas_address)
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1568  				break;
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1569  			parent_phy_number = event_data->start_phy_num + i;
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1570  			mpi3mr_update_links(mrioc, parent_sas_address, handle,
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1571  			    parent_phy_number, link_rate, hba_port);
e4b268bf60cc339 Sreekanth Reddy 2022-07-29  1572  		}
13ef29ea4aa0655 Kashyap Desai   2021-05-20 @1573  		default:
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1574  			break;
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1575  		}
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1576  		if (tgtdev)
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1577  			mpi3mr_tgtdev_put(tgtdev);
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1578  	}
eaf398d9cf51b23 Sreekanth Reddy 2022-07-29  1579  
eaf398d9cf51b23 Sreekanth Reddy 2022-07-29  1580  	if (mrioc->sas_transport_enabled && (event_data->exp_status ==
eaf398d9cf51b23 Sreekanth Reddy 2022-07-29  1581  	    MPI3_EVENT_SAS_TOPO_ES_NOT_RESPONDING)) {
eaf398d9cf51b23 Sreekanth Reddy 2022-07-29  1582  		if (sas_expander)
eaf398d9cf51b23 Sreekanth Reddy 2022-07-29  1583  			mpi3mr_expander_remove(mrioc, exp_sas_address,
eaf398d9cf51b23 Sreekanth Reddy 2022-07-29  1584  			    hba_port);
eaf398d9cf51b23 Sreekanth Reddy 2022-07-29  1585  	}
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1586  }
13ef29ea4aa0655 Kashyap Desai   2021-05-20  1587
diff mbox series

Patch

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..a486fe3 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,23 @@  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);
+		}
 		default:
 			break;
 		}
diff --git a/drivers/scsi/mpi3mr/mpi3mr_transport.c b/drivers/scsi/mpi3mr/mpi3mr_transport.c
index f7faf6e..c449820 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_transport.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_transport.c
@@ -1660,3 +1660,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;
+}