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_FCP_TSEND_CX:
121 case CMD_FCP_TRSP_CX:
122 case CMD_FCP_TRECEIVE_CX:
123 case CMD_FCP_AUTO_TRSP_CX:
124 case CMD_ADAPTER_MSG:
125 case CMD_ADAPTER_DUMP:
126 case CMD_XMIT_SEQUENCE64_CR:
127 case CMD_XMIT_SEQUENCE64_CX:
128 case CMD_XMIT_BCAST64_CN:
129 case CMD_XMIT_BCAST64_CX:
130 case CMD_ELS_REQUEST64_CR:
131 case CMD_ELS_REQUEST64_CX:
132 case CMD_FCP_IWRITE64_CR:
133 case CMD_FCP_IWRITE64_CX:
134 case CMD_FCP_IREAD64_CR:
135 case CMD_FCP_IREAD64_CX:
136 case CMD_FCP_ICMND64_CR:
137 case CMD_FCP_ICMND64_CX:
138 case CMD_FCP_TSEND64_CX:
139 case CMD_FCP_TRSP64_CX:
140 case CMD_FCP_TRECEIVE64_CX:
141 case CMD_GEN_REQUEST64_CR:
142 case CMD_GEN_REQUEST64_CX:
143 case CMD_XMIT_ELS_RSP64_CX:
144 type = LPFC_SOL_IOCB;
146 case CMD_ABORT_XRI_CN:
147 case CMD_ABORT_XRI_CX:
148 case CMD_CLOSE_XRI_CN:
149 case CMD_CLOSE_XRI_CX:
150 case CMD_XRI_ABORTED_CX:
151 case CMD_ABORT_MXRI64_CN:
152 type = LPFC_ABORT_IOCB;
154 case CMD_RCV_SEQUENCE_CX:
155 case CMD_RCV_ELS_REQ_CX:
156 case CMD_RCV_SEQUENCE64_CX:
157 case CMD_RCV_ELS_REQ64_CX:
158 type = LPFC_UNSOL_IOCB;
161 type = LPFC_UNKNOWN_IOCB;
169 lpfc_sli_ring_map(struct lpfc_hba * phba, LPFC_MBOXQ_t *pmb)
171 struct lpfc_sli *psli = &phba->sli;
172 MAILBOX_t *pmbox = &pmb->mb;
175 for (i = 0; i < psli->num_rings; i++) {
176 phba->hba_state = LPFC_INIT_MBX_CMDS;
177 lpfc_config_ring(phba, i, pmb);
178 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
179 if (rc != MBX_SUCCESS) {
180 lpfc_printf_log(phba,
183 "%d:0446 Adapter failed to init, "
184 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
190 phba->hba_state = LPFC_HBA_ERROR;
198 lpfc_sli_ringtxcmpl_put(struct lpfc_hba * phba,
199 struct lpfc_sli_ring * pring, struct lpfc_iocbq * piocb)
201 list_add_tail(&piocb->list, &pring->txcmplq);
202 pring->txcmplq_cnt++;
203 if (unlikely(pring->ringno == LPFC_ELS_RING))
204 mod_timer(&phba->els_tmofunc,
205 jiffies + HZ * (phba->fc_ratov << 1));
210 static struct lpfc_iocbq *
211 lpfc_sli_ringtx_get(struct lpfc_hba * phba, struct lpfc_sli_ring * pring)
213 struct list_head *dlp;
214 struct lpfc_iocbq *cmd_iocb;
218 list_remove_head((&pring->txq), cmd_iocb,
222 /* If the first ptr is not equal to the list header,
223 * deque the IOCBQ_t and return it.
231 lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
233 struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno];
234 uint32_t max_cmd_idx = pring->numCiocb;
237 if ((pring->next_cmdidx == pring->cmdidx) &&
238 (++pring->next_cmdidx >= max_cmd_idx))
239 pring->next_cmdidx = 0;
241 if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
243 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
245 if (unlikely(pring->local_getidx >= max_cmd_idx)) {
246 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
247 "%d:0315 Ring %d issue: portCmdGet %d "
248 "is bigger then cmd ring %d\n",
249 phba->brd_no, pring->ringno,
250 pring->local_getidx, max_cmd_idx);
252 phba->hba_state = LPFC_HBA_ERROR;
254 * All error attention handlers are posted to
257 phba->work_ha |= HA_ERATT;
258 phba->work_hs = HS_FFER3;
260 wake_up(phba->work_wait);
265 if (pring->local_getidx == pring->next_cmdidx)
269 iocb = IOCB_ENTRY(pring->cmdringaddr, pring->cmdidx);
275 lpfc_sli_next_iotag(struct lpfc_hba * phba, struct lpfc_iocbq * iocbq)
277 struct lpfc_iocbq ** new_arr;
278 struct lpfc_iocbq ** old_arr;
280 struct lpfc_sli *psli = &phba->sli;
283 spin_lock_irq(phba->host->host_lock);
284 iotag = psli->last_iotag;
285 if(++iotag < psli->iocbq_lookup_len) {
286 psli->last_iotag = iotag;
287 psli->iocbq_lookup[iotag] = iocbq;
288 spin_unlock_irq(phba->host->host_lock);
289 iocbq->iotag = iotag;
292 else if (psli->iocbq_lookup_len < (0xffff
293 - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
294 new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
295 spin_unlock_irq(phba->host->host_lock);
296 new_arr = kmalloc(new_len * sizeof (struct lpfc_iocbq *),
299 memset((char *)new_arr, 0,
300 new_len * sizeof (struct lpfc_iocbq *));
301 spin_lock_irq(phba->host->host_lock);
302 old_arr = psli->iocbq_lookup;
303 if (new_len <= psli->iocbq_lookup_len) {
304 /* highly unprobable case */
306 iotag = psli->last_iotag;
307 if(++iotag < psli->iocbq_lookup_len) {
308 psli->last_iotag = iotag;
309 psli->iocbq_lookup[iotag] = iocbq;
310 spin_unlock_irq(phba->host->host_lock);
311 iocbq->iotag = iotag;
314 spin_unlock_irq(phba->host->host_lock);
317 if (psli->iocbq_lookup)
318 memcpy(new_arr, old_arr,
319 ((psli->last_iotag + 1) *
320 sizeof (struct lpfc_iocbq *)));
321 psli->iocbq_lookup = new_arr;
322 psli->iocbq_lookup_len = new_len;
323 psli->last_iotag = iotag;
324 psli->iocbq_lookup[iotag] = iocbq;
325 spin_unlock_irq(phba->host->host_lock);
326 iocbq->iotag = iotag;
331 spin_unlock_irq(phba->host->host_lock);
333 lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
334 "%d:0318 Failed to allocate IOTAG.last IOTAG is %d\n",
335 phba->brd_no, psli->last_iotag);
341 lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
342 IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
347 nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
350 * Issue iocb command to adapter
352 lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, sizeof (IOCB_t));
354 pring->stats.iocb_cmd++;
357 * If there is no completion routine to call, we can release the
358 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
359 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
361 if (nextiocb->iocb_cmpl)
362 lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
364 lpfc_sli_release_iocbq(phba, nextiocb);
367 * Let the HBA know what IOCB slot will be the next one the
368 * driver will put a command into.
370 pring->cmdidx = pring->next_cmdidx;
371 writel(pring->cmdidx, phba->MBslimaddr
372 + (SLIMOFF + (pring->ringno * 2)) * 4);
376 lpfc_sli_update_full_ring(struct lpfc_hba * phba,
377 struct lpfc_sli_ring *pring)
379 int ringno = pring->ringno;
381 pring->flag |= LPFC_CALL_RING_AVAILABLE;
386 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
387 * The HBA will tell us when an IOCB entry is available.
389 writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
390 readl(phba->CAregaddr); /* flush */
392 pring->stats.iocb_cmd_full++;
396 lpfc_sli_update_ring(struct lpfc_hba * phba,
397 struct lpfc_sli_ring *pring)
399 int ringno = pring->ringno;
402 * Tell the HBA that there is work to do in this ring.
405 writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
406 readl(phba->CAregaddr); /* flush */
410 lpfc_sli_resume_iocb(struct lpfc_hba * phba, struct lpfc_sli_ring * pring)
413 struct lpfc_iocbq *nextiocb;
417 * (a) there is anything on the txq to send
419 * (c) link attention events can be processed (fcp ring only)
420 * (d) IOCB processing is not blocked by the outstanding mbox command.
422 if (pring->txq_cnt &&
423 (phba->hba_state > LPFC_LINK_DOWN) &&
424 (pring->ringno != phba->sli.fcp_ring ||
425 phba->sli.sli_flag & LPFC_PROCESS_LA) &&
426 !(pring->flag & LPFC_STOP_IOCB_MBX)) {
428 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
429 (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
430 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
433 lpfc_sli_update_ring(phba, pring);
435 lpfc_sli_update_full_ring(phba, pring);
441 /* lpfc_sli_turn_on_ring is only called by lpfc_sli_handle_mb_event below */
443 lpfc_sli_turn_on_ring(struct lpfc_hba * phba, int ringno)
445 struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[ringno];
447 /* If the ring is active, flag it */
448 if (phba->sli.ring[ringno].cmdringaddr) {
449 if (phba->sli.ring[ringno].flag & LPFC_STOP_IOCB_MBX) {
450 phba->sli.ring[ringno].flag &= ~LPFC_STOP_IOCB_MBX;
452 * Force update of the local copy of cmdGetInx
454 phba->sli.ring[ringno].local_getidx
455 = le32_to_cpu(pgp->cmdGetInx);
456 spin_lock_irq(phba->host->host_lock);
457 lpfc_sli_resume_iocb(phba, &phba->sli.ring[ringno]);
458 spin_unlock_irq(phba->host->host_lock);
464 lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
468 switch (mbxCommand) {
472 case MBX_RUN_BIU_DIAG:
475 case MBX_CONFIG_LINK:
476 case MBX_CONFIG_RING:
478 case MBX_READ_CONFIG:
479 case MBX_READ_RCONFIG:
481 case MBX_READ_STATUS:
485 case MBX_READ_LNK_STAT:
487 case MBX_UNREG_LOGIN:
490 case MBX_DUMP_MEMORY:
491 case MBX_DUMP_CONTEXT:
496 case MBX_DEL_LD_ENTRY:
497 case MBX_RUN_PROGRAM:
502 case MBX_CONFIG_FARP:
505 case MBX_RUN_BIU_DIAG64:
506 case MBX_CONFIG_PORT:
507 case MBX_READ_SPARM64:
509 case MBX_REG_LOGIN64:
511 case MBX_FLASH_WR_ULA:
513 case MBX_LOAD_EXP_ROM:
523 lpfc_sli_wake_mbox_wait(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
525 wait_queue_head_t *pdone_q;
528 * If pdone_q is empty, the driver thread gave up waiting and
531 pdone_q = (wait_queue_head_t *) pmboxq->context1;
533 wake_up_interruptible(pdone_q);
538 lpfc_sli_def_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
540 struct lpfc_dmabuf *mp;
541 mp = (struct lpfc_dmabuf *) (pmb->context1);
543 lpfc_mbuf_free(phba, mp->virt, mp->phys);
546 mempool_free( pmb, phba->mbox_mem_pool);
551 lpfc_sli_handle_mb_event(struct lpfc_hba * phba)
556 struct lpfc_sli *psli;
558 uint32_t process_next;
561 /* We should only get here if we are in SLI2 mode */
562 if (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE)) {
566 phba->sli.slistat.mbox_event++;
568 /* Get a Mailbox buffer to setup mailbox commands for callback */
569 if ((pmb = phba->sli.mbox_active)) {
571 mbox = &phba->slim2p->mbx;
573 /* First check out the status word */
574 lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof (uint32_t));
576 /* Sanity check to ensure the host owns the mailbox */
577 if (pmbox->mbxOwner != OWN_HOST) {
578 /* Lets try for a while */
579 for (i = 0; i < 10240; i++) {
580 /* First copy command data */
581 lpfc_sli_pcimem_bcopy(mbox, pmbox,
583 if (pmbox->mbxOwner == OWN_HOST)
586 /* Stray Mailbox Interrupt, mbxCommand <cmd> mbxStatus
588 lpfc_printf_log(phba,
591 "%d:0304 Stray Mailbox Interrupt "
592 "mbxCommand x%x mbxStatus x%x\n",
597 spin_lock_irq(phba->host->host_lock);
598 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
599 spin_unlock_irq(phba->host->host_lock);
604 del_timer_sync(&phba->sli.mbox_tmo);
605 phba->work_hba_events &= ~WORKER_MBOX_TMO;
608 * It is a fatal error if unknown mbox command completion.
610 if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
613 /* Unknow mailbox command compl */
614 lpfc_printf_log(phba,
617 "%d:0323 Unknown Mailbox command %x Cmpl\n",
620 phba->hba_state = LPFC_HBA_ERROR;
621 phba->work_hs = HS_FFER3;
622 lpfc_handle_eratt(phba);
626 phba->sli.mbox_active = NULL;
627 if (pmbox->mbxStatus) {
628 phba->sli.slistat.mbox_stat_err++;
629 if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
630 /* Mbox cmd cmpl error - RETRYing */
631 lpfc_printf_log(phba,
634 "%d:0305 Mbox cmd cmpl error - "
635 "RETRYing Data: x%x x%x x%x x%x\n",
639 pmbox->un.varWords[0],
641 pmbox->mbxStatus = 0;
642 pmbox->mbxOwner = OWN_HOST;
643 spin_lock_irq(phba->host->host_lock);
644 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
645 spin_unlock_irq(phba->host->host_lock);
646 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
647 if (rc == MBX_SUCCESS)
652 /* Mailbox cmd <cmd> Cmpl <cmpl> */
653 lpfc_printf_log(phba,
656 "%d:0307 Mailbox cmd x%x Cmpl x%p "
657 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
661 *((uint32_t *) pmbox),
662 pmbox->un.varWords[0],
663 pmbox->un.varWords[1],
664 pmbox->un.varWords[2],
665 pmbox->un.varWords[3],
666 pmbox->un.varWords[4],
667 pmbox->un.varWords[5],
668 pmbox->un.varWords[6],
669 pmbox->un.varWords[7]);
671 if (pmb->mbox_cmpl) {
672 lpfc_sli_pcimem_bcopy(mbox, pmbox, MAILBOX_CMD_SIZE);
673 pmb->mbox_cmpl(phba,pmb);
679 process_next = 0; /* by default don't loop */
680 spin_lock_irq(phba->host->host_lock);
681 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
683 /* Process next mailbox command if there is one */
684 if ((pmb = lpfc_mbox_get(phba))) {
685 spin_unlock_irq(phba->host->host_lock);
686 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
687 if (rc == MBX_NOT_FINISHED) {
688 pmb->mb.mbxStatus = MBX_NOT_FINISHED;
689 pmb->mbox_cmpl(phba,pmb);
691 continue; /* loop back */
694 spin_unlock_irq(phba->host->host_lock);
695 /* Turn on IOCB processing */
696 for (i = 0; i < phba->sli.num_rings; i++)
697 lpfc_sli_turn_on_ring(phba, i);
700 } while (process_next);
705 lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
706 struct lpfc_iocbq *saveq)
714 irsp = &(saveq->iocb);
715 if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX)
716 || (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX)) {
721 (WORD5 *) & (saveq->iocb.un.
723 Rctl = w5p->hcsw.Rctl;
724 Type = w5p->hcsw.Type;
726 /* Firmware Workaround */
727 if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
728 (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX)) {
731 w5p->hcsw.Rctl = Rctl;
732 w5p->hcsw.Type = Type;
735 /* unSolicited Responses */
736 if (pring->prt[0].profile) {
737 if (pring->prt[0].lpfc_sli_rcv_unsol_event)
738 (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
742 /* We must search, based on rctl / type
743 for the right routine */
744 for (i = 0; i < pring->num_mask;
746 if ((pring->prt[i].rctl ==
750 if (pring->prt[i].lpfc_sli_rcv_unsol_event)
751 (pring->prt[i].lpfc_sli_rcv_unsol_event)
752 (phba, pring, saveq);
759 /* Unexpected Rctl / Type received */
760 /* Ring <ringno> handler: unexpected
761 Rctl <Rctl> Type <Type> received */
762 lpfc_printf_log(phba,
765 "%d:0313 Ring %d handler: unexpected Rctl x%x "
766 "Type x%x received \n",
775 static struct lpfc_iocbq *
776 lpfc_sli_iocbq_lookup(struct lpfc_hba * phba,
777 struct lpfc_sli_ring * pring,
778 struct lpfc_iocbq * prspiocb)
780 struct lpfc_iocbq *cmd_iocb = NULL;
783 iotag = prspiocb->iocb.ulpIoTag;
785 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
786 cmd_iocb = phba->sli.iocbq_lookup[iotag];
787 list_del(&cmd_iocb->list);
788 pring->txcmplq_cnt--;
792 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
793 "%d:0317 iotag x%x is out off "
794 "range: max iotag x%x wd0 x%x\n",
796 phba->sli.last_iotag,
797 *(((uint32_t *) &prspiocb->iocb) + 7));
802 lpfc_sli_process_sol_iocb(struct lpfc_hba * phba, struct lpfc_sli_ring * pring,
803 struct lpfc_iocbq *saveq)
805 struct lpfc_iocbq * cmdiocbp;
809 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
810 spin_lock_irqsave(phba->host->host_lock, iflag);
811 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
813 if (cmdiocbp->iocb_cmpl) {
815 * Post all ELS completions to the worker thread.
816 * All other are passed to the completion callback.
818 if (pring->ringno == LPFC_ELS_RING) {
819 if (cmdiocbp->iocb_flag & LPFC_DRIVER_ABORTED) {
820 cmdiocbp->iocb_flag &=
821 ~LPFC_DRIVER_ABORTED;
822 saveq->iocb.ulpStatus =
824 saveq->iocb.un.ulpWord[4] =
827 spin_unlock_irqrestore(phba->host->host_lock,
829 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
830 spin_lock_irqsave(phba->host->host_lock, iflag);
833 spin_unlock_irqrestore(phba->host->host_lock,
835 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
836 spin_lock_irqsave(phba->host->host_lock, iflag);
839 lpfc_sli_release_iocbq(phba, cmdiocbp);
842 * Unknown initiating command based on the response iotag.
843 * This could be the case on the ELS ring because of
846 if (pring->ringno != LPFC_ELS_RING) {
848 * Ring <ringno> handler: unexpected completion IoTag
851 lpfc_printf_log(phba,
854 "%d:0322 Ring %d handler: unexpected "
855 "completion IoTag x%x Data: x%x x%x x%x x%x\n",
858 saveq->iocb.ulpIoTag,
859 saveq->iocb.ulpStatus,
860 saveq->iocb.un.ulpWord[4],
861 saveq->iocb.ulpCommand,
862 saveq->iocb.ulpContext);
866 spin_unlock_irqrestore(phba->host->host_lock, iflag);
870 static void lpfc_sli_rsp_pointers_error(struct lpfc_hba * phba,
871 struct lpfc_sli_ring * pring)
873 struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno];
875 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
876 * rsp ring <portRspMax>
878 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
879 "%d:0312 Ring %d handler: portRspPut %d "
880 "is bigger then rsp ring %d\n",
881 phba->brd_no, pring->ringno,
882 le32_to_cpu(pgp->rspPutInx),
885 phba->hba_state = LPFC_HBA_ERROR;
888 * All error attention handlers are posted to
891 phba->work_ha |= HA_ERATT;
892 phba->work_hs = HS_FFER3;
894 wake_up(phba->work_wait);
899 void lpfc_sli_poll_fcp_ring(struct lpfc_hba * phba)
901 struct lpfc_sli * psli = &phba->sli;
902 struct lpfc_sli_ring * pring = &psli->ring[LPFC_FCP_RING];
904 IOCB_t *entry = NULL;
905 struct lpfc_iocbq *cmdiocbq = NULL;
906 struct lpfc_iocbq rspiocbq;
907 struct lpfc_pgp *pgp;
909 uint32_t portRspPut, portRspMax;
911 uint32_t rsp_cmpl = 0;
912 void __iomem *to_slim;
915 pring->stats.iocb_event++;
917 /* The driver assumes SLI-2 mode */
918 pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno];
921 * The next available response entry should never exceed the maximum
922 * entries. If it does, treat it as an adapter hardware error.
924 portRspMax = pring->numRiocb;
925 portRspPut = le32_to_cpu(pgp->rspPutInx);
926 if (unlikely(portRspPut >= portRspMax)) {
927 lpfc_sli_rsp_pointers_error(phba, pring);
932 while (pring->rspidx != portRspPut) {
934 entry = IOCB_ENTRY(pring->rspringaddr, pring->rspidx);
936 if (++pring->rspidx >= portRspMax)
939 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
940 (uint32_t *) &rspiocbq.iocb,
942 irsp = &rspiocbq.iocb;
943 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
944 pring->stats.iocb_rsp++;
947 if (unlikely(irsp->ulpStatus)) {
948 /* Rsp ring <ringno> error: IOCB */
949 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
950 "%d:0326 Rsp Ring %d error: IOCB Data: "
951 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
952 phba->brd_no, pring->ringno,
959 *(((uint32_t *) irsp) + 6),
960 *(((uint32_t *) irsp) + 7));
964 case LPFC_ABORT_IOCB:
967 * Idle exchange closed via ABTS from port. No iocb
968 * resources need to be recovered.
970 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
971 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
972 "%d:0314 IOCB cmd 0x%x"
973 " processed. Skipping"
974 " completion", phba->brd_no,
979 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
981 if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
982 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
987 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
988 char adaptermsg[LPFC_MAX_ADPTMSG];
989 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
990 memcpy(&adaptermsg[0], (uint8_t *) irsp,
992 dev_warn(&((phba->pcidev)->dev), "lpfc%d: %s",
993 phba->brd_no, adaptermsg);
995 /* Unknown IOCB command */
996 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
997 "%d:0321 Unknown IOCB command "
998 "Data: x%x, x%x x%x x%x x%x\n",
1009 * The response IOCB has been processed. Update the ring
1010 * pointer in SLIM. If the port response put pointer has not
1011 * been updated, sync the pgp->rspPutInx and fetch the new port
1012 * response put pointer.
1014 to_slim = phba->MBslimaddr +
1015 (SLIMOFF + (pring->ringno * 2) + 1) * 4;
1016 writeb(pring->rspidx, to_slim);
1018 if (pring->rspidx == portRspPut)
1019 portRspPut = le32_to_cpu(pgp->rspPutInx);
1022 ha_copy = readl(phba->HAregaddr);
1023 ha_copy >>= (LPFC_FCP_RING * 4);
1025 if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) {
1026 pring->stats.iocb_rsp_full++;
1027 status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4));
1028 writel(status, phba->CAregaddr);
1029 readl(phba->CAregaddr);
1031 if ((ha_copy & HA_R0CE_RSP) &&
1032 (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1033 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1034 pring->stats.iocb_cmd_empty++;
1036 /* Force update of the local copy of cmdGetInx */
1037 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1038 lpfc_sli_resume_iocb(phba, pring);
1040 if ((pring->lpfc_sli_cmd_available))
1041 (pring->lpfc_sli_cmd_available) (phba, pring);
1049 * This routine presumes LPFC_FCP_RING handling and doesn't bother
1050 * to check it explicitly.
1053 lpfc_sli_handle_fast_ring_event(struct lpfc_hba * phba,
1054 struct lpfc_sli_ring * pring, uint32_t mask)
1056 struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno];
1057 IOCB_t *irsp = NULL;
1058 IOCB_t *entry = NULL;
1059 struct lpfc_iocbq *cmdiocbq = NULL;
1060 struct lpfc_iocbq rspiocbq;
1062 uint32_t portRspPut, portRspMax;
1064 lpfc_iocb_type type;
1065 unsigned long iflag;
1066 uint32_t rsp_cmpl = 0;
1067 void __iomem *to_slim;
1069 spin_lock_irqsave(phba->host->host_lock, iflag);
1070 pring->stats.iocb_event++;
1073 * The next available response entry should never exceed the maximum
1074 * entries. If it does, treat it as an adapter hardware error.
1076 portRspMax = pring->numRiocb;
1077 portRspPut = le32_to_cpu(pgp->rspPutInx);
1078 if (unlikely(portRspPut >= portRspMax)) {
1079 lpfc_sli_rsp_pointers_error(phba, pring);
1080 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1085 while (pring->rspidx != portRspPut) {
1087 * Fetch an entry off the ring and copy it into a local data
1088 * structure. The copy involves a byte-swap since the
1089 * network byte order and pci byte orders are different.
1091 entry = IOCB_ENTRY(pring->rspringaddr, pring->rspidx);
1093 if (++pring->rspidx >= portRspMax)
1096 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
1097 (uint32_t *) &rspiocbq.iocb,
1099 INIT_LIST_HEAD(&(rspiocbq.list));
1100 irsp = &rspiocbq.iocb;
1102 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
1103 pring->stats.iocb_rsp++;
1106 if (unlikely(irsp->ulpStatus)) {
1107 /* Rsp ring <ringno> error: IOCB */
1108 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1109 "%d:0336 Rsp Ring %d error: IOCB Data: "
1110 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
1111 phba->brd_no, pring->ringno,
1112 irsp->un.ulpWord[0], irsp->un.ulpWord[1],
1113 irsp->un.ulpWord[2], irsp->un.ulpWord[3],
1114 irsp->un.ulpWord[4], irsp->un.ulpWord[5],
1115 *(((uint32_t *) irsp) + 6),
1116 *(((uint32_t *) irsp) + 7));
1120 case LPFC_ABORT_IOCB:
1123 * Idle exchange closed via ABTS from port. No iocb
1124 * resources need to be recovered.
1126 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
1127 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1128 "%d:0333 IOCB cmd 0x%x"
1129 " processed. Skipping"
1130 " completion\n", phba->brd_no,
1135 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
1137 if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
1138 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
1139 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1142 spin_unlock_irqrestore(
1143 phba->host->host_lock, iflag);
1144 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1146 spin_lock_irqsave(phba->host->host_lock,
1151 case LPFC_UNSOL_IOCB:
1152 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1153 lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
1154 spin_lock_irqsave(phba->host->host_lock, iflag);
1157 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1158 char adaptermsg[LPFC_MAX_ADPTMSG];
1159 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
1160 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1162 dev_warn(&((phba->pcidev)->dev), "lpfc%d: %s",
1163 phba->brd_no, adaptermsg);
1165 /* Unknown IOCB command */
1166 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1167 "%d:0334 Unknown IOCB command "
1168 "Data: x%x, x%x x%x x%x x%x\n",
1169 phba->brd_no, type, irsp->ulpCommand,
1170 irsp->ulpStatus, irsp->ulpIoTag,
1177 * The response IOCB has been processed. Update the ring
1178 * pointer in SLIM. If the port response put pointer has not
1179 * been updated, sync the pgp->rspPutInx and fetch the new port
1180 * response put pointer.
1182 to_slim = phba->MBslimaddr +
1183 (SLIMOFF + (pring->ringno * 2) + 1) * 4;
1184 writel(pring->rspidx, to_slim);
1186 if (pring->rspidx == portRspPut)
1187 portRspPut = le32_to_cpu(pgp->rspPutInx);
1190 if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
1191 pring->stats.iocb_rsp_full++;
1192 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
1193 writel(status, phba->CAregaddr);
1194 readl(phba->CAregaddr);
1196 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1197 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1198 pring->stats.iocb_cmd_empty++;
1200 /* Force update of the local copy of cmdGetInx */
1201 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1202 lpfc_sli_resume_iocb(phba, pring);
1204 if ((pring->lpfc_sli_cmd_available))
1205 (pring->lpfc_sli_cmd_available) (phba, pring);
1209 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1215 lpfc_sli_handle_slow_ring_event(struct lpfc_hba * phba,
1216 struct lpfc_sli_ring * pring, uint32_t mask)
1219 IOCB_t *irsp = NULL;
1220 struct lpfc_iocbq *rspiocbp = NULL;
1221 struct lpfc_iocbq *next_iocb;
1222 struct lpfc_iocbq *cmdiocbp;
1223 struct lpfc_iocbq *saveq;
1224 struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno];
1225 uint8_t iocb_cmd_type;
1226 lpfc_iocb_type type;
1227 uint32_t status, free_saveq;
1228 uint32_t portRspPut, portRspMax;
1230 unsigned long iflag;
1231 void __iomem *to_slim;
1233 spin_lock_irqsave(phba->host->host_lock, iflag);
1234 pring->stats.iocb_event++;
1237 * The next available response entry should never exceed the maximum
1238 * entries. If it does, treat it as an adapter hardware error.
1240 portRspMax = pring->numRiocb;
1241 portRspPut = le32_to_cpu(pgp->rspPutInx);
1242 if (portRspPut >= portRspMax) {
1244 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
1245 * rsp ring <portRspMax>
1247 lpfc_printf_log(phba,
1250 "%d:0303 Ring %d handler: portRspPut %d "
1251 "is bigger then rsp ring %d\n",
1253 pring->ringno, portRspPut, portRspMax);
1255 phba->hba_state = LPFC_HBA_ERROR;
1256 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1258 phba->work_hs = HS_FFER3;
1259 lpfc_handle_eratt(phba);
1265 while (pring->rspidx != portRspPut) {
1267 * Build a completion list and call the appropriate handler.
1268 * The process is to get the next available response iocb, get
1269 * a free iocb from the list, copy the response data into the
1270 * free iocb, insert to the continuation list, and update the
1271 * next response index to slim. This process makes response
1272 * iocb's in the ring available to DMA as fast as possible but
1273 * pays a penalty for a copy operation. Since the iocb is
1274 * only 32 bytes, this penalty is considered small relative to
1275 * the PCI reads for register values and a slim write. When
1276 * the ulpLe field is set, the entire Command has been
1279 entry = IOCB_ENTRY(pring->rspringaddr, pring->rspidx);
1280 rspiocbp = lpfc_sli_get_iocbq(phba);
1281 if (rspiocbp == NULL) {
1282 printk(KERN_ERR "%s: out of buffers! Failing "
1283 "completion.\n", __FUNCTION__);
1287 lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, sizeof (IOCB_t));
1288 irsp = &rspiocbp->iocb;
1290 if (++pring->rspidx >= portRspMax)
1293 to_slim = phba->MBslimaddr + (SLIMOFF + (pring->ringno * 2)
1295 writel(pring->rspidx, to_slim);
1297 if (list_empty(&(pring->iocb_continueq))) {
1298 list_add(&rspiocbp->list, &(pring->iocb_continueq));
1300 list_add_tail(&rspiocbp->list,
1301 &(pring->iocb_continueq));
1304 pring->iocb_continueq_cnt++;
1307 * By default, the driver expects to free all resources
1308 * associated with this iocb completion.
1311 saveq = list_get_first(&pring->iocb_continueq,
1312 struct lpfc_iocbq, list);
1313 irsp = &(saveq->iocb);
1314 list_del_init(&pring->iocb_continueq);
1315 pring->iocb_continueq_cnt = 0;
1317 pring->stats.iocb_rsp++;
1319 if (irsp->ulpStatus) {
1320 /* Rsp ring <ringno> error: IOCB */
1321 lpfc_printf_log(phba,
1324 "%d:0328 Rsp Ring %d error: IOCB Data: "
1325 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
1328 irsp->un.ulpWord[0],
1329 irsp->un.ulpWord[1],
1330 irsp->un.ulpWord[2],
1331 irsp->un.ulpWord[3],
1332 irsp->un.ulpWord[4],
1333 irsp->un.ulpWord[5],
1334 *(((uint32_t *) irsp) + 6),
1335 *(((uint32_t *) irsp) + 7));
1339 * Fetch the IOCB command type and call the correct
1340 * completion routine. Solicited and Unsolicited
1341 * IOCBs on the ELS ring get freed back to the
1342 * lpfc_iocb_list by the discovery kernel thread.
1344 iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
1345 type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
1346 if (type == LPFC_SOL_IOCB) {
1347 spin_unlock_irqrestore(phba->host->host_lock,
1349 rc = lpfc_sli_process_sol_iocb(phba, pring,
1351 spin_lock_irqsave(phba->host->host_lock, iflag);
1352 } else if (type == LPFC_UNSOL_IOCB) {
1353 spin_unlock_irqrestore(phba->host->host_lock,
1355 rc = lpfc_sli_process_unsol_iocb(phba, pring,
1357 spin_lock_irqsave(phba->host->host_lock, iflag);
1358 } else if (type == LPFC_ABORT_IOCB) {
1359 if ((irsp->ulpCommand != CMD_XRI_ABORTED_CX) &&
1361 lpfc_sli_iocbq_lookup(phba, pring,
1363 /* Call the specified completion
1365 if (cmdiocbp->iocb_cmpl) {
1366 spin_unlock_irqrestore(
1367 phba->host->host_lock,
1369 (cmdiocbp->iocb_cmpl) (phba,
1372 phba->host->host_lock,
1375 lpfc_sli_release_iocbq(phba,
1378 } else if (type == LPFC_UNKNOWN_IOCB) {
1379 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1381 char adaptermsg[LPFC_MAX_ADPTMSG];
1383 memset(adaptermsg, 0,
1385 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1387 dev_warn(&((phba->pcidev)->dev),
1389 phba->brd_no, adaptermsg);
1391 /* Unknown IOCB command */
1392 lpfc_printf_log(phba,
1395 "%d:0335 Unknown IOCB command "
1396 "Data: x%x x%x x%x x%x\n",
1406 if (!list_empty(&saveq->list)) {
1407 list_for_each_entry_safe(rspiocbp,
1411 list_del(&rspiocbp->list);
1412 lpfc_sli_release_iocbq(phba,
1416 lpfc_sli_release_iocbq(phba, saveq);
1421 * If the port response put pointer has not been updated, sync
1422 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
1423 * response put pointer.
1425 if (pring->rspidx == portRspPut) {
1426 portRspPut = le32_to_cpu(pgp->rspPutInx);
1428 } /* while (pring->rspidx != portRspPut) */
1430 if ((rspiocbp != 0) && (mask & HA_R0RE_REQ)) {
1431 /* At least one response entry has been freed */
1432 pring->stats.iocb_rsp_full++;
1433 /* SET RxRE_RSP in Chip Att register */
1434 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
1435 writel(status, phba->CAregaddr);
1436 readl(phba->CAregaddr); /* flush */
1438 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1439 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1440 pring->stats.iocb_cmd_empty++;
1442 /* Force update of the local copy of cmdGetInx */
1443 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1444 lpfc_sli_resume_iocb(phba, pring);
1446 if ((pring->lpfc_sli_cmd_available))
1447 (pring->lpfc_sli_cmd_available) (phba, pring);
1451 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1456 lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1458 struct lpfc_iocbq *iocb, *next_iocb;
1459 IOCB_t *icmd = NULL, *cmd = NULL;
1464 /* Error everything on txq and txcmplq
1467 spin_lock_irq(phba->host->host_lock);
1468 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
1469 list_del_init(&iocb->list);
1470 if (iocb->iocb_cmpl) {
1472 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
1473 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
1474 spin_unlock_irq(phba->host->host_lock);
1475 (iocb->iocb_cmpl) (phba, iocb, iocb);
1476 spin_lock_irq(phba->host->host_lock);
1478 lpfc_sli_release_iocbq(phba, iocb);
1481 INIT_LIST_HEAD(&(pring->txq));
1483 /* Next issue ABTS for everything on the txcmplq */
1484 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1488 * Imediate abort of IOCB, deque and call compl
1491 list_del_init(&iocb->list);
1492 pring->txcmplq_cnt--;
1494 if (iocb->iocb_cmpl) {
1495 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
1496 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
1497 spin_unlock_irq(phba->host->host_lock);
1498 (iocb->iocb_cmpl) (phba, iocb, iocb);
1499 spin_lock_irq(phba->host->host_lock);
1501 lpfc_sli_release_iocbq(phba, iocb);
1504 INIT_LIST_HEAD(&pring->txcmplq);
1505 pring->txcmplq_cnt = 0;
1506 spin_unlock_irq(phba->host->host_lock);
1512 lpfc_sli_brdready(struct lpfc_hba * phba, uint32_t mask)
1518 /* Read the HBA Host Status Register */
1519 status = readl(phba->HSregaddr);
1522 * Check status register every 100ms for 5 retries, then every
1523 * 500ms for 5, then every 2.5 sec for 5, then reset board and
1524 * every 2.5 sec for 4.
1525 * Break our of the loop if errors occurred during init.
1527 while (((status & mask) != mask) &&
1528 !(status & HS_FFERM) &&
1539 phba->hba_state = LPFC_STATE_UNKNOWN; /* Do post */
1540 lpfc_sli_brdrestart(phba);
1542 /* Read the HBA Host Status Register */
1543 status = readl(phba->HSregaddr);
1546 /* Check to see if any errors occurred during init */
1547 if ((status & HS_FFERM) || (i >= 20)) {
1548 phba->hba_state = LPFC_HBA_ERROR;
1555 #define BARRIER_TEST_PATTERN (0xdeadbeef)
1557 void lpfc_reset_barrier(struct lpfc_hba * phba)
1559 uint32_t __iomem *resp_buf;
1560 uint32_t __iomem *mbox_buf;
1561 volatile uint32_t mbox;
1566 pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
1567 if (hdrtype != 0x80 ||
1568 (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
1569 FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
1573 * Tell the other part of the chip to suspend temporarily all
1576 resp_buf = phba->MBslimaddr;
1578 /* Disable the error attention */
1579 hc_copy = readl(phba->HCregaddr);
1580 writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
1581 readl(phba->HCregaddr); /* flush */
1583 if (readl(phba->HAregaddr) & HA_ERATT) {
1584 /* Clear Chip error bit */
1585 writel(HA_ERATT, phba->HAregaddr);
1590 ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
1591 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
1593 writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
1594 mbox_buf = phba->MBslimaddr;
1595 writel(mbox, mbox_buf);
1598 readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
1601 if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
1602 if (phba->sli.sli_flag & LPFC_SLI2_ACTIVE ||
1609 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
1610 for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
1615 while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
1618 if (readl(phba->HAregaddr) & HA_ERATT) {
1619 writel(HA_ERATT, phba->HAregaddr);
1624 writel(hc_copy, phba->HCregaddr);
1625 readl(phba->HCregaddr); /* flush */
1629 lpfc_sli_brdkill(struct lpfc_hba * phba)
1631 struct lpfc_sli *psli;
1641 lpfc_printf_log(phba,
1644 "%d:0329 Kill HBA Data: x%x x%x\n",
1649 if ((pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
1653 /* Disable the error attention */
1654 spin_lock_irq(phba->host->host_lock);
1655 status = readl(phba->HCregaddr);
1656 status &= ~HC_ERINT_ENA;
1657 writel(status, phba->HCregaddr);
1658 readl(phba->HCregaddr); /* flush */
1659 spin_unlock_irq(phba->host->host_lock);
1661 lpfc_kill_board(phba, pmb);
1662 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1663 retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
1665 if (retval != MBX_SUCCESS) {
1666 if (retval != MBX_BUSY)
1667 mempool_free(pmb, phba->mbox_mem_pool);
1671 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
1673 mempool_free(pmb, phba->mbox_mem_pool);
1675 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
1676 * attention every 100ms for 3 seconds. If we don't get ERATT after
1677 * 3 seconds we still set HBA_ERROR state because the status of the
1678 * board is now undefined.
1680 ha_copy = readl(phba->HAregaddr);
1682 while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
1684 ha_copy = readl(phba->HAregaddr);
1687 del_timer_sync(&psli->mbox_tmo);
1688 if (ha_copy & HA_ERATT) {
1689 writel(HA_ERATT, phba->HAregaddr);
1692 spin_lock_irq(phba->host->host_lock);
1693 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
1694 spin_unlock_irq(phba->host->host_lock);
1696 psli->mbox_active = NULL;
1697 lpfc_hba_down_post(phba);
1698 phba->hba_state = LPFC_HBA_ERROR;
1700 return (ha_copy & HA_ERATT ? 0 : 1);
1704 lpfc_sli_brdreset(struct lpfc_hba * phba)
1706 struct lpfc_sli *psli;
1707 struct lpfc_sli_ring *pring;
1714 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1715 "%d:0325 Reset HBA Data: x%x x%x\n", phba->brd_no,
1716 phba->hba_state, psli->sli_flag);
1718 /* perform board reset */
1719 phba->fc_eventTag = 0;
1721 phba->fc_prevDID = 0;
1723 /* Turn off parity checking and serr during the physical reset */
1724 pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
1725 pci_write_config_word(phba->pcidev, PCI_COMMAND,
1727 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
1729 psli->sli_flag &= ~(LPFC_SLI2_ACTIVE | LPFC_PROCESS_LA);
1730 /* Now toggle INITFF bit in the Host Control Register */
1731 writel(HC_INITFF, phba->HCregaddr);
1733 readl(phba->HCregaddr); /* flush */
1734 writel(0, phba->HCregaddr);
1735 readl(phba->HCregaddr); /* flush */
1737 /* Restore PCI cmd register */
1738 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
1740 /* Initialize relevant SLI info */
1741 for (i = 0; i < psli->num_rings; i++) {
1742 pring = &psli->ring[i];
1745 pring->next_cmdidx = 0;
1746 pring->local_getidx = 0;
1748 pring->missbufcnt = 0;
1751 phba->hba_state = LPFC_WARM_START;
1756 lpfc_sli_brdrestart(struct lpfc_hba * phba)
1759 struct lpfc_sli *psli;
1761 volatile uint32_t word0;
1762 void __iomem *to_slim;
1764 spin_lock_irq(phba->host->host_lock);
1769 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1770 "%d:0337 Restart HBA Data: x%x x%x\n", phba->brd_no,
1771 phba->hba_state, psli->sli_flag);
1774 mb = (MAILBOX_t *) &word0;
1775 mb->mbxCommand = MBX_RESTART;
1778 lpfc_reset_barrier(phba);
1780 to_slim = phba->MBslimaddr;
1781 writel(*(uint32_t *) mb, to_slim);
1782 readl(to_slim); /* flush */
1784 /* Only skip post after fc_ffinit is completed */
1785 if (phba->hba_state) {
1787 word0 = 1; /* This is really setting up word1 */
1790 word0 = 0; /* This is really setting up word1 */
1792 to_slim = phba->MBslimaddr + sizeof (uint32_t);
1793 writel(*(uint32_t *) mb, to_slim);
1794 readl(to_slim); /* flush */
1796 lpfc_sli_brdreset(phba);
1798 phba->hba_state = LPFC_INIT_START;
1800 spin_unlock_irq(phba->host->host_lock);
1802 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
1803 psli->stats_start = get_seconds();
1810 lpfc_hba_down_post(phba);
1816 lpfc_sli_chipset_init(struct lpfc_hba *phba)
1818 uint32_t status, i = 0;
1820 /* Read the HBA Host Status Register */
1821 status = readl(phba->HSregaddr);
1823 /* Check status register to see what current state is */
1825 while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
1827 /* Check every 100ms for 5 retries, then every 500ms for 5, then
1828 * every 2.5 sec for 5, then reset board and every 2.5 sec for
1832 /* Adapter failed to init, timeout, status reg
1834 lpfc_printf_log(phba,
1837 "%d:0436 Adapter failed to init, "
1838 "timeout, status reg x%x\n",
1841 phba->hba_state = LPFC_HBA_ERROR;
1845 /* Check to see if any errors occurred during init */
1846 if (status & HS_FFERM) {
1847 /* ERROR: During chipset initialization */
1848 /* Adapter failed to init, chipset, status reg
1850 lpfc_printf_log(phba,
1853 "%d:0437 Adapter failed to init, "
1854 "chipset, status reg x%x\n",
1857 phba->hba_state = LPFC_HBA_ERROR;
1863 } else if (i <= 10) {
1870 phba->hba_state = LPFC_STATE_UNKNOWN; /* Do post */
1871 lpfc_sli_brdrestart(phba);
1873 /* Read the HBA Host Status Register */
1874 status = readl(phba->HSregaddr);
1877 /* Check to see if any errors occurred during init */
1878 if (status & HS_FFERM) {
1879 /* ERROR: During chipset initialization */
1880 /* Adapter failed to init, chipset, status reg <status> */
1881 lpfc_printf_log(phba,
1884 "%d:0438 Adapter failed to init, chipset, "
1888 phba->hba_state = LPFC_HBA_ERROR;
1892 /* Clear all interrupt enable conditions */
1893 writel(0, phba->HCregaddr);
1894 readl(phba->HCregaddr); /* flush */
1896 /* setup host attn register */
1897 writel(0xffffffff, phba->HAregaddr);
1898 readl(phba->HAregaddr); /* flush */
1903 lpfc_sli_hba_setup(struct lpfc_hba * phba)
1906 uint32_t resetcount = 0, rc = 0, done = 0;
1908 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1910 phba->hba_state = LPFC_HBA_ERROR;
1914 while (resetcount < 2 && !done) {
1915 spin_lock_irq(phba->host->host_lock);
1916 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
1917 spin_unlock_irq(phba->host->host_lock);
1918 phba->hba_state = LPFC_STATE_UNKNOWN;
1919 lpfc_sli_brdrestart(phba);
1921 rc = lpfc_sli_chipset_init(phba);
1925 spin_lock_irq(phba->host->host_lock);
1926 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
1927 spin_unlock_irq(phba->host->host_lock);
1930 /* Call pre CONFIG_PORT mailbox command initialization. A value of 0
1931 * means the call was successful. Any other nonzero value is a failure,
1932 * but if ERESTART is returned, the driver may reset the HBA and try
1935 rc = lpfc_config_port_prep(phba);
1936 if (rc == -ERESTART) {
1937 phba->hba_state = 0;
1943 phba->hba_state = LPFC_INIT_MBX_CMDS;
1944 lpfc_config_port(phba, pmb);
1945 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
1946 if (rc == MBX_SUCCESS)
1949 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1950 "%d:0442 Adapter failed to init, mbxCmd x%x "
1951 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
1952 phba->brd_no, pmb->mb.mbxCommand,
1953 pmb->mb.mbxStatus, 0);
1954 phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE;
1958 goto lpfc_sli_hba_setup_error;
1960 rc = lpfc_sli_ring_map(phba, pmb);
1963 goto lpfc_sli_hba_setup_error;
1965 phba->sli.sli_flag |= LPFC_PROCESS_LA;
1967 rc = lpfc_config_port_post(phba);
1969 goto lpfc_sli_hba_setup_error;
1971 goto lpfc_sli_hba_setup_exit;
1972 lpfc_sli_hba_setup_error:
1973 phba->hba_state = LPFC_HBA_ERROR;
1974 lpfc_sli_hba_setup_exit:
1975 mempool_free(pmb, phba->mbox_mem_pool);
1979 /*! lpfc_mbox_timeout
1983 * \param hba Pointer to per struct lpfc_hba structure
1984 * \param l1 Pointer to the driver's mailbox queue.
1990 * This routine handles mailbox timeout events at timer interrupt context.
1993 lpfc_mbox_timeout(unsigned long ptr)
1995 struct lpfc_hba *phba;
1996 unsigned long iflag;
1998 phba = (struct lpfc_hba *)ptr;
1999 spin_lock_irqsave(phba->host->host_lock, iflag);
2000 if (!(phba->work_hba_events & WORKER_MBOX_TMO)) {
2001 phba->work_hba_events |= WORKER_MBOX_TMO;
2002 if (phba->work_wait)
2003 wake_up(phba->work_wait);
2005 spin_unlock_irqrestore(phba->host->host_lock, iflag);
2009 lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
2011 LPFC_MBOXQ_t *pmbox;
2013 struct lpfc_sli *psli = &phba->sli;
2014 struct lpfc_sli_ring *pring;
2016 spin_lock_irq(phba->host->host_lock);
2017 if (!(phba->work_hba_events & WORKER_MBOX_TMO)) {
2018 spin_unlock_irq(phba->host->host_lock);
2022 pmbox = phba->sli.mbox_active;
2025 /* Mbox cmd <mbxCommand> timeout */
2026 lpfc_printf_log(phba,
2029 "%d:0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
2034 phba->sli.mbox_active);
2036 /* Setting state unknown so lpfc_sli_abort_iocb_ring
2037 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
2038 * it to fail all oustanding SCSI IO.
2040 phba->hba_state = LPFC_STATE_UNKNOWN;
2041 phba->work_hba_events &= ~WORKER_MBOX_TMO;
2042 phba->fc_flag |= FC_ESTABLISH_LINK;
2043 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
2044 spin_unlock_irq(phba->host->host_lock);
2046 pring = &psli->ring[psli->fcp_ring];
2047 lpfc_sli_abort_iocb_ring(phba, pring);
2049 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
2050 "%d:0316 Resetting board due to mailbox timeout\n",
2053 * lpfc_offline calls lpfc_sli_hba_down which will clean up
2054 * on oustanding mailbox commands.
2056 lpfc_offline_prep(phba);
2058 lpfc_sli_brdrestart(phba);
2059 if (lpfc_online(phba) == 0) /* Initialize the HBA */
2060 mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
2061 lpfc_unblock_mgmt_io(phba);
2066 lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag)
2069 struct lpfc_sli *psli;
2070 uint32_t status, evtctr;
2073 unsigned long drvr_flag = 0;
2074 volatile uint32_t word0, ldata;
2075 void __iomem *to_slim;
2077 /* If the PCI channel is in offline state, do not post mbox. */
2078 if (unlikely(pci_channel_offline(phba->pcidev)))
2079 return MBX_NOT_FINISHED;
2083 spin_lock_irqsave(phba->host->host_lock, drvr_flag);
2087 status = MBX_SUCCESS;
2089 if (phba->hba_state == LPFC_HBA_ERROR) {
2090 spin_unlock_irqrestore(phba->host->host_lock, drvr_flag);
2092 /* Mbox command <mbxCommand> cannot issue */
2093 LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag)
2094 return (MBX_NOT_FINISHED);
2097 if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
2098 !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
2099 spin_unlock_irqrestore(phba->host->host_lock, drvr_flag);
2100 LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag)
2101 return (MBX_NOT_FINISHED);
2104 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
2105 /* Polling for a mbox command when another one is already active
2106 * is not allowed in SLI. Also, the driver must have established
2107 * SLI2 mode to queue and process multiple mbox commands.
2110 if (flag & MBX_POLL) {
2111 spin_unlock_irqrestore(phba->host->host_lock,
2114 /* Mbox command <mbxCommand> cannot issue */
2115 LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag)
2116 return (MBX_NOT_FINISHED);
2119 if (!(psli->sli_flag & LPFC_SLI2_ACTIVE)) {
2120 spin_unlock_irqrestore(phba->host->host_lock,
2122 /* Mbox command <mbxCommand> cannot issue */
2123 LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag)
2124 return (MBX_NOT_FINISHED);
2127 /* Handle STOP IOCB processing flag. This is only meaningful
2128 * if we are not polling for mbox completion.
2130 if (flag & MBX_STOP_IOCB) {
2131 flag &= ~MBX_STOP_IOCB;
2132 /* Now flag each ring */
2133 for (i = 0; i < psli->num_rings; i++) {
2134 /* If the ring is active, flag it */
2135 if (psli->ring[i].cmdringaddr) {
2136 psli->ring[i].flag |=
2142 /* Another mailbox command is still being processed, queue this
2143 * command to be processed later.
2145 lpfc_mbox_put(phba, pmbox);
2147 /* Mbox cmd issue - BUSY */
2148 lpfc_printf_log(phba,
2151 "%d:0308 Mbox cmd issue - BUSY Data: x%x x%x x%x x%x\n",
2158 psli->slistat.mbox_busy++;
2159 spin_unlock_irqrestore(phba->host->host_lock,
2165 /* Handle STOP IOCB processing flag. This is only meaningful
2166 * if we are not polling for mbox completion.
2168 if (flag & MBX_STOP_IOCB) {
2169 flag &= ~MBX_STOP_IOCB;
2170 if (flag == MBX_NOWAIT) {
2171 /* Now flag each ring */
2172 for (i = 0; i < psli->num_rings; i++) {
2173 /* If the ring is active, flag it */
2174 if (psli->ring[i].cmdringaddr) {
2175 psli->ring[i].flag |=
2182 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
2184 /* If we are not polling, we MUST be in SLI2 mode */
2185 if (flag != MBX_POLL) {
2186 if (!(psli->sli_flag & LPFC_SLI2_ACTIVE) &&
2187 (mb->mbxCommand != MBX_KILL_BOARD)) {
2188 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2189 spin_unlock_irqrestore(phba->host->host_lock,
2191 /* Mbox command <mbxCommand> cannot issue */
2192 LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag);
2193 return (MBX_NOT_FINISHED);
2195 /* timeout active mbox command */
2196 mod_timer(&psli->mbox_tmo, (jiffies +
2197 (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
2200 /* Mailbox cmd <cmd> issue */
2201 lpfc_printf_log(phba,
2204 "%d:0309 Mailbox cmd x%x issue Data: x%x x%x x%x\n",
2211 psli->slistat.mbox_cmd++;
2212 evtctr = psli->slistat.mbox_event;
2214 /* next set own bit for the adapter and copy over command word */
2215 mb->mbxOwner = OWN_CHIP;
2217 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2218 /* First copy command data to host SLIM area */
2219 lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx, MAILBOX_CMD_SIZE);
2221 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2222 /* copy command data into host mbox for cmpl */
2223 lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx,
2227 /* First copy mbox command data to HBA SLIM, skip past first
2229 to_slim = phba->MBslimaddr + sizeof (uint32_t);
2230 lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
2231 MAILBOX_CMD_SIZE - sizeof (uint32_t));
2233 /* Next copy over first word, with mbxOwner set */
2234 ldata = *((volatile uint32_t *)mb);
2235 to_slim = phba->MBslimaddr;
2236 writel(ldata, to_slim);
2237 readl(to_slim); /* flush */
2239 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2240 /* switch over to host mailbox */
2241 psli->sli_flag |= LPFC_SLI2_ACTIVE;
2246 /* interrupt board to doit right away */
2247 writel(CA_MBATT, phba->CAregaddr);
2248 readl(phba->CAregaddr); /* flush */
2252 /* Don't wait for it to finish, just return */
2253 psli->mbox_active = pmbox;
2257 psli->mbox_active = NULL;
2258 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2259 /* First read mbox status word */
2260 word0 = *((volatile uint32_t *)&phba->slim2p->mbx);
2261 word0 = le32_to_cpu(word0);
2263 /* First read mbox status word */
2264 word0 = readl(phba->MBslimaddr);
2267 /* Read the HBA Host Attention Register */
2268 ha_copy = readl(phba->HAregaddr);
2270 i = lpfc_mbox_tmo_val(phba, mb->mbxCommand);
2271 i *= 1000; /* Convert to ms */
2273 /* Wait for command to complete */
2274 while (((word0 & OWN_CHIP) == OWN_CHIP) ||
2275 (!(ha_copy & HA_MBATT) &&
2276 (phba->hba_state > LPFC_WARM_START))) {
2278 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2279 spin_unlock_irqrestore(phba->host->host_lock,
2281 return (MBX_NOT_FINISHED);
2284 /* Check if we took a mbox interrupt while we were
2286 if (((word0 & OWN_CHIP) != OWN_CHIP)
2287 && (evtctr != psli->slistat.mbox_event))
2290 spin_unlock_irqrestore(phba->host->host_lock,
2295 spin_lock_irqsave(phba->host->host_lock, drvr_flag);
2297 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2298 /* First copy command data */
2299 word0 = *((volatile uint32_t *)
2300 &phba->slim2p->mbx);
2301 word0 = le32_to_cpu(word0);
2302 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2304 volatile uint32_t slimword0;
2305 /* Check real SLIM for any errors */
2306 slimword0 = readl(phba->MBslimaddr);
2307 slimmb = (MAILBOX_t *) & slimword0;
2308 if (((slimword0 & OWN_CHIP) != OWN_CHIP)
2309 && slimmb->mbxStatus) {
2316 /* First copy command data */
2317 word0 = readl(phba->MBslimaddr);
2319 /* Read the HBA Host Attention Register */
2320 ha_copy = readl(phba->HAregaddr);
2323 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2324 /* copy results back to user */
2325 lpfc_sli_pcimem_bcopy(&phba->slim2p->mbx, mb,
2328 /* First copy command data */
2329 lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
2331 if ((mb->mbxCommand == MBX_DUMP_MEMORY) &&
2333 lpfc_memcpy_from_slim((void *)pmbox->context2,
2334 phba->MBslimaddr + DMP_RSP_OFFSET,
2335 mb->un.varDmp.word_cnt);
2339 writel(HA_MBATT, phba->HAregaddr);
2340 readl(phba->HAregaddr); /* flush */
2342 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2343 status = mb->mbxStatus;
2346 spin_unlock_irqrestore(phba->host->host_lock, drvr_flag);
2351 lpfc_sli_ringtx_put(struct lpfc_hba * phba, struct lpfc_sli_ring * pring,
2352 struct lpfc_iocbq * piocb)
2354 /* Insert the caller's iocb in the txq tail for later processing. */
2355 list_add_tail(&piocb->list, &pring->txq);
2360 static struct lpfc_iocbq *
2361 lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2362 struct lpfc_iocbq ** piocb)
2364 struct lpfc_iocbq * nextiocb;
2366 nextiocb = lpfc_sli_ringtx_get(phba, pring);
2376 lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2377 struct lpfc_iocbq *piocb, uint32_t flag)
2379 struct lpfc_iocbq *nextiocb;
2382 /* If the PCI channel is in offline state, do not post iocbs. */
2383 if (unlikely(pci_channel_offline(phba->pcidev)))
2387 * We should never get an IOCB if we are in a < LINK_DOWN state
2389 if (unlikely(phba->hba_state < LPFC_LINK_DOWN))
2393 * Check to see if we are blocking IOCB processing because of a
2394 * outstanding mbox command.
2396 if (unlikely(pring->flag & LPFC_STOP_IOCB_MBX))
2399 if (unlikely(phba->hba_state == LPFC_LINK_DOWN)) {
2401 * Only CREATE_XRI, CLOSE_XRI, ABORT_XRI, and QUE_RING_BUF
2402 * can be issued if the link is not up.
2404 switch (piocb->iocb.ulpCommand) {
2405 case CMD_QUE_RING_BUF_CN:
2406 case CMD_QUE_RING_BUF64_CN:
2408 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
2409 * completion, iocb_cmpl MUST be 0.
2411 if (piocb->iocb_cmpl)
2412 piocb->iocb_cmpl = NULL;
2414 case CMD_CREATE_XRI_CR:
2421 * For FCP commands, we must be in a state where we can process link
2424 } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
2425 !(phba->sli.sli_flag & LPFC_PROCESS_LA)))
2428 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
2429 (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
2430 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
2433 lpfc_sli_update_ring(phba, pring);
2435 lpfc_sli_update_full_ring(phba, pring);
2438 return IOCB_SUCCESS;
2443 pring->stats.iocb_cmd_delay++;
2447 if (!(flag & SLI_IOCB_RET_IOCB)) {
2448 lpfc_sli_ringtx_put(phba, pring, piocb);
2449 return IOCB_SUCCESS;
2456 lpfc_extra_ring_setup( struct lpfc_hba *phba)
2458 struct lpfc_sli *psli;
2459 struct lpfc_sli_ring *pring;
2463 /* Adjust cmd/rsp ring iocb entries more evenly */
2465 /* Take some away from the FCP ring */
2466 pring = &psli->ring[psli->fcp_ring];
2467 pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
2468 pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
2469 pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
2470 pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
2472 /* and give them to the extra ring */
2473 pring = &psli->ring[psli->extra_ring];
2475 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
2476 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
2477 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
2478 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
2480 /* Setup default profile for this ring */
2481 pring->iotag_max = 4096;
2482 pring->num_mask = 1;
2483 pring->prt[0].profile = 0; /* Mask 0 */
2484 pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
2485 pring->prt[0].type = phba->cfg_multi_ring_type;
2486 pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
2491 lpfc_sli_setup(struct lpfc_hba *phba)
2494 struct lpfc_sli *psli = &phba->sli;
2495 struct lpfc_sli_ring *pring;
2497 psli->num_rings = MAX_CONFIGURED_RINGS;
2499 psli->fcp_ring = LPFC_FCP_RING;
2500 psli->next_ring = LPFC_FCP_NEXT_RING;
2501 psli->extra_ring = LPFC_EXTRA_RING;
2503 psli->iocbq_lookup = NULL;
2504 psli->iocbq_lookup_len = 0;
2505 psli->last_iotag = 0;
2507 for (i = 0; i < psli->num_rings; i++) {
2508 pring = &psli->ring[i];
2510 case LPFC_FCP_RING: /* ring 0 - FCP */
2511 /* numCiocb and numRiocb are used in config_port */
2512 pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
2513 pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
2514 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
2515 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
2516 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
2517 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
2518 pring->iotag_ctr = 0;
2520 (phba->cfg_hba_queue_depth * 2);
2521 pring->fast_iotag = pring->iotag_max;
2522 pring->num_mask = 0;
2524 case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
2525 /* numCiocb and numRiocb are used in config_port */
2526 pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
2527 pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
2528 pring->num_mask = 0;
2530 case LPFC_ELS_RING: /* ring 2 - ELS / CT */
2531 /* numCiocb and numRiocb are used in config_port */
2532 pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
2533 pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
2534 pring->fast_iotag = 0;
2535 pring->iotag_ctr = 0;
2536 pring->iotag_max = 4096;
2537 pring->num_mask = 4;
2538 pring->prt[0].profile = 0; /* Mask 0 */
2539 pring->prt[0].rctl = FC_ELS_REQ;
2540 pring->prt[0].type = FC_ELS_DATA;
2541 pring->prt[0].lpfc_sli_rcv_unsol_event =
2542 lpfc_els_unsol_event;
2543 pring->prt[1].profile = 0; /* Mask 1 */
2544 pring->prt[1].rctl = FC_ELS_RSP;
2545 pring->prt[1].type = FC_ELS_DATA;
2546 pring->prt[1].lpfc_sli_rcv_unsol_event =
2547 lpfc_els_unsol_event;
2548 pring->prt[2].profile = 0; /* Mask 2 */
2549 /* NameServer Inquiry */
2550 pring->prt[2].rctl = FC_UNSOL_CTL;
2552 pring->prt[2].type = FC_COMMON_TRANSPORT_ULP;
2553 pring->prt[2].lpfc_sli_rcv_unsol_event =
2554 lpfc_ct_unsol_event;
2555 pring->prt[3].profile = 0; /* Mask 3 */
2556 /* NameServer response */
2557 pring->prt[3].rctl = FC_SOL_CTL;
2559 pring->prt[3].type = FC_COMMON_TRANSPORT_ULP;
2560 pring->prt[3].lpfc_sli_rcv_unsol_event =
2561 lpfc_ct_unsol_event;
2564 totiocb += (pring->numCiocb + pring->numRiocb);
2566 if (totiocb > MAX_SLI2_IOCB) {
2567 /* Too many cmd / rsp ring entries in SLI2 SLIM */
2568 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2569 "%d:0462 Too many cmd / rsp ring entries in "
2570 "SLI2 SLIM Data: x%x x%x\n",
2571 phba->brd_no, totiocb, MAX_SLI2_IOCB);
2573 if (phba->cfg_multi_ring_support == 2)
2574 lpfc_extra_ring_setup(phba);
2580 lpfc_sli_queue_setup(struct lpfc_hba * phba)
2582 struct lpfc_sli *psli;
2583 struct lpfc_sli_ring *pring;
2587 spin_lock_irq(phba->host->host_lock);
2588 INIT_LIST_HEAD(&psli->mboxq);
2589 /* Initialize list headers for txq and txcmplq as double linked lists */
2590 for (i = 0; i < psli->num_rings; i++) {
2591 pring = &psli->ring[i];
2593 pring->next_cmdidx = 0;
2594 pring->local_getidx = 0;
2596 INIT_LIST_HEAD(&pring->txq);
2597 INIT_LIST_HEAD(&pring->txcmplq);
2598 INIT_LIST_HEAD(&pring->iocb_continueq);
2599 INIT_LIST_HEAD(&pring->postbufq);
2601 spin_unlock_irq(phba->host->host_lock);
2606 lpfc_sli_hba_down(struct lpfc_hba * phba)
2608 struct lpfc_sli *psli;
2609 struct lpfc_sli_ring *pring;
2611 struct lpfc_iocbq *iocb, *next_iocb;
2612 IOCB_t *icmd = NULL;
2614 unsigned long flags = 0;
2617 lpfc_hba_down_prep(phba);
2619 spin_lock_irqsave(phba->host->host_lock, flags);
2621 for (i = 0; i < psli->num_rings; i++) {
2622 pring = &psli->ring[i];
2623 pring->flag |= LPFC_DEFERRED_RING_EVENT;
2626 * Error everything on the txq since these iocbs have not been
2627 * given to the FW yet.
2631 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
2632 list_del_init(&iocb->list);
2633 if (iocb->iocb_cmpl) {
2635 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2636 icmd->un.ulpWord[4] = IOERR_SLI_DOWN;
2637 spin_unlock_irqrestore(phba->host->host_lock,
2639 (iocb->iocb_cmpl) (phba, iocb, iocb);
2640 spin_lock_irqsave(phba->host->host_lock, flags);
2642 lpfc_sli_release_iocbq(phba, iocb);
2645 INIT_LIST_HEAD(&(pring->txq));
2649 spin_unlock_irqrestore(phba->host->host_lock, flags);
2651 /* Return any active mbox cmds */
2652 del_timer_sync(&psli->mbox_tmo);
2653 spin_lock_irqsave(phba->host->host_lock, flags);
2654 phba->work_hba_events &= ~WORKER_MBOX_TMO;
2655 if (psli->mbox_active) {
2656 pmb = psli->mbox_active;
2657 pmb->mb.mbxStatus = MBX_NOT_FINISHED;
2658 if (pmb->mbox_cmpl) {
2659 spin_unlock_irqrestore(phba->host->host_lock, flags);
2660 pmb->mbox_cmpl(phba,pmb);
2661 spin_lock_irqsave(phba->host->host_lock, flags);
2664 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2665 psli->mbox_active = NULL;
2667 /* Return any pending mbox cmds */
2668 while ((pmb = lpfc_mbox_get(phba)) != NULL) {
2669 pmb->mb.mbxStatus = MBX_NOT_FINISHED;
2670 if (pmb->mbox_cmpl) {
2671 spin_unlock_irqrestore(phba->host->host_lock, flags);
2672 pmb->mbox_cmpl(phba,pmb);
2673 spin_lock_irqsave(phba->host->host_lock, flags);
2677 INIT_LIST_HEAD(&psli->mboxq);
2679 spin_unlock_irqrestore(phba->host->host_lock, flags);
2685 lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
2687 uint32_t *src = srcp;
2688 uint32_t *dest = destp;
2692 for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
2694 ldata = le32_to_cpu(ldata);
2702 lpfc_sli_ringpostbuf_put(struct lpfc_hba * phba, struct lpfc_sli_ring * pring,
2703 struct lpfc_dmabuf * mp)
2705 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
2707 list_add_tail(&mp->list, &pring->postbufq);
2709 pring->postbufq_cnt++;
2714 struct lpfc_dmabuf *
2715 lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2718 struct lpfc_dmabuf *mp, *next_mp;
2719 struct list_head *slp = &pring->postbufq;
2721 /* Search postbufq, from the begining, looking for a match on phys */
2722 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
2723 if (mp->phys == phys) {
2724 list_del_init(&mp->list);
2725 pring->postbufq_cnt--;
2730 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2731 "%d:0410 Cannot find virtual addr for mapped buf on "
2732 "ring %d Data x%llx x%p x%p x%x\n",
2733 phba->brd_no, pring->ringno, (unsigned long long)phys,
2734 slp->next, slp->prev, pring->postbufq_cnt);
2739 lpfc_sli_abort_els_cmpl(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2740 struct lpfc_iocbq * rspiocb)
2742 spin_lock_irq(phba->host->host_lock);
2743 lpfc_sli_release_iocbq(phba, cmdiocb);
2744 spin_unlock_irq(phba->host->host_lock);
2749 lpfc_sli_issue_abort_iotag(struct lpfc_hba * phba,
2750 struct lpfc_sli_ring * pring,
2751 struct lpfc_iocbq * cmdiocb)
2753 struct lpfc_iocbq *abtsiocbp;
2754 IOCB_t *icmd = NULL;
2755 IOCB_t *iabt = NULL;
2756 int retval = IOCB_ERROR;
2758 /* There are certain command types we don't want
2761 icmd = &cmdiocb->iocb;
2762 if ((icmd->ulpCommand == CMD_ABORT_XRI_CN) ||
2763 (icmd->ulpCommand == CMD_CLOSE_XRI_CN))
2766 /* If we're unloading, interrupts are disabled so we
2767 * need to cleanup the iocb here.
2769 if (phba->fc_flag & FC_UNLOADING)
2770 goto abort_iotag_exit;
2772 /* issue ABTS for this IOCB based on iotag */
2773 abtsiocbp = lpfc_sli_get_iocbq(phba);
2774 if (abtsiocbp == NULL)
2777 /* This signals the response to set the correct status
2778 * before calling the completion handler.
2780 cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
2782 iabt = &abtsiocbp->iocb;
2783 iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
2784 iabt->un.acxri.abortContextTag = icmd->ulpContext;
2785 iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
2787 iabt->ulpClass = icmd->ulpClass;
2789 if (phba->hba_state >= LPFC_LINK_UP)
2790 iabt->ulpCommand = CMD_ABORT_XRI_CN;
2792 iabt->ulpCommand = CMD_CLOSE_XRI_CN;
2794 abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
2795 retval = lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0);
2799 /* If we could not issue an abort dequeue the iocb and handle
2800 * the completion here.
2802 if (retval == IOCB_ERROR) {
2803 list_del(&cmdiocb->list);
2804 pring->txcmplq_cnt--;
2806 if (cmdiocb->iocb_cmpl) {
2807 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2808 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
2809 spin_unlock_irq(phba->host->host_lock);
2810 (cmdiocb->iocb_cmpl) (phba, cmdiocb, cmdiocb);
2811 spin_lock_irq(phba->host->host_lock);
2813 lpfc_sli_release_iocbq(phba, cmdiocb);
2820 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, uint16_t tgt_id,
2821 uint64_t lun_id, uint32_t ctx,
2822 lpfc_ctx_cmd ctx_cmd)
2824 struct lpfc_scsi_buf *lpfc_cmd;
2825 struct scsi_cmnd *cmnd;
2828 if (!(iocbq->iocb_flag & LPFC_IO_FCP))
2831 lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
2832 cmnd = lpfc_cmd->pCmd;
2839 if ((cmnd->device->id == tgt_id) &&
2840 (cmnd->device->lun == lun_id))
2844 if (cmnd->device->id == tgt_id)
2848 if (iocbq->iocb.ulpContext == ctx)
2855 printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
2856 __FUNCTION__, ctx_cmd);
2864 lpfc_sli_sum_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2865 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd ctx_cmd)
2867 struct lpfc_iocbq *iocbq;
2870 for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
2871 iocbq = phba->sli.iocbq_lookup[i];
2873 if (lpfc_sli_validate_fcp_iocb (iocbq, tgt_id, lun_id,
2882 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2883 struct lpfc_iocbq * rspiocb)
2885 spin_lock_irq(phba->host->host_lock);
2886 lpfc_sli_release_iocbq(phba, cmdiocb);
2887 spin_unlock_irq(phba->host->host_lock);
2892 lpfc_sli_abort_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2893 uint16_t tgt_id, uint64_t lun_id, uint32_t ctx,
2894 lpfc_ctx_cmd abort_cmd)
2896 struct lpfc_iocbq *iocbq;
2897 struct lpfc_iocbq *abtsiocb;
2899 int errcnt = 0, ret_val = 0;
2902 for (i = 1; i <= phba->sli.last_iotag; i++) {
2903 iocbq = phba->sli.iocbq_lookup[i];
2905 if (lpfc_sli_validate_fcp_iocb (iocbq, tgt_id, lun_id,
2909 /* issue ABTS for this IOCB based on iotag */
2910 abtsiocb = lpfc_sli_get_iocbq(phba);
2911 if (abtsiocb == NULL) {
2917 abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
2918 abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
2919 abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
2920 abtsiocb->iocb.ulpLe = 1;
2921 abtsiocb->iocb.ulpClass = cmd->ulpClass;
2923 if (phba->hba_state >= LPFC_LINK_UP)
2924 abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
2926 abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
2928 /* Setup callback routine and issue the command. */
2929 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
2930 ret_val = lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0);
2931 if (ret_val == IOCB_ERROR) {
2932 lpfc_sli_release_iocbq(phba, abtsiocb);
2942 lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
2943 struct lpfc_iocbq *cmdiocbq,
2944 struct lpfc_iocbq *rspiocbq)
2946 wait_queue_head_t *pdone_q;
2947 unsigned long iflags;
2949 spin_lock_irqsave(phba->host->host_lock, iflags);
2950 cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
2951 if (cmdiocbq->context2 && rspiocbq)
2952 memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
2953 &rspiocbq->iocb, sizeof(IOCB_t));
2955 pdone_q = cmdiocbq->context_un.wait_queue;
2956 spin_unlock_irqrestore(phba->host->host_lock, iflags);
2963 * Issue the caller's iocb and wait for its completion, but no longer than the
2964 * caller's timeout. Note that iocb_flags is cleared before the
2965 * lpfc_sli_issue_call since the wake routine sets a unique value and by
2966 * definition this is a wait function.
2969 lpfc_sli_issue_iocb_wait(struct lpfc_hba * phba,
2970 struct lpfc_sli_ring * pring,
2971 struct lpfc_iocbq * piocb,
2972 struct lpfc_iocbq * prspiocbq,
2975 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
2976 long timeleft, timeout_req = 0;
2977 int retval = IOCB_SUCCESS;
2981 * If the caller has provided a response iocbq buffer, then context2
2982 * is NULL or its an error.
2985 if (piocb->context2)
2987 piocb->context2 = prspiocbq;
2990 piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
2991 piocb->context_un.wait_queue = &done_q;
2992 piocb->iocb_flag &= ~LPFC_IO_WAKE;
2994 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
2995 creg_val = readl(phba->HCregaddr);
2996 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
2997 writel(creg_val, phba->HCregaddr);
2998 readl(phba->HCregaddr); /* flush */
3001 retval = lpfc_sli_issue_iocb(phba, pring, piocb, 0);
3002 if (retval == IOCB_SUCCESS) {
3003 timeout_req = timeout * HZ;
3004 spin_unlock_irq(phba->host->host_lock);
3005 timeleft = wait_event_timeout(done_q,
3006 piocb->iocb_flag & LPFC_IO_WAKE,
3008 spin_lock_irq(phba->host->host_lock);
3010 if (timeleft == 0) {
3011 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3012 "%d:0338 IOCB wait timeout error - no "
3013 "wake response Data x%x\n",
3014 phba->brd_no, timeout);
3015 retval = IOCB_TIMEDOUT;
3016 } else if (!(piocb->iocb_flag & LPFC_IO_WAKE)) {
3017 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3018 "%d:0330 IOCB wake NOT set, "
3019 "Data x%x x%lx\n", phba->brd_no,
3020 timeout, (timeleft / jiffies));
3021 retval = IOCB_TIMEDOUT;
3023 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3024 "%d:0331 IOCB wake signaled\n",
3028 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3029 "%d:0332 IOCB wait issue failed, Data x%x\n",
3030 phba->brd_no, retval);
3031 retval = IOCB_ERROR;
3034 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
3035 creg_val = readl(phba->HCregaddr);
3036 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
3037 writel(creg_val, phba->HCregaddr);
3038 readl(phba->HCregaddr); /* flush */
3042 piocb->context2 = NULL;
3044 piocb->context_un.wait_queue = NULL;
3045 piocb->iocb_cmpl = NULL;
3050 lpfc_sli_issue_mbox_wait(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq,
3053 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
3054 DECLARE_WAITQUEUE(wq_entry, current);
3055 uint32_t timeleft = 0;
3058 /* The caller must leave context1 empty. */
3059 if (pmboxq->context1 != 0) {
3060 return (MBX_NOT_FINISHED);
3063 /* setup wake call as IOCB callback */
3064 pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
3065 /* setup context field to pass wait_queue pointer to wake function */
3066 pmboxq->context1 = &done_q;
3068 /* start to sleep before we wait, to avoid races */
3069 set_current_state(TASK_INTERRUPTIBLE);
3070 add_wait_queue(&done_q, &wq_entry);
3072 /* now issue the command */
3073 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
3075 if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
3076 timeleft = schedule_timeout(timeout * HZ);
3077 pmboxq->context1 = NULL;
3078 /* if schedule_timeout returns 0, we timed out and were not
3080 if ((timeleft == 0) || signal_pending(current))
3081 retval = MBX_TIMEOUT;
3083 retval = MBX_SUCCESS;
3087 set_current_state(TASK_RUNNING);
3088 remove_wait_queue(&done_q, &wq_entry);
3093 lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba)
3097 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE && !phba->stopped) {
3098 if (i++ > LPFC_MBOX_TMO * 1000)
3101 if (lpfc_sli_handle_mb_event(phba) == 0)
3107 return (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) ? 1 : 0;
3111 lpfc_intr_handler(int irq, void *dev_id)
3113 struct lpfc_hba *phba;
3115 uint32_t work_ha_copy;
3116 unsigned long status;
3121 * Get the driver's phba structure from the dev_id and
3122 * assume the HBA is not interrupting.
3124 phba = (struct lpfc_hba *) dev_id;
3126 if (unlikely(!phba))
3129 /* If the pci channel is offline, ignore all the interrupts. */
3130 if (unlikely(pci_channel_offline(phba->pcidev)))
3133 phba->sli.slistat.sli_intr++;
3136 * Call the HBA to see if it is interrupting. If not, don't claim
3140 /* Ignore all interrupts during initialization. */
3141 if (unlikely(phba->hba_state < LPFC_LINK_DOWN))
3145 * Read host attention register to determine interrupt source
3146 * Clear Attention Sources, except Error Attention (to
3147 * preserve status) and Link Attention
3149 spin_lock(phba->host->host_lock);
3150 ha_copy = readl(phba->HAregaddr);
3151 writel((ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
3152 readl(phba->HAregaddr); /* flush */
3153 spin_unlock(phba->host->host_lock);
3155 if (unlikely(!ha_copy))
3158 work_ha_copy = ha_copy & phba->work_ha_mask;
3160 if (unlikely(work_ha_copy)) {
3161 if (work_ha_copy & HA_LATT) {
3162 if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
3164 * Turn off Link Attention interrupts
3165 * until CLEAR_LA done
3167 spin_lock(phba->host->host_lock);
3168 phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
3169 control = readl(phba->HCregaddr);
3170 control &= ~HC_LAINT_ENA;
3171 writel(control, phba->HCregaddr);
3172 readl(phba->HCregaddr); /* flush */
3173 spin_unlock(phba->host->host_lock);
3176 work_ha_copy &= ~HA_LATT;
3179 if (work_ha_copy & ~(HA_ERATT|HA_MBATT|HA_LATT)) {
3180 for (i = 0; i < phba->sli.num_rings; i++) {
3181 if (work_ha_copy & (HA_RXATT << (4*i))) {
3183 * Turn off Slow Rings interrupts
3185 spin_lock(phba->host->host_lock);
3186 control = readl(phba->HCregaddr);
3187 control &= ~(HC_R0INT_ENA << i);
3188 writel(control, phba->HCregaddr);
3189 readl(phba->HCregaddr); /* flush */
3190 spin_unlock(phba->host->host_lock);
3195 if (work_ha_copy & HA_ERATT) {
3196 phba->hba_state = LPFC_HBA_ERROR;
3198 * There was a link/board error. Read the
3199 * status register to retrieve the error event
3202 phba->sli.slistat.err_attn_event++;
3203 /* Save status info */
3204 phba->work_hs = readl(phba->HSregaddr);
3205 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
3206 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
3208 /* Clear Chip error bit */
3209 writel(HA_ERATT, phba->HAregaddr);
3210 readl(phba->HAregaddr); /* flush */
3214 spin_lock(phba->host->host_lock);
3215 phba->work_ha |= work_ha_copy;
3216 if (phba->work_wait)
3217 wake_up(phba->work_wait);
3218 spin_unlock(phba->host->host_lock);
3221 ha_copy &= ~(phba->work_ha_mask);
3224 * Process all events on FCP ring. Take the optimized path for
3225 * FCP IO. Any other IO is slow path and is handled by
3226 * the worker thread.
3228 status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
3229 status >>= (4*LPFC_FCP_RING);
3230 if (status & HA_RXATT)
3231 lpfc_sli_handle_fast_ring_event(phba,
3232 &phba->sli.ring[LPFC_FCP_RING],
3235 if (phba->cfg_multi_ring_support == 2) {
3237 * Process all events on extra ring. Take the optimized path
3238 * for extra ring IO. Any other IO is slow path and is handled
3239 * by the worker thread.
3241 status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
3242 status >>= (4*LPFC_EXTRA_RING);
3243 if (status & HA_RXATT) {
3244 lpfc_sli_handle_fast_ring_event(phba,
3245 &phba->sli.ring[LPFC_EXTRA_RING],
3251 } /* lpfc_intr_handler */