lpfc_sli.c
来自「LINUX 2.6.17.4的源码」· C语言 代码 · 共 2,535 行 · 第 1/5 页
C
2,535 行
* void * * \b Description: * * This routine handles mailbox timeout events at timer interrupt context. */voidlpfc_mbox_timeout(unsigned long ptr){ struct lpfc_hba *phba; unsigned long iflag; phba = (struct lpfc_hba *)ptr; spin_lock_irqsave(phba->host->host_lock, iflag); if (!(phba->work_hba_events & WORKER_MBOX_TMO)) { phba->work_hba_events |= WORKER_MBOX_TMO; if (phba->work_wait) wake_up(phba->work_wait); } spin_unlock_irqrestore(phba->host->host_lock, iflag);}voidlpfc_mbox_timeout_handler(struct lpfc_hba *phba){ LPFC_MBOXQ_t *pmbox; MAILBOX_t *mb; spin_lock_irq(phba->host->host_lock); if (!(phba->work_hba_events & WORKER_MBOX_TMO)) { spin_unlock_irq(phba->host->host_lock); return; } phba->work_hba_events &= ~WORKER_MBOX_TMO; pmbox = phba->sli.mbox_active; mb = &pmbox->mb; /* Mbox cmd <mbxCommand> timeout */ lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, "%d:0310 Mailbox command x%x timeout Data: x%x x%x x%p\n", phba->brd_no, mb->mbxCommand, phba->hba_state, phba->sli.sli_flag, phba->sli.mbox_active); phba->sli.mbox_active = NULL; if (pmbox->mbox_cmpl) { mb->mbxStatus = MBX_NOT_FINISHED; spin_unlock_irq(phba->host->host_lock); (pmbox->mbox_cmpl) (phba, pmbox); spin_lock_irq(phba->host->host_lock); } phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; spin_unlock_irq(phba->host->host_lock); lpfc_mbox_abort(phba); return;}intlpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag){ MAILBOX_t *mb; struct lpfc_sli *psli; uint32_t status, evtctr; uint32_t ha_copy; int i; unsigned long drvr_flag = 0; volatile uint32_t word0, ldata; void __iomem *to_slim; psli = &phba->sli; spin_lock_irqsave(phba->host->host_lock, drvr_flag); mb = &pmbox->mb; status = MBX_SUCCESS; if (phba->hba_state == LPFC_HBA_ERROR) { spin_unlock_irqrestore(phba->host->host_lock, drvr_flag); /* Mbox command <mbxCommand> cannot issue */ LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag) return (MBX_NOT_FINISHED); } if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT && !(readl(phba->HCregaddr) & HC_MBINT_ENA)) { spin_unlock_irqrestore(phba->host->host_lock, drvr_flag); LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag) return (MBX_NOT_FINISHED); } if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { /* Polling for a mbox command when another one is already active * is not allowed in SLI. Also, the driver must have established * SLI2 mode to queue and process multiple mbox commands. */ if (flag & MBX_POLL) { spin_unlock_irqrestore(phba->host->host_lock, drvr_flag); /* Mbox command <mbxCommand> cannot issue */ LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag) return (MBX_NOT_FINISHED); } if (!(psli->sli_flag & LPFC_SLI2_ACTIVE)) { spin_unlock_irqrestore(phba->host->host_lock, drvr_flag); /* Mbox command <mbxCommand> cannot issue */ LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag) return (MBX_NOT_FINISHED); } /* Handle STOP IOCB processing flag. This is only meaningful * if we are not polling for mbox completion. */ if (flag & MBX_STOP_IOCB) { flag &= ~MBX_STOP_IOCB; /* Now flag each ring */ for (i = 0; i < psli->num_rings; i++) { /* If the ring is active, flag it */ if (psli->ring[i].cmdringaddr) { psli->ring[i].flag |= LPFC_STOP_IOCB_MBX; } } } /* Another mailbox command is still being processed, queue this * command to be processed later. */ lpfc_mbox_put(phba, pmbox); /* Mbox cmd issue - BUSY */ lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, "%d:0308 Mbox cmd issue - BUSY Data: x%x x%x x%x x%x\n", phba->brd_no, mb->mbxCommand, phba->hba_state, psli->sli_flag, flag); psli->slistat.mbox_busy++; spin_unlock_irqrestore(phba->host->host_lock, drvr_flag); return (MBX_BUSY); } /* Handle STOP IOCB processing flag. This is only meaningful * if we are not polling for mbox completion. */ if (flag & MBX_STOP_IOCB) { flag &= ~MBX_STOP_IOCB; if (flag == MBX_NOWAIT) { /* Now flag each ring */ for (i = 0; i < psli->num_rings; i++) { /* If the ring is active, flag it */ if (psli->ring[i].cmdringaddr) { psli->ring[i].flag |= LPFC_STOP_IOCB_MBX; } } } } psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; /* If we are not polling, we MUST be in SLI2 mode */ if (flag != MBX_POLL) { if (!(psli->sli_flag & LPFC_SLI2_ACTIVE) && (mb->mbxCommand != MBX_KILL_BOARD)) { psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; spin_unlock_irqrestore(phba->host->host_lock, drvr_flag); /* Mbox command <mbxCommand> cannot issue */ LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag); return (MBX_NOT_FINISHED); } /* timeout active mbox command */ mod_timer(&psli->mbox_tmo, jiffies + HZ * LPFC_MBOX_TMO); } /* Mailbox cmd <cmd> issue */ lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, "%d:0309 Mailbox cmd x%x issue Data: x%x x%x x%x\n", phba->brd_no, mb->mbxCommand, phba->hba_state, psli->sli_flag, flag); psli->slistat.mbox_cmd++; evtctr = psli->slistat.mbox_event; /* next set own bit for the adapter and copy over command word */ mb->mbxOwner = OWN_CHIP; if (psli->sli_flag & LPFC_SLI2_ACTIVE) { /* First copy command data to host SLIM area */ lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx, MAILBOX_CMD_SIZE); } else { if (mb->mbxCommand == MBX_CONFIG_PORT) { /* copy command data into host mbox for cmpl */ lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx, MAILBOX_CMD_SIZE); } /* First copy mbox command data to HBA SLIM, skip past first word */ to_slim = phba->MBslimaddr + sizeof (uint32_t); lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0], MAILBOX_CMD_SIZE - sizeof (uint32_t)); /* Next copy over first word, with mbxOwner set */ ldata = *((volatile uint32_t *)mb); to_slim = phba->MBslimaddr; writel(ldata, to_slim); readl(to_slim); /* flush */ if (mb->mbxCommand == MBX_CONFIG_PORT) { /* switch over to host mailbox */ psli->sli_flag |= LPFC_SLI2_ACTIVE; } } wmb(); /* interrupt board to doit right away */ writel(CA_MBATT, phba->CAregaddr); readl(phba->CAregaddr); /* flush */ switch (flag) { case MBX_NOWAIT: /* Don't wait for it to finish, just return */ psli->mbox_active = pmbox; break; case MBX_POLL: i = 0; psli->mbox_active = NULL; if (psli->sli_flag & LPFC_SLI2_ACTIVE) { /* First read mbox status word */ word0 = *((volatile uint32_t *)&phba->slim2p->mbx); word0 = le32_to_cpu(word0); } else { /* First read mbox status word */ word0 = readl(phba->MBslimaddr); } /* Read the HBA Host Attention Register */ ha_copy = readl(phba->HAregaddr); /* Wait for command to complete */ while (((word0 & OWN_CHIP) == OWN_CHIP) || (!(ha_copy & HA_MBATT) && (phba->hba_state > LPFC_WARM_START))) { if (i++ >= 100) { psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; spin_unlock_irqrestore(phba->host->host_lock, drvr_flag); return (MBX_NOT_FINISHED); } /* Check if we took a mbox interrupt while we were polling */ if (((word0 & OWN_CHIP) != OWN_CHIP) && (evtctr != psli->slistat.mbox_event)) break; spin_unlock_irqrestore(phba->host->host_lock, drvr_flag); /* Can be in interrupt context, do not sleep */ /* (or might be called with interrupts disabled) */ mdelay(i); spin_lock_irqsave(phba->host->host_lock, drvr_flag); if (psli->sli_flag & LPFC_SLI2_ACTIVE) { /* First copy command data */ word0 = *((volatile uint32_t *) &phba->slim2p->mbx); word0 = le32_to_cpu(word0); if (mb->mbxCommand == MBX_CONFIG_PORT) { MAILBOX_t *slimmb; volatile uint32_t slimword0; /* Check real SLIM for any errors */ slimword0 = readl(phba->MBslimaddr); slimmb = (MAILBOX_t *) & slimword0; if (((slimword0 & OWN_CHIP) != OWN_CHIP) && slimmb->mbxStatus) { psli->sli_flag &= ~LPFC_SLI2_ACTIVE; word0 = slimword0; } } } else { /* First copy command data */ word0 = readl(phba->MBslimaddr); } /* Read the HBA Host Attention Register */ ha_copy = readl(phba->HAregaddr); } if (psli->sli_flag & LPFC_SLI2_ACTIVE) { /* copy results back to user */ lpfc_sli_pcimem_bcopy(&phba->slim2p->mbx, mb, MAILBOX_CMD_SIZE); } else { /* First copy command data */ lpfc_memcpy_from_slim(mb, phba->MBslimaddr, MAILBOX_CMD_SIZE); if ((mb->mbxCommand == MBX_DUMP_MEMORY) && pmbox->context2) { lpfc_memcpy_from_slim((void *)pmbox->context2, phba->MBslimaddr + DMP_RSP_OFFSET, mb->un.varDmp.word_cnt); } } writel(HA_MBATT, phba->HAregaddr); readl(phba->HAregaddr); /* flush */ psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; status = mb->mbxStatus; } spin_unlock_irqrestore(phba->host->host_lock, drvr_flag); return (status);}static intlpfc_sli_ringtx_put(struct lpfc_hba * phba, struct lpfc_sli_ring * pring, struct lpfc_iocbq * piocb){ /* Insert the caller's iocb in the txq tail for later processing. */ list_add_tail(&piocb->list, &pring->txq); pring->txq_cnt++; return (0);}static struct lpfc_iocbq *lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, struct lpfc_iocbq ** piocb){ struct lpfc_iocbq * nextiocb; nextiocb = lpfc_sli_ringtx_get(phba, pring); if (!nextiocb) { nextiocb = *piocb; *piocb = NULL; } return nextiocb;}intlpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, struct lpfc_iocbq *piocb, uint32_t flag){ struct lpfc_iocbq *nextiocb; IOCB_t *iocb; /* * We should never get an IOCB if we are in a < LINK_DOWN state */ if (unlikely(phba->hba_state < LPFC_LINK_DOWN)) return IOCB_ERROR; /* * Check to see if we are blocking IOCB processing because of a * outstanding mbox command. */ if (unlikely(pring->flag & LPFC_STOP_IOCB_MBX)) goto iocb_busy; if (unlikely(phba->hba_state == LPFC_LINK_DOWN)) { /* * Only CREATE_XRI, CLOSE_XRI, ABORT_XRI, and QUE_RING_BUF * can be issued if the link is not up. */ switch (piocb->iocb.ulpCommand) { case CMD_QUE_RING_BUF_CN: case CMD_QUE_RING_BUF64_CN: /* * For IOCBs, like QUE_RING_BUF, that have no rsp ring * completion, iocb_cmpl MUST be 0. */ if (piocb->iocb_cmpl) piocb->iocb_cmpl = NULL; /*FALLTHROUGH*/ case CMD_CREATE_XRI_CR: break; default: goto iocb_busy; } /* * For FCP commands, we must be in a state where we can process link * attention events. */ } else if (unlikely(pring->ringno == phba->sli.fcp_ring && !(phba->sli.sli_flag & LPFC_PROCESS_LA))) goto iocb_busy; while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); if (iocb) lpfc_sli_update_ring(phba, pring); else lpfc_sli_update_full_ring(phba, pring); if (!piocb) return IOCB_SUCCESS; goto out_busy; iocb_busy: pring->stats.iocb_cmd_delay++; out_busy: if (!(flag & SLI_IOCB_RET_IOCB)) { lpfc_sli_ringtx_put(phba, pring, piocb); return IOCB_SUCCESS; } return IOCB_BUSY;}static intlpfc_extra_ring_setup( struct lpfc_hba *phba){ struct lpfc_sli *psli; struct lpfc_sli_ring *pring; psli = &phba->sli; /* Adjust cmd/rsp ring iocb entries more evenly */ pring = &psli->ring[psli->fcp_ring]; pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; pring = &psli->ring[1]; pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; /* Setup default profile for this ring */ pring->iotag_max = 4096; pring->num_mask = 1; pring->prt[0].profile = 0; /* Mask 0 */ pring->prt[0].rctl = FC_UNSOL_DATA; pring->prt[0].type = 5; pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; return 0;}intlpfc_sli_setup(struct lpfc_hba *phba){ int i, totiocb = 0; struct lpfc_sli *psli = &phba->sli; struct lpfc_sli_ring *pring; psli->num_rings = MAX_CONFIGURED_RINGS; psli->sli_flag = 0; psli->fcp_ring = LPFC_FCP_RING; psli->next_ring = LPFC_FCP_NEXT_RING; psli->ip_ring = LPFC_IP_RING; psli->iocbq_lookup = NULL; psli->iocbq_lookup_len = 0; psli->last_iotag = 0; for (i = 0; i < psli->num_rings; i++) { pring = &psli->ring[i]; switch (i) { case LPFC_FCP_RING: /* ring 0 - FCP */ /* numCiocb and numRiocb are used in config_port */ pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; pring->iotag_ctr = 0; pring->iotag_max =
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?