Commit 626665e9 authored by Sreekanth Reddy's avatar Sreekanth Reddy Committed by Martin K. Petersen

scsi: mpi3mr: Get target object based on rphy

When device is registered with the STL then get the corresponding device's
target object using the rphy in below callback functions:

 - mpi3mr_target_alloc()

 - mpi3mr_slave_alloc()

 - mpi3mr_slave_configure()

 - mpi3mr_slave_destroy()

Link: https://lore.kernel.org/r/20220804131226.16653-11-sreekanth.reddy@broadcom.comReviewed-by: default avatarHimanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: default avatarSreekanth Reddy <sreekanth.reddy@broadcom.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent e22bae30
......@@ -997,6 +997,7 @@ struct scmd_priv {
* @cfg_page_dma: Configuration page DMA address
* @cfg_page_sz: Default configuration page memory size
* @sas_transport_enabled: SAS transport enabled or not
* @scsi_device_channel: Channel ID for SCSI devices
* @sas_hba: SAS node for the controller
* @sas_expander_list: SAS node list of expanders
* @sas_node_lock: Lock to protect SAS node list
......@@ -1180,6 +1181,7 @@ struct mpi3mr_ioc {
u16 cfg_page_sz;
u8 sas_transport_enabled;
u8 scsi_device_channel;
struct mpi3mr_sas_node sas_hba;
struct list_head sas_expander_list;
spinlock_t sas_node_lock;
......@@ -1355,6 +1357,8 @@ 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);
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,
bool device_add);
#endif /*MPI3MR_H_INCLUDED*/
......@@ -3745,6 +3745,8 @@ int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc)
if (!(mrioc->facts.ioc_capabilities &
MPI3_IOCFACTS_CAPABILITY_MULTIPATH_ENABLED)) {
mrioc->sas_transport_enabled = 1;
mrioc->scsi_device_channel = 1;
mrioc->shost->max_channel = 1;
}
mrioc->reply_sz = mrioc->facts.reply_sz;
......
......@@ -4023,9 +4023,10 @@ static void mpi3mr_slave_destroy(struct scsi_device *sdev)
struct Scsi_Host *shost;
struct mpi3mr_ioc *mrioc;
struct mpi3mr_stgt_priv_data *scsi_tgt_priv_data;
struct mpi3mr_tgt_dev *tgt_dev;
struct mpi3mr_tgt_dev *tgt_dev = NULL;
unsigned long flags;
struct scsi_target *starget;
struct sas_rphy *rphy = NULL;
if (!sdev->hostdata)
return;
......@@ -4038,7 +4039,14 @@ static void mpi3mr_slave_destroy(struct scsi_device *sdev)
scsi_tgt_priv_data->num_luns--;
spin_lock_irqsave(&mrioc->tgtdev_lock, flags);
tgt_dev = __mpi3mr_get_tgtdev_by_perst_id(mrioc, starget->id);
if (starget->channel == mrioc->scsi_device_channel)
tgt_dev = __mpi3mr_get_tgtdev_by_perst_id(mrioc, starget->id);
else if (mrioc->sas_transport_enabled && !starget->channel) {
rphy = dev_to_rphy(starget->dev.parent);
tgt_dev = __mpi3mr_get_tgtdev_by_addr_and_rphy(mrioc,
rphy->identify.sas_address, rphy);
}
if (tgt_dev && (!scsi_tgt_priv_data->num_luns))
tgt_dev->starget = NULL;
if (tgt_dev)
......@@ -4103,16 +4111,23 @@ static int mpi3mr_slave_configure(struct scsi_device *sdev)
struct scsi_target *starget;
struct Scsi_Host *shost;
struct mpi3mr_ioc *mrioc;
struct mpi3mr_tgt_dev *tgt_dev;
struct mpi3mr_tgt_dev *tgt_dev = NULL;
unsigned long flags;
int retval = 0;
struct sas_rphy *rphy = NULL;
starget = scsi_target(sdev);
shost = dev_to_shost(&starget->dev);
mrioc = shost_priv(shost);
spin_lock_irqsave(&mrioc->tgtdev_lock, flags);
tgt_dev = __mpi3mr_get_tgtdev_by_perst_id(mrioc, starget->id);
if (starget->channel == mrioc->scsi_device_channel)
tgt_dev = __mpi3mr_get_tgtdev_by_perst_id(mrioc, starget->id);
else if (mrioc->sas_transport_enabled && !starget->channel) {
rphy = dev_to_rphy(starget->dev.parent);
tgt_dev = __mpi3mr_get_tgtdev_by_addr_and_rphy(mrioc,
rphy->identify.sas_address, rphy);
}
spin_unlock_irqrestore(&mrioc->tgtdev_lock, flags);
if (!tgt_dev)
return -ENXIO;
......@@ -4160,11 +4175,12 @@ static int mpi3mr_slave_alloc(struct scsi_device *sdev)
struct Scsi_Host *shost;
struct mpi3mr_ioc *mrioc;
struct mpi3mr_stgt_priv_data *scsi_tgt_priv_data;
struct mpi3mr_tgt_dev *tgt_dev;
struct mpi3mr_tgt_dev *tgt_dev = NULL;
struct mpi3mr_sdev_priv_data *scsi_dev_priv_data;
unsigned long flags;
struct scsi_target *starget;
int retval = 0;
struct sas_rphy *rphy = NULL;
starget = scsi_target(sdev);
shost = dev_to_shost(&starget->dev);
......@@ -4172,7 +4188,14 @@ static int mpi3mr_slave_alloc(struct scsi_device *sdev)
scsi_tgt_priv_data = starget->hostdata;
spin_lock_irqsave(&mrioc->tgtdev_lock, flags);
tgt_dev = __mpi3mr_get_tgtdev_by_perst_id(mrioc, starget->id);
if (starget->channel == mrioc->scsi_device_channel)
tgt_dev = __mpi3mr_get_tgtdev_by_perst_id(mrioc, starget->id);
else if (mrioc->sas_transport_enabled && !starget->channel) {
rphy = dev_to_rphy(starget->dev.parent);
tgt_dev = __mpi3mr_get_tgtdev_by_addr_and_rphy(mrioc,
rphy->identify.sas_address, rphy);
}
if (tgt_dev) {
if (tgt_dev->starget == NULL)
......@@ -4215,6 +4238,8 @@ static int mpi3mr_target_alloc(struct scsi_target *starget)
struct mpi3mr_tgt_dev *tgt_dev;
unsigned long flags;
int retval = 0;
struct sas_rphy *rphy = NULL;
bool update_stgt_priv_data = false;
scsi_tgt_priv_data = kzalloc(sizeof(*scsi_tgt_priv_data), GFP_KERNEL);
if (!scsi_tgt_priv_data)
......@@ -4223,8 +4248,25 @@ static int mpi3mr_target_alloc(struct scsi_target *starget)
starget->hostdata = scsi_tgt_priv_data;
spin_lock_irqsave(&mrioc->tgtdev_lock, flags);
tgt_dev = __mpi3mr_get_tgtdev_by_perst_id(mrioc, starget->id);
if (tgt_dev && !tgt_dev->is_hidden) {
if (starget->channel == mrioc->scsi_device_channel) {
tgt_dev = __mpi3mr_get_tgtdev_by_perst_id(mrioc, starget->id);
if (tgt_dev && !tgt_dev->is_hidden)
update_stgt_priv_data = true;
else
retval = -ENXIO;
} else if (mrioc->sas_transport_enabled && !starget->channel) {
rphy = dev_to_rphy(starget->dev.parent);
tgt_dev = __mpi3mr_get_tgtdev_by_addr_and_rphy(mrioc,
rphy->identify.sas_address, rphy);
if (tgt_dev && !tgt_dev->is_hidden && !tgt_dev->non_stl &&
(tgt_dev->dev_type == MPI3_DEVICE_DEVFORM_SAS_SATA))
update_stgt_priv_data = true;
else
retval = -ENXIO;
}
if (update_stgt_priv_data) {
scsi_tgt_priv_data->starget = starget;
scsi_tgt_priv_data->dev_handle = tgt_dev->dev_handle;
scsi_tgt_priv_data->perst_id = tgt_dev->perst_id;
......@@ -4238,8 +4280,7 @@ static int mpi3mr_target_alloc(struct scsi_target *starget)
if (tgt_dev->dev_type == MPI3_DEVICE_DEVFORM_VD)
scsi_tgt_priv_data->throttle_group =
tgt_dev->dev_spec.vd_inf.tg;
} else
retval = -ENXIO;
}
spin_unlock_irqrestore(&mrioc->tgtdev_lock, flags);
return retval;
......
......@@ -198,6 +198,35 @@ static void mpi3mr_remove_device_by_sas_address(struct mpi3mr_ioc *mrioc,
}
}
/**
* __mpi3mr_get_tgtdev_by_addr_and_rphy - target device search
* @mrioc: Adapter instance reference
* @sas_address: SAS address of the device
* @rphy: SAS transport layer rphy object
*
* This searches for target device from sas address and rphy
* pointer then return mpi3mr_tgt_dev object.
*
* Return: Valid tget_dev or NULL
*/
struct mpi3mr_tgt_dev *__mpi3mr_get_tgtdev_by_addr_and_rphy(
struct mpi3mr_ioc *mrioc, u64 sas_address, struct sas_rphy *rphy)
{
struct mpi3mr_tgt_dev *tgtdev;
assert_spin_locked(&mrioc->tgtdev_lock);
list_for_each_entry(tgtdev, &mrioc->tgtdev_list, list)
if ((tgtdev->dev_type == MPI3_DEVICE_DEVFORM_SAS_SATA) &&
(tgtdev->dev_spec.sas_sata_inf.sas_address == sas_address)
&& (tgtdev->dev_spec.sas_sata_inf.rphy == rphy))
goto found_device;
return NULL;
found_device:
mpi3mr_tgtdev_get(tgtdev);
return tgtdev;
}
/**
* mpi3mr_expander_find_by_sas_address - sas expander search
* @mrioc: Adapter instance reference
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment