Skip to contentSkip to conversation

scsi: ufs: Rework UFS host driver implementation

RFC New Sujit Reddy Thumma 1 participant 1 message May 3, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC 1/1 scsi: ufs: Rework UFS host driver implementation

UFS protocol comprises of two specifications, UFS device and UFS host controller specification. The current UFSHCD driver combines implementation of both the specs into one file. As new features evolve in both specifications one single file looks cumbersome and hard to maintain. Split the UFS driver file into two -

ufs.c:
- Behave as a LLD to SCSI mid layer.
- Implements UFS device specification
o Driver interfaces to UFS device in terms of UPIUs.
o Prepares UPIUs for SCSI commands and internal commands and send it to host driver through host ops.
o Handles full device initialization.
o Handles device power management
o Handles device specific features like bkops etc.
o Handles task management commands.

ufshcd.c:
- Driver interfaces with host controller and UIC layer on host side.
- Implements UFS HCI specification
o Configure memory and transfer descriptors
o Build UTRD and UTMRD based on request from ufs.c and allow controller to execute the commands
o Handle hardware interrupts from controller including errors.
o Handle UIC commands
o Handle host controller/UIC specific power management

---
The patch is not complete and does not handle some of the points mentioned above. This is just for review on design part.

---
 drivers/scsi/ufs/Makefile |    2 +-
 drivers/scsi/ufs/ufs.c    |  341 +++++++++++++++++++++++++++++++++++++++++++
 drivers/scsi/ufs/ufs.h    |   37 +++++
 drivers/scsi/ufs/ufshcd.c |  352 +++++++++++++--------------------------------
 drivers/scsi/ufs/ufshcd.h |   10 ++
 5 files changed, 487 insertions(+), 255 deletions(-)
 create mode 100644 drivers/scsi/ufs/ufs.c
drivers/scsi/ufs/Makefile +1 -1
index 1e5bd48..386b17a 100644
@@ -1,4 +1,4 @@
 # UFSHCD makefile
-obj-$(CONFIG_SCSI_UFSHCD) += ufshcd.o
+obj-$(CONFIG_SCSI_UFSHCD) += ufshcd.o ufs.o
 obj-$(CONFIG_SCSI_UFSHCD_PCI) += ufshcd-pci.o
 obj-$(CONFIG_SCSI_UFSHCD_PLATFORM) += ufshcd-pltfrm.o
drivers/scsi/ufs/ufs.c new file +341 -0

341 lines not on this page · raw message

drivers/scsi/ufs/ufs.h +37 -0
index 139bc06..fa513e0 100644
@@ -36,6 +36,7 @@
 #ifndef _UFS_H
 #define _UFS_H
 
+#define UFS_MAX_QUEUE	32
 #define MAX_CDB_SIZE	16
 
 #define UPIU_HEADER_DWORD(byte3, byte2, byte1, byte0)\
@@ -112,6 +113,7 @@ enum {
 
 enum {
 	MASK_SCSI_STATUS	= 0xFF,
+	MASK_TRANSFER_RESPONSE	= 0xFF00,
 	MASK_TASK_RESPONSE	= 0xFF00,
 	MASK_RSP_UPIU_RESULT	= 0xFFFF,
 };
@@ -124,6 +126,14 @@ enum {
 	UPIU_TASK_MANAGEMENT_FUNC_FAILED	= 0x05,
 	UPIU_INCORRECT_LOGICAL_UNIT_NO		= 0x09,
 };
+
+/* UFS command status in host layer */
+enum {
+	UFS_CMD_SUCCESS	= 0x0,
+	UFS_CMD_ABORTED	= 0x1,
+	UFS_CMD_ERROR	= 0x2,
+};
+
 /**
  * struct utp_upiu_header - UPIU header structure
  * @dword_0: UPIU header DW-0
@@ -194,4 +204,31 @@ struct utp_upiu_task_rsp {
 	u32 reserved[3];
 };
 
+/**
+ * struct ufs_tr_queue_cmd - UFS Transfer request command structure
+ * @hba: pointer to host adapter
+ * @scmd: pointer to scsi command
+ * @req_upiu: request UPIU structure
+ * @resp_upiu: response UPIU structure
+ * @command_type: SCSI, UFS, Query.
+ * @tag: Task tag of the command
+ * @lun: LUN of the command
+ * @done: transfer request completion function
+ */
+struct ufs_tr_queue_cmd {
+	struct utp_upiu_cmd *req_upiu;
+	struct utp_upiu_rsp *resp_upiu;
+	struct ufs_hba *hba;
+	struct scsi_cmnd *scmd;
+	int command_type;
+	int tag;
+	int dir;
+	int result;
+	unsigned int lun;
+	struct scatterlist *sgl;
+	int sg_segments;
+	int (*done)(struct ufs_tr_queue_cmd *);
+};
+
+extern int ufs_scsi_queuecmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd);
 #endif /* End of Header */
drivers/scsi/ufs/ufshcd.c +98 -254

473 lines not on this page · raw message

drivers/scsi/ufs/ufshcd.h +10 -0
index 6b99a42..712e1ad 100644
@@ -113,8 +113,15 @@ struct ufshcd_lrb {
 	int command_type;
 	int task_tag;
 	unsigned int lun;
+	struct ufs_tr_queue_cmd trcmd;
 };
 
+struct ufshcd_hba_ops {
+	struct ufs_tr_queue_cmd *(*get_tr_cmd)(struct ufs_hba *, int);
+	struct utp_upiu_cmd *(*get_tr_upiu)(struct ufs_tr_queue_cmd *);
+	int (*issue_tr_cmd)(struct ufs_tr_queue_cmd *);
+	int (*get_lun_qdepth)(struct ufs_hba *, int);
+};
 
 /**
  * struct ufs_hba - per adapter private structure
@@ -184,6 +191,9 @@ struct ufs_hba {
 
 	/* HBA Errors */
 	u32 errors;
+
+	/* HBA operations */
+	const struct ufshcd_hba_ops *ops;
 };
 
 int ufshcd_init(struct device *, struct ufs_hba ** , void __iomem * ,
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation.