@@ -264,12 +264,36 @@ static u32 pm8001_request_irq(struct pm8001_hba_info *pm8001_ha);
264264static int pm8001_alloc (struct pm8001_hba_info * pm8001_ha ,
265265 const struct pci_device_id * ent )
266266{
267- int i ;
267+ int i , count = 0 , rc = 0 ;
268+ u32 ci_offset , ib_offset , ob_offset , pi_offset ;
269+ struct inbound_queue_table * circularQ ;
270+
268271 spin_lock_init (& pm8001_ha -> lock );
269272 spin_lock_init (& pm8001_ha -> bitmap_lock );
270273 PM8001_INIT_DBG (pm8001_ha ,
271274 pm8001_printk ("pm8001_alloc: PHY:%x\n" ,
272275 pm8001_ha -> chip -> n_phy ));
276+
277+ /* Setup Interrupt */
278+ rc = pm8001_setup_irq (pm8001_ha );
279+ if (rc ) {
280+ PM8001_FAIL_DBG (pm8001_ha , pm8001_printk (
281+ "pm8001_setup_irq failed [ret: %d]\n" , rc ));
282+ goto err_out_shost ;
283+ }
284+ /* Request Interrupt */
285+ rc = pm8001_request_irq (pm8001_ha );
286+ if (rc )
287+ goto err_out_shost ;
288+
289+ count = pm8001_ha -> max_q_num ;
290+ /* Queues are chosen based on the number of cores/msix availability */
291+ ib_offset = pm8001_ha -> ib_offset = USI_MAX_MEMCNT_BASE + 1 ;
292+ ci_offset = pm8001_ha -> ci_offset = ib_offset + count ;
293+ ob_offset = pm8001_ha -> ob_offset = ci_offset + count ;
294+ pi_offset = pm8001_ha -> pi_offset = ob_offset + count ;
295+ pm8001_ha -> max_memcnt = pi_offset + count ;
296+
273297 for (i = 0 ; i < pm8001_ha -> chip -> n_phy ; i ++ ) {
274298 pm8001_phy_init (pm8001_ha , i );
275299 pm8001_ha -> port [i ].wide_port_phymap = 0 ;
@@ -293,54 +317,62 @@ static int pm8001_alloc(struct pm8001_hba_info *pm8001_ha,
293317 pm8001_ha -> memoryMap .region [IOP ].total_len = PM8001_EVENT_LOG_SIZE ;
294318 pm8001_ha -> memoryMap .region [IOP ].alignment = 32 ;
295319
296- for (i = 0 ; i < PM8001_MAX_SPCV_INB_NUM ; i ++ ) {
320+ for (i = 0 ; i < count ; i ++ ) {
321+ circularQ = & pm8001_ha -> inbnd_q_tbl [i ];
322+ spin_lock_init (& circularQ -> iq_lock );
297323 /* MPI Memory region 3 for consumer Index of inbound queues */
298- pm8001_ha -> memoryMap .region [CI + i ].num_elements = 1 ;
299- pm8001_ha -> memoryMap .region [CI + i ].element_size = 4 ;
300- pm8001_ha -> memoryMap .region [CI + i ].total_len = 4 ;
301- pm8001_ha -> memoryMap .region [CI + i ].alignment = 4 ;
324+ pm8001_ha -> memoryMap .region [ci_offset + i ].num_elements = 1 ;
325+ pm8001_ha -> memoryMap .region [ci_offset + i ].element_size = 4 ;
326+ pm8001_ha -> memoryMap .region [ci_offset + i ].total_len = 4 ;
327+ pm8001_ha -> memoryMap .region [ci_offset + i ].alignment = 4 ;
302328
303329 if ((ent -> driver_data ) != chip_8001 ) {
304330 /* MPI Memory region 5 inbound queues */
305- pm8001_ha -> memoryMap .region [IB + i ].num_elements =
331+ pm8001_ha -> memoryMap .region [ib_offset + i ].num_elements =
306332 PM8001_MPI_QUEUE ;
307- pm8001_ha -> memoryMap .region [IB + i ].element_size = 128 ;
308- pm8001_ha -> memoryMap .region [IB + i ].total_len =
333+ pm8001_ha -> memoryMap .region [ib_offset + i ].element_size
334+ = 128 ;
335+ pm8001_ha -> memoryMap .region [ib_offset + i ].total_len =
309336 PM8001_MPI_QUEUE * 128 ;
310- pm8001_ha -> memoryMap .region [IB + i ].alignment = 128 ;
337+ pm8001_ha -> memoryMap .region [ib_offset + i ].alignment
338+ = 128 ;
311339 } else {
312- pm8001_ha -> memoryMap .region [IB + i ].num_elements =
340+ pm8001_ha -> memoryMap .region [ib_offset + i ].num_elements =
313341 PM8001_MPI_QUEUE ;
314- pm8001_ha -> memoryMap .region [IB + i ].element_size = 64 ;
315- pm8001_ha -> memoryMap .region [IB + i ].total_len =
342+ pm8001_ha -> memoryMap .region [ib_offset + i ].element_size
343+ = 64 ;
344+ pm8001_ha -> memoryMap .region [ib_offset + i ].total_len =
316345 PM8001_MPI_QUEUE * 64 ;
317- pm8001_ha -> memoryMap .region [IB + i ].alignment = 64 ;
346+ pm8001_ha -> memoryMap .region [ib_offset + i ].alignment = 64 ;
318347 }
319348 }
320349
321- for (i = 0 ; i < PM8001_MAX_SPCV_OUTB_NUM ; i ++ ) {
350+ for (i = 0 ; i < count ; i ++ ) {
322351 /* MPI Memory region 4 for producer Index of outbound queues */
323- pm8001_ha -> memoryMap .region [PI + i ].num_elements = 1 ;
324- pm8001_ha -> memoryMap .region [PI + i ].element_size = 4 ;
325- pm8001_ha -> memoryMap .region [PI + i ].total_len = 4 ;
326- pm8001_ha -> memoryMap .region [PI + i ].alignment = 4 ;
352+ pm8001_ha -> memoryMap .region [pi_offset + i ].num_elements = 1 ;
353+ pm8001_ha -> memoryMap .region [pi_offset + i ].element_size = 4 ;
354+ pm8001_ha -> memoryMap .region [pi_offset + i ].total_len = 4 ;
355+ pm8001_ha -> memoryMap .region [pi_offset + i ].alignment = 4 ;
327356
328357 if (ent -> driver_data != chip_8001 ) {
329358 /* MPI Memory region 6 Outbound queues */
330- pm8001_ha -> memoryMap .region [OB + i ].num_elements =
359+ pm8001_ha -> memoryMap .region [ob_offset + i ].num_elements =
331360 PM8001_MPI_QUEUE ;
332- pm8001_ha -> memoryMap .region [OB + i ].element_size = 128 ;
333- pm8001_ha -> memoryMap .region [OB + i ].total_len =
361+ pm8001_ha -> memoryMap .region [ob_offset + i ].element_size
362+ = 128 ;
363+ pm8001_ha -> memoryMap .region [ob_offset + i ].total_len =
334364 PM8001_MPI_QUEUE * 128 ;
335- pm8001_ha -> memoryMap .region [OB + i ].alignment = 128 ;
365+ pm8001_ha -> memoryMap .region [ob_offset + i ].alignment
366+ = 128 ;
336367 } else {
337368 /* MPI Memory region 6 Outbound queues */
338- pm8001_ha -> memoryMap .region [OB + i ].num_elements =
369+ pm8001_ha -> memoryMap .region [ob_offset + i ].num_elements =
339370 PM8001_MPI_QUEUE ;
340- pm8001_ha -> memoryMap .region [OB + i ].element_size = 64 ;
341- pm8001_ha -> memoryMap .region [OB + i ].total_len =
371+ pm8001_ha -> memoryMap .region [ob_offset + i ].element_size
372+ = 64 ;
373+ pm8001_ha -> memoryMap .region [ob_offset + i ].total_len =
342374 PM8001_MPI_QUEUE * 64 ;
343- pm8001_ha -> memoryMap .region [OB + i ].alignment = 64 ;
375+ pm8001_ha -> memoryMap .region [ob_offset + i ].alignment = 64 ;
344376 }
345377
346378 }
@@ -369,7 +401,7 @@ static int pm8001_alloc(struct pm8001_hba_info *pm8001_ha,
369401 pm8001_ha -> memoryMap .region [FORENSIC_MEM ].total_len = 0x10000 ;
370402 pm8001_ha -> memoryMap .region [FORENSIC_MEM ].element_size = 0x10000 ;
371403 pm8001_ha -> memoryMap .region [FORENSIC_MEM ].alignment = 0x10000 ;
372- for (i = 0 ; i < USI_MAX_MEMCNT ; i ++ ) {
404+ for (i = 0 ; i < pm8001_ha -> max_memcnt ; i ++ ) {
373405 if (pm8001_mem_alloc (pm8001_ha -> pdev ,
374406 & pm8001_ha -> memoryMap .region [i ].virt_ptr ,
375407 & pm8001_ha -> memoryMap .region [i ].phys_addr ,
@@ -405,6 +437,8 @@ static int pm8001_alloc(struct pm8001_hba_info *pm8001_ha,
405437 /* Initialize tags */
406438 pm8001_tag_init (pm8001_ha );
407439 return 0 ;
440+ err_out_shost :
441+ scsi_remove_host (pm8001_ha -> shost );
408442err_out :
409443 return 1 ;
410444}
@@ -899,7 +933,8 @@ static int pm8001_configure_phy_settings(struct pm8001_hba_info *pm8001_ha)
899933static u32 pm8001_setup_msix (struct pm8001_hba_info * pm8001_ha )
900934{
901935 u32 number_of_intr ;
902- int rc ;
936+ int rc , cpu_online_count ;
937+ unsigned int allocated_irq_vectors ;
903938
904939 /* SPCv controllers supports 64 msi-x */
905940 if (pm8001_ha -> chip_id == chip_8001 ) {
@@ -908,13 +943,21 @@ static u32 pm8001_setup_msix(struct pm8001_hba_info *pm8001_ha)
908943 number_of_intr = PM8001_MAX_MSIX_VEC ;
909944 }
910945
946+ cpu_online_count = num_online_cpus ();
947+ number_of_intr = min_t (int , cpu_online_count , number_of_intr );
911948 rc = pci_alloc_irq_vectors (pm8001_ha -> pdev , number_of_intr ,
912949 number_of_intr , PCI_IRQ_MSIX );
913- number_of_intr = rc ;
950+ allocated_irq_vectors = rc ;
914951 if (rc < 0 )
915952 return rc ;
953+
954+ /* Assigns the number of interrupts */
955+ number_of_intr = min_t (int , allocated_irq_vectors , number_of_intr );
916956 pm8001_ha -> number_of_intr = number_of_intr ;
917957
958+ /* Maximum queue number updating in HBA structure */
959+ pm8001_ha -> max_q_num = number_of_intr ;
960+
918961 PM8001_INIT_DBG (pm8001_ha , pm8001_printk (
919962 "pci_alloc_irq_vectors request ret:%d no of intr %d\n" ,
920963 rc , pm8001_ha -> number_of_intr ));
@@ -1069,13 +1112,6 @@ static int pm8001_pci_probe(struct pci_dev *pdev,
10691112 rc = - ENOMEM ;
10701113 goto err_out_free ;
10711114 }
1072- /* Setup Interrupt */
1073- rc = pm8001_setup_irq (pm8001_ha );
1074- if (rc ) {
1075- PM8001_FAIL_DBG (pm8001_ha , pm8001_printk (
1076- "pm8001_setup_irq failed [ret: %d]\n" , rc ));
1077- goto err_out_shost ;
1078- }
10791115
10801116 PM8001_CHIP_DISP -> chip_soft_rst (pm8001_ha );
10811117 rc = PM8001_CHIP_DISP -> chip_init (pm8001_ha );
@@ -1088,13 +1124,6 @@ static int pm8001_pci_probe(struct pci_dev *pdev,
10881124 rc = scsi_add_host (shost , & pdev -> dev );
10891125 if (rc )
10901126 goto err_out_ha_free ;
1091- /* Request Interrupt */
1092- rc = pm8001_request_irq (pm8001_ha );
1093- if (rc ) {
1094- PM8001_FAIL_DBG (pm8001_ha , pm8001_printk (
1095- "pm8001_request_irq failed [ret: %d]\n" , rc ));
1096- goto err_out_shost ;
1097- }
10981127
10991128 PM8001_CHIP_DISP -> interrupt_enable (pm8001_ha , 0 );
11001129 if (pm8001_ha -> chip_id != chip_8001 ) {
0 commit comments