lpfc_sli.c

来自「linux2.6.16版本」· C语言 代码 · 共 2,499 行 · 第 1/5 页

C
2,499
字号
			spin_unlock_irq(phba->host->host_lock);			(iocb->iocb_cmpl) (phba, iocb, iocb);			spin_lock_irq(phba->host->host_lock);		} else			lpfc_sli_release_iocbq(phba, iocb);	}	INIT_LIST_HEAD(&pring->txcmplq);	pring->txcmplq_cnt = 0;	spin_unlock_irq(phba->host->host_lock);	return errcnt;}/******************************************************************************* lpfc_sli_send_reset** Note: After returning from this function, the HBA cannot be accessed for* 1 ms. Since we do not wish to delay in interrupt context, it is the* responsibility of the caller to perform the mdelay(1) and flush via readl().******************************************************************************/static intlpfc_sli_send_reset(struct lpfc_hba * phba, uint16_t skip_post){	MAILBOX_t *swpmb;	volatile uint32_t word0;	void __iomem *to_slim;	unsigned long flags = 0;	spin_lock_irqsave(phba->host->host_lock, flags);	/* A board reset must use REAL SLIM. */	phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE;	word0 = 0;	swpmb = (MAILBOX_t *) & word0;	swpmb->mbxCommand = MBX_RESTART;	swpmb->mbxHc = 1;	to_slim = phba->MBslimaddr;	writel(*(uint32_t *) swpmb, to_slim);	readl(to_slim); /* flush */	/* Only skip post after fc_ffinit is completed */	if (skip_post) {		word0 = 1;	/* This is really setting up word1 */	} else {		word0 = 0;	/* This is really setting up word1 */	}	to_slim = phba->MBslimaddr + sizeof (uint32_t);	writel(*(uint32_t *) swpmb, to_slim);	readl(to_slim); /* flush */	/* Turn off parity checking and serr during the physical reset */	pci_read_config_word(phba->pcidev, PCI_COMMAND, &phba->pci_cfg_value);	pci_write_config_word(phba->pcidev, PCI_COMMAND,			      (phba->pci_cfg_value &			       ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));	writel(HC_INITFF, phba->HCregaddr);	phba->hba_state = LPFC_INIT_START;	spin_unlock_irqrestore(phba->host->host_lock, flags);	return 0;}static intlpfc_sli_brdreset(struct lpfc_hba * phba, uint16_t skip_post){	struct lpfc_sli_ring *pring;	int i;	struct lpfc_dmabuf *mp, *next_mp;	unsigned long flags = 0;	lpfc_sli_send_reset(phba, skip_post);	mdelay(1);	spin_lock_irqsave(phba->host->host_lock, flags);	/* Risk the write on flush case ie no delay after the readl */	readl(phba->HCregaddr); /* flush */	/* Now toggle INITFF bit set by lpfc_sli_send_reset */	writel(0, phba->HCregaddr);	readl(phba->HCregaddr); /* flush */	/* Restore PCI cmd register */	pci_write_config_word(phba->pcidev, PCI_COMMAND, phba->pci_cfg_value);	/* perform board reset */	phba->fc_eventTag = 0;	phba->fc_myDID = 0;	phba->fc_prevDID = Mask_DID;	/* Reset HBA */	lpfc_printf_log(phba,		KERN_INFO,		LOG_SLI,		"%d:0325 Reset HBA Data: x%x x%x x%x\n",		phba->brd_no,		phba->hba_state,		phba->sli.sli_flag,		skip_post);	/* Initialize relevant SLI info */	for (i = 0; i < phba->sli.num_rings; i++) {		pring = &phba->sli.ring[i];		pring->flag = 0;		pring->rspidx = 0;		pring->next_cmdidx  = 0;		pring->local_getidx = 0;		pring->cmdidx = 0;		pring->missbufcnt = 0;	}	spin_unlock_irqrestore(phba->host->host_lock, flags);	if (skip_post) {		mdelay(100);	} else {		mdelay(2000);	}	spin_lock_irqsave(phba->host->host_lock, flags);	/* Cleanup preposted buffers on the ELS ring */	pring = &phba->sli.ring[LPFC_ELS_RING];	list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {		list_del(&mp->list);		pring->postbufq_cnt--;		lpfc_mbuf_free(phba, mp->virt, mp->phys);		kfree(mp);	}	spin_unlock_irqrestore(phba->host->host_lock, flags);	for (i = 0; i < phba->sli.num_rings; i++)		lpfc_sli_abort_iocb_ring(phba, &phba->sli.ring[i]);	return 0;}static intlpfc_sli_chipset_init(struct lpfc_hba *phba){	uint32_t status, i = 0;	/* Read the HBA Host Status Register */	status = readl(phba->HSregaddr);	/* Check status register to see what current state is */	i = 0;	while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {		/* Check every 100ms for 5 retries, then every 500ms for 5, then		 * every 2.5 sec for 5, then reset board and every 2.5 sec for		 * 4.		 */		if (i++ >= 20) {			/* Adapter failed to init, timeout, status reg			   <status> */			lpfc_printf_log(phba,					KERN_ERR,					LOG_INIT,					"%d:0436 Adapter failed to init, "					"timeout, status reg x%x\n",					phba->brd_no,					status);			phba->hba_state = LPFC_HBA_ERROR;			return -ETIMEDOUT;		}		/* Check to see if any errors occurred during init */		if (status & HS_FFERM) {			/* ERROR: During chipset initialization */			/* Adapter failed to init, chipset, status reg			   <status> */			lpfc_printf_log(phba,					KERN_ERR,					LOG_INIT,					"%d:0437 Adapter failed to init, "					"chipset, status reg x%x\n",					phba->brd_no,					status);			phba->hba_state = LPFC_HBA_ERROR;			return -EIO;		}		if (i <= 5) {			msleep(10);		} else if (i <= 10) {			msleep(500);		} else {			msleep(2500);		}		if (i == 15) {			lpfc_sli_brdreset(phba, 0);		}		/* Read the HBA Host Status Register */		status = readl(phba->HSregaddr);	}	/* Check to see if any errors occurred during init */	if (status & HS_FFERM) {		/* ERROR: During chipset initialization */		/* Adapter failed to init, chipset, status reg <status> */		lpfc_printf_log(phba,				KERN_ERR,				LOG_INIT,				"%d:0438 Adapter failed to init, chipset, "				"status reg x%x\n",				phba->brd_no,				status);		phba->hba_state = LPFC_HBA_ERROR;		return -EIO;	}	/* Clear all interrupt enable conditions */	writel(0, phba->HCregaddr);	readl(phba->HCregaddr); /* flush */	/* setup host attn register */	writel(0xffffffff, phba->HAregaddr);	readl(phba->HAregaddr); /* flush */	return 0;}intlpfc_sli_hba_setup(struct lpfc_hba * phba){	LPFC_MBOXQ_t *pmb;	uint32_t resetcount = 0, rc = 0, done = 0;	pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);	if (!pmb) {		phba->hba_state = LPFC_HBA_ERROR;		return -ENOMEM;	}	while (resetcount < 2 && !done) {		phba->hba_state = 0;		lpfc_sli_brdreset(phba, 0);		msleep(2500);		rc = lpfc_sli_chipset_init(phba);		if (rc)			break;		resetcount++;	/* Call pre CONFIG_PORT mailbox command initialization.  A value of 0	 * means the call was successful.  Any other nonzero value is a failure,	 * but if ERESTART is returned, the driver may reset the HBA and try	 * again.	 */		rc = lpfc_config_port_prep(phba);		if (rc == -ERESTART) {			phba->hba_state = 0;			continue;		} else if (rc) {			break;		}		phba->hba_state = LPFC_INIT_MBX_CMDS;		lpfc_config_port(phba, pmb);		rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);		if (rc == MBX_SUCCESS)			done = 1;		else {			lpfc_printf_log(phba, KERN_ERR, LOG_INIT,				"%d:0442 Adapter failed to init, mbxCmd x%x "				"CONFIG_PORT, mbxStatus x%x Data: x%x\n",				phba->brd_no, pmb->mb.mbxCommand,				pmb->mb.mbxStatus, 0);			phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE;		}	}	if (!done)		goto lpfc_sli_hba_setup_error;	rc = lpfc_sli_ring_map(phba, pmb);	if (rc)		goto lpfc_sli_hba_setup_error;	phba->sli.sli_flag |= LPFC_PROCESS_LA;	rc = lpfc_config_port_post(phba);	if (rc)		goto lpfc_sli_hba_setup_error;	goto lpfc_sli_hba_setup_exit;lpfc_sli_hba_setup_error:	phba->hba_state = LPFC_HBA_ERROR;lpfc_sli_hba_setup_exit:	mempool_free(pmb, phba->mbox_mem_pool);	return rc;}static voidlpfc_mbox_abort(struct lpfc_hba * phba){	LPFC_MBOXQ_t *pmbox;	MAILBOX_t *mb;	if (phba->sli.mbox_active) {		del_timer_sync(&phba->sli.mbox_tmo);		phba->work_hba_events &= ~WORKER_MBOX_TMO;		pmbox = phba->sli.mbox_active;		mb = &pmbox->mb;		phba->sli.mbox_active = NULL;		if (pmbox->mbox_cmpl) {			mb->mbxStatus = MBX_NOT_FINISHED;			(pmbox->mbox_cmpl) (phba, pmbox);		}		phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;	}	/* Abort all the non active mailbox commands. */	spin_lock_irq(phba->host->host_lock);	pmbox = lpfc_mbox_get(phba);	while (pmbox) {		mb = &pmbox->mb;		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);		}		pmbox = lpfc_mbox_get(phba);	}	spin_unlock_irq(phba->host->host_lock);	return;}/*! lpfc_mbox_timeout * * \pre * \post * \param hba Pointer to per struct lpfc_hba structure * \param l1  Pointer to the driver's mailbox queue. * \return *   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 (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;				}			}		}	}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?