refactor(ufs): adds a function for sending command

new function for sending commands and reuses that function in the
driver, this can also be used to have retries for specific
commands in the future

Signed-off-by: anans <anans@google.com>
Change-Id: Ie01f36ff8e2df072db4d97929d293b80ed24f04b
diff --git a/drivers/ufs/ufs.c b/drivers/ufs/ufs.c
index 3d6d99f..b040a95 100644
--- a/drivers/ufs/ufs.c
+++ b/drivers/ufs/ufs.c
@@ -490,6 +490,21 @@
 	return 0;
 }
 
+static void ufs_send_cmd(utp_utrd_t *utrd, uint8_t cmd_op, uint8_t lun, int lba, uintptr_t buf,
+			 size_t length)
+{
+	int result;
+
+	get_utrd(utrd);
+
+	result = ufs_prepare_cmd(utrd, cmd_op, lun, lba, buf, length);
+	assert(result == 0);
+	ufs_send_request(utrd->task_tag);
+	result = ufs_check_resp(utrd, RESPONSE_UPIU);
+	assert(result == 0);
+	(void)result;
+}
+
 #ifdef UFS_RESP_DEBUG
 static void dump_upiu(utp_utrd_t *utrd)
 {
@@ -540,14 +555,7 @@
 static void ufs_verify_ready(void)
 {
 	utp_utrd_t utrd;
-	int result;
-
-	get_utrd(&utrd);
-	ufs_prepare_cmd(&utrd, CDBCMD_TEST_UNIT_READY, 0, 0, 0, 0);
-	ufs_send_request(utrd.task_tag);
-	result = ufs_check_resp(&utrd, RESPONSE_UPIU);
-	assert(result == 0);
-	(void)result;
+	ufs_send_cmd(&utrd, CDBCMD_TEST_UNIT_READY, 0, 0, 0, 0);
 }
 
 static void ufs_query(uint8_t op, uint8_t idn, uint8_t index, uint8_t sel,
@@ -663,12 +671,8 @@
 	memset((void *)buf, 0, CACHE_WRITEBACK_GRANULE);
 	flush_dcache_range(buf, CACHE_WRITEBACK_GRANULE);
 	do {
-		get_utrd(&utrd);
-		ufs_prepare_cmd(&utrd, CDBCMD_READ_CAPACITY_10, lun, 0,
-				buf, READ_CAPACITY_LENGTH);
-		ufs_send_request(utrd.task_tag);
-		result = ufs_check_resp(&utrd, RESPONSE_UPIU);
-		assert(result == 0);
+		ufs_send_cmd(&utrd, CDBCMD_READ_CAPACITY_10, lun, 0,
+			    buf, READ_CAPACITY_LENGTH);
 #ifdef UFS_RESP_DEBUG
 		dump_upiu(&utrd);
 #endif
@@ -702,11 +706,7 @@
 	       (ufs_params.desc_base != 0) &&
 	       (ufs_params.desc_size >= UFS_DESC_SIZE));
 
-	get_utrd(&utrd);
-	ufs_prepare_cmd(&utrd, CDBCMD_READ_10, lun, lba, buf, size);
-	ufs_send_request(utrd.task_tag);
-	result = ufs_check_resp(&utrd, RESPONSE_UPIU);
-	assert(result == 0);
+	ufs_send_cmd(&utrd, CDBCMD_READ_10, lun, lba, buf, size);
 #ifdef UFS_RESP_DEBUG
 	dump_upiu(&utrd);
 #endif
@@ -725,11 +725,7 @@
 	       (ufs_params.desc_base != 0) &&
 	       (ufs_params.desc_size >= UFS_DESC_SIZE));
 
-	get_utrd(&utrd);
-	ufs_prepare_cmd(&utrd, CDBCMD_WRITE_10, lun, lba, buf, size);
-	ufs_send_request(utrd.task_tag);
-	result = ufs_check_resp(&utrd, RESPONSE_UPIU);
-	assert(result == 0);
+	ufs_send_cmd(&utrd, CDBCMD_WRITE_10, lun, lba, buf, size);
 #ifdef UFS_RESP_DEBUG
 	dump_upiu(&utrd);
 #endif