scsi:ufs: query, bkops support and other fixes
cover scsi:ufs: query, bkops support and other fixes
Hi James,
Please apply the following patches to 'misc' branch.
Thanks,
Santosh
Akinobu Mita (3):
ufshcd-pci: release ioremapped region during removing driver
ufs: don't disable_irq() if the IRQ can be shared among devices
ufs: don't stop controller before scsi_remove_host()
Dolev Raviv (1):
scsi: ufs: Set fDeviceInit flag to initiate device initialization
Sujit Reddy Thumma (3):
scsi: ufs: Add support for sending NOP OUT UPIU
scsi: ufs: Add support for host assisted background operations
scsi: ufs: Add runtime PM support for UFS host controller driver
Wei Yongjun (1):
ufshcd-pltfrm: remove redundant dev_err call in ufshcd_pltfrm_probe()
Wolfram Sang (1):
drivers/scsi/ufs: don't check resource with devm_ioremap_resource
drivers/scsi/ufs/ufs.h | 155 ++++- drivers/scsi/ufs/ufshcd-pci.c | 99 ++-- drivers/scsi/ufs/ufshcd-pltfrm.c | 57 +- drivers/scsi/ufs/ufshcd.c | 1170 ++++++++++++++++++++++++++++++++++---- drivers/scsi/ufs/ufshcd.h | 59 +- drivers/scsi/ufs/ufshci.h | 2 +- 6 files changed, 1376 insertions(+), 166 deletions(-)
Signature · 1 line
1.8.3.1
PATCH 1/9 scsi: ufs: Add support for sending NOP OUT UPIU
From: Sujit Reddy Thumma <[email protected]>
As part of device initialization sequence, sending NOP OUT UPIU and waiting for NOP IN UPIU response is mandatory. This confirms that the device UFS Transport (UTP) layer is functional and the host can configure the device with further commands. Add support for sending NOP OUT UPIU to check the device connection path and test whether the UTP layer on the device side is functional during initialization.
A tag is acquired from the SCSI tag map space in order to send the device management command. When the tag is acquired by internal command the scsi command is rejected with host busy flag in order to requeue the request. To avoid frequent collisions between internal commands and scsi commands the device management command tag is allocated in the opposite direction w.r.t block layer tag allocation.
drivers/scsi/ufs/ufs.h +33 -7
@@ -36,10 +36,13 @@#ifndef _UFS_H#define _UFS_H +#include <linux/mutex.h> +#include <linux/types.h> +#define MAX_CDB_SIZE 16#define UPIU_HEADER_DWORD (byte3, byte2, byte1, byte0)\ - ((byte3 << 24) | (byte2 << 16) |\ + cpu_to_be32((byte3 << 24) | (byte2 << 16) |\ (byte1 << 8) | (byte0))/*
@@ -73,6 +76,7 @@ enum {UPIU_TRANSACTION_TASK_RSP =0x24 ,UPIU_TRANSACTION_READY_XFER =0x31 ,UPIU_TRANSACTION_QUERY_RSP =0x36 , + UPIU_TRANSACTION_REJECT_UPIU = 0x3F, };/* UPIU Read/Write flags */
@@ -110,6 +114,12 @@ enum { UPIU_COMMAND_SET_TYPE_QUERY = 0x2, }; +/* UTP Transfer Request Command Offset */ +#define UPIU_COMMAND_TYPE_OFFSET 28 + +/* Offset of the response code in the UPIU header */ +#define UPIU_RSP_CODE_OFFSET 8 +enum {MASK_SCSI_STATUS =0xFF ,MASK_TASK_RESPONSE =0xFF00 ,
@@ -138,26 +148,32 @@ struct utp_upiu_header {/** * struct utp_upiu_cmd - Command UPIU structure -* @header: UPIU header structure DW-0 to DW-2 * @data_transfer_len: Data Transfer Length DW-3 * @cdb: Command Descriptor Block CDB DW-4 to DW-7 */ struct utp_upiu_cmd { -struct utp_upiu_header header;u32 exp_data_transfer_len;u8 cdb[MAX_CDB_SIZE ]; };/** -* struct utp_upiu_rsp - Response UPIU structure -* @header: UPIU header DW-0 to DW-2 +* struct utp_upiu_req - general upiu request structure +* @header:UPIU header structure DW-0 to DW-2 +* @sc: fields structure for scsi command DW-3 to DW-7 +*/ +struct utp_upiu_req { +struct utp_upiu_header header; +struct utp_upiu_cmd sc; +}; + +/** +* struct utp_cmd_rsp - Response UPIU structure * @residual_transfer_count: Residual transfer count DW-3 * @reserved: Reserved double words DW-4 to DW-7 * @sense_data_len: Sense data length DW-8 U16 * @sense_data: Sense data field DW-8 to DW-12 */ -struct utp_upiu_rsp { -struct utp_upiu_header header; +struct utp_cmd_rsp {u32 residual_transfer_count;u32 reserved[4 ];u16 sense_data_len;
@@ -165,6 +181,16 @@ struct utp_upiu_rsp { };/** +* struct utp_upiu_rsp - general upiu response structure +* @header: UPIU header structure DW-0 to DW-2 +* @sr: fields structure for scsi command DW-3 to DW-12 +*/ +struct utp_upiu_rsp { +struct utp_upiu_header header; +struct utp_cmd_rsp sr; +}; + +/** * struct utp_upiu_task_req - Task request UPIU structure * @header - UPIU header structure DW0 to DW-2 * @input_param1: Input parameter 1 DW-3
drivers/scsi/ufs/ufshcd.c +479 -106
750 lines not on this page · raw message
drivers/scsi/ufs/ufshcd.h +27 -2
@@ -68,6 +68,10 @@#define UFSHCD "ufshcd"#define UFSHCD_DRIVER_VERSION "0.2" +enum dev_cmd_type { +DEV_CMD_TYPE_NOP =0x0 , +}; +/** * struct uic_command - UIC command structure * @command: UIC command
@@ -91,7 +95,7 @@ struct uic_command {/** * struct ufshcd_lrb - local reference block * @utr_descriptor_ptr: UTRD address of the command -* @ucd_cmd_ptr: UCD address of the command +* @ucd_req_ptr: UCD address of the command * @ucd_rsp_ptr: Response UPIU address for this command * @ucd_prdt_ptr: PRDT address of the command * @cmd: pointer to SCSI command
@@ -101,10 +105,11 @@ struct uic_command {* @command_type: SCSI, UFS, Query. * @task_tag: Task tag of the command * @lun: LUN of the command +* @intr_cmd: Interrupt command (doesn't participate in interrupt aggregation) */ struct ufshcd_lrb {struct utp_transfer_req_desc *utr_descriptor_ptr; -struct utp_upiu_cmd *ucd_cmd_ptr; +struct utp_upiu_req *ucd_req_ptr;struct utp_upiu_rsp *ucd_rsp_ptr;struct ufshcd_sg_entry *ucd_prdt_ptr;
@@ -116,8 +121,22 @@ struct ufshcd_lrb {int command_type;int task_tag;unsigned int lun; +bool intr_cmd; }; +/** +* struct ufs_dev_cmd - all assosiated fields with device management commands +* @type: device management command type - Query, NOP OUT +* @lock: lock to allow one command at a time +* @complete: internal commands completion +* @tag_wq: wait queue until free command slot is available +*/ +struct ufs_dev_cmd { +enum dev_cmd_type type; +struct mutex lock; +struct completion *complete; +wait_queue_head_t tag_wq; +};/** * struct ufs_hba - per adapter private structure
@@ -131,6 +150,7 @@ struct ufshcd_lrb {* @host: Scsi_Host instance of the driver * @dev: device handle * @lrb: local reference block +* @lrb_in_use: lrb in use * @outstanding_tasks: Bits representing outstanding task requests * @outstanding_reqs: Bits representing outstanding transfer requests * @capabilities: UFS Controller Capabilities
@@ -146,6 +166,7 @@ struct ufshcd_lrb {* @intr_mask: Interrupt Mask Bits * @feh_workq: Work queue for fatal controller error handling * @errors: HBA errors +* @dev_cmd: ufs device management command information */ struct ufs_hba {void __iomem *mmio_base;
@@ -164,6 +185,7 @@ struct ufs_hba {struct device *dev;struct ufshcd_lrb *lrb; +unsigned long lrb_in_use;unsigned long outstanding_tasks;unsigned long outstanding_reqs;
@@ -188,6 +210,9 @@ struct ufs_hba {/* HBA Errors */ u32 errors; + +/* Device management request data */ +struct ufs_dev_cmd dev_cmd; };#define ufshcd_writel (hba, val, reg) \
Signature · 1 line
1.8.3.1
James Bottomley
maintainerRe: [PATCH 1/9] scsi: ufs: Add support for sending NOP OUT UPIU
Quoted 16 lines · Santosh Y
From: Sujit Reddy Thumma <[email protected]>
As part of device initialization sequence, sending NOP OUT UPIU and waiting for NOP IN UPIU response is mandatory. This confirms that the device UFS Transport (UTP) layer is functional and the host can configure the device with further commands. Add support for sending NOP OUT UPIU to check the device connection path and test whether the UTP layer on the device side is functional during initialization.
A tag is acquired from the SCSI tag map space in order to send the device management command. When the tag is acquired by internal command the scsi command is rejected with host busy flag in order to requeue the request. To avoid frequent collisions between internal commands and scsi commands the device management command tag is allocated in the opposite direction w.r.t block layer tag allocation.
Quoted 3 lines
Signed-off-by Sujit Reddy Thumma <[email protected]>Signed-off-by Dolev Raviv <[email protected]>Signed-off-by Santosh Y <[email protected]>
This signoff chain looks wrong to me. The patch has quite a long history. Originally, it was sent in by Sujit, then later resent by Dolev with his signoff, then Sujit did a V2 which incorrectly seemed to include Dolev's signoff (that's not correct: signoffs should follow the chain of transmission, so a new patch wouldn't have a previous transmission signoff). Then we got a V3 which was tested by Maya Erez, and finally a v4 which looks to have no testers. In your last submission, you picked up this signoff, so I've changed it to a reviewed-by which seems to be the most appropriate (although I'm not entirely sure Dolev did review the v4 patch).
If this is wrong and Dolev did rewrite the patch (so is one of the authors, which would explain the signoff chain) let me know and I'll edit it in the tree (rebasing is acceptable to get the correct history).
James
Re: [PATCH 1/9] scsi: ufs: Add support for sending NOP OUT UPIU
Quoted 22 lines · James Bottomley
Quoted 16 lines · Santosh Y
From: Sujit Reddy Thumma <[email protected]>
As part of device initialization sequence, sending NOP OUT UPIU and waiting for NOP IN UPIU response is mandatory. This confirms that the device UFS Transport (UTP) layer is functional and the host can configure the device with further commands. Add support for sending NOP OUT UPIU to check the device connection path and test whether the UTP layer on the device side is functional during initialization.
A tag is acquired from the SCSI tag map space in order to send the device management command. When the tag is acquired by internal command the scsi command is rejected with host busy flag in order to requeue the request. To avoid frequent collisions between internal commands and scsi commands the device management command tag is allocated in the opposite direction w.r.t block layer tag allocation.
Quoted 3 lines
Signed-off-by Sujit Reddy Thumma <[email protected]>Signed-off-by Dolev Raviv <[email protected]>Signed-off-by Santosh Y <[email protected]>
Quoted 6 lines
This signoff chain looks wrong to me. The patch has quite a long history. Originally, it was sent in by Sujit, then later resent by Dolev with his signoff, then Sujit did a V2 which incorrectly seemed to include Dolev's signoff (that's not correct: signoffs should follow the chain of transmission, so a new patch wouldn't have a previous transmission signoff).
Initially we had two patches -
scsi: ufs: add support for query requests authored by Dolev and
scsi: ufs: Add support for sending NOP OUT UPIU authored by me.
Based on a possible design issue with the former patch, Dolev merged the patch into the later (NOP OUT patch).
http://thread.gmane.org/gmane.linux.ports.arm.msm/4202/focus=1505731
Since some of the contents are picked from the original patch during rework, I have asked Dolev include his Signed-off-by as a co-author.
Then we got a V3 which was tested by Maya Erez,
Quoted 13 lines
and finally a v4 which looks to have no testers. In your last submission, you picked up this signoff, so I've changed it to a reviewed-by which seems to be the most appropriate (although I'm not entirely sure Dolev did review the v4 patch).
If this is wrong and Dolev did rewrite the patch (so is one of the authors, which would explain the signoff chain) let me know and I'll edit it in the tree (rebasing is acceptable to get the correct history).
James
Signature · 2 lines
Regards, Sujit
James Bottomley
maintainerRe: [PATCH 1/9] scsi: ufs: Add support for sending NOP OUT UPIU
Quoted 35 lines · Sujit Reddy Thumma
Quoted 22 lines · James Bottomley
Quoted 16 lines · Santosh Y
From: Sujit Reddy Thumma <[email protected]>
As part of device initialization sequence, sending NOP OUT UPIU and waiting for NOP IN UPIU response is mandatory. This confirms that the device UFS Transport (UTP) layer is functional and the host can configure the device with further commands. Add support for sending NOP OUT UPIU to check the device connection path and test whether the UTP layer on the device side is functional during initialization.
A tag is acquired from the SCSI tag map space in order to send the device management command. When the tag is acquired by internal command the scsi command is rejected with host busy flag in order to requeue the request. To avoid frequent collisions between internal commands and scsi commands the device management command tag is allocated in the opposite direction w.r.t block layer tag allocation.
Quoted 3 lines
Signed-off-by Sujit Reddy Thumma <[email protected]>Signed-off-by Dolev Raviv <[email protected]>Signed-off-by Santosh Y <[email protected]>Quoted 6 lines
This signoff chain looks wrong to me. The patch has quite a long history. Originally, it was sent in by Sujit, then later resent by Dolev with his signoff, then Sujit did a V2 which incorrectly seemed to include Dolev's signoff (that's not correct: signoffs should follow the chain of transmission, so a new patch wouldn't have a previous transmission signoff).
Initially we had two patches -
scsi: ufs: add support for query requests authored by Dolev and
scsi: ufs: Add support for sending NOP OUT UPIU authored by me.
Quoted 6 lines
Based on a possible design issue with the former patch, Dolev merged the patch into the later (NOP OUT patch).
http://thread.gmane.org/gmane.linux.ports.arm.msm/4202/focus=1505731Since some of the contents are picked from the original patch during rework, I have asked Dolev include his Signed-off-by as a co-author.
OK thanks for the clarification, I redid the signoffs and rebased the misc tree.
James
PATCH 2/9 scsi: ufs: Set fDeviceInit flag to initiate device initialization
In reply to Santosh YFrom: Dolev Raviv <[email protected]>
Allow UFS device to complete its initialization and accept SCSI commands by setting fDeviceInit flag. The device may take time for this operation and hence the host should poll until fDeviceInit flag is toggled to zero. This step is mandated by UFS device specification for device initialization completion.
drivers/scsi/ufs/ufs.h +89 -7
@@ -40,6 +40,10 @@#include <linux/types.h> #define MAX_CDB_SIZE 16 +#define GENERAL_UPIU_REQUEST_SIZE 32 +#define QUERY_DESC_MAX_SIZE 256 +#define QUERY_OSF_SIZE (GENERAL_UPIU_REQUEST_SIZE - \ + (sizeof(struct utp_upiu_header)))#define UPIU_HEADER_DWORD (byte3, byte2, byte1, byte0)\ cpu_to_be32((byte3 << 24) | (byte2 << 16) |\
@@ -65,7 +69,7 @@ enum {UPIU_TRANSACTION_COMMAND =0x01 ,UPIU_TRANSACTION_DATA_OUT =0x02 ,UPIU_TRANSACTION_TASK_REQ =0x04 , - UPIU_TRANSACTION_QUERY_REQ = 0x26, + UPIU_TRANSACTION_QUERY_REQ = 0x16, };/* UTP UPIU Transaction Codes Target to Initiator */
@@ -94,8 +98,19 @@ enum { UPIU_TASK_ATTR_ACA = 0x03, }; -/* UTP QUERY Transaction Specific Fields OpCode */ +/* UPIU Query request function */ enum { +UPIU_QUERY_FUNC_STANDARD_READ_REQUEST =0x01 , +UPIU_QUERY_FUNC_STANDARD_WRITE_REQUEST =0x81 , +}; + +/* Flag idn for Query Requests*/ +enum flag_idn { +QUERY_FLAG_IDN_FDEVICEINIT =0x01 , +}; + +/* UTP QUERY Transaction Specific Fields OpCode */ +enum query_opcode {UPIU_QUERY_OPCODE_NOP =0x0 ,UPIU_QUERY_OPCODE_READ_DESC =0x1 ,UPIU_QUERY_OPCODE_WRITE_DESC =0x2 ,
@@ -107,6 +122,21 @@ enum { UPIU_QUERY_OPCODE_TOGGLE_FLAG = 0x8, }; +/* Query response result code */ +enum { +QUERY_RESULT_SUCCESS =0x00 , +QUERY_RESULT_NOT_READABLE =0xF6 , +QUERY_RESULT_NOT_WRITEABLE =0xF7 , +QUERY_RESULT_ALREADY_WRITTEN =0xF8 , +QUERY_RESULT_INVALID_LENGTH =0xF9 , +QUERY_RESULT_INVALID_VALUE =0xFA , +QUERY_RESULT_INVALID_SELECTOR =0xFB , +QUERY_RESULT_INVALID_INDEX =0xFC , +QUERY_RESULT_INVALID_IDN =0xFD , +QUERY_RESULT_INVALID_OPCODE =0xFE , +QUERY_RESULT_GENERAL_FAILURE =0xFF , +}; +/* UTP Transfer Request Command Type (CT) */ enum {UPIU_COMMAND_SET_TYPE_SCSI =0x0 ,
@@ -121,9 +151,10 @@ enum {#define UPIU_RSP_CODE_OFFSET 8enum { -MASK_SCSI_STATUS =0xFF , -MASK_TASK_RESPONSE =0xFF00 , -MASK_RSP_UPIU_RESULT =0xFFFF , +MASK_SCSI_STATUS =0xFF , +MASK_TASK_RESPONSE =0xFF00 , +MASK_RSP_UPIU_RESULT =0xFFFF , +MASK_QUERY_DATA_SEG_LEN =0xFFFF , };/* Task management service response */
@@ -157,13 +188,40 @@ struct utp_upiu_cmd { };/** +* struct utp_upiu_query - upiu request buffer structure for +* query request. +* @opcode: command to perform B-0 +* @idn: a value that indicates the particular type of data B-1 +* @index: Index to further identify data B-2 +* @selector: Index to further identify data B-3 +* @reserved_osf: spec reserved field B-4,5 +* @length: number of descriptor bytes to read/write B-6,7 +* @value: Attribute value to be written DW-5 +* @reserved: spec reserved DW-6,7 +*/ +struct utp_upiu_query { +u8 opcode; +u8 idn; +u8 index; +u8 selector; +u16 reserved_osf; +u16 length; +u32 value; +u32 reserved[2 ]; +}; + +/** * struct utp_upiu_req - general upiu request structure * @header:UPIU header structure DW-0 to DW-2 * @sc: fields structure for scsi command DW-3 to DW-7 +* @qr: fields structure for query request DW-3 to DW-7 */ struct utp_upiu_req {struct utp_upiu_header header; -struct utp_upiu_cmd sc; +union { +struct utp_upiu_cmd sc; +struct utp_upiu_query qr; + }; };/**
@@ -184,10 +242,14 @@ struct utp_cmd_rsp {* struct utp_upiu_rsp - general upiu response structure * @header: UPIU header structure DW-0 to DW-2 * @sr: fields structure for scsi command DW-3 to DW-12 +* @qr: fields structure for query request DW-3 to DW-7 */ struct utp_upiu_rsp {struct utp_upiu_header header; -struct utp_cmd_rsp sr; +union { +struct utp_cmd_rsp sr; +struct utp_upiu_query qr; + }; };/**
@@ -220,4 +282,24 @@ struct utp_upiu_task_rsp { u32 reserved[3]; }; +/** +* struct ufs_query_req - parameters for building a query request +* @query_func: UPIU header query function +* @upiu_req: the query request data +*/ +struct ufs_query_req { +u8 query_func; +struct utp_upiu_query upiu_req; +}; + +/** +* struct ufs_query_resp - UPIU QUERY +* @response: device response code +* @upiu_res: query response data +*/ +struct ufs_query_res { +u8 response; +struct utp_upiu_query upiu_res; +}; +#endif /* End of Header */
drivers/scsi/ufs/ufshcd.c +235 -3
292 lines not on this page · raw message
drivers/scsi/ufs/ufshcd.h +20 -0
@@ -70,6 +70,7 @@enum dev_cmd_type {DEV_CMD_TYPE_NOP =0x0 , +DEV_CMD_TYPE_QUERY =0x1 , };/**
@@ -125,6 +126,18 @@ struct ufshcd_lrb { };/** +* struct ufs_query - holds relevent data structures for query request +* @request: request upiu and function +* @descriptor: buffer for sending/receiving descriptor +* @response: response upiu and response +*/ +struct ufs_query { +struct ufs_query_req request; +u8 *descriptor; +struct ufs_query_res response; +}; + +/** * struct ufs_dev_cmd - all assosiated fields with device management commands * @type: device management command type - Query, NOP OUT * @lock: lock to allow one command at a time
@@ -136,6 +149,7 @@ struct ufs_dev_cmd {struct mutex lock;struct completion *complete;wait_queue_head_t tag_wq; +struct ufs_query query; };/**
@@ -233,4 +247,10 @@ static inline void ufshcd_hba_stop(struct ufs_hba *hba) ufshcd_writel(hba, CONTROLLER_DISABLE, REG_CONTROLLER_ENABLE); } +static inline void check_upiu_size (void ) +{ +BUILD_BUG_ON (ALIGNED_UPIU_SIZE < +GENERAL_UPIU_REQUEST_SIZE +QUERY_DESC_MAX_SIZE ); +} +#endif /* End of Header */
drivers/scsi/ufs/ufshci.h +1 -1
@@ -39,7 +39,7 @@enum {TASK_REQ_UPIU_SIZE_DWORDS =8 ,TASK_RSP_UPIU_SIZE_DWORDS =8 , -ALIGNED_UPIU_SIZE =128 , +ALIGNED_UPIU_SIZE =512 , };/* UFSHCI Registers */
Signature · 1 line
1.8.3.1
PATCH 3/9 scsi: ufs: Add support for host assisted background operations
In reply to Santosh YFrom: Sujit Reddy Thumma <[email protected]>
Background operations in the UFS device can be disabled by the host to reduce the response latency of transfer requests. Add support for enabling/disabling the background operations during runtime suspend/resume of the device.
If the device is in critical need of BKOPS it will raise an URGENT_BKOPS exception which should be handled by the host to make sure the device performs as expected.
During bootup, the BKOPS is enabled in the device by default. The disable of BKOPS is supported only when the driver supports runtime suspend/resume operations as the runtime PM framework provides a way to determine the device idleness and hence BKOPS can be managed effectively. During runtime resume the BKOPS is disabled to reduce latency and during runtime suspend the BKOPS is enabled to allow device to carry out idle time BKOPS.
In some cases where the BKOPS is disabled during runtime resume and due to continuous data transfers the runtime suspend is not triggered, the BKOPS is enabled when the device raises a level-2 exception (outstanding operations - performance impact).
drivers/scsi/ufs/ufs.h +23 -0
@@ -107,6 +107,28 @@ enum {/* Flag idn for Query Requests*/ enum flag_idn {QUERY_FLAG_IDN_FDEVICEINIT =0x01 , +QUERY_FLAG_IDN_BKOPS_EN =0x04 , +}; + +/* Attribute idn for Query requests */ +enum attr_idn { +QUERY_ATTR_IDN_BKOPS_STATUS =0x05 , +QUERY_ATTR_IDN_EE_CONTROL =0x0D , +QUERY_ATTR_IDN_EE_STATUS =0x0E , +}; + +/* Exception event mask values */ +enum { +MASK_EE_STATUS =0xFFFF , +MASK_EE_URGENT_BKOPS = (1 <<2 ), +}; + +/* Background operation status */ +enum { +BKOPS_STATUS_NO_OP =0x0 , +BKOPS_STATUS_NON_CRITICAL =0x1 , +BKOPS_STATUS_PERF_IMPACT =0x2 , +BKOPS_STATUS_CRITICAL =0x3 , };/* UTP QUERY Transaction Specific Fields OpCode */
@@ -155,6 +177,7 @@ enum {MASK_TASK_RESPONSE =0xFF00 ,MASK_RSP_UPIU_RESULT =0xFFFF ,MASK_QUERY_DATA_SEG_LEN =0xFFFF , + MASK_RSP_EXCEPTION_EVENT = 0x10000, };/* Task management service response */
drivers/scsi/ufs/ufshcd.c +343 -0
385 lines not on this page · raw message
drivers/scsi/ufs/ufshcd.h +10 -0
@@ -178,9 +178,12 @@ struct ufs_dev_cmd {* @tm_condition: condition variable for task management * @ufshcd_state: UFSHCD states * @intr_mask: Interrupt Mask Bits +* @ee_ctrl_mask: Exception event control mask * @feh_workq: Work queue for fatal controller error handling +* @eeh_work: Worker to handle exception events * @errors: HBA errors * @dev_cmd: ufs device management command information +* @auto_bkops_enabled: to track whether bkops is enabled in device */ struct ufs_hba {void __iomem *mmio_base;
@@ -218,15 +221,19 @@ struct ufs_hba {u32 ufshcd_state;u32 intr_mask; +u16 ee_ctrl_mask;/* Work Queues */ struct work_struct feh_workq; +struct work_struct eeh_work;/* HBA Errors */ u32 errors;/* Device management request data */ struct ufs_dev_cmd dev_cmd; + +bool auto_bkops_enabled; };#define ufshcd_writel (hba, val, reg) \
@@ -253,4 +260,7 @@ static inline void check_upiu_size(void) GENERAL_UPIU_REQUEST_SIZE + QUERY_DESC_MAX_SIZE); } +extern int ufshcd_runtime_suspend (struct ufs_hba *hba); +extern int ufshcd_runtime_resume (struct ufs_hba *hba); +extern int ufshcd_runtime_idle (struct ufs_hba *hba);#endif /* End of Header */
Signature · 1 line
1.8.3.1
PATCH 4/9 scsi: ufs: Add runtime PM support for UFS host controller driver
In reply to Santosh YFrom: Sujit Reddy Thumma <[email protected]>
Add runtime PM helpers to suspend/resume UFS controller at runtime. Enable runtime PM by default for pci and platform drivers as the initialized hardware can suspend if it is not used after bootup.
drivers/scsi/ufs/ufshcd-pci.c +56 -6
@@ -35,6 +35,7 @@#include "ufshcd.h" #include <linux/pci.h> +#include <linux/pm_runtime.h> #ifdef CONFIG_PM /**
@@ -44,7 +45,7 @@* * Returns -ENOSYS */ -static int ufshcd_pci_suspend (struct pci_dev *pdev,pm_message_t state) +static int ufshcd_pci_suspend (struct device *dev) {/* * TODO:
@@ -61,7 +62,7 @@ static int ufshcd_pci_suspend(struct pci_dev *pdev, pm_message_t state)* * Returns -ENOSYS */ -static int ufshcd_pci_resume (struct pci_dev *pdev) +static int ufshcd_pci_resume (struct device *dev) {/* * TODO:
@@ -71,8 +72,45 @@ static int ufshcd_pci_resume(struct pci_dev *pdev)return -ENOSYS ; } +#else +#define ufshcd_pci_suspend NULL +#define ufshcd_pci_resume NULL#endif /* CONFIG_PM */ +#ifdef CONFIG_PM_RUNTIME +static int ufshcd_pci_runtime_suspend (struct device *dev) +{ +struct ufs_hba *hba =dev_get_drvdata (dev); + +if (!hba) +return 0 ; + +return ufshcd_runtime_suspend (hba); +} +static int ufshcd_pci_runtime_resume (struct device *dev) +{ +struct ufs_hba *hba =dev_get_drvdata (dev); + +if (!hba) +return 0 ; + +return ufshcd_runtime_resume (hba); +} +static int ufshcd_pci_runtime_idle (struct device *dev) +{ +struct ufs_hba *hba =dev_get_drvdata (dev); + +if (!hba) +return 0 ; + +return ufshcd_runtime_idle (hba); +} +#else /* !CONFIG_PM_RUNTIME */ +#define ufshcd_pci_runtime_suspend NULL +#define ufshcd_pci_runtime_resume NULL +#define ufshcd_pci_runtime_idle NULL +#endif /* CONFIG_PM_RUNTIME */ +/** * ufshcd_pci_shutdown - main function to put the controller in reset state * @pdev: pointer to PCI device handle
@@ -91,6 +129,9 @@ static void ufshcd_pci_remove(struct pci_dev *pdev) {struct ufs_hba *hba =pci_get_drvdata (pdev); +pm_runtime_forbid (&pdev->dev); +pm_runtime_get_noresume (&pdev->dev); +disable_irq (pdev->irq);ufshcd_remove (hba);pci_release_regions (pdev);
@@ -168,6 +209,8 @@ ufshcd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) }pci_set_drvdata (pdev, hba); +pm_runtime_put_noidle (&pdev->dev); +pm_runtime_allow (&pdev->dev);return 0 ;
@@ -182,6 +225,14 @@ out_error:return err; } +static const struct dev_pm_ops ufshcd_pci_pm_ops = { + .suspend = ufshcd_pci_suspend, + .resume = ufshcd_pci_resume, + .runtime_suspend = ufshcd_pci_runtime_suspend, + .runtime_resume = ufshcd_pci_runtime_resume, + .runtime_idle = ufshcd_pci_runtime_idle, +}; +static DEFINE_PCI_DEVICE_TABLE (ufshcd_pci_tbl) = { {PCI_VENDOR_ID_SAMSUNG ,0xC00C ,PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 ,0 }, { }/* terminate list */
@@ -195,10 +246,9 @@ static struct pci_driver ufshcd_pci_driver = { .probe = ufshcd_pci_probe, .remove = ufshcd_pci_remove, .shutdown = ufshcd_pci_shutdown, -#ifdef CONFIG_PM - .suspend = ufshcd_pci_suspend, - .resume = ufshcd_pci_resume, -#endif + .driver = { + .pm = &ufshcd_pci_pm_ops + }, };module_pci_driver (ufshcd_pci_driver);
drivers/scsi/ufs/ufshcd-pltfrm.c +49 -1
87 lines not on this page · raw message
drivers/scsi/ufs/ufshcd.c +8 -0
@@ -2169,6 +2169,7 @@ static void ufshcd_exception_event_handler(struct work_struct *work)u32 status =0 ; hba = container_of(work, struct ufs_hba, eeh_work); +pm_runtime_get_sync (hba->dev); err =ufshcd_get_ee_status (hba, &status);if (err) { dev_err(hba->dev, "%s: failed to get exception status %d\n",
@@ -2184,6 +2185,7 @@ static void ufshcd_exception_event_handler(struct work_struct *work) __func__, err); } out: +pm_runtime_put_sync (hba->dev);return ; }
@@ -2196,9 +2198,11 @@ static void ufshcd_fatal_err_handler(struct work_struct *work)struct ufs_hba *hba; hba = container_of(work, struct ufs_hba, feh_workq); +pm_runtime_get_sync (hba->dev);/* check if reset is already in progress */ if (hba->ufshcd_state !=UFSHCD_STATE_RESET )ufshcd_do_reset (hba); +pm_runtime_put_sync (hba->dev); }/**
@@ -2500,6 +2504,7 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie)ufshcd_force_reset_auto_bkops (hba);scsi_scan_host (hba->host); +pm_runtime_put_sync (hba->dev); out:return ; }
@@ -2721,6 +2726,9 @@ int ufshcd_init(struct device *dev, struct ufs_hba **hba_handle, *hba_handle = hba; +/* Hold auto suspend until async scan completes */ +pm_runtime_get_sync (dev); +async_schedule (ufshcd_async_scan, hba);return 0 ;
Signature · 1 line
1.8.3.1
PATCH 5/9 ufshcd-pci: release ioremapped region during removing driver
In reply to Santosh YFrom: Akinobu Mita <[email protected]>
Before commit 2953f850c3b80bdca004967c83733365d8aa0aa2 ("[SCSI] ufs:
use devres functions for ufshcd"), UFSHCI register was ioremapped by each glue-driver (ufshcd-pltfrm and ufshcd-pci) during probing and it was iounmapped by core-driver during removing driver. The commit converted ufshcd-pltfrm to use devres functions, but it didn't convert ufshcd-pci.
Therefore, the change causes ufshcd-pci driver not to iounmap UFSHCI register region during removing driver. This fixes it by converting ufshcd-pci to use devres functions.
drivers/scsi/ufs/ufshcd-pci.c +9 -28
@@ -134,10 +134,7 @@ static void ufshcd_pci_remove(struct pci_dev *pdev)disable_irq (pdev->irq);ufshcd_remove (hba); -pci_release_regions (pdev);pci_set_drvdata (pdev,NULL ); -pci_clear_master (pdev); -pci_disable_device (pdev); }/**
@@ -174,38 +171,32 @@ ufshcd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)void __iomem *mmio_base;int err; - err =pci_enable_device (pdev); + err =pcim_enable_device (pdev);if (err) { -dev_err (&pdev->dev,"pci_enable_device failed\n" ); - goto out_error; +dev_err (&pdev->dev,"pcim_enable_device failed\n" ); +return err; }pci_set_master (pdev); - - err =pci_request_regions (pdev,UFSHCD ); + err =pcim_iomap_regions (pdev,1 <<0 ,UFSHCD );if (err <0 ) { -dev_err (&pdev->dev,"request regions failed\n" ); - goto out_disable; +dev_err (&pdev->dev,"request and iomap failed\n" ); +return err; } - mmio_base =pci_ioremap_bar (pdev,0 ); -if (!mmio_base) { -dev_err (&pdev->dev,"memory map failed\n" ); - err = -ENOMEM ; - goto out_release_regions; - } + mmio_base =pcim_iomap_table (pdev)[0 ]; err =ufshcd_set_dma_mask (pdev);if (err) {dev_err (&pdev->dev,"set dma mask failed\n" ); - goto out_iounmap; +return err; } err =ufshcd_init (&pdev->dev, &hba, mmio_base, pdev->irq);if (err) {dev_err (&pdev->dev,"Initialization failed\n" ); - goto out_iounmap; +return err; }pci_set_drvdata (pdev, hba);
@@ -213,16 +204,6 @@ ufshcd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)pm_runtime_allow (&pdev->dev);return 0 ; - -out_iounmap: -iounmap (mmio_base); -out_release_regions: -pci_release_regions (pdev); -out_disable: -pci_clear_master (pdev); -pci_disable_device (pdev); -out_error: -return err; }static const struct dev_pm_ops ufshcd_pci_pm_ops = {
Signature · 1 line
1.8.3.1
PATCH 6/9 ufs: don't disable_irq() if the IRQ can be shared among devices
In reply to Santosh YFrom: Akinobu Mita <[email protected]>
When removing the UFS driver, disable_irq() is called and the IRQ is not enabled again. Unfortunately, the IRQ is requested with IRQF_SHARED and it can be shared among several devices. So disabling the IRQ in this way is just breaking other devices which are sharing the IRQ.
drivers/scsi/ufs/ufshcd-pci.c +0 -2
@@ -131,8 +131,6 @@ static void ufshcd_pci_remove(struct pci_dev *pdev)pm_runtime_forbid (&pdev->dev);pm_runtime_get_noresume (&pdev->dev); - -disable_irq (pdev->irq);ufshcd_remove (hba);pci_set_drvdata (pdev,NULL ); }
drivers/scsi/ufs/ufshcd-pltfrm.c +0 -2
@@ -188,8 +188,6 @@ static int ufshcd_pltfrm_remove(struct platform_device *pdev)struct ufs_hba *hba =platform_get_drvdata (pdev);pm_runtime_get_sync (&(pdev)->dev); - -disable_irq (hba->irq);ufshcd_remove (hba);return 0 ; }
Signature · 1 line
1.8.3.1
PATCH 7/9 ufs: don't stop controller before scsi_remove_host()
In reply to Santosh YFrom: Akinobu Mita <[email protected]>
scsi_remove_host() sends SYNCHRONIZE CACHE commands for write cache enabled scsi disk devices. So stopping controller working shouldn't be done before scsi_remove_host().
drivers/scsi/ufs/ufshcd.c +1 -1
@@ -2603,11 +2603,11 @@ EXPORT_SYMBOL(ufshcd_runtime_idle);*/ void ufshcd_remove (struct ufs_hba *hba) { +scsi_remove_host (hba->host);/* disable interrupts */ ufshcd_disable_intr (hba, hba->intr_mask);ufshcd_hba_stop (hba); -scsi_remove_host (hba->host);scsi_host_put (hba->host); }EXPORT_SYMBOL_GPL (ufshcd_remove);
Signature · 1 line
1.8.3.1
PATCH 8/9 ufshcd-pltfrm: remove redundant dev_err call in ufshcd_pltfrm_probe()
In reply to Santosh YFrom: Wei Yongjun <[email protected]>
There is a error message within devm_ioremap_resource already, so remove the dev_err call to avoid redundant error message.
drivers/scsi/ufs/ufshcd-pltfrm.c +0 -1
@@ -145,7 +145,6 @@ static int ufshcd_pltfrm_probe(struct platform_device *pdev) mmio_base =devm_ioremap_resource (dev, mem_res);if (IS_ERR (mmio_base)) { -dev_err (dev,"memory map failed\n" ); err =PTR_ERR (mmio_base); goto out; }
Signature · 1 line
1.8.3.1
PATCH 9/9 drivers/scsi/ufs: don't check resource with devm_ioremap_resource
In reply to Santosh YFrom: Wolfram Sang <[email protected]>
devm_ioremap_resource does sanity checks on the given resource. No need to duplicate this in the driver.
drivers/scsi/ufs/ufshcd-pltfrm.c +0 -6
@@ -137,12 +137,6 @@ static int ufshcd_pltfrm_probe(struct platform_device *pdev)struct device *dev = &pdev->dev; mem_res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); -if (!mem_res) { -dev_err (dev,"Memory resource not available\n" ); - err = -ENODEV ; - goto out; - } - mmio_base =devm_ioremap_resource (dev, mem_res);if (IS_ERR (mmio_base)) { err =PTR_ERR (mmio_base);
Signature · 1 line
1.8.3.1