@@ -1336,10 +1336,13 @@ int pm8001_mpi_msg_free_get(struct inbound_queue_table *circularQ,
1336
1336
* @circularQ: the inbound queue we want to transfer to HBA.
1337
1337
* @opCode: the operation code represents commands which LLDD and fw recognized.
1338
1338
* @payload: the command payload of each operation command.
1339
+ * @nb: size in bytes of the command payload
1340
+ * @responseQueue: queue to interrupt on w/ command response (if any)
1339
1341
*/
1340
1342
int pm8001_mpi_build_cmd (struct pm8001_hba_info * pm8001_ha ,
1341
1343
struct inbound_queue_table * circularQ ,
1342
- u32 opCode , void * payload , u32 responseQueue )
1344
+ u32 opCode , void * payload , size_t nb ,
1345
+ u32 responseQueue )
1343
1346
{
1344
1347
u32 Header = 0 , hpriority = 0 , bc = 1 , category = 0x02 ;
1345
1348
void * pMessage ;
@@ -1350,10 +1353,13 @@ int pm8001_mpi_build_cmd(struct pm8001_hba_info *pm8001_ha,
1350
1353
pm8001_printk ("No free mpi buffer\n" ));
1351
1354
return - ENOMEM ;
1352
1355
}
1353
- BUG_ON (!payload );
1354
- /*Copy to the payload*/
1355
- memcpy (pMessage , payload , (pm8001_ha -> iomb_size -
1356
- sizeof (struct mpi_msg_hdr )));
1356
+
1357
+ if (nb > (pm8001_ha -> iomb_size - sizeof (struct mpi_msg_hdr )))
1358
+ nb = pm8001_ha -> iomb_size - sizeof (struct mpi_msg_hdr );
1359
+ memcpy (pMessage , payload , nb );
1360
+ if (nb + sizeof (struct mpi_msg_hdr ) < pm8001_ha -> iomb_size )
1361
+ memset (pMessage + nb , 0 , pm8001_ha -> iomb_size -
1362
+ (nb + sizeof (struct mpi_msg_hdr )));
1357
1363
1358
1364
/*Build the header*/
1359
1365
Header = ((1 << 31 ) | (hpriority << 30 ) | ((bc & 0x1f ) << 24 )
@@ -1763,7 +1769,8 @@ static void pm8001_send_abort_all(struct pm8001_hba_info *pm8001_ha,
1763
1769
task_abort .device_id = cpu_to_le32 (pm8001_ha_dev -> device_id );
1764
1770
task_abort .tag = cpu_to_le32 (ccb_tag );
1765
1771
1766
- ret = pm8001_mpi_build_cmd (pm8001_ha , circularQ , opc , & task_abort , 0 );
1772
+ ret = pm8001_mpi_build_cmd (pm8001_ha , circularQ , opc , & task_abort ,
1773
+ sizeof (task_abort ), 0 );
1767
1774
if (ret )
1768
1775
pm8001_tag_free (pm8001_ha , ccb_tag );
1769
1776
@@ -1836,7 +1843,8 @@ static void pm8001_send_read_log(struct pm8001_hba_info *pm8001_ha,
1836
1843
sata_cmd .ncqtag_atap_dir_m |= ((0x1 << 7 ) | (0x5 << 9 ));
1837
1844
memcpy (& sata_cmd .sata_fis , & fis , sizeof (struct host_to_dev_fis ));
1838
1845
1839
- res = pm8001_mpi_build_cmd (pm8001_ha , circularQ , opc , & sata_cmd , 0 );
1846
+ res = pm8001_mpi_build_cmd (pm8001_ha , circularQ , opc , & sata_cmd ,
1847
+ sizeof (sata_cmd ), 0 );
1840
1848
if (res ) {
1841
1849
sas_free_task (task );
1842
1850
pm8001_tag_free (pm8001_ha , ccb_tag );
@@ -3375,7 +3383,8 @@ static void pm8001_hw_event_ack_req(struct pm8001_hba_info *pm8001_ha,
3375
3383
((phyId & 0x0F ) << 4 ) | (port_id & 0x0F ));
3376
3384
payload .param0 = cpu_to_le32 (param0 );
3377
3385
payload .param1 = cpu_to_le32 (param1 );
3378
- pm8001_mpi_build_cmd (pm8001_ha , circularQ , opc , & payload , 0 );
3386
+ pm8001_mpi_build_cmd (pm8001_ha , circularQ , opc , & payload ,
3387
+ sizeof (payload ), 0 );
3379
3388
}
3380
3389
3381
3390
static int pm8001_chip_phy_ctl_req (struct pm8001_hba_info * pm8001_ha ,
@@ -4305,7 +4314,7 @@ static int pm8001_chip_smp_req(struct pm8001_hba_info *pm8001_ha,
4305
4314
cpu_to_le32 ((u32 )sg_dma_len (& task -> smp_task .smp_resp )- 4 );
4306
4315
build_smp_cmd (pm8001_dev -> device_id , smp_cmd .tag , & smp_cmd );
4307
4316
rc = pm8001_mpi_build_cmd (pm8001_ha , circularQ , opc ,
4308
- ( u32 * ) & smp_cmd , 0 );
4317
+ & smp_cmd , sizeof ( smp_cmd ) , 0 );
4309
4318
if (rc )
4310
4319
goto err_out_2 ;
4311
4320
@@ -4373,7 +4382,8 @@ static int pm8001_chip_ssp_io_req(struct pm8001_hba_info *pm8001_ha,
4373
4382
ssp_cmd .len = cpu_to_le32 (task -> total_xfer_len );
4374
4383
ssp_cmd .esgl = 0 ;
4375
4384
}
4376
- ret = pm8001_mpi_build_cmd (pm8001_ha , circularQ , opc , & ssp_cmd , 0 );
4385
+ ret = pm8001_mpi_build_cmd (pm8001_ha , circularQ , opc , & ssp_cmd ,
4386
+ sizeof (ssp_cmd ), 0 );
4377
4387
return ret ;
4378
4388
}
4379
4389
@@ -4482,7 +4492,8 @@ static int pm8001_chip_sata_req(struct pm8001_hba_info *pm8001_ha,
4482
4492
}
4483
4493
}
4484
4494
4485
- ret = pm8001_mpi_build_cmd (pm8001_ha , circularQ , opc , & sata_cmd , 0 );
4495
+ ret = pm8001_mpi_build_cmd (pm8001_ha , circularQ , opc , & sata_cmd ,
4496
+ sizeof (sata_cmd ), 0 );
4486
4497
return ret ;
4487
4498
}
4488
4499
@@ -4517,7 +4528,8 @@ pm8001_chip_phy_start_req(struct pm8001_hba_info *pm8001_ha, u8 phy_id)
4517
4528
memcpy (payload .sas_identify .sas_addr ,
4518
4529
pm8001_ha -> sas_addr , SAS_ADDR_SIZE );
4519
4530
payload .sas_identify .phy_id = phy_id ;
4520
- ret = pm8001_mpi_build_cmd (pm8001_ha , circularQ , opcode , & payload , 0 );
4531
+ ret = pm8001_mpi_build_cmd (pm8001_ha , circularQ , opcode , & payload ,
4532
+ sizeof (payload ), 0 );
4521
4533
return ret ;
4522
4534
}
4523
4535
@@ -4539,7 +4551,8 @@ static int pm8001_chip_phy_stop_req(struct pm8001_hba_info *pm8001_ha,
4539
4551
memset (& payload , 0 , sizeof (payload ));
4540
4552
payload .tag = cpu_to_le32 (tag );
4541
4553
payload .phy_id = cpu_to_le32 (phy_id );
4542
- ret = pm8001_mpi_build_cmd (pm8001_ha , circularQ , opcode , & payload , 0 );
4554
+ ret = pm8001_mpi_build_cmd (pm8001_ha , circularQ , opcode , & payload ,
4555
+ sizeof (payload ), 0 );
4543
4556
return ret ;
4544
4557
}
4545
4558
@@ -4598,7 +4611,8 @@ static int pm8001_chip_reg_dev_req(struct pm8001_hba_info *pm8001_ha,
4598
4611
cpu_to_le32 (ITNT | (firstBurstSize * 0x10000 ));
4599
4612
memcpy (payload .sas_addr , pm8001_dev -> sas_device -> sas_addr ,
4600
4613
SAS_ADDR_SIZE );
4601
- rc = pm8001_mpi_build_cmd (pm8001_ha , circularQ , opc , & payload , 0 );
4614
+ rc = pm8001_mpi_build_cmd (pm8001_ha , circularQ , opc , & payload ,
4615
+ sizeof (payload ), 0 );
4602
4616
return rc ;
4603
4617
}
4604
4618
@@ -4619,7 +4633,8 @@ int pm8001_chip_dereg_dev_req(struct pm8001_hba_info *pm8001_ha,
4619
4633
payload .device_id = cpu_to_le32 (device_id );
4620
4634
PM8001_MSG_DBG (pm8001_ha ,
4621
4635
pm8001_printk ("unregister device device_id = %d\n" , device_id ));
4622
- ret = pm8001_mpi_build_cmd (pm8001_ha , circularQ , opc , & payload , 0 );
4636
+ ret = pm8001_mpi_build_cmd (pm8001_ha , circularQ , opc , & payload ,
4637
+ sizeof (payload ), 0 );
4623
4638
return ret ;
4624
4639
}
4625
4640
@@ -4642,7 +4657,8 @@ static int pm8001_chip_phy_ctl_req(struct pm8001_hba_info *pm8001_ha,
4642
4657
payload .tag = cpu_to_le32 (1 );
4643
4658
payload .phyop_phyid =
4644
4659
cpu_to_le32 (((phy_op & 0xff ) << 8 ) | (phyId & 0x0F ));
4645
- ret = pm8001_mpi_build_cmd (pm8001_ha , circularQ , opc , & payload , 0 );
4660
+ ret = pm8001_mpi_build_cmd (pm8001_ha , circularQ , opc , & payload ,
4661
+ sizeof (payload ), 0 );
4646
4662
return ret ;
4647
4663
}
4648
4664
@@ -4696,7 +4712,8 @@ static int send_task_abort(struct pm8001_hba_info *pm8001_ha, u32 opc,
4696
4712
task_abort .device_id = cpu_to_le32 (dev_id );
4697
4713
task_abort .tag = cpu_to_le32 (cmd_tag );
4698
4714
}
4699
- ret = pm8001_mpi_build_cmd (pm8001_ha , circularQ , opc , & task_abort , 0 );
4715
+ ret = pm8001_mpi_build_cmd (pm8001_ha , circularQ , opc , & task_abort ,
4716
+ sizeof (task_abort ), 0 );
4700
4717
return ret ;
4701
4718
}
4702
4719
@@ -4753,7 +4770,8 @@ int pm8001_chip_ssp_tm_req(struct pm8001_hba_info *pm8001_ha,
4753
4770
if (pm8001_ha -> chip_id != chip_8001 )
4754
4771
sspTMCmd .ds_ads_m = 0x08 ;
4755
4772
circularQ = & pm8001_ha -> inbnd_q_tbl [0 ];
4756
- ret = pm8001_mpi_build_cmd (pm8001_ha , circularQ , opc , & sspTMCmd , 0 );
4773
+ ret = pm8001_mpi_build_cmd (pm8001_ha , circularQ , opc , & sspTMCmd ,
4774
+ sizeof (sspTMCmd ), 0 );
4757
4775
return ret ;
4758
4776
}
4759
4777
@@ -4843,7 +4861,8 @@ int pm8001_chip_get_nvmd_req(struct pm8001_hba_info *pm8001_ha,
4843
4861
default :
4844
4862
break ;
4845
4863
}
4846
- rc = pm8001_mpi_build_cmd (pm8001_ha , circularQ , opc , & nvmd_req , 0 );
4864
+ rc = pm8001_mpi_build_cmd (pm8001_ha , circularQ , opc , & nvmd_req ,
4865
+ sizeof (nvmd_req ), 0 );
4847
4866
if (rc ) {
4848
4867
kfree (fw_control_context );
4849
4868
pm8001_tag_free (pm8001_ha , tag );
@@ -4927,7 +4946,8 @@ int pm8001_chip_set_nvmd_req(struct pm8001_hba_info *pm8001_ha,
4927
4946
default :
4928
4947
break ;
4929
4948
}
4930
- rc = pm8001_mpi_build_cmd (pm8001_ha , circularQ , opc , & nvmd_req , 0 );
4949
+ rc = pm8001_mpi_build_cmd (pm8001_ha , circularQ , opc , & nvmd_req ,
4950
+ sizeof (nvmd_req ), 0 );
4931
4951
if (rc ) {
4932
4952
kfree (fw_control_context );
4933
4953
pm8001_tag_free (pm8001_ha , tag );
@@ -4962,7 +4982,8 @@ pm8001_chip_fw_flash_update_build(struct pm8001_hba_info *pm8001_ha,
4962
4982
cpu_to_le32 (lower_32_bits (le64_to_cpu (info -> sgl .addr )));
4963
4983
payload .sgl_addr_hi =
4964
4984
cpu_to_le32 (upper_32_bits (le64_to_cpu (info -> sgl .addr )));
4965
- ret = pm8001_mpi_build_cmd (pm8001_ha , circularQ , opc , & payload , 0 );
4985
+ ret = pm8001_mpi_build_cmd (pm8001_ha , circularQ , opc , & payload ,
4986
+ sizeof (payload ), 0 );
4966
4987
return ret ;
4967
4988
}
4968
4989
@@ -5109,7 +5130,8 @@ pm8001_chip_set_dev_state_req(struct pm8001_hba_info *pm8001_ha,
5109
5130
payload .tag = cpu_to_le32 (tag );
5110
5131
payload .device_id = cpu_to_le32 (pm8001_dev -> device_id );
5111
5132
payload .nds = cpu_to_le32 (state );
5112
- rc = pm8001_mpi_build_cmd (pm8001_ha , circularQ , opc , & payload , 0 );
5133
+ rc = pm8001_mpi_build_cmd (pm8001_ha , circularQ , opc , & payload ,
5134
+ sizeof (payload ), 0 );
5113
5135
return rc ;
5114
5136
5115
5137
}
@@ -5134,7 +5156,8 @@ pm8001_chip_sas_re_initialization(struct pm8001_hba_info *pm8001_ha)
5134
5156
payload .SSAHOLT = cpu_to_le32 (0xd << 25 );
5135
5157
payload .sata_hol_tmo = cpu_to_le32 (80 );
5136
5158
payload .open_reject_cmdretries_data_retries = cpu_to_le32 (0xff00ff );
5137
- rc = pm8001_mpi_build_cmd (pm8001_ha , circularQ , opc , & payload , 0 );
5159
+ rc = pm8001_mpi_build_cmd (pm8001_ha , circularQ , opc , & payload ,
5160
+ sizeof (payload ), 0 );
5138
5161
if (rc )
5139
5162
pm8001_tag_free (pm8001_ha , tag );
5140
5163
return rc ;
0 commit comments