[SCSI] megaraid_sas: frame count optimization

This patch removes duplicated code in frame calculation & adds
megasas_get_frame_count() that also takes into account the number of frames
that can be contained in the Main frame.
FW uses the frame count to pull sufficient number of frames from host memory.

Signed-off-by: Sumant Patro <Sumant.Patro@lsil.com>
Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>

authored by Sumant Patro and committed by James Bottomley b1df99d9 e3bbff9f

+47 -25
+47 -25
drivers/scsi/megaraid/megaraid_sas.c
··· 495 return sge_count; 496 } 497 498 /** 499 * megasas_build_dcdb - Prepares a direct cdb (DCDB) command 500 * @instance: Adapter soft state ··· 548 megasas_build_dcdb(struct megasas_instance *instance, struct scsi_cmnd *scp, 549 struct megasas_cmd *cmd) 550 { 551 - u32 sge_sz; 552 - int sge_bytes; 553 u32 is_logical; 554 u32 device_id; 555 u16 flags = 0; ··· 582 /* 583 * Construct SGL 584 */ 585 - sge_sz = (IS_DMA64) ? sizeof(struct megasas_sge64) : 586 - sizeof(struct megasas_sge32); 587 - 588 if (IS_DMA64) { 589 pthru->flags |= MFI_FRAME_SGL64; 590 pthru->sge_count = megasas_make_sgl64(instance, scp, ··· 597 pthru->sense_buf_phys_addr_hi = 0; 598 pthru->sense_buf_phys_addr_lo = cmd->sense_phys_addr; 599 600 - sge_bytes = sge_sz * pthru->sge_count; 601 - 602 /* 603 * Compute the total number of frames this command consumes. FW uses 604 * this number to pull sufficient number of frames from host memory. 605 */ 606 - cmd->frame_count = (sge_bytes / MEGAMFI_FRAME_SIZE) + 607 - ((sge_bytes % MEGAMFI_FRAME_SIZE) ? 1 : 0) + 1; 608 - 609 - if (cmd->frame_count > 7) 610 - cmd->frame_count = 8; 611 612 return cmd->frame_count; 613 } ··· 618 megasas_build_ldio(struct megasas_instance *instance, struct scsi_cmnd *scp, 619 struct megasas_cmd *cmd) 620 { 621 - u32 sge_sz; 622 - int sge_bytes; 623 u32 device_id; 624 u8 sc = scp->cmnd[0]; 625 u16 flags = 0; ··· 632 flags = MFI_FRAME_DIR_READ; 633 634 /* 635 - * Preare the Logical IO frame: 2nd bit is zero for all read cmds 636 */ 637 ldio->cmd = (sc & 0x02) ? MFI_CMD_LD_WRITE : MFI_CMD_LD_READ; 638 ldio->cmd_status = 0x0; ··· 701 /* 702 * Construct SGL 703 */ 704 - sge_sz = (IS_DMA64) ? sizeof(struct megasas_sge64) : 705 - sizeof(struct megasas_sge32); 706 - 707 if (IS_DMA64) { 708 ldio->flags |= MFI_FRAME_SGL64; 709 ldio->sge_count = megasas_make_sgl64(instance, scp, &ldio->sgl); ··· 714 ldio->sense_buf_phys_addr_hi = 0; 715 ldio->sense_buf_phys_addr_lo = cmd->sense_phys_addr; 716 717 - sge_bytes = sge_sz * ldio->sge_count; 718 - 719 - cmd->frame_count = (sge_bytes / MEGAMFI_FRAME_SIZE) + 720 - ((sge_bytes % MEGAMFI_FRAME_SIZE) ? 1 : 0) + 1; 721 - 722 - if (cmd->frame_count > 7) 723 - cmd->frame_count = 8; 724 725 return cmd->frame_count; 726 }
··· 495 return sge_count; 496 } 497 498 + /** 499 + * megasas_get_frame_count - Computes the number of frames 500 + * @sge_count : number of sg elements 501 + * 502 + * Returns the number of frames required for numnber of sge's (sge_count) 503 + */ 504 + 505 + u32 megasas_get_frame_count(u8 sge_count) 506 + { 507 + int num_cnt; 508 + int sge_bytes; 509 + u32 sge_sz; 510 + u32 frame_count=0; 511 + 512 + sge_sz = (IS_DMA64) ? sizeof(struct megasas_sge64) : 513 + sizeof(struct megasas_sge32); 514 + 515 + /* 516 + * Main frame can contain 2 SGEs for 64-bit SGLs and 517 + * 3 SGEs for 32-bit SGLs 518 + */ 519 + if (IS_DMA64) 520 + num_cnt = sge_count - 2; 521 + else 522 + num_cnt = sge_count - 3; 523 + 524 + if(num_cnt>0){ 525 + sge_bytes = sge_sz * num_cnt; 526 + 527 + frame_count = (sge_bytes / MEGAMFI_FRAME_SIZE) + 528 + ((sge_bytes % MEGAMFI_FRAME_SIZE) ? 1 : 0) ; 529 + } 530 + /* Main frame */ 531 + frame_count +=1; 532 + 533 + if (frame_count > 7) 534 + frame_count = 8; 535 + return frame_count; 536 + } 537 + 538 /** 539 * megasas_build_dcdb - Prepares a direct cdb (DCDB) command 540 * @instance: Adapter soft state ··· 508 megasas_build_dcdb(struct megasas_instance *instance, struct scsi_cmnd *scp, 509 struct megasas_cmd *cmd) 510 { 511 u32 is_logical; 512 u32 device_id; 513 u16 flags = 0; ··· 544 /* 545 * Construct SGL 546 */ 547 if (IS_DMA64) { 548 pthru->flags |= MFI_FRAME_SGL64; 549 pthru->sge_count = megasas_make_sgl64(instance, scp, ··· 562 pthru->sense_buf_phys_addr_hi = 0; 563 pthru->sense_buf_phys_addr_lo = cmd->sense_phys_addr; 564 565 /* 566 * Compute the total number of frames this command consumes. FW uses 567 * this number to pull sufficient number of frames from host memory. 568 */ 569 + cmd->frame_count = megasas_get_frame_count(pthru->sge_count); 570 571 return cmd->frame_count; 572 } ··· 589 megasas_build_ldio(struct megasas_instance *instance, struct scsi_cmnd *scp, 590 struct megasas_cmd *cmd) 591 { 592 u32 device_id; 593 u8 sc = scp->cmnd[0]; 594 u16 flags = 0; ··· 605 flags = MFI_FRAME_DIR_READ; 606 607 /* 608 + * Prepare the Logical IO frame: 2nd bit is zero for all read cmds 609 */ 610 ldio->cmd = (sc & 0x02) ? MFI_CMD_LD_WRITE : MFI_CMD_LD_READ; 611 ldio->cmd_status = 0x0; ··· 674 /* 675 * Construct SGL 676 */ 677 if (IS_DMA64) { 678 ldio->flags |= MFI_FRAME_SGL64; 679 ldio->sge_count = megasas_make_sgl64(instance, scp, &ldio->sgl); ··· 690 ldio->sense_buf_phys_addr_hi = 0; 691 ldio->sense_buf_phys_addr_lo = cmd->sense_phys_addr; 692 693 + /* 694 + * Compute the total number of frames this command consumes. FW uses 695 + * this number to pull sufficient number of frames from host memory. 696 + */ 697 + cmd->frame_count = megasas_get_frame_count(ldio->sge_count); 698 699 return cmd->frame_count; 700 }