Re: [PATCH 10/15] mpi3mr: Get target object based on rphy

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




> On Jul 29, 2022, at 6:16 AM, Sreekanth Reddy <sreekanth.reddy@xxxxxxxxxxxx> wrote:
> 
> 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
> 
> Signed-off-by: Sreekanth Reddy <sreekanth.reddy@xxxxxxxxxxxx>
> ---
> drivers/scsi/mpi3mr/mpi3mr.h           |  4 ++
> drivers/scsi/mpi3mr/mpi3mr_fw.c        |  2 +
> drivers/scsi/mpi3mr/mpi3mr_os.c        | 61 +++++++++++++++++++++-----
> drivers/scsi/mpi3mr/mpi3mr_transport.c | 29 ++++++++++++
> 4 files changed, 86 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h
> index 9cd5f88..a91a57b 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr.h
> +++ b/drivers/scsi/mpi3mr/mpi3mr.h
> @@ -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*/
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
> index 0659d3f..9155434 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
> +++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
> @@ -3745,6 +3745,8 @@ retry_init:
> 	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;
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
> index 9a32dc6..aed9b60 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr_os.c
> +++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
> @@ -4031,9 +4031,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;
> @@ -4046,7 +4047,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)
> @@ -4111,16 +4119,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;
> @@ -4168,11 +4183,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);
> @@ -4180,7 +4196,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)
> @@ -4223,6 +4246,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)
> @@ -4231,8 +4256,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;
> @@ -4246,8 +4288,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;
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_transport.c b/drivers/scsi/mpi3mr/mpi3mr_transport.c
> index 1d6ae9d..f7faf6e 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr_transport.c
> +++ b/drivers/scsi/mpi3mr/mpi3mr_transport.c
> @@ -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
> -- 
> 2.27.0
> 

Reviewed-by: Himanshu Madhani <himanshu.madhani@xxxxxxxxxx>

--
Himanshu Madhani	Oracle Linux Engineering





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]

  Powered by Linux