linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Subhash Jadavani <subhashj@codeaurora.org>
To: Seungwon Jeon <tgih.jun@samsung.com>
Cc: linux-scsi@vger.kernel.org,
	'Vinayak Holikatti' <vinholikatti@gmail.com>,
	'Santosh Y' <santoshsy@gmail.com>,
	"'James E.J. Bottomley'" <JBottomley@parallels.com>
Subject: Re: [PATCH 6/7] scsi: ufs: add operation for the uic power mode change
Date: Mon, 29 Jul 2013 15:23:50 +0530	[thread overview]
Message-ID: <51F63BAE.4080709@codeaurora.org> (raw)
In-Reply-To: <002101ce8a06$dac280e0$904782a0$%jun@samsung.com>

Change looks good except few minor comments.

On 7/26/2013 7:18 PM, Seungwon Jeon wrote:
> Setting PA_PWRMode using DME_SET triggers the power mode
> change. And then the result will be given by the HCS.UPMCRS.
> This operation should be done atomically.
>
> Signed-off-by: Seungwon Jeon <tgih.jun@samsung.com>
> ---
>   drivers/scsi/ufs/ufshcd.c |   80 ++++++++++++++++++++++++++++++++++++++++++--
>   drivers/scsi/ufs/ufshcd.h |    3 ++
>   drivers/scsi/ufs/ufshci.h |   12 +++++++
>   3 files changed, 91 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
> index 8277c40..ffda72d 100644
> --- a/drivers/scsi/ufs/ufshcd.c
> +++ b/drivers/scsi/ufs/ufshcd.c
> @@ -36,9 +36,11 @@
>   #include <linux/async.h>
>   
>   #include "ufshcd.h"
> +#include "unipro.h"
>   
>   #define UFSHCD_ENABLE_INTRS	(UTP_TRANSFER_REQ_COMPL |\
>   				 UTP_TASK_REQ_COMPL |\
> +				 UIC_POWER_MODE |\
>   				 UFSHCD_ERROR_MASK)
>   /* UIC command timeout, unit: ms */
>   #define UIC_CMD_TIMEOUT	500
> @@ -359,6 +361,18 @@ static inline bool ufshcd_ready_for_uic_cmd(struct ufs_hba *hba)
>   }
>   
>   /**
> + * ufshcd_get_upmcrs - Get the power mode change request status
> + * @hba: Pointer to adapter instance
> + *
> + * This function gets the UPMCRS field of HCS register
> + * Returns value of UPMCRS field
> + */
> +static inline u8 ufshcd_get_upmcrs(struct ufs_hba *hba)
> +{
> +	return (ufshcd_readl(hba, REG_CONTROLLER_STATUS) >> 8) & 0x7;
> +}
> +
> +/**
>    * ufshcd_dispatch_uic_cmd - Dispatch UIC commands to unipro layers
>    * @hba: per adapter instance
>    * @uic_cmd: UIC command
> @@ -907,6 +921,60 @@ out:
>   EXPORT_SYMBOL_GPL(ufshcd_dme_get_attr);
>   
>   /**
> + * ufshcd_uic_change_pwr_mode - Perform the UIC power mode chage
> + *				using DME_SET primitives.
> + * @hba: per adapter instance
> + * @mode: powr mode value
> + *
> + * Returns 0 on success, non-zero value on failure
> + */
> +int ufshcd_uic_change_pwr_mode(struct ufs_hba *hba, u8 mode)
> +{
> +	struct uic_command uic_cmd = {0};
> +	struct completion pwr_done;
> +	unsigned long flags;
> +	u8 status;
> +	int ret;
> +
> +	uic_cmd.command = UIC_CMD_DME_SET;
> +	uic_cmd.argument1 = UIC_ARG_MIB(PA_PWRMODE);
> +	uic_cmd.argument3 = mode;
> +	init_completion(&pwr_done);
> +
> +	mutex_lock(&hba->uic_cmd_mutex);
> +
> +	spin_lock_irqsave(hba->host->host_lock, flags);
> +	hba->pwr_done = &pwr_done;
> +	spin_unlock_irqrestore(hba->host->host_lock, flags);
> +	ret = __ufshcd_send_uic_cmd(hba, &uic_cmd);
> +	if (ret) {
> +		dev_err(hba->dev, "pwr mode change uic error %d\n", ret);

we should also print the power "mode" which we were trying to set here.

> +		goto out;
> +	}
> +
> +	if (!wait_for_completion_timeout(hba->pwr_done,
> +					 msecs_to_jiffies(UIC_CMD_TIMEOUT))) {
> +		dev_err(hba->dev, "pwr mode change completion timeout\n");

we should also print the power "mode" which we were trying to set here.

> +		ret = -ETIMEDOUT;
> +		goto out;
> +	}
> +
> +	status = ufshcd_get_upmcrs(hba);
> +	if (status != PWR_LOCAL) {
> +		dev_err(hba->dev,
> +			"pwr mode change failed, host umpcrs:0x%x\n",
> +			status);
> +		ret = (status != PWR_OK) ? status : -1;
> +	}
> +out:
> +	spin_lock_irqsave(hba->host->host_lock, flags);
> +	hba->pwr_done = NULL;
> +	spin_unlock_irqrestore(hba->host->host_lock, flags);
> +	mutex_unlock(&hba->uic_cmd_mutex);
> +	return ret;
> +}
> +
> +/**
>    * ufshcd_make_hba_operational - Make UFS controller operational
>    * @hba: per adapter instance
>    *
> @@ -1336,16 +1404,20 @@ ufshcd_transfer_rsp_status(struct ufs_hba *hba, struct ufshcd_lrb *lrbp)
>   /**
>    * ufshcd_uic_cmd_compl - handle completion of uic command
>    * @hba: per adapter instance
> + * @intr_status: interrupt status generated by the controller
>    */
> -static void ufshcd_uic_cmd_compl(struct ufs_hba *hba)
> +static void ufshcd_uic_cmd_compl(struct ufs_hba *hba, u32 intr_status)
>   {
> -	if (hba->active_uic_cmd) {
> +	if ((intr_status & UIC_COMMAND_COMPL) && hba->active_uic_cmd) {
>   		hba->active_uic_cmd->argument2 |=
>   			ufshcd_get_uic_cmd_result(hba);
>   		hba->active_uic_cmd->argument3 =
>   			ufshcd_get_dme_attr_val(hba);
>   		complete(&hba->active_uic_cmd->done);
>   	}
> +
> +	if ((intr_status & UIC_POWER_MODE) && hba->pwr_done)
> +		complete(hba->pwr_done);
>   }
>   
>   /**
> @@ -1447,8 +1519,8 @@ static void ufshcd_sl_intr(struct ufs_hba *hba, u32 intr_status)
>   	if (hba->errors)
>   		ufshcd_err_handler(hba);
>   
> -	if (intr_status & UIC_COMMAND_COMPL)
> -		ufshcd_uic_cmd_compl(hba);
> +	if (intr_status & UFSHCD_UIC_MASK)
> +		ufshcd_uic_cmd_compl(hba, intr_status);
>   
>   	if (intr_status & UTP_TASK_REQ_COMPL)
>   		ufshcd_tmc_handler(hba);
> diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
> index 50bcd29..246c0e1 100644
> --- a/drivers/scsi/ufs/ufshcd.h
> +++ b/drivers/scsi/ufs/ufshcd.h
> @@ -142,6 +142,7 @@ struct ufshcd_lrb {
>    * @uic_cmd_mutex: mutex for uic command
>    * @ufshcd_tm_wait_queue: wait queue for task management
>    * @tm_condition: condition variable for task management
> + * @pwr_done: completion for powr mode change

typo: s/powr/power

>    * @ufshcd_state: UFSHCD states
>    * @intr_mask: Interrupt Mask Bits
>    * @feh_workq: Work queue for fatal controller error handling
> @@ -180,6 +181,8 @@ struct ufs_hba {
>   	wait_queue_head_t ufshcd_tm_wait_queue;
>   	unsigned long tm_condition;
>   
> +	struct completion *pwr_done;
> +
>   	u32 ufshcd_state;
>   	u32 intr_mask;
>   
> diff --git a/drivers/scsi/ufs/ufshci.h b/drivers/scsi/ufs/ufshci.h
> index df4901e..d92fd9c 100644
> --- a/drivers/scsi/ufs/ufshci.h
> +++ b/drivers/scsi/ufs/ufshci.h
> @@ -124,6 +124,9 @@ enum {
>   #define CONTROLLER_FATAL_ERROR			UFS_BIT(16)
>   #define SYSTEM_BUS_FATAL_ERROR			UFS_BIT(17)
>   
> +#define UFSHCD_UIC_MASK		(UIC_COMMAND_COMPL |\
> +				 UIC_POWER_MODE)
> +
>   #define UFSHCD_ERROR_MASK	(UIC_ERROR |\
>   				DEVICE_FATAL_ERROR |\
>   				CONTROLLER_FATAL_ERROR |\
> @@ -142,6 +145,15 @@ enum {
>   #define DEVICE_ERROR_INDICATOR			UFS_BIT(5)
>   #define UIC_POWER_MODE_CHANGE_REQ_STATUS_MASK	UFS_MASK(0x7, 8)
>   
> +enum {
> +	PWR_OK		= 0x0,
> +	PWR_LOCAL	= 0x01,
> +	PWR_REMOTE	= 0x02,
> +	PWR_BUSY	= 0x03,
> +	PWR_ERROR_CAP	= 0x04,
> +	PWR_FATAL_ERROR	= 0x05,
> +};
> +
>   /* HCE - Host Controller Enable 34h */
>   #define CONTROLLER_ENABLE	UFS_BIT(0)
>   #define CONTROLLER_DISABLE	0x0


  reply	other threads:[~2013-07-29  9:53 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-20  0:41 [PATCH v2 0/3] ufs: fix bugs in probing and removing driver paths Akinobu Mita
2013-07-20  0:41 ` [PATCH v2 1/3] ufshcd-pci: release ioremapped region during removing driver Akinobu Mita
2013-07-26 13:45   ` [PATCH 1/7] scsi: ufs: amend the ocs handling with fatal error Seungwon Jeon
2013-07-29  6:17     ` Subhash Jadavani
2013-07-29 10:05       ` Seungwon Jeon
2013-07-29 10:27         ` Subhash Jadavani
2013-07-29 10:51       ` Sujit Reddy Thumma
2013-07-30 13:02         ` Seungwon Jeon
2013-08-12  7:17           ` Subhash Jadavani
2013-08-13 11:50             ` Seungwon Jeon
2013-08-13 13:39               ` Subhash Jadavani
2013-07-29 18:03     ` Santosh Y
2013-07-20  0:41 ` [PATCH v2 2/3] ufs: don't disable_irq() if the IRQ can be shared among devices Akinobu Mita
2013-07-26 13:44   ` [PATCH 0/7] scsi: ufs: some fixes and updates Seungwon Jeon
2013-08-23 13:00     ` [PATCH v2 0/6] " Seungwon Jeon
2013-08-25 11:23       ` Dolev Raviv
2013-08-26 14:40     ` [PATCH v3 " Seungwon Jeon
2013-08-28 10:46       ` Subhash Jadavani
2013-07-20  0:41 ` [PATCH v2 3/3] ufs: don't stop controller before scsi_remove_host() Akinobu Mita
2013-07-26 13:46 ` [PATCH 2/7] scsi: ufs: find out sense data over scsi status values Seungwon Jeon
2013-07-29  6:35   ` Subhash Jadavani
2013-07-30 13:00     ` Seungwon Jeon
2013-07-29 10:51   ` Sujit Reddy Thumma
2013-07-30 13:03     ` Seungwon Jeon
2013-07-30  3:53   ` Santosh Y
2013-07-30 13:03     ` Seungwon Jeon
2013-07-31  0:15       ` Elliott, Robert (Server Storage)
2013-08-06 12:08         ` Seungwon Jeon
2013-08-23 13:00   ` [PATCH v2 1/6] " Seungwon Jeon
2013-08-23 13:00   ` [PATCH v2 2/6] scsi: ufs: fix the setting interrupt aggregation counter Seungwon Jeon
2013-08-23 13:00   ` [PATCH v2 3/6] scsi: ufs: add dme configuration primitives Seungwon Jeon
2013-08-23 13:00   ` [PATCH v2 4/6] scsi: ufs: add unipro attribute IDs Seungwon Jeon
2013-08-23 13:00   ` [PATCH v2 5/6] scsi: ufs: add operation for the uic power mode change Seungwon Jeon
2013-08-23 13:00   ` [PATCH v2 6/6] scsi: ufs: configure the attribute for power mode Seungwon Jeon
2013-08-26 14:40   ` [PATCH v3 1/6] scsi: ufs: find out sense data over scsi status values Seungwon Jeon
2013-08-27  8:53     ` Subhash Jadavani
2013-08-28 12:43       ` Yaniv Gardi
2013-08-26 14:40   ` [PATCH v3 2/6] scsi: ufs: fix the setting interrupt aggregation counter Seungwon Jeon
2013-08-27  9:01     ` Subhash Jadavani
2013-08-28 12:43       ` Yaniv Gardi
2013-08-26 14:40   ` [PATCH v3 3/6] scsi: ufs: add dme configuration primitives Seungwon Jeon
2013-08-27  9:15     ` Subhash Jadavani
2013-08-28 12:44       ` Yaniv Gardi
2013-08-26 14:40   ` [PATCH v3 4/6] scsi: ufs: add unipro attribute IDs Seungwon Jeon
2013-08-27  9:14     ` Subhash Jadavani
2013-08-28 12:46       ` Yaniv Gardi
2013-08-26 14:40   ` [PATCH v3 5/6] scsi: ufs: add operation for the uic power mode change Seungwon Jeon
2013-08-27  9:53     ` Subhash Jadavani
2013-08-27 11:28       ` Seungwon Jeon
2013-08-27 11:47         ` Subhash Jadavani
2013-08-27 11:58           ` Seungwon Jeon
2013-08-28 12:45             ` Yaniv Gardi
2013-08-26 14:41   ` [PATCH v3 6/6] scsi: ufs: configure the attribute for power mode Seungwon Jeon
2013-08-27 10:21     ` Subhash Jadavani
2013-08-27 10:27       ` Subhash Jadavani
2013-09-09 11:51   ` [PATCH] scsi: ufs: export the helper functions for vender probe/remove Seungwon Jeon
2013-07-26 13:46 ` [PATCH 3/7] scsi: ufs: fix the setting interrupt aggregation counter Seungwon Jeon
2013-07-29  7:03   ` Subhash Jadavani
2013-07-30 13:01     ` Seungwon Jeon
2013-07-26 13:47 ` [PATCH 4/7] scsi: ufs: add dme configuration primitives Seungwon Jeon
2013-07-29  9:24   ` Subhash Jadavani
2013-07-30 13:02     ` Seungwon Jeon
2013-08-13  6:56       ` Subhash Jadavani
2013-07-26 13:48 ` [PATCH 5/7] scsi: ufs: add unipro attribute IDs Seungwon Jeon
2013-07-29  9:26   ` Subhash Jadavani
2013-07-26 13:48 ` [PATCH 6/7] scsi: ufs: add operation for the uic power mode change Seungwon Jeon
2013-07-29  9:53   ` Subhash Jadavani [this message]
2013-07-30 13:02     ` Seungwon Jeon
2013-07-26 13:49 ` [PATCH 7/7] scsi: ufs: configure the attribute for power mode Seungwon Jeon
2013-07-31 13:28   ` Subhash Jadavani
2013-08-06 12:08     ` Seungwon Jeon
2013-08-13  7:00       ` Subhash Jadavani

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=51F63BAE.4080709@codeaurora.org \
    --to=subhashj@codeaurora.org \
    --cc=JBottomley@parallels.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=santoshsy@gmail.com \
    --cc=tgih.jun@samsung.com \
    --cc=vinholikatti@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).