Commit 8270ee2abb78c73b73e04f2909b0de15540c9017

Authored by Santosh Nayak
Committed by James Bottomley
1 parent 50ec5babd3

[SCSI] pm8001: fix endian issue with code optimization.

1. Fix endian issue.
2. Fix the following warning :
    " drivers/scsi/pm8001/pm8001_hwi.c:2932:32: warning: comparison
      between ‘enum sas_device_type’ and ‘enum sas_dev_type’".
3. Few code optimization.

Signed-off-by: Santosh Nayak <santoshprasadnayak@gmail.com>
Acked-by: Jack Wang <jack_wang@usish.com>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>

Showing 3 changed files with 49 additions and 46 deletions Side-by-side Diff

drivers/scsi/pm8001/pm8001_chips.h
... ... @@ -46,9 +46,9 @@
46 46 return *((u32 *)virt_addr);
47 47 }
48 48  
49   -static inline void pm8001_write_32(void *addr, u32 offset, u32 val)
  49 +static inline void pm8001_write_32(void *addr, u32 offset, __le32 val)
50 50 {
51   - *((u32 *)(addr + offset)) = val;
  51 + *((__le32 *)(addr + offset)) = val;
52 52 }
53 53  
54 54 static inline u32 pm8001_cr32(struct pm8001_hba_info *pm8001_ha, u32 bar,
drivers/scsi/pm8001/pm8001_hwi.c
... ... @@ -1246,7 +1246,7 @@
1246 1246 consumer_index = pm8001_read_32(circularQ->ci_virt);
1247 1247 circularQ->consumer_index = cpu_to_le32(consumer_index);
1248 1248 if (((circularQ->producer_idx + bcCount) % 256) ==
1249   - circularQ->consumer_index) {
  1249 + le32_to_cpu(circularQ->consumer_index)) {
1250 1250 *messagePtr = NULL;
1251 1251 return -1;
1252 1252 }
... ... @@ -1355,7 +1355,8 @@
1355 1355 u32 header_tmp;
1356 1356 do {
1357 1357 /* If there are not-yet-delivered messages ... */
1358   - if (circularQ->producer_index != circularQ->consumer_idx) {
  1358 + if (le32_to_cpu(circularQ->producer_index)
  1359 + != circularQ->consumer_idx) {
1359 1360 /*Get the pointer to the circular queue buffer element*/
1360 1361 msgHeader = (struct mpi_msg_hdr *)
1361 1362 (circularQ->base_virt +
1362 1363  
1363 1364  
... ... @@ -1363,14 +1364,14 @@
1363 1364 /* read header */
1364 1365 header_tmp = pm8001_read_32(msgHeader);
1365 1366 msgHeader_tmp = cpu_to_le32(header_tmp);
1366   - if (0 != (msgHeader_tmp & 0x80000000)) {
  1367 + if (0 != (le32_to_cpu(msgHeader_tmp) & 0x80000000)) {
1367 1368 if (OPC_OUB_SKIP_ENTRY !=
1368   - (msgHeader_tmp & 0xfff)) {
  1369 + (le32_to_cpu(msgHeader_tmp) & 0xfff)) {
1369 1370 *messagePtr1 =
1370 1371 ((u8 *)msgHeader) +
1371 1372 sizeof(struct mpi_msg_hdr);
1372   - *pBC = (u8)((msgHeader_tmp >> 24) &
1373   - 0x1f);
  1373 + *pBC = (u8)((le32_to_cpu(msgHeader_tmp)
  1374 + >> 24) & 0x1f);
1374 1375 PM8001_IO_DBG(pm8001_ha,
1375 1376 pm8001_printk(": CI=%d PI=%d "
1376 1377 "msgHeader=%x\n",
... ... @@ -1381,8 +1382,8 @@
1381 1382 } else {
1382 1383 circularQ->consumer_idx =
1383 1384 (circularQ->consumer_idx +
1384   - ((msgHeader_tmp >> 24) & 0x1f))
1385   - % 256;
  1385 + ((le32_to_cpu(msgHeader_tmp)
  1386 + >> 24) & 0x1f)) % 256;
1386 1387 msgHeader_tmp = 0;
1387 1388 pm8001_write_32(msgHeader, 0, 0);
1388 1389 /* update the CI of outbound queue */
... ... @@ -1394,7 +1395,8 @@
1394 1395 } else {
1395 1396 circularQ->consumer_idx =
1396 1397 (circularQ->consumer_idx +
1397   - ((msgHeader_tmp >> 24) & 0x1f)) % 256;
  1398 + ((le32_to_cpu(msgHeader_tmp) >> 24) &
  1399 + 0x1f)) % 256;
1398 1400 msgHeader_tmp = 0;
1399 1401 pm8001_write_32(msgHeader, 0, 0);
1400 1402 /* update the CI of outbound queue */
... ... @@ -1410,7 +1412,8 @@
1410 1412 producer_index = pm8001_read_32(pi_virt);
1411 1413 circularQ->producer_index = cpu_to_le32(producer_index);
1412 1414 }
1413   - } while (circularQ->producer_index != circularQ->consumer_idx);
  1415 + } while (le32_to_cpu(circularQ->producer_index) !=
  1416 + circularQ->consumer_idx);
1414 1417 /* while we don't have any more not-yet-delivered message */
1415 1418 /* report empty */
1416 1419 return MPI_IO_STATUS_BUSY;
... ... @@ -3060,7 +3063,7 @@
3060 3063  
3061 3064 memset((u8 *)&payload, 0, sizeof(payload));
3062 3065 circularQ = &pm8001_ha->inbnd_q_tbl[Qnum];
3063   - payload.tag = 1;
  3066 + payload.tag = cpu_to_le32(1);
3064 3067 payload.sea_phyid_portid = cpu_to_le32(((SEA & 0xFFFF) << 8) |
3065 3068 ((phyId & 0x0F) << 4) | (port_id & 0x0F));
3066 3069 payload.param0 = cpu_to_le32(param0);
3067 3070  
... ... @@ -3132,9 +3135,9 @@
3132 3135 phy->phy_type |= PORT_TYPE_SAS;
3133 3136 phy->identify.device_type = deviceType;
3134 3137 phy->phy_attached = 1;
3135   - if (phy->identify.device_type == SAS_END_DEV)
  3138 + if (phy->identify.device_type == SAS_END_DEVICE)
3136 3139 phy->identify.target_port_protocols = SAS_PROTOCOL_SSP;
3137   - else if (phy->identify.device_type != NO_DEVICE)
  3140 + else if (phy->identify.device_type != SAS_PHY_UNUSED)
3138 3141 phy->identify.target_port_protocols = SAS_PROTOCOL_SMP;
3139 3142 phy->sas_phy.oob_mode = SAS_OOB_MODE;
3140 3143 sas_ha->notify_phy_event(&phy->sas_phy, PHYE_OOB_DONE);
... ... @@ -3278,7 +3281,7 @@
3278 3281 (struct dev_reg_resp *)(piomb + 4);
3279 3282  
3280 3283 htag = le32_to_cpu(registerRespPayload->tag);
3281   - ccb = &pm8001_ha->ccb_info[registerRespPayload->tag];
  3284 + ccb = &pm8001_ha->ccb_info[htag];
3282 3285 pm8001_dev = ccb->device;
3283 3286 status = le32_to_cpu(registerRespPayload->status);
3284 3287 device_id = le32_to_cpu(registerRespPayload->device_id);
... ... @@ -3352,7 +3355,7 @@
3352 3355 struct fw_control_ex fw_control_context;
3353 3356 struct fw_flash_Update_resp *ppayload =
3354 3357 (struct fw_flash_Update_resp *)(piomb + 4);
3355   - u32 tag = le32_to_cpu(ppayload->tag);
  3358 + u32 tag = ppayload->tag;
3356 3359 struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[tag];
3357 3360 status = le32_to_cpu(ppayload->status);
3358 3361 memcpy(&fw_control_context,
3359 3362  
3360 3363  
... ... @@ -3441,13 +3444,12 @@
3441 3444  
3442 3445 struct task_abort_resp *pPayload =
3443 3446 (struct task_abort_resp *)(piomb + 4);
3444   - ccb = &pm8001_ha->ccb_info[pPayload->tag];
3445   - t = ccb->task;
3446 3447  
3447   -
3448 3448 status = le32_to_cpu(pPayload->status);
3449 3449 tag = le32_to_cpu(pPayload->tag);
3450 3450 scp = le32_to_cpu(pPayload->scp);
  3451 + ccb = &pm8001_ha->ccb_info[tag];
  3452 + t = ccb->task;
3451 3453 PM8001_IO_DBG(pm8001_ha,
3452 3454 pm8001_printk(" status = 0x%x\n", status));
3453 3455 if (t == NULL)
... ... @@ -3473,7 +3475,7 @@
3473 3475 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
3474 3476 t->task_state_flags |= SAS_TASK_STATE_DONE;
3475 3477 spin_unlock_irqrestore(&t->task_state_lock, flags);
3476   - pm8001_ccb_task_free(pm8001_ha, t, ccb, pPayload->tag);
  3478 + pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
3477 3479 mb();
3478 3480 t->task_done(t);
3479 3481 return 0;
... ... @@ -3700,7 +3702,7 @@
3700 3702 static void process_one_iomb(struct pm8001_hba_info *pm8001_ha, void *piomb)
3701 3703 {
3702 3704 u32 pHeader = (u32)*(u32 *)piomb;
3703   - u8 opc = (u8)((le32_to_cpu(pHeader)) & 0xFFF);
  3705 + u8 opc = (u8)(pHeader & 0xFFF);
3704 3706  
3705 3707 PM8001_MSG_DBG(pm8001_ha, pm8001_printk("process_one_iomb:"));
3706 3708  
... ... @@ -3867,7 +3869,7 @@
3867 3869 {
3868 3870 struct outbound_queue_table *circularQ;
3869 3871 void *pMsg1 = NULL;
3870   - u8 bc = 0;
  3872 + u8 uninitialized_var(bc);
3871 3873 u32 ret = MPI_IO_STATUS_FAIL;
3872 3874 unsigned long flags;
3873 3875  
3874 3876  
... ... @@ -3882,11 +3884,10 @@
3882 3884 mpi_msg_free_set(pm8001_ha, pMsg1, circularQ, bc);
3883 3885 }
3884 3886 if (MPI_IO_STATUS_BUSY == ret) {
3885   - u32 producer_idx;
3886 3887 /* Update the producer index from SPC */
3887   - producer_idx = pm8001_read_32(circularQ->pi_virt);
3888   - circularQ->producer_index = cpu_to_le32(producer_idx);
3889   - if (circularQ->producer_index ==
  3888 + circularQ->producer_index =
  3889 + cpu_to_le32(pm8001_read_32(circularQ->pi_virt));
  3890 + if (le32_to_cpu(circularQ->producer_index) ==
3890 3891 circularQ->consumer_idx)
3891 3892 /* OQ is empty */
3892 3893 break;
3893 3894  
... ... @@ -3918,9 +3919,9 @@
3918 3919 }
3919 3920 }
3920 3921  
3921   -static void build_smp_cmd(u32 deviceID, u32 hTag, struct smp_req *psmp_cmd)
  3922 +static void build_smp_cmd(u32 deviceID, __le32 hTag, struct smp_req *psmp_cmd)
3922 3923 {
3923   - psmp_cmd->tag = cpu_to_le32(hTag);
  3924 + psmp_cmd->tag = hTag;
3924 3925 psmp_cmd->device_id = cpu_to_le32(deviceID);
3925 3926 psmp_cmd->len_ip_ir = cpu_to_le32(1|(1 << 1));
3926 3927 }
... ... @@ -4004,7 +4005,7 @@
4004 4005 struct ssp_ini_io_start_req ssp_cmd;
4005 4006 u32 tag = ccb->ccb_tag;
4006 4007 int ret;
4007   - __le64 phys_addr;
  4008 + u64 phys_addr;
4008 4009 struct inbound_queue_table *circularQ;
4009 4010 u32 opc = OPC_INB_SSPINIIOSTART;
4010 4011 memset(&ssp_cmd, 0, sizeof(ssp_cmd));
4011 4012  
... ... @@ -4025,15 +4026,15 @@
4025 4026 /* fill in PRD (scatter/gather) table, if any */
4026 4027 if (task->num_scatter > 1) {
4027 4028 pm8001_chip_make_sg(task->scatter, ccb->n_elem, ccb->buf_prd);
4028   - phys_addr = cpu_to_le64(ccb->ccb_dma_handle +
4029   - offsetof(struct pm8001_ccb_info, buf_prd[0]));
4030   - ssp_cmd.addr_low = lower_32_bits(phys_addr);
4031   - ssp_cmd.addr_high = upper_32_bits(phys_addr);
  4029 + phys_addr = ccb->ccb_dma_handle +
  4030 + offsetof(struct pm8001_ccb_info, buf_prd[0]);
  4031 + ssp_cmd.addr_low = cpu_to_le32(lower_32_bits(phys_addr));
  4032 + ssp_cmd.addr_high = cpu_to_le32(upper_32_bits(phys_addr));
4032 4033 ssp_cmd.esgl = cpu_to_le32(1<<31);
4033 4034 } else if (task->num_scatter == 1) {
4034   - __le64 dma_addr = cpu_to_le64(sg_dma_address(task->scatter));
4035   - ssp_cmd.addr_low = lower_32_bits(dma_addr);
4036   - ssp_cmd.addr_high = upper_32_bits(dma_addr);
  4035 + u64 dma_addr = sg_dma_address(task->scatter);
  4036 + ssp_cmd.addr_low = cpu_to_le32(lower_32_bits(dma_addr));
  4037 + ssp_cmd.addr_high = cpu_to_le32(upper_32_bits(dma_addr));
4037 4038 ssp_cmd.len = cpu_to_le32(task->total_xfer_len);
4038 4039 ssp_cmd.esgl = 0;
4039 4040 } else if (task->num_scatter == 0) {
... ... @@ -4056,7 +4057,7 @@
4056 4057 int ret;
4057 4058 struct sata_start_req sata_cmd;
4058 4059 u32 hdr_tag, ncg_tag = 0;
4059   - __le64 phys_addr;
  4060 + u64 phys_addr;
4060 4061 u32 ATAP = 0x0;
4061 4062 u32 dir;
4062 4063 struct inbound_queue_table *circularQ;
4063 4064  
... ... @@ -4095,13 +4096,13 @@
4095 4096 /* fill in PRD (scatter/gather) table, if any */
4096 4097 if (task->num_scatter > 1) {
4097 4098 pm8001_chip_make_sg(task->scatter, ccb->n_elem, ccb->buf_prd);
4098   - phys_addr = cpu_to_le64(ccb->ccb_dma_handle +
4099   - offsetof(struct pm8001_ccb_info, buf_prd[0]));
  4099 + phys_addr = ccb->ccb_dma_handle +
  4100 + offsetof(struct pm8001_ccb_info, buf_prd[0]);
4100 4101 sata_cmd.addr_low = lower_32_bits(phys_addr);
4101 4102 sata_cmd.addr_high = upper_32_bits(phys_addr);
4102 4103 sata_cmd.esgl = cpu_to_le32(1 << 31);
4103 4104 } else if (task->num_scatter == 1) {
4104   - __le64 dma_addr = cpu_to_le64(sg_dma_address(task->scatter));
  4105 + u64 dma_addr = sg_dma_address(task->scatter);
4105 4106 sata_cmd.addr_low = lower_32_bits(dma_addr);
4106 4107 sata_cmd.addr_high = upper_32_bits(dma_addr);
4107 4108 sata_cmd.len = cpu_to_le32(task->total_xfer_len);
... ... @@ -4245,7 +4246,7 @@
4245 4246  
4246 4247 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4247 4248 memset(&payload, 0, sizeof(payload));
4248   - payload.tag = 1;
  4249 + payload.tag = cpu_to_le32(1);
4249 4250 payload.device_id = cpu_to_le32(device_id);
4250 4251 PM8001_MSG_DBG(pm8001_ha,
4251 4252 pm8001_printk("unregister device device_id = %d\n", device_id));
... ... @@ -4269,7 +4270,7 @@
4269 4270 u32 opc = OPC_INB_LOCAL_PHY_CONTROL;
4270 4271 memset(&payload, 0, sizeof(payload));
4271 4272 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4272   - payload.tag = 1;
  4273 + payload.tag = cpu_to_le32(1);
4273 4274 payload.phyop_phyid =
4274 4275 cpu_to_le32(((phy_op & 0xff) << 8) | (phyId & 0x0F));
4275 4276 ret = mpi_build_cmd(pm8001_ha, circularQ, opc, &payload);
... ... @@ -4563,8 +4564,10 @@
4563 4564 payload.cur_image_offset = cpu_to_le32(info->cur_image_offset);
4564 4565 payload.total_image_len = cpu_to_le32(info->total_image_len);
4565 4566 payload.len = info->sgl.im_len.len ;
4566   - payload.sgl_addr_lo = lower_32_bits(info->sgl.addr);
4567   - payload.sgl_addr_hi = upper_32_bits(info->sgl.addr);
  4567 + payload.sgl_addr_lo =
  4568 + cpu_to_le32(lower_32_bits(le64_to_cpu(info->sgl.addr)));
  4569 + payload.sgl_addr_hi =
  4570 + cpu_to_le32(upper_32_bits(le64_to_cpu(info->sgl.addr)));
4568 4571 ret = mpi_build_cmd(pm8001_ha, circularQ, opc, &payload);
4569 4572 return ret;
4570 4573 }
drivers/scsi/pm8001/pm8001_hwi.h
... ... @@ -625,7 +625,7 @@
625 625 __le32 tag;
626 626 __le32 len_ir_vpdd;
627 627 __le32 vpd_offset;
628   - u32 reserved[8];
  628 + __le32 reserved[8];
629 629 __le32 resp_addr_lo;
630 630 __le32 resp_addr_hi;
631 631 __le32 resp_len;