aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/ufs/ufshcd.c
diff options
context:
space:
mode:
authorSujit Reddy Thumma <sthumma@codeaurora.org>2014-05-26 01:29:10 -0400
committerChristoph Hellwig <hch@lst.de>2014-05-28 06:25:13 -0400
commite8c8e82ae96c68cb03e0e877b5a226633d999549 (patch)
tree91279f40b47eba227fe0dee67b3031497266f76d /drivers/scsi/ufs/ufshcd.c
parent2bbf5c7f9fe8fea2b2ccf02b9b5d2cbd997f2de1 (diff)
scsi: ufs: fix endianness sparse warnings
Fix many warnings with incorrect endian assumptions which makes the code unportable to new architectures. The UFS specification defines the byte order as big-endian for UPIU structure and little-endian for the host controller transfer/task management descriptors. Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org> Acked-by: Vinayak Holikatti <vinholikatti@gmail.com> Signed-off-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'drivers/scsi/ufs/ufshcd.c')
-rw-r--r--drivers/scsi/ufs/ufshcd.c42
1 files changed, 8 insertions, 34 deletions
diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 04884d663e4e..064c9d9d763b 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -163,7 +163,7 @@ static inline int ufshcd_is_device_present(u32 reg_hcs)
163 */ 163 */
164static inline int ufshcd_get_tr_ocs(struct ufshcd_lrb *lrbp) 164static inline int ufshcd_get_tr_ocs(struct ufshcd_lrb *lrbp)
165{ 165{
166 return lrbp->utr_descriptor_ptr->header.dword_2 & MASK_OCS; 166 return le32_to_cpu(lrbp->utr_descriptor_ptr->header.dword_2) & MASK_OCS;
167} 167}
168 168
169/** 169/**
@@ -176,7 +176,7 @@ static inline int ufshcd_get_tr_ocs(struct ufshcd_lrb *lrbp)
176static inline int 176static inline int
177ufshcd_get_tmr_ocs(struct utp_task_req_desc *task_req_descp) 177ufshcd_get_tmr_ocs(struct utp_task_req_desc *task_req_descp)
178{ 178{
179 return task_req_descp->header.dword_2 & MASK_OCS; 179 return le32_to_cpu(task_req_descp->header.dword_2) & MASK_OCS;
180} 180}
181 181
182/** 182/**
@@ -390,26 +390,6 @@ static inline void ufshcd_copy_sense_data(struct ufshcd_lrb *lrbp)
390} 390}
391 391
392/** 392/**
393 * ufshcd_query_to_cpu() - formats the buffer to native cpu endian
394 * @response: upiu query response to convert
395 */
396static inline void ufshcd_query_to_cpu(struct utp_upiu_query *response)
397{
398 response->length = be16_to_cpu(response->length);
399 response->value = be32_to_cpu(response->value);
400}
401
402/**
403 * ufshcd_query_to_be() - formats the buffer to big endian
404 * @request: upiu query request to convert
405 */
406static inline void ufshcd_query_to_be(struct utp_upiu_query *request)
407{
408 request->length = cpu_to_be16(request->length);
409 request->value = cpu_to_be32(request->value);
410}
411
412/**
413 * ufshcd_copy_query_response() - Copy the Query Response and the data 393 * ufshcd_copy_query_response() - Copy the Query Response and the data
414 * descriptor 394 * descriptor
415 * @hba: per adapter instance 395 * @hba: per adapter instance
@@ -425,7 +405,6 @@ void ufshcd_copy_query_response(struct ufs_hba *hba, struct ufshcd_lrb *lrbp)
425 UPIU_RSP_CODE_OFFSET; 405 UPIU_RSP_CODE_OFFSET;
426 406
427 memcpy(&query_res->upiu_res, &lrbp->ucd_rsp_ptr->qr, QUERY_OSF_SIZE); 407 memcpy(&query_res->upiu_res, &lrbp->ucd_rsp_ptr->qr, QUERY_OSF_SIZE);
428 ufshcd_query_to_cpu(&query_res->upiu_res);
429 408
430 409
431 /* Get the descriptor */ 410 /* Get the descriptor */
@@ -749,7 +728,7 @@ static void ufshcd_prepare_utp_query_req_upiu(struct ufs_hba *hba,
749{ 728{
750 struct utp_upiu_req *ucd_req_ptr = lrbp->ucd_req_ptr; 729 struct utp_upiu_req *ucd_req_ptr = lrbp->ucd_req_ptr;
751 struct ufs_query *query = &hba->dev_cmd.query; 730 struct ufs_query *query = &hba->dev_cmd.query;
752 u16 len = query->request.upiu_req.length; 731 u16 len = be16_to_cpu(query->request.upiu_req.length);
753 u8 *descp = (u8 *)lrbp->ucd_req_ptr + GENERAL_UPIU_REQUEST_SIZE; 732 u8 *descp = (u8 *)lrbp->ucd_req_ptr + GENERAL_UPIU_REQUEST_SIZE;
754 733
755 /* Query request header */ 734 /* Query request header */
@@ -766,7 +745,6 @@ static void ufshcd_prepare_utp_query_req_upiu(struct ufs_hba *hba,
766 /* Copy the Query Request buffer as is */ 745 /* Copy the Query Request buffer as is */
767 memcpy(&ucd_req_ptr->qr, &query->request.upiu_req, 746 memcpy(&ucd_req_ptr->qr, &query->request.upiu_req,
768 QUERY_OSF_SIZE); 747 QUERY_OSF_SIZE);
769 ufshcd_query_to_be(&ucd_req_ptr->qr);
770 748
771 /* Copy the Descriptor */ 749 /* Copy the Descriptor */
772 if ((len > 0) && (query->request.upiu_req.opcode == 750 if ((len > 0) && (query->request.upiu_req.opcode ==
@@ -1151,7 +1129,7 @@ static int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode,
1151 } 1129 }
1152 1130
1153 if (flag_res) 1131 if (flag_res)
1154 *flag_res = (response->upiu_res.value & 1132 *flag_res = (be32_to_cpu(response->upiu_res.value) &
1155 MASK_QUERY_UPIU_FLAG_LOC) & 0x1; 1133 MASK_QUERY_UPIU_FLAG_LOC) & 0x1;
1156 1134
1157out_unlock: 1135out_unlock:
@@ -1195,7 +1173,7 @@ int ufshcd_query_attr(struct ufs_hba *hba, enum query_opcode opcode,
1195 switch (opcode) { 1173 switch (opcode) {
1196 case UPIU_QUERY_OPCODE_WRITE_ATTR: 1174 case UPIU_QUERY_OPCODE_WRITE_ATTR:
1197 request->query_func = UPIU_QUERY_FUNC_STANDARD_WRITE_REQUEST; 1175 request->query_func = UPIU_QUERY_FUNC_STANDARD_WRITE_REQUEST;
1198 request->upiu_req.value = *attr_val; 1176 request->upiu_req.value = cpu_to_be32(*attr_val);
1199 break; 1177 break;
1200 case UPIU_QUERY_OPCODE_READ_ATTR: 1178 case UPIU_QUERY_OPCODE_READ_ATTR:
1201 request->query_func = UPIU_QUERY_FUNC_STANDARD_READ_REQUEST; 1179 request->query_func = UPIU_QUERY_FUNC_STANDARD_READ_REQUEST;
@@ -1222,7 +1200,7 @@ int ufshcd_query_attr(struct ufs_hba *hba, enum query_opcode opcode,
1222 goto out_unlock; 1200 goto out_unlock;
1223 } 1201 }
1224 1202
1225 *attr_val = response->upiu_res.value; 1203 *attr_val = be32_to_cpu(response->upiu_res.value);
1226 1204
1227out_unlock: 1205out_unlock:
1228 mutex_unlock(&hba->dev_cmd.lock); 1206 mutex_unlock(&hba->dev_cmd.lock);
@@ -2568,12 +2546,8 @@ ufshcd_issue_tm_cmd(struct ufs_hba *hba,
2568 task_req_upiup->header.dword_1 = 2546 task_req_upiup->header.dword_1 =
2569 UPIU_HEADER_DWORD(0, tm_function, 0, 0); 2547 UPIU_HEADER_DWORD(0, tm_function, 0, 0);
2570 2548
2571 task_req_upiup->input_param1 = lrbp->lun; 2549 task_req_upiup->input_param1 = cpu_to_be32(lrbp->lun);
2572 task_req_upiup->input_param1 = 2550 task_req_upiup->input_param2 = cpu_to_be32(lrbp->task_tag);
2573 cpu_to_be32(task_req_upiup->input_param1);
2574 task_req_upiup->input_param2 = lrbp->task_tag;
2575 task_req_upiup->input_param2 =
2576 cpu_to_be32(task_req_upiup->input_param2);
2577 2551
2578 /* send command to the controller */ 2552 /* send command to the controller */
2579 __set_bit(free_slot, &hba->outstanding_tasks); 2553 __set_bit(free_slot, &hba->outstanding_tasks);