[PATCH] megaraid2 reorder inline functions
Linux Kernel Mailing List <[email protected]> Wed, 23 Feb 2005 07:03:37 +0000
| Newsgroups | gmane.linux.kernel.commits.2-4 |
|---|---|
| Message-ID | <[email protected]> |
ChangeSet 1.1548, 2005/02/23 04:03:37-03:00, [email protected] [PATCH] megaraid2 reorder inline functions Reorder inline functions Uninline big mega_cmd_done() function Signed-off-by: <[email protected]> megaraid2.c | 670 +++++++++++++++++++++++++++++------------------------------- megaraid2.h | 2 2 files changed, 335 insertions(+), 337 deletions(-) diff -Nru a/drivers/scsi/megaraid2.c b/drivers/scsi/megaraid2.c --- a/drivers/scsi/megaraid2.c 2005-02-23 11:03:15 -08:00 +++ b/drivers/scsi/megaraid2.c 2005-02-23 11:03:15 -08:00 @@ -989,6 +989,268 @@ } +/** + * issue_scb() + * @adapter - pointer to our soft state + * @scb - scsi control block + * + * Post a command to the card if the mailbox is available, otherwise return + * busy. We also take the scb from the pending list if the mailbox is + * available. + */ +static inline int +issue_scb(adapter_t *adapter, scb_t *scb) +{ + volatile mbox64_t *mbox64 = adapter->mbox64; + volatile mbox_t *mbox = adapter->mbox; + unsigned int i = 0; + + if(unlikely(mbox->busy)) { + do { + udelay(1); + i++; + } while( mbox->busy && (i < max_mbox_busy_wait) ); + + if(mbox->busy) return -1; + } + + /* Copy mailbox data into host structure */ + memcpy((char *)mbox, (char *)scb->raw_mbox, 16); + + mbox->cmdid = scb->idx; /* Set cmdid */ + mbox->busy = 1; /* Set busy */ + + + /* + * Increment the pending queue counter + */ + atomic_inc(&adapter->pend_cmds); + + switch (mbox->cmd) { + case MEGA_MBOXCMD_EXTPTHRU: + if( !adapter->has_64bit_addr ) break; + // else fall through + case MEGA_MBOXCMD_LREAD64: + case MEGA_MBOXCMD_LWRITE64: + case MEGA_MBOXCMD_PASSTHRU64: + mbox64->xfer_segment_lo = mbox->xferaddr; + mbox64->xfer_segment_hi = 0; + mbox->xferaddr = 0xFFFFFFFF; + break; + default: + mbox64->xfer_segment_lo = 0; + mbox64->xfer_segment_hi = 0; + } + + /* + * post the command + */ + scb->state |= SCB_ISSUED; + + if( likely(adapter->flag & BOARD_MEMMAP) ) { + mbox->poll = 0; + mbox->ack = 0; + WRINDOOR(adapter, adapter->mbox_dma | 0x1); + } + else { + irq_enable(adapter); + issue_command(adapter); + } + + return 0; +} + + +/** + * mega_runpendq() + * @adapter - pointer to our soft state + * + * Runs through the list of pending requests. + */ +static inline void +mega_runpendq(adapter_t *adapter) +{ + if(!list_empty(&adapter->pending_list)) + __mega_runpendq(adapter); +} + + +static void +__mega_runpendq(adapter_t *adapter) +{ + scb_t *scb; + struct list_head *pos, *next; + + /* Issue any pending commands to the card */ + list_for_each_safe(pos, next, &adapter->pending_list) { + + scb = list_entry(pos, scb_t, list); + + if( !(scb->state & SCB_ISSUED) ) { + + if( issue_scb(adapter, scb) != 0 ) + return; + } + } + + return; +} + + +/** + * mega_allocate_scb() + * @adapter - pointer to our soft state + * @cmd - scsi command from the mid-layer + * + * Allocate a SCB structure. This is the central structure for controller + * commands. + */ +static inline scb_t * +mega_allocate_scb(adapter_t *adapter, Scsi_Cmnd *cmd) +{ + struct list_head *head = &adapter->free_list; + scb_t *scb; + + /* Unlink command from Free List */ + if( !list_empty(head) ) { + + scb = list_entry(head->next, scb_t, list); + + list_del_init(head->next); + + scb->state = SCB_ACTIVE; + scb->cmd = cmd; + scb->dma_type = MEGA_DMA_TYPE_NONE; + + return scb; + } + + return NULL; +} + + +/** + * mega_get_ldrv_num() + * @adapter - pointer to our soft state + * @cmd - scsi mid layer command + * @channel - channel on the controller + * + * Calculate the logical drive number based on the information in scsi command + * and the channel number. + */ +static inline int +mega_get_ldrv_num(adapter_t *adapter, Scsi_Cmnd *cmd, int channel) +{ + int tgt; + int ldrv_num; + + tgt = cmd->target; + + if ( tgt > adapter->this_id ) + tgt--; /* we do not get inquires for initiator id */ + + ldrv_num = (channel * 15) + tgt; + + + /* + * If we have a logical drive with boot enabled, project it first + */ + if( adapter->boot_ldrv_enabled ) { + if( ldrv_num == 0 ) { + ldrv_num = adapter->boot_ldrv; + } + else { + if( ldrv_num <= adapter->boot_ldrv ) { + ldrv_num--; + } + } + } + + /* + * If "delete logical drive" feature is enabled on this controller, + * the value returned should be 0x80+logical drive id. + */ + if (adapter->support_random_del) + ldrv_num += 0x80; + + return ldrv_num; +} + +/* + * Wait until the controller's mailbox is available + */ +static inline int +mega_busywait_mbox (adapter_t *adapter) +{ + if (adapter->mbox->busy) + return __mega_busywait_mbox(adapter); + return 0; +} + + +/** + * megaraid_iombox_ack_sequence - interrupt ack sequence for IO mapped HBAs + * @adapter - controller's soft state + * + * Interrupt ackrowledgement sequence for IO mapped HBAs + */ +static inline void +megaraid_iombox_ack_sequence(adapter_t *adapter) +{ + u8 status; + u8 nstatus; + u8 completed[MAX_FIRMWARE_STATUS]; + u8 byte; + int i; + + + /* + * loop till F/W has more commands for us to complete. + */ + do { + /* Check if a valid interrupt is pending */ + byte = irq_state(adapter); + if( (byte & VALID_INTR_BYTE) == 0 ) { + return; + } + set_irq_state(adapter, byte); + + while ((nstatus = adapter->mbox->numstatus) == 0xFF) { + cpu_relax(); + } + adapter->mbox->numstatus = 0xFF; + + for (i = 0; i < nstatus; i++) { + while ((completed[i] = adapter->mbox->completed[i]) + == 0xFF) { + cpu_relax(); + } + + adapter->mbox->completed[i] = 0xFF; + } + + // we must read the valid status now + if ((status = adapter->mbox->status) == 0xFF) { + printk(KERN_WARNING + "megaraid critical: status 0xFF from firmware.\n"); + } + adapter->mbox->status = 0xFF; + + /* + * decrement the pending queue counter + */ + atomic_sub(nstatus, &adapter->pend_cmds); + + /* Acknowledge interrupt */ + irq_ack(adapter); + + mega_cmd_done(adapter, completed, nstatus, status); + + } while(1); +} + + + /* * megaraid_queue() * @scmd - Issue this scsi command @@ -1601,145 +1863,6 @@ /** - * mega_allocate_scb() - * @adapter - pointer to our soft state - * @cmd - scsi command from the mid-layer - * - * Allocate a SCB structure. This is the central structure for controller - * commands. - */ -static inline scb_t * -mega_allocate_scb(adapter_t *adapter, Scsi_Cmnd *cmd) -{ - struct list_head *head = &adapter->free_list; - scb_t *scb; - - /* Unlink command from Free List */ - if( !list_empty(head) ) { - - scb = list_entry(head->next, scb_t, list); - - list_del_init(head->next); - - scb->state = SCB_ACTIVE; - scb->cmd = cmd; - scb->dma_type = MEGA_DMA_TYPE_NONE; - - return scb; - } - - return NULL; -} - - -/** - * mega_runpendq() - * @adapter - pointer to our soft state - * - * Runs through the list of pending requests. - */ -static inline void -mega_runpendq(adapter_t *adapter) -{ - if(!list_empty(&adapter->pending_list)) - __mega_runpendq(adapter); -} - -static void -__mega_runpendq(adapter_t *adapter) -{ - scb_t *scb; - struct list_head *pos, *next; - - /* Issue any pending commands to the card */ - list_for_each_safe(pos, next, &adapter->pending_list) { - - scb = list_entry(pos, scb_t, list); - - if( !(scb->state & SCB_ISSUED) ) { - - if( issue_scb(adapter, scb) != 0 ) - return; - } - } - - return; -} - - -/** - * issue_scb() - * @adapter - pointer to our soft state - * @scb - scsi control block - * - * Post a command to the card if the mailbox is available, otherwise return - * busy. We also take the scb from the pending list if the mailbox is - * available. - */ -static inline int -issue_scb(adapter_t *adapter, scb_t *scb) -{ - volatile mbox64_t *mbox64 = adapter->mbox64; - volatile mbox_t *mbox = adapter->mbox; - unsigned int i = 0; - - if(unlikely(mbox->busy)) { - do { - udelay(1); - i++; - } while( mbox->busy && (i < max_mbox_busy_wait) ); - - if(mbox->busy) return -1; - } - - /* Copy mailbox data into host structure */ - memcpy((char *)mbox, (char *)scb->raw_mbox, 16); - - mbox->cmdid = scb->idx; /* Set cmdid */ - mbox->busy = 1; /* Set busy */ - - - /* - * Increment the pending queue counter - */ - atomic_inc(&adapter->pend_cmds); - - switch (mbox->cmd) { - case MEGA_MBOXCMD_EXTPTHRU: - if( !adapter->has_64bit_addr ) break; - // else fall through - case MEGA_MBOXCMD_LREAD64: - case MEGA_MBOXCMD_LWRITE64: - case MEGA_MBOXCMD_PASSTHRU64: - mbox64->xfer_segment_lo = mbox->xferaddr; - mbox64->xfer_segment_hi = 0; - mbox->xferaddr = 0xFFFFFFFF; - break; - default: - mbox64->xfer_segment_lo = 0; - mbox64->xfer_segment_hi = 0; - } - - /* - * post the command - */ - scb->state |= SCB_ISSUED; - - if( likely(adapter->flag & BOARD_MEMMAP) ) { - mbox->poll = 0; - mbox->ack = 0; - WRINDOOR(adapter, adapter->mbox_dma | 0x1); - } - else { - irq_enable(adapter); - issue_command(adapter); - } - - return 0; -} - - -/** * issue_scb_block() * @adapter - pointer to our soft state * @raw_mbox - the mailbox @@ -1873,18 +1996,18 @@ /** - * megaraid_iombox_ack_sequence - interrupt ack sequence for IO mapped HBAs + * megaraid_memmbox_ack_sequence - interrupt ack sequence for memory mapped HBAs * @adapter - controller's soft state * - * Interrupt ackrowledgement sequence for IO mapped HBAs + * Interrupt ackrowledgement sequence for memory mapped HBAs */ static inline void -megaraid_iombox_ack_sequence(adapter_t *adapter) +megaraid_memmbox_ack_sequence(adapter_t *adapter) { u8 status; + u32 dword = 0; u8 nstatus; u8 completed[MAX_FIRMWARE_STATUS]; - u8 byte; int i; @@ -1893,18 +2016,21 @@ */ do { /* Check if a valid interrupt is pending */ - byte = irq_state(adapter); - if( (byte & VALID_INTR_BYTE) == 0 ) { + dword = RDOUTDOOR(adapter); + if( dword != 0x10001234 ) { + /* + * No more pending commands + */ return; } - set_irq_state(adapter, byte); + WROUTDOOR(adapter, 0x10001234); while ((nstatus = adapter->mbox->numstatus) == 0xFF) { cpu_relax(); } adapter->mbox->numstatus = 0xFF; - for (i = 0; i < nstatus; i++) { + for (i = 0; i < nstatus; i++ ) { while ((completed[i] = adapter->mbox->completed[i]) == 0xFF) { cpu_relax(); @@ -1926,7 +2052,9 @@ atomic_sub(nstatus, &adapter->pend_cmds); /* Acknowledge interrupt */ - irq_ack(adapter); + WRINDOOR(adapter, 0x2); + + while( RDINDOOR(adapter) & 0x02 ) cpu_relax(); mega_cmd_done(adapter, completed, nstatus, status); @@ -1965,74 +2093,6 @@ return; } - -/** - * megaraid_memmbox_ack_sequence - interrupt ack sequence for memory mapped HBAs - * @adapter - controller's soft state - * - * Interrupt ackrowledgement sequence for memory mapped HBAs - */ -static inline void -megaraid_memmbox_ack_sequence(adapter_t *adapter) -{ - u8 status; - u32 dword = 0; - u8 nstatus; - u8 completed[MAX_FIRMWARE_STATUS]; - int i; - - - /* - * loop till F/W has more commands for us to complete. - */ - do { - /* Check if a valid interrupt is pending */ - dword = RDOUTDOOR(adapter); - if( dword != 0x10001234 ) { - /* - * No more pending commands - */ - return; - } - WROUTDOOR(adapter, 0x10001234); - - while ((nstatus = adapter->mbox->numstatus) == 0xFF) { - cpu_relax(); - } - adapter->mbox->numstatus = 0xFF; - - for (i = 0; i < nstatus; i++ ) { - while ((completed[i] = adapter->mbox->completed[i]) - == 0xFF) { - cpu_relax(); - } - - adapter->mbox->completed[i] = 0xFF; - } - - // we must read the valid status now - if ((status = adapter->mbox->status) == 0xFF) { - printk(KERN_WARNING - "megaraid critical: status 0xFF from firmware.\n"); - } - adapter->mbox->status = 0xFF; - - /* - * decrement the pending queue counter - */ - atomic_sub(nstatus, &adapter->pend_cmds); - - /* Acknowledge interrupt */ - WRINDOOR(adapter, 0x2); - - while( RDINDOOR(adapter) & 0x02 ) cpu_relax(); - - mega_cmd_done(adapter, completed, nstatus, status); - - } while(1); -} - - /** * mega_cmd_done() * @adapter - pointer to our soft state @@ -2042,7 +2102,7 @@ * * Complete the comamnds and call the scsi mid-layer callback hooks. */ -static inline void +static void mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status) { mega_ext_passthru *epthru = NULL; @@ -2344,18 +2404,6 @@ list_add(&scb->list, &adapter->free_list); } - -/* - * Wait until the controller's mailbox is available - */ -static inline int -mega_busywait_mbox (adapter_t *adapter) -{ - if (adapter->mbox->busy) - return __mega_busywait_mbox(adapter); - return 0; -} - static int __mega_busywait_mbox (adapter_t *adapter) { @@ -2513,6 +2561,43 @@ enquiry3->pdrv_state[i] = inquiry->pdrv_info.pdrv_state[i]; } +static inline void +mega_free_sgl(adapter_t *adapter) +{ + scb_t *scb; + int i; + + for(i = 0; i < adapter->max_cmds; i++) { + + scb = &adapter->scb_list[i]; + + if( scb->sgl64 ) { + pci_free_consistent(adapter->dev, + sizeof(mega_sgl64) * adapter->sglen, + scb->sgl64, + scb->sgl_dma_addr); + + scb->sgl64 = NULL; + } + + if( scb->pthru ) { + pci_free_consistent(adapter->dev, sizeof(mega_passthru), + scb->pthru, scb->pthru_dma_addr); + + scb->pthru = NULL; + } + + if( scb->epthru ) { + pci_free_consistent(adapter->dev, + sizeof(mega_ext_passthru), + scb->epthru, scb->epthru_dma_addr); + + scb->epthru = NULL; + } + + } +} + /* * Release the controller's resources @@ -2650,44 +2735,6 @@ return 0; } -static inline void -mega_free_sgl(adapter_t *adapter) -{ - scb_t *scb; - int i; - - for(i = 0; i < adapter->max_cmds; i++) { - - scb = &adapter->scb_list[i]; - - if( scb->sgl64 ) { - pci_free_consistent(adapter->dev, - sizeof(mega_sgl64) * adapter->sglen, - scb->sgl64, - scb->sgl_dma_addr); - - scb->sgl64 = NULL; - } - - if( scb->pthru ) { - pci_free_consistent(adapter->dev, sizeof(mega_passthru), - scb->pthru, scb->pthru_dma_addr); - - scb->pthru = NULL; - } - - if( scb->epthru ) { - pci_free_consistent(adapter->dev, - sizeof(mega_ext_passthru), - scb->epthru, scb->epthru_dma_addr); - - scb->epthru = NULL; - } - - } -} - - /* * Get information about the card/driver */ @@ -3153,6 +3200,26 @@ return len; } +/** + * mega_allocate_inquiry() + * @dma_handle - handle returned for dma address + * @pdev - handle to pci device + * + * allocates memory for inquiry structure + */ +static inline caddr_t +mega_allocate_inquiry(dma_addr_t *dma_handle, struct pci_dev *pdev) +{ + return pci_alloc_consistent(pdev, sizeof(mega_inquiry3), dma_handle); +} + + +static inline void +mega_free_inquiry(caddr_t inquiry, dma_addr_t dma_handle, struct pci_dev *pdev) +{ + pci_free_consistent(pdev, sizeof(mega_inquiry3), inquiry, dma_handle); +} + /** * proc_rebuild_rate() @@ -5112,55 +5179,6 @@ } - -/** - * mega_get_ldrv_num() - * @adapter - pointer to our soft state - * @cmd - scsi mid layer command - * @channel - channel on the controller - * - * Calculate the logical drive number based on the information in scsi command - * and the channel number. - */ -static inline int -mega_get_ldrv_num(adapter_t *adapter, Scsi_Cmnd *cmd, int channel) -{ - int tgt; - int ldrv_num; - - tgt = cmd->target; - - if ( tgt > adapter->this_id ) - tgt--; /* we do not get inquires for initiator id */ - - ldrv_num = (channel * 15) + tgt; - - - /* - * If we have a logical drive with boot enabled, project it first - */ - if( adapter->boot_ldrv_enabled ) { - if( ldrv_num == 0 ) { - ldrv_num = adapter->boot_ldrv; - } - else { - if( ldrv_num <= adapter->boot_ldrv ) { - ldrv_num--; - } - } - } - - /* - * If "delete logical drive" feature is enabled on this controller, - * the value returned should be 0x80+logical drive id. - */ - if (adapter->support_random_del) - ldrv_num += 0x80; - - return ldrv_num; -} - - /** * mega_reorder_hosts() * @@ -5374,26 +5392,6 @@ return 0; } - -/** - * mega_allocate_inquiry() - * @dma_handle - handle returned for dma address - * @pdev - handle to pci device - * - * allocates memory for inquiry structure - */ -static inline caddr_t -mega_allocate_inquiry(dma_addr_t *dma_handle, struct pci_dev *pdev) -{ - return pci_alloc_consistent(pdev, sizeof(mega_inquiry3), dma_handle); -} - - -static inline void -mega_free_inquiry(caddr_t inquiry, dma_addr_t dma_handle, struct pci_dev *pdev) -{ - pci_free_consistent(pdev, sizeof(mega_inquiry3), inquiry, dma_handle); -} /** mega_internal_dev_inquiry() diff -Nru a/drivers/scsi/megaraid2.h b/drivers/scsi/megaraid2.h --- a/drivers/scsi/megaraid2.h 2005-02-23 11:03:15 -08:00 +++ b/drivers/scsi/megaraid2.h 2005-02-23 11:03:15 -08:00 @@ -1128,7 +1128,7 @@ u32 *buffer, u32 *length); static inline int mega_busywait_mbox (adapter_t *); static int __mega_busywait_mbox (adapter_t *); -static inline void mega_cmd_done(adapter_t *, u8 [], int, int); +static void mega_cmd_done(adapter_t *, u8 [], int, int); static inline void mega_free_sgl (adapter_t *adapter); static void mega_8_to_40ld (mraid_inquiry *inquiry, mega_inquiry3 *enquiry3, mega_product_info *);