1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2006 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/interrupt.h>
25 #include <linux/delay.h>
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_cmnd.h>
29 #include <scsi/scsi_device.h>
30 #include <scsi/scsi_host.h>
31 #include <scsi/scsi_transport_fc.h>
35 #include "lpfc_disc.h"
36 #include "lpfc_scsi.h"
38 #include "lpfc_crtn.h"
39 #include "lpfc_logmsg.h"
40 #include "lpfc_compat.h"
43 * Define macro to log: Mailbox command x%x cannot issue Data
44 * This allows multiple uses of lpfc_msgBlk0311
45 * w/o perturbing log msg utility.
47 #define LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag) \
48 lpfc_printf_log(phba, \
51 "%d:0311 Mailbox command x%x cannot issue " \
52 "Data: x%x x%x x%x\n", \
60 /* There are only four IOCB completion types. */
61 typedef enum _lpfc_iocb_type {
69 lpfc_sli_get_iocbq(struct lpfc_hba * phba)
71 struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
72 struct lpfc_iocbq * iocbq = NULL;
74 list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
79 lpfc_sli_release_iocbq(struct lpfc_hba * phba, struct lpfc_iocbq * iocbq)
81 size_t start_clean = (size_t)(&((struct lpfc_iocbq *)NULL)->iocb);
84 * Clean all volatile data fields, preserve iotag and node struct.
86 memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
87 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
91 * Translate the iocb command to an iocb command type used to decide the final
92 * disposition of each completed IOCB.
95 lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
97 lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
99 if (iocb_cmnd > CMD_MAX_IOCB_CMD)
103 case CMD_XMIT_SEQUENCE_CR:
104 case CMD_XMIT_SEQUENCE_CX:
105 case CMD_XMIT_BCAST_CN:
106 case CMD_XMIT_BCAST_CX:
107 case CMD_ELS_REQUEST_CR:
108 case CMD_ELS_REQUEST_CX:
109 case CMD_CREATE_XRI_CR:
110 case CMD_CREATE_XRI_CX:
112 case CMD_XMIT_ELS_RSP_CX:
114 case CMD_FCP_IWRITE_CR:
115 case CMD_FCP_IWRITE_CX:
116 case CMD_FCP_IREAD_CR:
117 case CMD_FCP_IREAD_CX:
118 case CMD_FCP_ICMND_CR:
119 case CMD_FCP_ICMND_CX:
120 case CMD_ADAPTER_MSG:
121 case CMD_ADAPTER_DUMP:
122 case CMD_XMIT_SEQUENCE64_CR:
123 case CMD_XMIT_SEQUENCE64_CX:
124 case CMD_XMIT_BCAST64_CN:
125 case CMD_XMIT_BCAST64_CX:
126 case CMD_ELS_REQUEST64_CR:
127 case CMD_ELS_REQUEST64_CX:
128 case CMD_FCP_IWRITE64_CR:
129 case CMD_FCP_IWRITE64_CX:
130 case CMD_FCP_IREAD64_CR:
131 case CMD_FCP_IREAD64_CX:
132 case CMD_FCP_ICMND64_CR:
133 case CMD_FCP_ICMND64_CX:
134 case CMD_GEN_REQUEST64_CR:
135 case CMD_GEN_REQUEST64_CX:
136 case CMD_XMIT_ELS_RSP64_CX:
137 type = LPFC_SOL_IOCB;
139 case CMD_ABORT_XRI_CN:
140 case CMD_ABORT_XRI_CX:
141 case CMD_CLOSE_XRI_CN:
142 case CMD_CLOSE_XRI_CX:
143 case CMD_XRI_ABORTED_CX:
144 case CMD_ABORT_MXRI64_CN:
145 type = LPFC_ABORT_IOCB;
147 case CMD_RCV_SEQUENCE_CX:
148 case CMD_RCV_ELS_REQ_CX:
149 case CMD_RCV_SEQUENCE64_CX:
150 case CMD_RCV_ELS_REQ64_CX:
151 type = LPFC_UNSOL_IOCB;
154 type = LPFC_UNKNOWN_IOCB;
162 lpfc_sli_ring_map(struct lpfc_hba * phba, LPFC_MBOXQ_t *pmb)
164 struct lpfc_sli *psli = &phba->sli;
165 MAILBOX_t *pmbox = &pmb->mb;
168 for (i = 0; i < psli->num_rings; i++) {
169 phba->hba_state = LPFC_INIT_MBX_CMDS;
170 lpfc_config_ring(phba, i, pmb);
171 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
172 if (rc != MBX_SUCCESS) {
173 lpfc_printf_log(phba,
176 "%d:0446 Adapter failed to init, "
177 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
183 phba->hba_state = LPFC_HBA_ERROR;
191 lpfc_sli_ringtxcmpl_put(struct lpfc_hba * phba,
192 struct lpfc_sli_ring * pring, struct lpfc_iocbq * piocb)
196 list_add_tail(&piocb->list, &pring->txcmplq);
197 pring->txcmplq_cnt++;
198 if (unlikely(pring->ringno == LPFC_ELS_RING))
199 mod_timer(&phba->els_tmofunc,
200 jiffies + HZ * (phba->fc_ratov << 1));
202 if (pring->fast_lookup) {
203 /* Setup fast lookup based on iotag for completion */
204 iotag = piocb->iocb.ulpIoTag;
205 if (iotag && (iotag < pring->fast_iotag))
206 *(pring->fast_lookup + iotag) = piocb;
209 /* Cmd ring <ringno> put: iotag <iotag> greater then
210 configured max <fast_iotag> wd0 <icmd> */
211 lpfc_printf_log(phba,
214 "%d:0316 Cmd ring %d put: iotag x%x "
215 "greater then configured max x%x "
218 pring->ringno, iotag,
220 *(((uint32_t *)(&piocb->iocb)) + 7));
226 static struct lpfc_iocbq *
227 lpfc_sli_ringtx_get(struct lpfc_hba * phba, struct lpfc_sli_ring * pring)
229 struct list_head *dlp;
230 struct lpfc_iocbq *cmd_iocb;
234 list_remove_head((&pring->txq), cmd_iocb,
238 /* If the first ptr is not equal to the list header,
239 * deque the IOCBQ_t and return it.
247 lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
249 struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno];
250 uint32_t max_cmd_idx = pring->numCiocb;
253 if ((pring->next_cmdidx == pring->cmdidx) &&
254 (++pring->next_cmdidx >= max_cmd_idx))
255 pring->next_cmdidx = 0;
257 if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
259 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
261 if (unlikely(pring->local_getidx >= max_cmd_idx)) {
262 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
263 "%d:0315 Ring %d issue: portCmdGet %d "
264 "is bigger then cmd ring %d\n",
265 phba->brd_no, pring->ringno,
266 pring->local_getidx, max_cmd_idx);
268 phba->hba_state = LPFC_HBA_ERROR;
270 * All error attention handlers are posted to
273 phba->work_ha |= HA_ERATT;
274 phba->work_hs = HS_FFER3;
276 wake_up(phba->work_wait);
281 if (pring->local_getidx == pring->next_cmdidx)
285 iocb = IOCB_ENTRY(pring->cmdringaddr, pring->cmdidx);
291 lpfc_sli_next_iotag(struct lpfc_hba * phba, struct lpfc_iocbq * iocbq)
293 struct lpfc_iocbq ** new_arr;
294 struct lpfc_iocbq ** old_arr;
296 struct lpfc_sli *psli = &phba->sli;
299 spin_lock_irq(phba->host->host_lock);
300 iotag = psli->last_iotag;
301 if(++iotag < psli->iocbq_lookup_len) {
302 psli->last_iotag = iotag;
303 psli->iocbq_lookup[iotag] = iocbq;
304 spin_unlock_irq(phba->host->host_lock);
305 iocbq->iotag = iotag;
308 else if (psli->iocbq_lookup_len < (0xffff
309 - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
310 new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
311 spin_unlock_irq(phba->host->host_lock);
312 new_arr = kmalloc(new_len * sizeof (struct lpfc_iocbq *),
315 memset((char *)new_arr, 0,
316 new_len * sizeof (struct lpfc_iocbq *));
317 spin_lock_irq(phba->host->host_lock);
318 old_arr = psli->iocbq_lookup;
319 if (new_len <= psli->iocbq_lookup_len) {
320 /* highly unprobable case */
322 iotag = psli->last_iotag;
323 if(++iotag < psli->iocbq_lookup_len) {
324 psli->last_iotag = iotag;
325 psli->iocbq_lookup[iotag] = iocbq;
326 spin_unlock_irq(phba->host->host_lock);
327 iocbq->iotag = iotag;
330 spin_unlock_irq(phba->host->host_lock);
333 if (psli->iocbq_lookup)
334 memcpy(new_arr, old_arr,
335 ((psli->last_iotag + 1) *
336 sizeof (struct lpfc_iocbq *)));
337 psli->iocbq_lookup = new_arr;
338 psli->iocbq_lookup_len = new_len;
339 psli->last_iotag = iotag;
340 psli->iocbq_lookup[iotag] = iocbq;
341 spin_unlock_irq(phba->host->host_lock);
342 iocbq->iotag = iotag;
348 lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
349 "%d:0318 Failed to allocate IOTAG.last IOTAG is %d\n",
350 phba->brd_no, psli->last_iotag);
356 lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
357 IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
362 nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
365 * Issue iocb command to adapter
367 lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, sizeof (IOCB_t));
369 pring->stats.iocb_cmd++;
372 * If there is no completion routine to call, we can release the
373 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
374 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
376 if (nextiocb->iocb_cmpl)
377 lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
379 lpfc_sli_release_iocbq(phba, nextiocb);
382 * Let the HBA know what IOCB slot will be the next one the
383 * driver will put a command into.
385 pring->cmdidx = pring->next_cmdidx;
386 writel(pring->cmdidx, phba->MBslimaddr
387 + (SLIMOFF + (pring->ringno * 2)) * 4);
391 lpfc_sli_update_full_ring(struct lpfc_hba * phba,
392 struct lpfc_sli_ring *pring)
394 int ringno = pring->ringno;
396 pring->flag |= LPFC_CALL_RING_AVAILABLE;
401 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
402 * The HBA will tell us when an IOCB entry is available.
404 writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
405 readl(phba->CAregaddr); /* flush */
407 pring->stats.iocb_cmd_full++;
411 lpfc_sli_update_ring(struct lpfc_hba * phba,
412 struct lpfc_sli_ring *pring)
414 int ringno = pring->ringno;
417 * Tell the HBA that there is work to do in this ring.
420 writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
421 readl(phba->CAregaddr); /* flush */
425 lpfc_sli_resume_iocb(struct lpfc_hba * phba, struct lpfc_sli_ring * pring)
428 struct lpfc_iocbq *nextiocb;
432 * (a) there is anything on the txq to send
434 * (c) link attention events can be processed (fcp ring only)
435 * (d) IOCB processing is not blocked by the outstanding mbox command.
437 if (pring->txq_cnt &&
438 (phba->hba_state > LPFC_LINK_DOWN) &&
439 (pring->ringno != phba->sli.fcp_ring ||
440 phba->sli.sli_flag & LPFC_PROCESS_LA) &&
441 !(pring->flag & LPFC_STOP_IOCB_MBX)) {
443 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
444 (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
445 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
448 lpfc_sli_update_ring(phba, pring);
450 lpfc_sli_update_full_ring(phba, pring);
456 /* lpfc_sli_turn_on_ring is only called by lpfc_sli_handle_mb_event below */
458 lpfc_sli_turn_on_ring(struct lpfc_hba * phba, int ringno)
460 struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[ringno];
462 /* If the ring is active, flag it */
463 if (phba->sli.ring[ringno].cmdringaddr) {
464 if (phba->sli.ring[ringno].flag & LPFC_STOP_IOCB_MBX) {
465 phba->sli.ring[ringno].flag &= ~LPFC_STOP_IOCB_MBX;
467 * Force update of the local copy of cmdGetInx
469 phba->sli.ring[ringno].local_getidx
470 = le32_to_cpu(pgp->cmdGetInx);
471 spin_lock_irq(phba->host->host_lock);
472 lpfc_sli_resume_iocb(phba, &phba->sli.ring[ringno]);
473 spin_unlock_irq(phba->host->host_lock);
479 lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
483 switch (mbxCommand) {
487 case MBX_RUN_BIU_DIAG:
490 case MBX_CONFIG_LINK:
491 case MBX_CONFIG_RING:
493 case MBX_READ_CONFIG:
494 case MBX_READ_RCONFIG:
496 case MBX_READ_STATUS:
500 case MBX_READ_LNK_STAT:
502 case MBX_UNREG_LOGIN:
505 case MBX_DUMP_MEMORY:
506 case MBX_DUMP_CONTEXT:
511 case MBX_DEL_LD_ENTRY:
512 case MBX_RUN_PROGRAM:
517 case MBX_CONFIG_FARP:
520 case MBX_RUN_BIU_DIAG64:
521 case MBX_CONFIG_PORT:
522 case MBX_READ_SPARM64:
524 case MBX_REG_LOGIN64:
526 case MBX_FLASH_WR_ULA:
528 case MBX_LOAD_EXP_ROM:
538 lpfc_sli_wake_mbox_wait(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
540 wait_queue_head_t *pdone_q;
543 * If pdone_q is empty, the driver thread gave up waiting and
546 pdone_q = (wait_queue_head_t *) pmboxq->context1;
548 wake_up_interruptible(pdone_q);
553 lpfc_sli_def_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
555 struct lpfc_dmabuf *mp;
556 mp = (struct lpfc_dmabuf *) (pmb->context1);
558 lpfc_mbuf_free(phba, mp->virt, mp->phys);
561 mempool_free( pmb, phba->mbox_mem_pool);
566 lpfc_sli_handle_mb_event(struct lpfc_hba * phba)
571 struct lpfc_sli *psli;
573 uint32_t process_next;
576 /* We should only get here if we are in SLI2 mode */
577 if (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE)) {
581 phba->sli.slistat.mbox_event++;
583 /* Get a Mailbox buffer to setup mailbox commands for callback */
584 if ((pmb = phba->sli.mbox_active)) {
586 mbox = &phba->slim2p->mbx;
588 /* First check out the status word */
589 lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof (uint32_t));
591 /* Sanity check to ensure the host owns the mailbox */
592 if (pmbox->mbxOwner != OWN_HOST) {
593 /* Lets try for a while */
594 for (i = 0; i < 10240; i++) {
595 /* First copy command data */
596 lpfc_sli_pcimem_bcopy(mbox, pmbox,
598 if (pmbox->mbxOwner == OWN_HOST)
601 /* Stray Mailbox Interrupt, mbxCommand <cmd> mbxStatus
603 lpfc_printf_log(phba,
606 "%d:0304 Stray Mailbox Interrupt "
607 "mbxCommand x%x mbxStatus x%x\n",
612 spin_lock_irq(phba->host->host_lock);
613 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
614 spin_unlock_irq(phba->host->host_lock);
619 del_timer_sync(&phba->sli.mbox_tmo);
620 phba->work_hba_events &= ~WORKER_MBOX_TMO;
623 * It is a fatal error if unknown mbox command completion.
625 if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
628 /* Unknow mailbox command compl */
629 lpfc_printf_log(phba,
632 "%d:0323 Unknown Mailbox command %x Cmpl\n",
635 phba->hba_state = LPFC_HBA_ERROR;
636 phba->work_hs = HS_FFER3;
637 lpfc_handle_eratt(phba);
641 phba->sli.mbox_active = NULL;
642 if (pmbox->mbxStatus) {
643 phba->sli.slistat.mbox_stat_err++;
644 if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
645 /* Mbox cmd cmpl error - RETRYing */
646 lpfc_printf_log(phba,
649 "%d:0305 Mbox cmd cmpl error - "
650 "RETRYing Data: x%x x%x x%x x%x\n",
654 pmbox->un.varWords[0],
656 pmbox->mbxStatus = 0;
657 pmbox->mbxOwner = OWN_HOST;
658 spin_lock_irq(phba->host->host_lock);
659 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
660 spin_unlock_irq(phba->host->host_lock);
661 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
662 if (rc == MBX_SUCCESS)
667 /* Mailbox cmd <cmd> Cmpl <cmpl> */
668 lpfc_printf_log(phba,
671 "%d:0307 Mailbox cmd x%x Cmpl x%p "
672 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
676 *((uint32_t *) pmbox),
677 pmbox->un.varWords[0],
678 pmbox->un.varWords[1],
679 pmbox->un.varWords[2],
680 pmbox->un.varWords[3],
681 pmbox->un.varWords[4],
682 pmbox->un.varWords[5],
683 pmbox->un.varWords[6],
684 pmbox->un.varWords[7]);
686 if (pmb->mbox_cmpl) {
687 lpfc_sli_pcimem_bcopy(mbox, pmbox, MAILBOX_CMD_SIZE);
688 pmb->mbox_cmpl(phba,pmb);
694 process_next = 0; /* by default don't loop */
695 spin_lock_irq(phba->host->host_lock);
696 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
698 /* Process next mailbox command if there is one */
699 if ((pmb = lpfc_mbox_get(phba))) {
700 spin_unlock_irq(phba->host->host_lock);
701 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
702 if (rc == MBX_NOT_FINISHED) {
703 pmb->mb.mbxStatus = MBX_NOT_FINISHED;
704 pmb->mbox_cmpl(phba,pmb);
706 continue; /* loop back */
709 spin_unlock_irq(phba->host->host_lock);
710 /* Turn on IOCB processing */
711 for (i = 0; i < phba->sli.num_rings; i++) {
712 lpfc_sli_turn_on_ring(phba, i);
715 /* Free any lpfc_dmabuf's waiting for mbox cmd cmpls */
716 while (!list_empty(&phba->freebufList)) {
717 struct lpfc_dmabuf *mp;
720 list_remove_head((&phba->freebufList),
725 lpfc_mbuf_free(phba, mp->virt,
732 } while (process_next);
737 lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
738 struct lpfc_iocbq *saveq)
746 irsp = &(saveq->iocb);
747 if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX)
748 || (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX)) {
753 (WORD5 *) & (saveq->iocb.un.
755 Rctl = w5p->hcsw.Rctl;
756 Type = w5p->hcsw.Type;
758 /* Firmware Workaround */
759 if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
760 (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX)) {
763 w5p->hcsw.Rctl = Rctl;
764 w5p->hcsw.Type = Type;
767 /* unSolicited Responses */
768 if (pring->prt[0].profile) {
769 if (pring->prt[0].lpfc_sli_rcv_unsol_event)
770 (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
774 /* We must search, based on rctl / type
775 for the right routine */
776 for (i = 0; i < pring->num_mask;
778 if ((pring->prt[i].rctl ==
782 if (pring->prt[i].lpfc_sli_rcv_unsol_event)
783 (pring->prt[i].lpfc_sli_rcv_unsol_event)
784 (phba, pring, saveq);
791 /* Unexpected Rctl / Type received */
792 /* Ring <ringno> handler: unexpected
793 Rctl <Rctl> Type <Type> received */
794 lpfc_printf_log(phba,
797 "%d:0313 Ring %d handler: unexpected Rctl x%x "
798 "Type x%x received \n",
807 static struct lpfc_iocbq *
808 lpfc_sli_iocbq_lookup(struct lpfc_hba * phba,
809 struct lpfc_sli_ring * pring,
810 struct lpfc_iocbq * prspiocb)
812 struct lpfc_iocbq *cmd_iocb = NULL;
815 iotag = prspiocb->iocb.ulpIoTag;
817 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
818 cmd_iocb = phba->sli.iocbq_lookup[iotag];
819 list_del(&cmd_iocb->list);
820 pring->txcmplq_cnt--;
824 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
825 "%d:0317 iotag x%x is out off "
826 "range: max iotag x%x wd0 x%x\n",
828 phba->sli.last_iotag,
829 *(((uint32_t *) &prspiocb->iocb) + 7));
834 lpfc_sli_process_sol_iocb(struct lpfc_hba * phba, struct lpfc_sli_ring * pring,
835 struct lpfc_iocbq *saveq)
837 struct lpfc_iocbq * cmdiocbp;
841 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
842 spin_lock_irqsave(phba->host->host_lock, iflag);
843 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
845 if (cmdiocbp->iocb_cmpl) {
847 * Post all ELS completions to the worker thread.
848 * All other are passed to the completion callback.
850 if (pring->ringno == LPFC_ELS_RING) {
851 spin_unlock_irqrestore(phba->host->host_lock,
853 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
854 spin_lock_irqsave(phba->host->host_lock, iflag);
857 spin_unlock_irqrestore(phba->host->host_lock,
859 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
860 spin_lock_irqsave(phba->host->host_lock, iflag);
863 lpfc_sli_release_iocbq(phba, cmdiocbp);
866 * Unknown initiating command based on the response iotag.
867 * This could be the case on the ELS ring because of
870 if (pring->ringno != LPFC_ELS_RING) {
872 * Ring <ringno> handler: unexpected completion IoTag
875 lpfc_printf_log(phba,
878 "%d:0322 Ring %d handler: unexpected "
879 "completion IoTag x%x Data: x%x x%x x%x x%x\n",
882 saveq->iocb.ulpIoTag,
883 saveq->iocb.ulpStatus,
884 saveq->iocb.un.ulpWord[4],
885 saveq->iocb.ulpCommand,
886 saveq->iocb.ulpContext);
890 spin_unlock_irqrestore(phba->host->host_lock, iflag);
894 static void lpfc_sli_rsp_pointers_error(struct lpfc_hba * phba,
895 struct lpfc_sli_ring * pring)
897 struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno];
899 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
900 * rsp ring <portRspMax>
902 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
903 "%d:0312 Ring %d handler: portRspPut %d "
904 "is bigger then rsp ring %d\n",
905 phba->brd_no, pring->ringno,
906 le32_to_cpu(pgp->rspPutInx),
909 phba->hba_state = LPFC_HBA_ERROR;
912 * All error attention handlers are posted to
915 phba->work_ha |= HA_ERATT;
916 phba->work_hs = HS_FFER3;
918 wake_up(phba->work_wait);
923 void lpfc_sli_poll_fcp_ring(struct lpfc_hba * phba)
925 struct lpfc_sli * psli = &phba->sli;
926 struct lpfc_sli_ring * pring = &psli->ring[LPFC_FCP_RING];
928 IOCB_t *entry = NULL;
929 struct lpfc_iocbq *cmdiocbq = NULL;
930 struct lpfc_iocbq rspiocbq;
931 struct lpfc_pgp *pgp;
933 uint32_t portRspPut, portRspMax;
935 uint32_t rsp_cmpl = 0;
936 void __iomem *to_slim;
939 pring->stats.iocb_event++;
941 /* The driver assumes SLI-2 mode */
942 pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno];
945 * The next available response entry should never exceed the maximum
946 * entries. If it does, treat it as an adapter hardware error.
948 portRspMax = pring->numRiocb;
949 portRspPut = le32_to_cpu(pgp->rspPutInx);
950 if (unlikely(portRspPut >= portRspMax)) {
951 lpfc_sli_rsp_pointers_error(phba, pring);
956 while (pring->rspidx != portRspPut) {
958 entry = IOCB_ENTRY(pring->rspringaddr, pring->rspidx);
960 if (++pring->rspidx >= portRspMax)
963 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
964 (uint32_t *) &rspiocbq.iocb,
966 irsp = &rspiocbq.iocb;
967 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
968 pring->stats.iocb_rsp++;
971 if (unlikely(irsp->ulpStatus)) {
972 /* Rsp ring <ringno> error: IOCB */
973 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
974 "%d:0326 Rsp Ring %d error: IOCB Data: "
975 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
976 phba->brd_no, pring->ringno,
983 *(((uint32_t *) irsp) + 6),
984 *(((uint32_t *) irsp) + 7));
988 case LPFC_ABORT_IOCB:
991 * Idle exchange closed via ABTS from port. No iocb
992 * resources need to be recovered.
994 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
995 printk(KERN_INFO "%s: IOCB cmd 0x%x processed."
996 " Skipping completion\n", __FUNCTION__,
1001 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
1003 if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
1004 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1009 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1010 char adaptermsg[LPFC_MAX_ADPTMSG];
1011 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
1012 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1014 dev_warn(&((phba->pcidev)->dev), "lpfc%d: %s",
1015 phba->brd_no, adaptermsg);
1017 /* Unknown IOCB command */
1018 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1019 "%d:0321 Unknown IOCB command "
1020 "Data: x%x, x%x x%x x%x x%x\n",
1031 * The response IOCB has been processed. Update the ring
1032 * pointer in SLIM. If the port response put pointer has not
1033 * been updated, sync the pgp->rspPutInx and fetch the new port
1034 * response put pointer.
1036 to_slim = phba->MBslimaddr +
1037 (SLIMOFF + (pring->ringno * 2) + 1) * 4;
1038 writeb(pring->rspidx, to_slim);
1040 if (pring->rspidx == portRspPut)
1041 portRspPut = le32_to_cpu(pgp->rspPutInx);
1044 ha_copy = readl(phba->HAregaddr);
1045 ha_copy >>= (LPFC_FCP_RING * 4);
1047 if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) {
1048 pring->stats.iocb_rsp_full++;
1049 status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4));
1050 writel(status, phba->CAregaddr);
1051 readl(phba->CAregaddr);
1053 if ((ha_copy & HA_R0CE_RSP) &&
1054 (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1055 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1056 pring->stats.iocb_cmd_empty++;
1058 /* Force update of the local copy of cmdGetInx */
1059 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1060 lpfc_sli_resume_iocb(phba, pring);
1062 if ((pring->lpfc_sli_cmd_available))
1063 (pring->lpfc_sli_cmd_available) (phba, pring);
1071 * This routine presumes LPFC_FCP_RING handling and doesn't bother
1072 * to check it explicitly.
1075 lpfc_sli_handle_fast_ring_event(struct lpfc_hba * phba,
1076 struct lpfc_sli_ring * pring, uint32_t mask)
1078 struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno];
1079 IOCB_t *irsp = NULL;
1080 IOCB_t *entry = NULL;
1081 struct lpfc_iocbq *cmdiocbq = NULL;
1082 struct lpfc_iocbq rspiocbq;
1084 uint32_t portRspPut, portRspMax;
1086 lpfc_iocb_type type;
1087 unsigned long iflag;
1088 uint32_t rsp_cmpl = 0;
1089 void __iomem *to_slim;
1091 spin_lock_irqsave(phba->host->host_lock, iflag);
1092 pring->stats.iocb_event++;
1095 * The next available response entry should never exceed the maximum
1096 * entries. If it does, treat it as an adapter hardware error.
1098 portRspMax = pring->numRiocb;
1099 portRspPut = le32_to_cpu(pgp->rspPutInx);
1100 if (unlikely(portRspPut >= portRspMax)) {
1101 lpfc_sli_rsp_pointers_error(phba, pring);
1102 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1107 while (pring->rspidx != portRspPut) {
1109 * Fetch an entry off the ring and copy it into a local data
1110 * structure. The copy involves a byte-swap since the
1111 * network byte order and pci byte orders are different.
1113 entry = IOCB_ENTRY(pring->rspringaddr, pring->rspidx);
1115 if (++pring->rspidx >= portRspMax)
1118 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
1119 (uint32_t *) &rspiocbq.iocb,
1121 irsp = &rspiocbq.iocb;
1123 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
1124 pring->stats.iocb_rsp++;
1127 if (unlikely(irsp->ulpStatus)) {
1128 /* Rsp ring <ringno> error: IOCB */
1129 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1130 "%d:0326 Rsp Ring %d error: IOCB Data: "
1131 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
1132 phba->brd_no, pring->ringno,
1133 irsp->un.ulpWord[0], irsp->un.ulpWord[1],
1134 irsp->un.ulpWord[2], irsp->un.ulpWord[3],
1135 irsp->un.ulpWord[4], irsp->un.ulpWord[5],
1136 *(((uint32_t *) irsp) + 6),
1137 *(((uint32_t *) irsp) + 7));
1141 case LPFC_ABORT_IOCB:
1144 * Idle exchange closed via ABTS from port. No iocb
1145 * resources need to be recovered.
1147 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
1148 printk(KERN_INFO "%s: IOCB cmd 0x%x processed. "
1149 "Skipping completion\n", __FUNCTION__,
1154 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
1156 if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
1157 spin_unlock_irqrestore(
1158 phba->host->host_lock, iflag);
1159 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1161 spin_lock_irqsave(phba->host->host_lock,
1166 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1167 char adaptermsg[LPFC_MAX_ADPTMSG];
1168 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
1169 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1171 dev_warn(&((phba->pcidev)->dev), "lpfc%d: %s",
1172 phba->brd_no, adaptermsg);
1174 /* Unknown IOCB command */
1175 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1176 "%d:0321 Unknown IOCB command "
1177 "Data: x%x, x%x x%x x%x x%x\n",
1178 phba->brd_no, type, irsp->ulpCommand,
1179 irsp->ulpStatus, irsp->ulpIoTag,
1186 * The response IOCB has been processed. Update the ring
1187 * pointer in SLIM. If the port response put pointer has not
1188 * been updated, sync the pgp->rspPutInx and fetch the new port
1189 * response put pointer.
1191 to_slim = phba->MBslimaddr +
1192 (SLIMOFF + (pring->ringno * 2) + 1) * 4;
1193 writel(pring->rspidx, to_slim);
1195 if (pring->rspidx == portRspPut)
1196 portRspPut = le32_to_cpu(pgp->rspPutInx);
1199 if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
1200 pring->stats.iocb_rsp_full++;
1201 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
1202 writel(status, phba->CAregaddr);
1203 readl(phba->CAregaddr);
1205 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1206 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1207 pring->stats.iocb_cmd_empty++;
1209 /* Force update of the local copy of cmdGetInx */
1210 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1211 lpfc_sli_resume_iocb(phba, pring);
1213 if ((pring->lpfc_sli_cmd_available))
1214 (pring->lpfc_sli_cmd_available) (phba, pring);
1218 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1224 lpfc_sli_handle_slow_ring_event(struct lpfc_hba * phba,
1225 struct lpfc_sli_ring * pring, uint32_t mask)
1228 IOCB_t *irsp = NULL;
1229 struct lpfc_iocbq *rspiocbp = NULL;
1230 struct lpfc_iocbq *next_iocb;
1231 struct lpfc_iocbq *cmdiocbp;
1232 struct lpfc_iocbq *saveq;
1233 struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno];
1234 uint8_t iocb_cmd_type;
1235 lpfc_iocb_type type;
1236 uint32_t status, free_saveq;
1237 uint32_t portRspPut, portRspMax;
1239 unsigned long iflag;
1240 void __iomem *to_slim;
1242 spin_lock_irqsave(phba->host->host_lock, iflag);
1243 pring->stats.iocb_event++;
1246 * The next available response entry should never exceed the maximum
1247 * entries. If it does, treat it as an adapter hardware error.
1249 portRspMax = pring->numRiocb;
1250 portRspPut = le32_to_cpu(pgp->rspPutInx);
1251 if (portRspPut >= portRspMax) {
1253 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
1254 * rsp ring <portRspMax>
1256 lpfc_printf_log(phba,
1259 "%d:0312 Ring %d handler: portRspPut %d "
1260 "is bigger then rsp ring %d\n",
1262 pring->ringno, portRspPut, portRspMax);
1264 phba->hba_state = LPFC_HBA_ERROR;
1265 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1267 phba->work_hs = HS_FFER3;
1268 lpfc_handle_eratt(phba);
1274 while (pring->rspidx != portRspPut) {
1276 * Build a completion list and call the appropriate handler.
1277 * The process is to get the next available response iocb, get
1278 * a free iocb from the list, copy the response data into the
1279 * free iocb, insert to the continuation list, and update the
1280 * next response index to slim. This process makes response
1281 * iocb's in the ring available to DMA as fast as possible but
1282 * pays a penalty for a copy operation. Since the iocb is
1283 * only 32 bytes, this penalty is considered small relative to
1284 * the PCI reads for register values and a slim write. When
1285 * the ulpLe field is set, the entire Command has been
1288 entry = IOCB_ENTRY(pring->rspringaddr, pring->rspidx);
1289 rspiocbp = lpfc_sli_get_iocbq(phba);
1290 if (rspiocbp == NULL) {
1291 printk(KERN_ERR "%s: out of buffers! Failing "
1292 "completion.\n", __FUNCTION__);
1296 lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, sizeof (IOCB_t));
1297 irsp = &rspiocbp->iocb;
1299 if (++pring->rspidx >= portRspMax)
1302 to_slim = phba->MBslimaddr + (SLIMOFF + (pring->ringno * 2)
1304 writel(pring->rspidx, to_slim);
1306 if (list_empty(&(pring->iocb_continueq))) {
1307 list_add(&rspiocbp->list, &(pring->iocb_continueq));
1309 list_add_tail(&rspiocbp->list,
1310 &(pring->iocb_continueq));
1313 pring->iocb_continueq_cnt++;
1316 * By default, the driver expects to free all resources
1317 * associated with this iocb completion.
1320 saveq = list_get_first(&pring->iocb_continueq,
1321 struct lpfc_iocbq, list);
1322 irsp = &(saveq->iocb);
1323 list_del_init(&pring->iocb_continueq);
1324 pring->iocb_continueq_cnt = 0;
1326 pring->stats.iocb_rsp++;
1328 if (irsp->ulpStatus) {
1329 /* Rsp ring <ringno> error: IOCB */
1330 lpfc_printf_log(phba,
1333 "%d:0328 Rsp Ring %d error: IOCB Data: "
1334 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
1337 irsp->un.ulpWord[0],
1338 irsp->un.ulpWord[1],
1339 irsp->un.ulpWord[2],
1340 irsp->un.ulpWord[3],
1341 irsp->un.ulpWord[4],
1342 irsp->un.ulpWord[5],
1343 *(((uint32_t *) irsp) + 6),
1344 *(((uint32_t *) irsp) + 7));
1348 * Fetch the IOCB command type and call the correct
1349 * completion routine. Solicited and Unsolicited
1350 * IOCBs on the ELS ring get freed back to the
1351 * lpfc_iocb_list by the discovery kernel thread.
1353 iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
1354 type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
1355 if (type == LPFC_SOL_IOCB) {
1356 spin_unlock_irqrestore(phba->host->host_lock,
1358 rc = lpfc_sli_process_sol_iocb(phba, pring,
1360 spin_lock_irqsave(phba->host->host_lock, iflag);
1361 } else if (type == LPFC_UNSOL_IOCB) {
1362 spin_unlock_irqrestore(phba->host->host_lock,
1364 rc = lpfc_sli_process_unsol_iocb(phba, pring,
1366 spin_lock_irqsave(phba->host->host_lock, iflag);
1367 } else if (type == LPFC_ABORT_IOCB) {
1368 if ((irsp->ulpCommand != CMD_XRI_ABORTED_CX) &&
1370 lpfc_sli_iocbq_lookup(phba, pring,
1372 /* Call the specified completion
1374 if (cmdiocbp->iocb_cmpl) {
1375 spin_unlock_irqrestore(
1376 phba->host->host_lock,
1378 (cmdiocbp->iocb_cmpl) (phba,
1381 phba->host->host_lock,
1384 lpfc_sli_release_iocbq(phba,
1387 } else if (type == LPFC_UNKNOWN_IOCB) {
1388 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1390 char adaptermsg[LPFC_MAX_ADPTMSG];
1392 memset(adaptermsg, 0,
1394 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1396 dev_warn(&((phba->pcidev)->dev),
1398 phba->brd_no, adaptermsg);
1400 /* Unknown IOCB command */
1401 lpfc_printf_log(phba,
1404 "%d:0321 Unknown IOCB command "
1405 "Data: x%x x%x x%x x%x\n",
1415 if (!list_empty(&saveq->list)) {
1416 list_for_each_entry_safe(rspiocbp,
1420 lpfc_sli_release_iocbq(phba,
1425 lpfc_sli_release_iocbq(phba, saveq);
1430 * If the port response put pointer has not been updated, sync
1431 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
1432 * response put pointer.
1434 if (pring->rspidx == portRspPut) {
1435 portRspPut = le32_to_cpu(pgp->rspPutInx);
1437 } /* while (pring->rspidx != portRspPut) */
1439 if ((rspiocbp != 0) && (mask & HA_R0RE_REQ)) {
1440 /* At least one response entry has been freed */
1441 pring->stats.iocb_rsp_full++;
1442 /* SET RxRE_RSP in Chip Att register */
1443 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
1444 writel(status, phba->CAregaddr);
1445 readl(phba->CAregaddr); /* flush */
1447 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1448 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1449 pring->stats.iocb_cmd_empty++;
1451 /* Force update of the local copy of cmdGetInx */
1452 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1453 lpfc_sli_resume_iocb(phba, pring);
1455 if ((pring->lpfc_sli_cmd_available))
1456 (pring->lpfc_sli_cmd_available) (phba, pring);
1460 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1465 lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1467 struct lpfc_iocbq *iocb, *next_iocb;
1468 IOCB_t *icmd = NULL, *cmd = NULL;
1473 /* Error everything on txq and txcmplq
1476 spin_lock_irq(phba->host->host_lock);
1477 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
1478 list_del_init(&iocb->list);
1479 if (iocb->iocb_cmpl) {
1481 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
1482 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
1483 spin_unlock_irq(phba->host->host_lock);
1484 (iocb->iocb_cmpl) (phba, iocb, iocb);
1485 spin_lock_irq(phba->host->host_lock);
1487 lpfc_sli_release_iocbq(phba, iocb);
1490 INIT_LIST_HEAD(&(pring->txq));
1492 /* Next issue ABTS for everything on the txcmplq */
1493 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1497 * Imediate abort of IOCB, deque and call compl
1500 list_del_init(&iocb->list);
1501 pring->txcmplq_cnt--;
1503 if (iocb->iocb_cmpl) {
1504 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
1505 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
1506 spin_unlock_irq(phba->host->host_lock);
1507 (iocb->iocb_cmpl) (phba, iocb, iocb);
1508 spin_lock_irq(phba->host->host_lock);
1510 lpfc_sli_release_iocbq(phba, iocb);
1513 INIT_LIST_HEAD(&pring->txcmplq);
1514 pring->txcmplq_cnt = 0;
1515 spin_unlock_irq(phba->host->host_lock);
1521 lpfc_sli_brdready(struct lpfc_hba * phba, uint32_t mask)
1527 /* Read the HBA Host Status Register */
1528 status = readl(phba->HSregaddr);
1531 * Check status register every 100ms for 5 retries, then every
1532 * 500ms for 5, then every 2.5 sec for 5, then reset board and
1533 * every 2.5 sec for 4.
1534 * Break our of the loop if errors occurred during init.
1536 while (((status & mask) != mask) &&
1537 !(status & HS_FFERM) &&
1548 phba->hba_state = LPFC_STATE_UNKNOWN; /* Do post */
1549 lpfc_sli_brdrestart(phba);
1551 /* Read the HBA Host Status Register */
1552 status = readl(phba->HSregaddr);
1555 /* Check to see if any errors occurred during init */
1556 if ((status & HS_FFERM) || (i >= 20)) {
1557 phba->hba_state = LPFC_HBA_ERROR;
1565 lpfc_sli_brdkill(struct lpfc_hba * phba)
1567 struct lpfc_sli *psli;
1577 lpfc_printf_log(phba,
1580 "%d:0329 Kill HBA Data: x%x x%x\n",
1585 if ((pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
1586 GFP_ATOMIC)) == 0) {
1590 /* Disable the error attention */
1591 spin_lock_irq(phba->host->host_lock);
1592 status = readl(phba->HCregaddr);
1593 status &= ~HC_ERINT_ENA;
1594 writel(status, phba->HCregaddr);
1595 readl(phba->HCregaddr); /* flush */
1596 spin_unlock_irq(phba->host->host_lock);
1598 lpfc_kill_board(phba, pmb);
1599 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1600 retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
1602 if (retval != MBX_SUCCESS) {
1603 if (retval != MBX_BUSY)
1604 mempool_free(pmb, phba->mbox_mem_pool);
1608 mempool_free(pmb, phba->mbox_mem_pool);
1610 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
1611 * attention every 100ms for 3 seconds. If we don't get ERATT after
1612 * 3 seconds we still set HBA_ERROR state because the status of the
1613 * board is now undefined.
1615 ha_copy = readl(phba->HAregaddr);
1617 while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
1619 ha_copy = readl(phba->HAregaddr);
1622 del_timer_sync(&psli->mbox_tmo);
1624 spin_lock_irq(phba->host->host_lock);
1625 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
1626 spin_unlock_irq(phba->host->host_lock);
1628 psli->mbox_active = NULL;
1629 lpfc_hba_down_post(phba);
1630 phba->hba_state = LPFC_HBA_ERROR;
1632 return (ha_copy & HA_ERATT ? 0 : 1);
1636 lpfc_sli_brdreset(struct lpfc_hba * phba)
1638 struct lpfc_sli *psli;
1639 struct lpfc_sli_ring *pring;
1646 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1647 "%d:0325 Reset HBA Data: x%x x%x\n", phba->brd_no,
1648 phba->hba_state, psli->sli_flag);
1650 /* perform board reset */
1651 phba->fc_eventTag = 0;
1653 phba->fc_prevDID = 0;
1657 /* Turn off parity checking and serr during the physical reset */
1658 pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
1659 pci_write_config_word(phba->pcidev, PCI_COMMAND,
1661 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
1663 /* Now toggle INITFF bit in the Host Control Register */
1664 writel(HC_INITFF, phba->HCregaddr);
1666 readl(phba->HCregaddr); /* flush */
1667 writel(0, phba->HCregaddr);
1668 readl(phba->HCregaddr); /* flush */
1670 /* Restore PCI cmd register */
1671 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
1673 /* Initialize relevant SLI info */
1674 for (i = 0; i < psli->num_rings; i++) {
1675 pring = &psli->ring[i];
1678 pring->next_cmdidx = 0;
1679 pring->local_getidx = 0;
1681 pring->missbufcnt = 0;
1684 phba->hba_state = LPFC_WARM_START;
1689 lpfc_sli_brdrestart(struct lpfc_hba * phba)
1692 struct lpfc_sli *psli;
1694 volatile uint32_t word0;
1695 void __iomem *to_slim;
1697 spin_lock_irq(phba->host->host_lock);
1702 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1703 "%d:0328 Restart HBA Data: x%x x%x\n", phba->brd_no,
1704 phba->hba_state, psli->sli_flag);
1707 mb = (MAILBOX_t *) &word0;
1708 mb->mbxCommand = MBX_RESTART;
1711 to_slim = phba->MBslimaddr;
1712 writel(*(uint32_t *) mb, to_slim);
1713 readl(to_slim); /* flush */
1715 /* Only skip post after fc_ffinit is completed */
1716 if (phba->hba_state) {
1718 word0 = 1; /* This is really setting up word1 */
1721 word0 = 0; /* This is really setting up word1 */
1723 to_slim = (uint8_t *) phba->MBslimaddr + sizeof (uint32_t);
1724 writel(*(uint32_t *) mb, to_slim);
1725 readl(to_slim); /* flush */
1727 lpfc_sli_brdreset(phba);
1729 phba->hba_state = LPFC_INIT_START;
1731 spin_unlock_irq(phba->host->host_lock);
1738 lpfc_hba_down_post(phba);
1744 lpfc_sli_chipset_init(struct lpfc_hba *phba)
1746 uint32_t status, i = 0;
1748 /* Read the HBA Host Status Register */
1749 status = readl(phba->HSregaddr);
1751 /* Check status register to see what current state is */
1753 while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
1755 /* Check every 100ms for 5 retries, then every 500ms for 5, then
1756 * every 2.5 sec for 5, then reset board and every 2.5 sec for
1760 /* Adapter failed to init, timeout, status reg
1762 lpfc_printf_log(phba,
1765 "%d:0436 Adapter failed to init, "
1766 "timeout, status reg x%x\n",
1769 phba->hba_state = LPFC_HBA_ERROR;
1773 /* Check to see if any errors occurred during init */
1774 if (status & HS_FFERM) {
1775 /* ERROR: During chipset initialization */
1776 /* Adapter failed to init, chipset, status reg
1778 lpfc_printf_log(phba,
1781 "%d:0437 Adapter failed to init, "
1782 "chipset, status reg x%x\n",
1785 phba->hba_state = LPFC_HBA_ERROR;
1791 } else if (i <= 10) {
1798 phba->hba_state = LPFC_STATE_UNKNOWN; /* Do post */
1799 lpfc_sli_brdrestart(phba);
1801 /* Read the HBA Host Status Register */
1802 status = readl(phba->HSregaddr);
1805 /* Check to see if any errors occurred during init */
1806 if (status & HS_FFERM) {
1807 /* ERROR: During chipset initialization */
1808 /* Adapter failed to init, chipset, status reg <status> */
1809 lpfc_printf_log(phba,
1812 "%d:0438 Adapter failed to init, chipset, "
1816 phba->hba_state = LPFC_HBA_ERROR;
1820 /* Clear all interrupt enable conditions */
1821 writel(0, phba->HCregaddr);
1822 readl(phba->HCregaddr); /* flush */
1824 /* setup host attn register */
1825 writel(0xffffffff, phba->HAregaddr);
1826 readl(phba->HAregaddr); /* flush */
1831 lpfc_sli_hba_setup(struct lpfc_hba * phba)
1834 uint32_t resetcount = 0, rc = 0, done = 0;
1836 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1838 phba->hba_state = LPFC_HBA_ERROR;
1842 while (resetcount < 2 && !done) {
1843 phba->hba_state = LPFC_STATE_UNKNOWN;
1844 lpfc_sli_brdrestart(phba);
1846 rc = lpfc_sli_chipset_init(phba);
1852 /* Call pre CONFIG_PORT mailbox command initialization. A value of 0
1853 * means the call was successful. Any other nonzero value is a failure,
1854 * but if ERESTART is returned, the driver may reset the HBA and try
1857 rc = lpfc_config_port_prep(phba);
1858 if (rc == -ERESTART) {
1859 phba->hba_state = 0;
1865 phba->hba_state = LPFC_INIT_MBX_CMDS;
1866 lpfc_config_port(phba, pmb);
1867 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
1868 if (rc == MBX_SUCCESS)
1871 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1872 "%d:0442 Adapter failed to init, mbxCmd x%x "
1873 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
1874 phba->brd_no, pmb->mb.mbxCommand,
1875 pmb->mb.mbxStatus, 0);
1876 phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE;
1880 goto lpfc_sli_hba_setup_error;
1882 rc = lpfc_sli_ring_map(phba, pmb);
1885 goto lpfc_sli_hba_setup_error;
1887 phba->sli.sli_flag |= LPFC_PROCESS_LA;
1889 rc = lpfc_config_port_post(phba);
1891 goto lpfc_sli_hba_setup_error;
1893 goto lpfc_sli_hba_setup_exit;
1894 lpfc_sli_hba_setup_error:
1895 phba->hba_state = LPFC_HBA_ERROR;
1896 lpfc_sli_hba_setup_exit:
1897 mempool_free(pmb, phba->mbox_mem_pool);
1902 lpfc_mbox_abort(struct lpfc_hba * phba)
1904 LPFC_MBOXQ_t *pmbox;
1907 if (phba->sli.mbox_active) {
1908 del_timer_sync(&phba->sli.mbox_tmo);
1909 phba->work_hba_events &= ~WORKER_MBOX_TMO;
1910 pmbox = phba->sli.mbox_active;
1912 phba->sli.mbox_active = NULL;
1913 if (pmbox->mbox_cmpl) {
1914 mb->mbxStatus = MBX_NOT_FINISHED;
1915 (pmbox->mbox_cmpl) (phba, pmbox);
1917 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
1920 /* Abort all the non active mailbox commands. */
1921 spin_lock_irq(phba->host->host_lock);
1922 pmbox = lpfc_mbox_get(phba);
1925 if (pmbox->mbox_cmpl) {
1926 mb->mbxStatus = MBX_NOT_FINISHED;
1927 spin_unlock_irq(phba->host->host_lock);
1928 (pmbox->mbox_cmpl) (phba, pmbox);
1929 spin_lock_irq(phba->host->host_lock);
1931 pmbox = lpfc_mbox_get(phba);
1933 spin_unlock_irq(phba->host->host_lock);
1937 /*! lpfc_mbox_timeout
1941 * \param hba Pointer to per struct lpfc_hba structure
1942 * \param l1 Pointer to the driver's mailbox queue.
1948 * This routine handles mailbox timeout events at timer interrupt context.
1951 lpfc_mbox_timeout(unsigned long ptr)
1953 struct lpfc_hba *phba;
1954 unsigned long iflag;
1956 phba = (struct lpfc_hba *)ptr;
1957 spin_lock_irqsave(phba->host->host_lock, iflag);
1958 if (!(phba->work_hba_events & WORKER_MBOX_TMO)) {
1959 phba->work_hba_events |= WORKER_MBOX_TMO;
1960 if (phba->work_wait)
1961 wake_up(phba->work_wait);
1963 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1967 lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
1969 LPFC_MBOXQ_t *pmbox;
1972 spin_lock_irq(phba->host->host_lock);
1973 if (!(phba->work_hba_events & WORKER_MBOX_TMO)) {
1974 spin_unlock_irq(phba->host->host_lock);
1978 phba->work_hba_events &= ~WORKER_MBOX_TMO;
1980 pmbox = phba->sli.mbox_active;
1983 /* Mbox cmd <mbxCommand> timeout */
1984 lpfc_printf_log(phba,
1987 "%d:0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
1992 phba->sli.mbox_active);
1994 phba->sli.mbox_active = NULL;
1995 if (pmbox->mbox_cmpl) {
1996 mb->mbxStatus = MBX_NOT_FINISHED;
1997 spin_unlock_irq(phba->host->host_lock);
1998 (pmbox->mbox_cmpl) (phba, pmbox);
1999 spin_lock_irq(phba->host->host_lock);
2001 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2003 spin_unlock_irq(phba->host->host_lock);
2004 lpfc_mbox_abort(phba);
2009 lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag)
2012 struct lpfc_sli *psli;
2013 uint32_t status, evtctr;
2016 unsigned long drvr_flag = 0;
2017 volatile uint32_t word0, ldata;
2018 void __iomem *to_slim;
2022 spin_lock_irqsave(phba->host->host_lock, drvr_flag);
2026 status = MBX_SUCCESS;
2028 if (phba->hba_state == LPFC_HBA_ERROR) {
2029 spin_unlock_irqrestore(phba->host->host_lock, drvr_flag);
2031 /* Mbox command <mbxCommand> cannot issue */
2032 LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag)
2033 return (MBX_NOT_FINISHED);
2036 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
2037 /* Polling for a mbox command when another one is already active
2038 * is not allowed in SLI. Also, the driver must have established
2039 * SLI2 mode to queue and process multiple mbox commands.
2042 if (flag & MBX_POLL) {
2043 spin_unlock_irqrestore(phba->host->host_lock,
2046 /* Mbox command <mbxCommand> cannot issue */
2047 LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag)
2048 return (MBX_NOT_FINISHED);
2051 if (!(psli->sli_flag & LPFC_SLI2_ACTIVE)) {
2052 spin_unlock_irqrestore(phba->host->host_lock,
2054 /* Mbox command <mbxCommand> cannot issue */
2055 LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag)
2056 return (MBX_NOT_FINISHED);
2059 /* Handle STOP IOCB processing flag. This is only meaningful
2060 * if we are not polling for mbox completion.
2062 if (flag & MBX_STOP_IOCB) {
2063 flag &= ~MBX_STOP_IOCB;
2064 /* Now flag each ring */
2065 for (i = 0; i < psli->num_rings; i++) {
2066 /* If the ring is active, flag it */
2067 if (psli->ring[i].cmdringaddr) {
2068 psli->ring[i].flag |=
2074 /* Another mailbox command is still being processed, queue this
2075 * command to be processed later.
2077 lpfc_mbox_put(phba, pmbox);
2079 /* Mbox cmd issue - BUSY */
2080 lpfc_printf_log(phba,
2083 "%d:0308 Mbox cmd issue - BUSY Data: x%x x%x x%x x%x\n",
2090 psli->slistat.mbox_busy++;
2091 spin_unlock_irqrestore(phba->host->host_lock,
2097 /* Handle STOP IOCB processing flag. This is only meaningful
2098 * if we are not polling for mbox completion.
2100 if (flag & MBX_STOP_IOCB) {
2101 flag &= ~MBX_STOP_IOCB;
2102 if (flag == MBX_NOWAIT) {
2103 /* Now flag each ring */
2104 for (i = 0; i < psli->num_rings; i++) {
2105 /* If the ring is active, flag it */
2106 if (psli->ring[i].cmdringaddr) {
2107 psli->ring[i].flag |=
2114 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
2116 /* If we are not polling, we MUST be in SLI2 mode */
2117 if (flag != MBX_POLL) {
2118 if (!(psli->sli_flag & LPFC_SLI2_ACTIVE) &&
2119 (mb->mbxCommand != MBX_KILL_BOARD)) {
2120 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2121 spin_unlock_irqrestore(phba->host->host_lock,
2123 /* Mbox command <mbxCommand> cannot issue */
2124 LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag);
2125 return (MBX_NOT_FINISHED);
2127 /* timeout active mbox command */
2128 mod_timer(&psli->mbox_tmo, jiffies + HZ * LPFC_MBOX_TMO);
2131 /* Mailbox cmd <cmd> issue */
2132 lpfc_printf_log(phba,
2135 "%d:0309 Mailbox cmd x%x issue Data: x%x x%x x%x\n",
2142 psli->slistat.mbox_cmd++;
2143 evtctr = psli->slistat.mbox_event;
2145 /* next set own bit for the adapter and copy over command word */
2146 mb->mbxOwner = OWN_CHIP;
2148 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2149 /* First copy command data to host SLIM area */
2150 lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx, MAILBOX_CMD_SIZE);
2152 if (mb->mbxCommand == MBX_CONFIG_PORT ||
2153 mb->mbxCommand == MBX_KILL_BOARD) {
2154 /* copy command data into host mbox for cmpl */
2155 lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx,
2159 /* First copy mbox command data to HBA SLIM, skip past first
2161 to_slim = phba->MBslimaddr + sizeof (uint32_t);
2162 lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
2163 MAILBOX_CMD_SIZE - sizeof (uint32_t));
2165 /* Next copy over first word, with mbxOwner set */
2166 ldata = *((volatile uint32_t *)mb);
2167 to_slim = phba->MBslimaddr;
2168 writel(ldata, to_slim);
2169 readl(to_slim); /* flush */
2171 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2172 /* switch over to host mailbox */
2173 psli->sli_flag |= LPFC_SLI2_ACTIVE;
2178 /* interrupt board to doit right away */
2179 writel(CA_MBATT, phba->CAregaddr);
2180 readl(phba->CAregaddr); /* flush */
2184 /* Don't wait for it to finish, just return */
2185 psli->mbox_active = pmbox;
2190 psli->mbox_active = NULL;
2191 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2192 /* First read mbox status word */
2193 word0 = *((volatile uint32_t *)&phba->slim2p->mbx);
2194 word0 = le32_to_cpu(word0);
2196 /* First read mbox status word */
2197 word0 = readl(phba->MBslimaddr);
2200 /* Read the HBA Host Attention Register */
2201 ha_copy = readl(phba->HAregaddr);
2203 /* Wait for command to complete */
2204 while (((word0 & OWN_CHIP) == OWN_CHIP) ||
2205 (!(ha_copy & HA_MBATT) &&
2206 (phba->hba_state > LPFC_WARM_START))) {
2208 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2209 spin_unlock_irqrestore(phba->host->host_lock,
2211 return (MBX_NOT_FINISHED);
2214 /* Check if we took a mbox interrupt while we were
2216 if (((word0 & OWN_CHIP) != OWN_CHIP)
2217 && (evtctr != psli->slistat.mbox_event))
2220 spin_unlock_irqrestore(phba->host->host_lock,
2223 /* Can be in interrupt context, do not sleep */
2224 /* (or might be called with interrupts disabled) */
2227 spin_lock_irqsave(phba->host->host_lock, drvr_flag);
2229 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2230 /* First copy command data */
2231 word0 = *((volatile uint32_t *)
2232 &phba->slim2p->mbx);
2233 word0 = le32_to_cpu(word0);
2234 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2236 volatile uint32_t slimword0;
2237 /* Check real SLIM for any errors */
2238 slimword0 = readl(phba->MBslimaddr);
2239 slimmb = (MAILBOX_t *) & slimword0;
2240 if (((slimword0 & OWN_CHIP) != OWN_CHIP)
2241 && slimmb->mbxStatus) {
2248 /* First copy command data */
2249 word0 = readl(phba->MBslimaddr);
2251 /* Read the HBA Host Attention Register */
2252 ha_copy = readl(phba->HAregaddr);
2255 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2256 /* copy results back to user */
2257 lpfc_sli_pcimem_bcopy(&phba->slim2p->mbx, mb,
2260 /* First copy command data */
2261 lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
2263 if ((mb->mbxCommand == MBX_DUMP_MEMORY) &&
2265 lpfc_memcpy_from_slim((void *)pmbox->context2,
2266 phba->MBslimaddr + DMP_RSP_OFFSET,
2267 mb->un.varDmp.word_cnt);
2271 writel(HA_MBATT, phba->HAregaddr);
2272 readl(phba->HAregaddr); /* flush */
2274 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2275 status = mb->mbxStatus;
2278 spin_unlock_irqrestore(phba->host->host_lock, drvr_flag);
2283 lpfc_sli_ringtx_put(struct lpfc_hba * phba, struct lpfc_sli_ring * pring,
2284 struct lpfc_iocbq * piocb)
2286 /* Insert the caller's iocb in the txq tail for later processing. */
2287 list_add_tail(&piocb->list, &pring->txq);
2292 static struct lpfc_iocbq *
2293 lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2294 struct lpfc_iocbq ** piocb)
2296 struct lpfc_iocbq * nextiocb;
2298 nextiocb = lpfc_sli_ringtx_get(phba, pring);
2308 lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2309 struct lpfc_iocbq *piocb, uint32_t flag)
2311 struct lpfc_iocbq *nextiocb;
2315 * We should never get an IOCB if we are in a < LINK_DOWN state
2317 if (unlikely(phba->hba_state < LPFC_LINK_DOWN))
2321 * Check to see if we are blocking IOCB processing because of a
2322 * outstanding mbox command.
2324 if (unlikely(pring->flag & LPFC_STOP_IOCB_MBX))
2327 if (unlikely(phba->hba_state == LPFC_LINK_DOWN)) {
2329 * Only CREATE_XRI, CLOSE_XRI, ABORT_XRI, and QUE_RING_BUF
2330 * can be issued if the link is not up.
2332 switch (piocb->iocb.ulpCommand) {
2333 case CMD_QUE_RING_BUF_CN:
2334 case CMD_QUE_RING_BUF64_CN:
2336 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
2337 * completion, iocb_cmpl MUST be 0.
2339 if (piocb->iocb_cmpl)
2340 piocb->iocb_cmpl = NULL;
2342 case CMD_CREATE_XRI_CR:
2349 * For FCP commands, we must be in a state where we can process link
2352 } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
2353 !(phba->sli.sli_flag & LPFC_PROCESS_LA)))
2356 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
2357 (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
2358 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
2361 lpfc_sli_update_ring(phba, pring);
2363 lpfc_sli_update_full_ring(phba, pring);
2366 return IOCB_SUCCESS;
2371 pring->stats.iocb_cmd_delay++;
2375 if (!(flag & SLI_IOCB_RET_IOCB)) {
2376 lpfc_sli_ringtx_put(phba, pring, piocb);
2377 return IOCB_SUCCESS;
2384 lpfc_extra_ring_setup( struct lpfc_hba *phba)
2386 struct lpfc_sli *psli;
2387 struct lpfc_sli_ring *pring;
2391 /* Adjust cmd/rsp ring iocb entries more evenly */
2392 pring = &psli->ring[psli->fcp_ring];
2393 pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
2394 pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
2395 pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
2396 pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
2398 pring = &psli->ring[1];
2399 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
2400 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
2401 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
2402 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
2404 /* Setup default profile for this ring */
2405 pring->iotag_max = 4096;
2406 pring->num_mask = 1;
2407 pring->prt[0].profile = 0; /* Mask 0 */
2408 pring->prt[0].rctl = FC_UNSOL_DATA;
2409 pring->prt[0].type = 5;
2410 pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
2415 lpfc_sli_setup(struct lpfc_hba *phba)
2418 struct lpfc_sli *psli = &phba->sli;
2419 struct lpfc_sli_ring *pring;
2421 psli->num_rings = MAX_CONFIGURED_RINGS;
2423 psli->fcp_ring = LPFC_FCP_RING;
2424 psli->next_ring = LPFC_FCP_NEXT_RING;
2425 psli->ip_ring = LPFC_IP_RING;
2427 psli->iocbq_lookup = NULL;
2428 psli->iocbq_lookup_len = 0;
2429 psli->last_iotag = 0;
2431 for (i = 0; i < psli->num_rings; i++) {
2432 pring = &psli->ring[i];
2434 case LPFC_FCP_RING: /* ring 0 - FCP */
2435 /* numCiocb and numRiocb are used in config_port */
2436 pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
2437 pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
2438 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
2439 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
2440 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
2441 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
2442 pring->iotag_ctr = 0;
2444 (phba->cfg_hba_queue_depth * 2);
2445 pring->fast_iotag = pring->iotag_max;
2446 pring->num_mask = 0;
2448 case LPFC_IP_RING: /* ring 1 - IP */
2449 /* numCiocb and numRiocb are used in config_port */
2450 pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
2451 pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
2452 pring->num_mask = 0;
2454 case LPFC_ELS_RING: /* ring 2 - ELS / CT */
2455 /* numCiocb and numRiocb are used in config_port */
2456 pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
2457 pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
2458 pring->fast_iotag = 0;
2459 pring->iotag_ctr = 0;
2460 pring->iotag_max = 4096;
2461 pring->num_mask = 4;
2462 pring->prt[0].profile = 0; /* Mask 0 */
2463 pring->prt[0].rctl = FC_ELS_REQ;
2464 pring->prt[0].type = FC_ELS_DATA;
2465 pring->prt[0].lpfc_sli_rcv_unsol_event =
2466 lpfc_els_unsol_event;
2467 pring->prt[1].profile = 0; /* Mask 1 */
2468 pring->prt[1].rctl = FC_ELS_RSP;
2469 pring->prt[1].type = FC_ELS_DATA;
2470 pring->prt[1].lpfc_sli_rcv_unsol_event =
2471 lpfc_els_unsol_event;
2472 pring->prt[2].profile = 0; /* Mask 2 */
2473 /* NameServer Inquiry */
2474 pring->prt[2].rctl = FC_UNSOL_CTL;
2476 pring->prt[2].type = FC_COMMON_TRANSPORT_ULP;
2477 pring->prt[2].lpfc_sli_rcv_unsol_event =
2478 lpfc_ct_unsol_event;
2479 pring->prt[3].profile = 0; /* Mask 3 */
2480 /* NameServer response */
2481 pring->prt[3].rctl = FC_SOL_CTL;
2483 pring->prt[3].type = FC_COMMON_TRANSPORT_ULP;
2484 pring->prt[3].lpfc_sli_rcv_unsol_event =
2485 lpfc_ct_unsol_event;
2488 totiocb += (pring->numCiocb + pring->numRiocb);
2490 if (totiocb > MAX_SLI2_IOCB) {
2491 /* Too many cmd / rsp ring entries in SLI2 SLIM */
2492 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2493 "%d:0462 Too many cmd / rsp ring entries in "
2494 "SLI2 SLIM Data: x%x x%x\n",
2495 phba->brd_no, totiocb, MAX_SLI2_IOCB);
2497 if (phba->cfg_multi_ring_support == 2)
2498 lpfc_extra_ring_setup(phba);
2504 lpfc_sli_queue_setup(struct lpfc_hba * phba)
2506 struct lpfc_sli *psli;
2507 struct lpfc_sli_ring *pring;
2511 spin_lock_irq(phba->host->host_lock);
2512 INIT_LIST_HEAD(&psli->mboxq);
2513 /* Initialize list headers for txq and txcmplq as double linked lists */
2514 for (i = 0; i < psli->num_rings; i++) {
2515 pring = &psli->ring[i];
2517 pring->next_cmdidx = 0;
2518 pring->local_getidx = 0;
2520 INIT_LIST_HEAD(&pring->txq);
2521 INIT_LIST_HEAD(&pring->txcmplq);
2522 INIT_LIST_HEAD(&pring->iocb_continueq);
2523 INIT_LIST_HEAD(&pring->postbufq);
2525 spin_unlock_irq(phba->host->host_lock);
2530 lpfc_sli_hba_down(struct lpfc_hba * phba)
2532 struct lpfc_sli *psli;
2533 struct lpfc_sli_ring *pring;
2535 struct lpfc_iocbq *iocb, *next_iocb;
2536 IOCB_t *icmd = NULL;
2538 unsigned long flags = 0;
2541 lpfc_hba_down_prep(phba);
2543 spin_lock_irqsave(phba->host->host_lock, flags);
2545 for (i = 0; i < psli->num_rings; i++) {
2546 pring = &psli->ring[i];
2547 pring->flag |= LPFC_DEFERRED_RING_EVENT;
2550 * Error everything on the txq since these iocbs have not been
2551 * given to the FW yet.
2555 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
2556 list_del_init(&iocb->list);
2557 if (iocb->iocb_cmpl) {
2559 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2560 icmd->un.ulpWord[4] = IOERR_SLI_DOWN;
2561 spin_unlock_irqrestore(phba->host->host_lock,
2563 (iocb->iocb_cmpl) (phba, iocb, iocb);
2564 spin_lock_irqsave(phba->host->host_lock, flags);
2566 lpfc_sli_release_iocbq(phba, iocb);
2569 INIT_LIST_HEAD(&(pring->txq));
2571 kfree(pring->fast_lookup);
2572 pring->fast_lookup = NULL;
2575 spin_unlock_irqrestore(phba->host->host_lock, flags);
2577 /* Return any active mbox cmds */
2578 del_timer_sync(&psli->mbox_tmo);
2579 spin_lock_irqsave(phba->host->host_lock, flags);
2580 phba->work_hba_events &= ~WORKER_MBOX_TMO;
2581 if (psli->mbox_active) {
2582 pmb = psli->mbox_active;
2583 pmb->mb.mbxStatus = MBX_NOT_FINISHED;
2584 if (pmb->mbox_cmpl) {
2585 spin_unlock_irqrestore(phba->host->host_lock, flags);
2586 pmb->mbox_cmpl(phba,pmb);
2587 spin_lock_irqsave(phba->host->host_lock, flags);
2590 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2591 psli->mbox_active = NULL;
2593 /* Return any pending mbox cmds */
2594 while ((pmb = lpfc_mbox_get(phba)) != NULL) {
2595 pmb->mb.mbxStatus = MBX_NOT_FINISHED;
2596 if (pmb->mbox_cmpl) {
2597 spin_unlock_irqrestore(phba->host->host_lock, flags);
2598 pmb->mbox_cmpl(phba,pmb);
2599 spin_lock_irqsave(phba->host->host_lock, flags);
2603 INIT_LIST_HEAD(&psli->mboxq);
2605 spin_unlock_irqrestore(phba->host->host_lock, flags);
2611 lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
2613 uint32_t *src = srcp;
2614 uint32_t *dest = destp;
2618 for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
2620 ldata = le32_to_cpu(ldata);
2628 lpfc_sli_ringpostbuf_put(struct lpfc_hba * phba, struct lpfc_sli_ring * pring,
2629 struct lpfc_dmabuf * mp)
2631 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
2633 list_add_tail(&mp->list, &pring->postbufq);
2635 pring->postbufq_cnt++;
2640 struct lpfc_dmabuf *
2641 lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2644 struct lpfc_dmabuf *mp, *next_mp;
2645 struct list_head *slp = &pring->postbufq;
2647 /* Search postbufq, from the begining, looking for a match on phys */
2648 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
2649 if (mp->phys == phys) {
2650 list_del_init(&mp->list);
2651 pring->postbufq_cnt--;
2656 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2657 "%d:0410 Cannot find virtual addr for mapped buf on "
2658 "ring %d Data x%llx x%p x%p x%x\n",
2659 phba->brd_no, pring->ringno, (unsigned long long)phys,
2660 slp->next, slp->prev, pring->postbufq_cnt);
2665 lpfc_sli_abort_elsreq_cmpl(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2666 struct lpfc_iocbq * rspiocb)
2668 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
2669 /* Free the resources associated with the ELS_REQUEST64 IOCB the driver
2671 * In this case, context2 = cmd, context2->next = rsp, context3 = bpl
2673 if (cmdiocb->context2) {
2674 buf_ptr1 = (struct lpfc_dmabuf *) cmdiocb->context2;
2676 /* Free the response IOCB before completing the abort
2679 list_remove_head((&buf_ptr1->list), buf_ptr,
2680 struct lpfc_dmabuf, list);
2682 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2685 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
2689 if (cmdiocb->context3) {
2690 buf_ptr = (struct lpfc_dmabuf *) cmdiocb->context3;
2691 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2695 lpfc_sli_release_iocbq(phba, cmdiocb);
2700 lpfc_sli_issue_abort_iotag32(struct lpfc_hba * phba,
2701 struct lpfc_sli_ring * pring,
2702 struct lpfc_iocbq * cmdiocb)
2704 struct lpfc_iocbq *abtsiocbp;
2705 IOCB_t *icmd = NULL;
2706 IOCB_t *iabt = NULL;
2708 /* issue ABTS for this IOCB based on iotag */
2709 abtsiocbp = lpfc_sli_get_iocbq(phba);
2710 if (abtsiocbp == NULL)
2713 iabt = &abtsiocbp->iocb;
2714 icmd = &cmdiocb->iocb;
2715 switch (icmd->ulpCommand) {
2716 case CMD_ELS_REQUEST64_CR:
2717 /* Even though we abort the ELS command, the firmware may access
2718 * the BPL or other resources before it processes our
2719 * ABORT_MXRI64. Thus we must delay reusing the cmdiocb
2720 * resources till the actual abort request completes.
2722 abtsiocbp->context1 = (void *)((unsigned long)icmd->ulpCommand);
2723 abtsiocbp->context2 = cmdiocb->context2;
2724 abtsiocbp->context3 = cmdiocb->context3;
2725 cmdiocb->context2 = NULL;
2726 cmdiocb->context3 = NULL;
2727 abtsiocbp->iocb_cmpl = lpfc_sli_abort_elsreq_cmpl;
2730 lpfc_sli_release_iocbq(phba, abtsiocbp);
2734 iabt->un.amxri.abortType = ABORT_TYPE_ABTS;
2735 iabt->un.amxri.iotag32 = icmd->un.elsreq64.bdl.ulpIoTag32;
2738 iabt->ulpClass = CLASS3;
2739 iabt->ulpCommand = CMD_ABORT_MXRI64_CN;
2741 if (lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0) == IOCB_ERROR) {
2742 lpfc_sli_release_iocbq(phba, abtsiocbp);
2750 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, uint16_t tgt_id,
2751 uint64_t lun_id, uint32_t ctx,
2752 lpfc_ctx_cmd ctx_cmd)
2754 struct lpfc_scsi_buf *lpfc_cmd;
2755 struct scsi_cmnd *cmnd;
2758 if (!(iocbq->iocb_flag & LPFC_IO_FCP))
2761 lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
2762 cmnd = lpfc_cmd->pCmd;
2769 if ((cmnd->device->id == tgt_id) &&
2770 (cmnd->device->lun == lun_id))
2774 if (cmnd->device->id == tgt_id)
2778 if (iocbq->iocb.ulpContext == ctx)
2785 printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
2786 __FUNCTION__, ctx_cmd);
2794 lpfc_sli_sum_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2795 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd ctx_cmd)
2797 struct lpfc_iocbq *iocbq;
2800 for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
2801 iocbq = phba->sli.iocbq_lookup[i];
2803 if (lpfc_sli_validate_fcp_iocb (iocbq, tgt_id, lun_id,
2812 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2813 struct lpfc_iocbq * rspiocb)
2815 spin_lock_irq(phba->host->host_lock);
2816 lpfc_sli_release_iocbq(phba, cmdiocb);
2817 spin_unlock_irq(phba->host->host_lock);
2822 lpfc_sli_abort_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2823 uint16_t tgt_id, uint64_t lun_id, uint32_t ctx,
2824 lpfc_ctx_cmd abort_cmd)
2826 struct lpfc_iocbq *iocbq;
2827 struct lpfc_iocbq *abtsiocb;
2829 int errcnt = 0, ret_val = 0;
2832 for (i = 1; i <= phba->sli.last_iotag; i++) {
2833 iocbq = phba->sli.iocbq_lookup[i];
2835 if (lpfc_sli_validate_fcp_iocb (iocbq, tgt_id, lun_id,
2839 /* issue ABTS for this IOCB based on iotag */
2840 abtsiocb = lpfc_sli_get_iocbq(phba);
2841 if (abtsiocb == NULL) {
2847 abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
2848 abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
2849 abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
2850 abtsiocb->iocb.ulpLe = 1;
2851 abtsiocb->iocb.ulpClass = cmd->ulpClass;
2853 if (phba->hba_state >= LPFC_LINK_UP)
2854 abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
2856 abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
2858 /* Setup callback routine and issue the command. */
2859 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
2860 ret_val = lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0);
2861 if (ret_val == IOCB_ERROR) {
2862 lpfc_sli_release_iocbq(phba, abtsiocb);
2872 lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
2873 struct lpfc_iocbq *cmdiocbq,
2874 struct lpfc_iocbq *rspiocbq)
2876 wait_queue_head_t *pdone_q;
2877 unsigned long iflags;
2879 spin_lock_irqsave(phba->host->host_lock, iflags);
2880 cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
2881 if (cmdiocbq->context2 && rspiocbq)
2882 memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
2883 &rspiocbq->iocb, sizeof(IOCB_t));
2885 pdone_q = cmdiocbq->context_un.wait_queue;
2886 spin_unlock_irqrestore(phba->host->host_lock, iflags);
2893 * Issue the caller's iocb and wait for its completion, but no longer than the
2894 * caller's timeout. Note that iocb_flags is cleared before the
2895 * lpfc_sli_issue_call since the wake routine sets a unique value and by
2896 * definition this is a wait function.
2899 lpfc_sli_issue_iocb_wait(struct lpfc_hba * phba,
2900 struct lpfc_sli_ring * pring,
2901 struct lpfc_iocbq * piocb,
2902 struct lpfc_iocbq * prspiocbq,
2905 DECLARE_WAIT_QUEUE_HEAD(done_q);
2906 long timeleft, timeout_req = 0;
2907 int retval = IOCB_SUCCESS;
2911 * If the caller has provided a response iocbq buffer, then context2
2912 * is NULL or its an error.
2915 if (piocb->context2)
2917 piocb->context2 = prspiocbq;
2920 piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
2921 piocb->context_un.wait_queue = &done_q;
2922 piocb->iocb_flag &= ~LPFC_IO_WAKE;
2924 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
2925 creg_val = readl(phba->HCregaddr);
2926 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
2927 writel(creg_val, phba->HCregaddr);
2928 readl(phba->HCregaddr); /* flush */
2931 retval = lpfc_sli_issue_iocb(phba, pring, piocb, 0);
2932 if (retval == IOCB_SUCCESS) {
2933 timeout_req = timeout * HZ;
2934 spin_unlock_irq(phba->host->host_lock);
2935 timeleft = wait_event_timeout(done_q,
2936 piocb->iocb_flag & LPFC_IO_WAKE,
2938 spin_lock_irq(phba->host->host_lock);
2940 if (timeleft == 0) {
2941 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2942 "%d:0329 IOCB wait timeout error - no "
2943 "wake response Data x%x\n",
2944 phba->brd_no, timeout);
2945 retval = IOCB_TIMEDOUT;
2946 } else if (!(piocb->iocb_flag & LPFC_IO_WAKE)) {
2947 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2948 "%d:0330 IOCB wake NOT set, "
2949 "Data x%x x%lx\n", phba->brd_no,
2950 timeout, (timeleft / jiffies));
2951 retval = IOCB_TIMEDOUT;
2953 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2954 "%d:0331 IOCB wake signaled\n",
2958 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2959 "%d:0332 IOCB wait issue failed, Data x%x\n",
2960 phba->brd_no, retval);
2961 retval = IOCB_ERROR;
2964 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
2965 creg_val = readl(phba->HCregaddr);
2966 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
2967 writel(creg_val, phba->HCregaddr);
2968 readl(phba->HCregaddr); /* flush */
2972 piocb->context2 = NULL;
2974 piocb->context_un.wait_queue = NULL;
2975 piocb->iocb_cmpl = NULL;
2980 lpfc_sli_issue_mbox_wait(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq,
2983 DECLARE_WAIT_QUEUE_HEAD(done_q);
2984 DECLARE_WAITQUEUE(wq_entry, current);
2985 uint32_t timeleft = 0;
2988 /* The caller must leave context1 empty. */
2989 if (pmboxq->context1 != 0) {
2990 return (MBX_NOT_FINISHED);
2993 /* setup wake call as IOCB callback */
2994 pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
2995 /* setup context field to pass wait_queue pointer to wake function */
2996 pmboxq->context1 = &done_q;
2998 /* start to sleep before we wait, to avoid races */
2999 set_current_state(TASK_INTERRUPTIBLE);
3000 add_wait_queue(&done_q, &wq_entry);
3002 /* now issue the command */
3003 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
3005 if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
3006 timeleft = schedule_timeout(timeout * HZ);
3007 pmboxq->context1 = NULL;
3008 /* if schedule_timeout returns 0, we timed out and were not
3010 if ((timeleft == 0) || signal_pending(current))
3011 retval = MBX_TIMEOUT;
3013 retval = MBX_SUCCESS;
3017 set_current_state(TASK_RUNNING);
3018 remove_wait_queue(&done_q, &wq_entry);
3023 lpfc_intr_handler(int irq, void *dev_id, struct pt_regs * regs)
3025 struct lpfc_hba *phba;
3027 uint32_t work_ha_copy;
3028 unsigned long status;
3033 * Get the driver's phba structure from the dev_id and
3034 * assume the HBA is not interrupting.
3036 phba = (struct lpfc_hba *) dev_id;
3038 if (unlikely(!phba))
3041 phba->sli.slistat.sli_intr++;
3044 * Call the HBA to see if it is interrupting. If not, don't claim
3048 /* Ignore all interrupts during initialization. */
3049 if (unlikely(phba->hba_state < LPFC_LINK_DOWN))
3053 * Read host attention register to determine interrupt source
3054 * Clear Attention Sources, except Error Attention (to
3055 * preserve status) and Link Attention
3057 spin_lock(phba->host->host_lock);
3058 ha_copy = readl(phba->HAregaddr);
3059 writel((ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
3060 readl(phba->HAregaddr); /* flush */
3061 spin_unlock(phba->host->host_lock);
3063 if (unlikely(!ha_copy))
3066 work_ha_copy = ha_copy & phba->work_ha_mask;
3068 if (unlikely(work_ha_copy)) {
3069 if (work_ha_copy & HA_LATT) {
3070 if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
3072 * Turn off Link Attention interrupts
3073 * until CLEAR_LA done
3075 spin_lock(phba->host->host_lock);
3076 phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
3077 control = readl(phba->HCregaddr);
3078 control &= ~HC_LAINT_ENA;
3079 writel(control, phba->HCregaddr);
3080 readl(phba->HCregaddr); /* flush */
3081 spin_unlock(phba->host->host_lock);
3084 work_ha_copy &= ~HA_LATT;
3087 if (work_ha_copy & ~(HA_ERATT|HA_MBATT|HA_LATT)) {
3088 for (i = 0; i < phba->sli.num_rings; i++) {
3089 if (work_ha_copy & (HA_RXATT << (4*i))) {
3091 * Turn off Slow Rings interrupts
3093 spin_lock(phba->host->host_lock);
3094 control = readl(phba->HCregaddr);
3095 control &= ~(HC_R0INT_ENA << i);
3096 writel(control, phba->HCregaddr);
3097 readl(phba->HCregaddr); /* flush */
3098 spin_unlock(phba->host->host_lock);
3103 if (work_ha_copy & HA_ERATT) {
3104 phba->hba_state = LPFC_HBA_ERROR;
3106 * There was a link/board error. Read the
3107 * status register to retrieve the error event
3110 phba->sli.slistat.err_attn_event++;
3111 /* Save status info */
3112 phba->work_hs = readl(phba->HSregaddr);
3113 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
3114 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
3116 /* Clear Chip error bit */
3117 writel(HA_ERATT, phba->HAregaddr);
3118 readl(phba->HAregaddr); /* flush */
3121 spin_lock(phba->host->host_lock);
3122 phba->work_ha |= work_ha_copy;
3123 if (phba->work_wait)
3124 wake_up(phba->work_wait);
3125 spin_unlock(phba->host->host_lock);
3128 ha_copy &= ~(phba->work_ha_mask);
3131 * Process all events on FCP ring. Take the optimized path for
3132 * FCP IO. Any other IO is slow path and is handled by
3133 * the worker thread.
3135 status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
3136 status >>= (4*LPFC_FCP_RING);
3137 if (status & HA_RXATT)
3138 lpfc_sli_handle_fast_ring_event(phba,
3139 &phba->sli.ring[LPFC_FCP_RING],
3143 } /* lpfc_intr_handler */