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 LIST_HEAD(completions);
1459 struct lpfc_iocbq *iocb, *next_iocb;
1465 /* Error everything on txq and txcmplq
1468 spin_lock_irq(phba->host->host_lock);
1469 list_splice_init(&pring->txq, &completions);
1472 /* Next issue ABTS for everything on the txcmplq */
1473 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
1474 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1476 spin_unlock_irq(phba->host->host_lock);
1478 while (!list_empty(&completions)) {
1479 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
1481 list_del(&iocb->list);
1483 if (iocb->iocb_cmpl) {
1484 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
1485 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
1486 (iocb->iocb_cmpl) (phba, iocb, iocb);
1488 lpfc_sli_release_iocbq(phba, iocb);
1495 lpfc_sli_brdready(struct lpfc_hba * phba, uint32_t mask)
1501 /* Read the HBA Host Status Register */
1502 status = readl(phba->HSregaddr);
1505 * Check status register every 100ms for 5 retries, then every
1506 * 500ms for 5, then every 2.5 sec for 5, then reset board and
1507 * every 2.5 sec for 4.
1508 * Break our of the loop if errors occurred during init.
1510 while (((status & mask) != mask) &&
1511 !(status & HS_FFERM) &&
1522 phba->hba_state = LPFC_STATE_UNKNOWN; /* Do post */
1523 lpfc_sli_brdrestart(phba);
1525 /* Read the HBA Host Status Register */
1526 status = readl(phba->HSregaddr);
1529 /* Check to see if any errors occurred during init */
1530 if ((status & HS_FFERM) || (i >= 20)) {
1531 phba->hba_state = LPFC_HBA_ERROR;
1538 #define BARRIER_TEST_PATTERN (0xdeadbeef)
1540 void lpfc_reset_barrier(struct lpfc_hba * phba)
1542 uint32_t __iomem *resp_buf;
1543 uint32_t __iomem *mbox_buf;
1544 volatile uint32_t mbox;
1549 pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
1550 if (hdrtype != 0x80 ||
1551 (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
1552 FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
1556 * Tell the other part of the chip to suspend temporarily all
1559 resp_buf = phba->MBslimaddr;
1561 /* Disable the error attention */
1562 hc_copy = readl(phba->HCregaddr);
1563 writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
1564 readl(phba->HCregaddr); /* flush */
1566 if (readl(phba->HAregaddr) & HA_ERATT) {
1567 /* Clear Chip error bit */
1568 writel(HA_ERATT, phba->HAregaddr);
1573 ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
1574 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
1576 writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
1577 mbox_buf = phba->MBslimaddr;
1578 writel(mbox, mbox_buf);
1581 readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
1584 if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
1585 if (phba->sli.sli_flag & LPFC_SLI2_ACTIVE ||
1592 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
1593 for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
1598 while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
1601 if (readl(phba->HAregaddr) & HA_ERATT) {
1602 writel(HA_ERATT, phba->HAregaddr);
1607 writel(hc_copy, phba->HCregaddr);
1608 readl(phba->HCregaddr); /* flush */
1612 lpfc_sli_brdkill(struct lpfc_hba * phba)
1614 struct lpfc_sli *psli;
1624 lpfc_printf_log(phba,
1627 "%d:0329 Kill HBA Data: x%x x%x\n",
1632 if ((pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
1636 /* Disable the error attention */
1637 spin_lock_irq(phba->host->host_lock);
1638 status = readl(phba->HCregaddr);
1639 status &= ~HC_ERINT_ENA;
1640 writel(status, phba->HCregaddr);
1641 readl(phba->HCregaddr); /* flush */
1642 spin_unlock_irq(phba->host->host_lock);
1644 lpfc_kill_board(phba, pmb);
1645 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1646 retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
1648 if (retval != MBX_SUCCESS) {
1649 if (retval != MBX_BUSY)
1650 mempool_free(pmb, phba->mbox_mem_pool);
1654 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
1656 mempool_free(pmb, phba->mbox_mem_pool);
1658 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
1659 * attention every 100ms for 3 seconds. If we don't get ERATT after
1660 * 3 seconds we still set HBA_ERROR state because the status of the
1661 * board is now undefined.
1663 ha_copy = readl(phba->HAregaddr);
1665 while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
1667 ha_copy = readl(phba->HAregaddr);
1670 del_timer_sync(&psli->mbox_tmo);
1671 if (ha_copy & HA_ERATT) {
1672 writel(HA_ERATT, phba->HAregaddr);
1675 spin_lock_irq(phba->host->host_lock);
1676 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
1677 spin_unlock_irq(phba->host->host_lock);
1679 psli->mbox_active = NULL;
1680 lpfc_hba_down_post(phba);
1681 phba->hba_state = LPFC_HBA_ERROR;
1683 return (ha_copy & HA_ERATT ? 0 : 1);
1687 lpfc_sli_brdreset(struct lpfc_hba * phba)
1689 struct lpfc_sli *psli;
1690 struct lpfc_sli_ring *pring;
1697 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1698 "%d:0325 Reset HBA Data: x%x x%x\n", phba->brd_no,
1699 phba->hba_state, psli->sli_flag);
1701 /* perform board reset */
1702 phba->fc_eventTag = 0;
1704 phba->fc_prevDID = 0;
1706 /* Turn off parity checking and serr during the physical reset */
1707 pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
1708 pci_write_config_word(phba->pcidev, PCI_COMMAND,
1710 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
1712 psli->sli_flag &= ~(LPFC_SLI2_ACTIVE | LPFC_PROCESS_LA);
1713 /* Now toggle INITFF bit in the Host Control Register */
1714 writel(HC_INITFF, phba->HCregaddr);
1716 readl(phba->HCregaddr); /* flush */
1717 writel(0, phba->HCregaddr);
1718 readl(phba->HCregaddr); /* flush */
1720 /* Restore PCI cmd register */
1721 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
1723 /* Initialize relevant SLI info */
1724 for (i = 0; i < psli->num_rings; i++) {
1725 pring = &psli->ring[i];
1728 pring->next_cmdidx = 0;
1729 pring->local_getidx = 0;
1731 pring->missbufcnt = 0;
1734 phba->hba_state = LPFC_WARM_START;
1739 lpfc_sli_brdrestart(struct lpfc_hba * phba)
1742 struct lpfc_sli *psli;
1744 volatile uint32_t word0;
1745 void __iomem *to_slim;
1747 spin_lock_irq(phba->host->host_lock);
1752 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1753 "%d:0337 Restart HBA Data: x%x x%x\n", phba->brd_no,
1754 phba->hba_state, psli->sli_flag);
1757 mb = (MAILBOX_t *) &word0;
1758 mb->mbxCommand = MBX_RESTART;
1761 lpfc_reset_barrier(phba);
1763 to_slim = phba->MBslimaddr;
1764 writel(*(uint32_t *) mb, to_slim);
1765 readl(to_slim); /* flush */
1767 /* Only skip post after fc_ffinit is completed */
1768 if (phba->hba_state) {
1770 word0 = 1; /* This is really setting up word1 */
1773 word0 = 0; /* This is really setting up word1 */
1775 to_slim = phba->MBslimaddr + sizeof (uint32_t);
1776 writel(*(uint32_t *) mb, to_slim);
1777 readl(to_slim); /* flush */
1779 lpfc_sli_brdreset(phba);
1781 phba->hba_state = LPFC_INIT_START;
1783 spin_unlock_irq(phba->host->host_lock);
1785 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
1786 psli->stats_start = get_seconds();
1793 lpfc_hba_down_post(phba);
1799 lpfc_sli_chipset_init(struct lpfc_hba *phba)
1801 uint32_t status, i = 0;
1803 /* Read the HBA Host Status Register */
1804 status = readl(phba->HSregaddr);
1806 /* Check status register to see what current state is */
1808 while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
1810 /* Check every 100ms for 5 retries, then every 500ms for 5, then
1811 * every 2.5 sec for 5, then reset board and every 2.5 sec for
1815 /* Adapter failed to init, timeout, status reg
1817 lpfc_printf_log(phba,
1820 "%d:0436 Adapter failed to init, "
1821 "timeout, status reg x%x\n",
1824 phba->hba_state = LPFC_HBA_ERROR;
1828 /* Check to see if any errors occurred during init */
1829 if (status & HS_FFERM) {
1830 /* ERROR: During chipset initialization */
1831 /* Adapter failed to init, chipset, status reg
1833 lpfc_printf_log(phba,
1836 "%d:0437 Adapter failed to init, "
1837 "chipset, status reg x%x\n",
1840 phba->hba_state = LPFC_HBA_ERROR;
1846 } else if (i <= 10) {
1853 phba->hba_state = LPFC_STATE_UNKNOWN; /* Do post */
1854 lpfc_sli_brdrestart(phba);
1856 /* Read the HBA Host Status Register */
1857 status = readl(phba->HSregaddr);
1860 /* Check to see if any errors occurred during init */
1861 if (status & HS_FFERM) {
1862 /* ERROR: During chipset initialization */
1863 /* Adapter failed to init, chipset, status reg <status> */
1864 lpfc_printf_log(phba,
1867 "%d:0438 Adapter failed to init, chipset, "
1871 phba->hba_state = LPFC_HBA_ERROR;
1875 /* Clear all interrupt enable conditions */
1876 writel(0, phba->HCregaddr);
1877 readl(phba->HCregaddr); /* flush */
1879 /* setup host attn register */
1880 writel(0xffffffff, phba->HAregaddr);
1881 readl(phba->HAregaddr); /* flush */
1886 lpfc_sli_hba_setup(struct lpfc_hba * phba)
1889 uint32_t resetcount = 0, rc = 0, done = 0;
1891 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1893 phba->hba_state = LPFC_HBA_ERROR;
1897 while (resetcount < 2 && !done) {
1898 spin_lock_irq(phba->host->host_lock);
1899 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
1900 spin_unlock_irq(phba->host->host_lock);
1901 phba->hba_state = LPFC_STATE_UNKNOWN;
1902 lpfc_sli_brdrestart(phba);
1904 rc = lpfc_sli_chipset_init(phba);
1908 spin_lock_irq(phba->host->host_lock);
1909 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
1910 spin_unlock_irq(phba->host->host_lock);
1913 /* Call pre CONFIG_PORT mailbox command initialization. A value of 0
1914 * means the call was successful. Any other nonzero value is a failure,
1915 * but if ERESTART is returned, the driver may reset the HBA and try
1918 rc = lpfc_config_port_prep(phba);
1919 if (rc == -ERESTART) {
1920 phba->hba_state = 0;
1926 phba->hba_state = LPFC_INIT_MBX_CMDS;
1927 lpfc_config_port(phba, pmb);
1928 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
1929 if (rc == MBX_SUCCESS)
1932 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1933 "%d:0442 Adapter failed to init, mbxCmd x%x "
1934 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
1935 phba->brd_no, pmb->mb.mbxCommand,
1936 pmb->mb.mbxStatus, 0);
1937 phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE;
1941 goto lpfc_sli_hba_setup_error;
1943 rc = lpfc_sli_ring_map(phba, pmb);
1946 goto lpfc_sli_hba_setup_error;
1948 phba->sli.sli_flag |= LPFC_PROCESS_LA;
1950 rc = lpfc_config_port_post(phba);
1952 goto lpfc_sli_hba_setup_error;
1954 goto lpfc_sli_hba_setup_exit;
1955 lpfc_sli_hba_setup_error:
1956 phba->hba_state = LPFC_HBA_ERROR;
1957 lpfc_sli_hba_setup_exit:
1958 mempool_free(pmb, phba->mbox_mem_pool);
1962 /*! lpfc_mbox_timeout
1966 * \param hba Pointer to per struct lpfc_hba structure
1967 * \param l1 Pointer to the driver's mailbox queue.
1973 * This routine handles mailbox timeout events at timer interrupt context.
1976 lpfc_mbox_timeout(unsigned long ptr)
1978 struct lpfc_hba *phba;
1979 unsigned long iflag;
1981 phba = (struct lpfc_hba *)ptr;
1982 spin_lock_irqsave(phba->host->host_lock, iflag);
1983 if (!(phba->work_hba_events & WORKER_MBOX_TMO)) {
1984 phba->work_hba_events |= WORKER_MBOX_TMO;
1985 if (phba->work_wait)
1986 wake_up(phba->work_wait);
1988 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1992 lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
1994 LPFC_MBOXQ_t *pmbox;
1996 struct lpfc_sli *psli = &phba->sli;
1997 struct lpfc_sli_ring *pring;
1999 spin_lock_irq(phba->host->host_lock);
2000 if (!(phba->work_hba_events & WORKER_MBOX_TMO)) {
2001 spin_unlock_irq(phba->host->host_lock);
2005 pmbox = phba->sli.mbox_active;
2008 /* Mbox cmd <mbxCommand> timeout */
2009 lpfc_printf_log(phba,
2012 "%d:0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
2017 phba->sli.mbox_active);
2019 /* Setting state unknown so lpfc_sli_abort_iocb_ring
2020 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
2021 * it to fail all oustanding SCSI IO.
2023 phba->hba_state = LPFC_STATE_UNKNOWN;
2024 phba->work_hba_events &= ~WORKER_MBOX_TMO;
2025 phba->fc_flag |= FC_ESTABLISH_LINK;
2026 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
2027 spin_unlock_irq(phba->host->host_lock);
2029 pring = &psli->ring[psli->fcp_ring];
2030 lpfc_sli_abort_iocb_ring(phba, pring);
2032 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
2033 "%d:0316 Resetting board due to mailbox timeout\n",
2036 * lpfc_offline calls lpfc_sli_hba_down which will clean up
2037 * on oustanding mailbox commands.
2039 lpfc_offline_prep(phba);
2041 lpfc_sli_brdrestart(phba);
2042 if (lpfc_online(phba) == 0) /* Initialize the HBA */
2043 mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
2044 lpfc_unblock_mgmt_io(phba);
2049 lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag)
2052 struct lpfc_sli *psli;
2053 uint32_t status, evtctr;
2056 unsigned long drvr_flag = 0;
2057 volatile uint32_t word0, ldata;
2058 void __iomem *to_slim;
2060 /* If the PCI channel is in offline state, do not post mbox. */
2061 if (unlikely(pci_channel_offline(phba->pcidev)))
2062 return MBX_NOT_FINISHED;
2066 spin_lock_irqsave(phba->host->host_lock, drvr_flag);
2070 status = MBX_SUCCESS;
2072 if (phba->hba_state == LPFC_HBA_ERROR) {
2073 spin_unlock_irqrestore(phba->host->host_lock, drvr_flag);
2075 /* Mbox command <mbxCommand> cannot issue */
2076 LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag)
2077 return (MBX_NOT_FINISHED);
2080 if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
2081 !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
2082 spin_unlock_irqrestore(phba->host->host_lock, drvr_flag);
2083 LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag)
2084 return (MBX_NOT_FINISHED);
2087 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
2088 /* Polling for a mbox command when another one is already active
2089 * is not allowed in SLI. Also, the driver must have established
2090 * SLI2 mode to queue and process multiple mbox commands.
2093 if (flag & MBX_POLL) {
2094 spin_unlock_irqrestore(phba->host->host_lock,
2097 /* Mbox command <mbxCommand> cannot issue */
2098 LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag)
2099 return (MBX_NOT_FINISHED);
2102 if (!(psli->sli_flag & LPFC_SLI2_ACTIVE)) {
2103 spin_unlock_irqrestore(phba->host->host_lock,
2105 /* Mbox command <mbxCommand> cannot issue */
2106 LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag)
2107 return (MBX_NOT_FINISHED);
2110 /* Handle STOP IOCB processing flag. This is only meaningful
2111 * if we are not polling for mbox completion.
2113 if (flag & MBX_STOP_IOCB) {
2114 flag &= ~MBX_STOP_IOCB;
2115 /* Now flag each ring */
2116 for (i = 0; i < psli->num_rings; i++) {
2117 /* If the ring is active, flag it */
2118 if (psli->ring[i].cmdringaddr) {
2119 psli->ring[i].flag |=
2125 /* Another mailbox command is still being processed, queue this
2126 * command to be processed later.
2128 lpfc_mbox_put(phba, pmbox);
2130 /* Mbox cmd issue - BUSY */
2131 lpfc_printf_log(phba,
2134 "%d:0308 Mbox cmd issue - BUSY Data: x%x x%x x%x x%x\n",
2141 psli->slistat.mbox_busy++;
2142 spin_unlock_irqrestore(phba->host->host_lock,
2148 /* Handle STOP IOCB processing flag. This is only meaningful
2149 * if we are not polling for mbox completion.
2151 if (flag & MBX_STOP_IOCB) {
2152 flag &= ~MBX_STOP_IOCB;
2153 if (flag == MBX_NOWAIT) {
2154 /* Now flag each ring */
2155 for (i = 0; i < psli->num_rings; i++) {
2156 /* If the ring is active, flag it */
2157 if (psli->ring[i].cmdringaddr) {
2158 psli->ring[i].flag |=
2165 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
2167 /* If we are not polling, we MUST be in SLI2 mode */
2168 if (flag != MBX_POLL) {
2169 if (!(psli->sli_flag & LPFC_SLI2_ACTIVE) &&
2170 (mb->mbxCommand != MBX_KILL_BOARD)) {
2171 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2172 spin_unlock_irqrestore(phba->host->host_lock,
2174 /* Mbox command <mbxCommand> cannot issue */
2175 LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag);
2176 return (MBX_NOT_FINISHED);
2178 /* timeout active mbox command */
2179 mod_timer(&psli->mbox_tmo, (jiffies +
2180 (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
2183 /* Mailbox cmd <cmd> issue */
2184 lpfc_printf_log(phba,
2187 "%d:0309 Mailbox cmd x%x issue Data: x%x x%x x%x\n",
2194 psli->slistat.mbox_cmd++;
2195 evtctr = psli->slistat.mbox_event;
2197 /* next set own bit for the adapter and copy over command word */
2198 mb->mbxOwner = OWN_CHIP;
2200 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2201 /* First copy command data to host SLIM area */
2202 lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx, MAILBOX_CMD_SIZE);
2204 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2205 /* copy command data into host mbox for cmpl */
2206 lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx,
2210 /* First copy mbox command data to HBA SLIM, skip past first
2212 to_slim = phba->MBslimaddr + sizeof (uint32_t);
2213 lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
2214 MAILBOX_CMD_SIZE - sizeof (uint32_t));
2216 /* Next copy over first word, with mbxOwner set */
2217 ldata = *((volatile uint32_t *)mb);
2218 to_slim = phba->MBslimaddr;
2219 writel(ldata, to_slim);
2220 readl(to_slim); /* flush */
2222 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2223 /* switch over to host mailbox */
2224 psli->sli_flag |= LPFC_SLI2_ACTIVE;
2229 /* interrupt board to doit right away */
2230 writel(CA_MBATT, phba->CAregaddr);
2231 readl(phba->CAregaddr); /* flush */
2235 /* Don't wait for it to finish, just return */
2236 psli->mbox_active = pmbox;
2240 psli->mbox_active = NULL;
2241 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2242 /* First read mbox status word */
2243 word0 = *((volatile uint32_t *)&phba->slim2p->mbx);
2244 word0 = le32_to_cpu(word0);
2246 /* First read mbox status word */
2247 word0 = readl(phba->MBslimaddr);
2250 /* Read the HBA Host Attention Register */
2251 ha_copy = readl(phba->HAregaddr);
2253 i = lpfc_mbox_tmo_val(phba, mb->mbxCommand);
2254 i *= 1000; /* Convert to ms */
2256 /* Wait for command to complete */
2257 while (((word0 & OWN_CHIP) == OWN_CHIP) ||
2258 (!(ha_copy & HA_MBATT) &&
2259 (phba->hba_state > LPFC_WARM_START))) {
2261 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2262 spin_unlock_irqrestore(phba->host->host_lock,
2264 return (MBX_NOT_FINISHED);
2267 /* Check if we took a mbox interrupt while we were
2269 if (((word0 & OWN_CHIP) != OWN_CHIP)
2270 && (evtctr != psli->slistat.mbox_event))
2273 spin_unlock_irqrestore(phba->host->host_lock,
2278 spin_lock_irqsave(phba->host->host_lock, drvr_flag);
2280 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2281 /* First copy command data */
2282 word0 = *((volatile uint32_t *)
2283 &phba->slim2p->mbx);
2284 word0 = le32_to_cpu(word0);
2285 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2287 volatile uint32_t slimword0;
2288 /* Check real SLIM for any errors */
2289 slimword0 = readl(phba->MBslimaddr);
2290 slimmb = (MAILBOX_t *) & slimword0;
2291 if (((slimword0 & OWN_CHIP) != OWN_CHIP)
2292 && slimmb->mbxStatus) {
2299 /* First copy command data */
2300 word0 = readl(phba->MBslimaddr);
2302 /* Read the HBA Host Attention Register */
2303 ha_copy = readl(phba->HAregaddr);
2306 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2307 /* copy results back to user */
2308 lpfc_sli_pcimem_bcopy(&phba->slim2p->mbx, mb,
2311 /* First copy command data */
2312 lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
2314 if ((mb->mbxCommand == MBX_DUMP_MEMORY) &&
2316 lpfc_memcpy_from_slim((void *)pmbox->context2,
2317 phba->MBslimaddr + DMP_RSP_OFFSET,
2318 mb->un.varDmp.word_cnt);
2322 writel(HA_MBATT, phba->HAregaddr);
2323 readl(phba->HAregaddr); /* flush */
2325 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2326 status = mb->mbxStatus;
2329 spin_unlock_irqrestore(phba->host->host_lock, drvr_flag);
2334 lpfc_sli_ringtx_put(struct lpfc_hba * phba, struct lpfc_sli_ring * pring,
2335 struct lpfc_iocbq * piocb)
2337 /* Insert the caller's iocb in the txq tail for later processing. */
2338 list_add_tail(&piocb->list, &pring->txq);
2343 static struct lpfc_iocbq *
2344 lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2345 struct lpfc_iocbq ** piocb)
2347 struct lpfc_iocbq * nextiocb;
2349 nextiocb = lpfc_sli_ringtx_get(phba, pring);
2359 lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2360 struct lpfc_iocbq *piocb, uint32_t flag)
2362 struct lpfc_iocbq *nextiocb;
2365 /* If the PCI channel is in offline state, do not post iocbs. */
2366 if (unlikely(pci_channel_offline(phba->pcidev)))
2370 * We should never get an IOCB if we are in a < LINK_DOWN state
2372 if (unlikely(phba->hba_state < LPFC_LINK_DOWN))
2376 * Check to see if we are blocking IOCB processing because of a
2377 * outstanding mbox command.
2379 if (unlikely(pring->flag & LPFC_STOP_IOCB_MBX))
2382 if (unlikely(phba->hba_state == LPFC_LINK_DOWN)) {
2384 * Only CREATE_XRI, CLOSE_XRI, ABORT_XRI, and QUE_RING_BUF
2385 * can be issued if the link is not up.
2387 switch (piocb->iocb.ulpCommand) {
2388 case CMD_QUE_RING_BUF_CN:
2389 case CMD_QUE_RING_BUF64_CN:
2391 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
2392 * completion, iocb_cmpl MUST be 0.
2394 if (piocb->iocb_cmpl)
2395 piocb->iocb_cmpl = NULL;
2397 case CMD_CREATE_XRI_CR:
2404 * For FCP commands, we must be in a state where we can process link
2407 } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
2408 !(phba->sli.sli_flag & LPFC_PROCESS_LA)))
2411 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
2412 (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
2413 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
2416 lpfc_sli_update_ring(phba, pring);
2418 lpfc_sli_update_full_ring(phba, pring);
2421 return IOCB_SUCCESS;
2426 pring->stats.iocb_cmd_delay++;
2430 if (!(flag & SLI_IOCB_RET_IOCB)) {
2431 lpfc_sli_ringtx_put(phba, pring, piocb);
2432 return IOCB_SUCCESS;
2439 lpfc_extra_ring_setup( struct lpfc_hba *phba)
2441 struct lpfc_sli *psli;
2442 struct lpfc_sli_ring *pring;
2446 /* Adjust cmd/rsp ring iocb entries more evenly */
2448 /* Take some away from the FCP ring */
2449 pring = &psli->ring[psli->fcp_ring];
2450 pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
2451 pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
2452 pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
2453 pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
2455 /* and give them to the extra ring */
2456 pring = &psli->ring[psli->extra_ring];
2458 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
2459 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
2460 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
2461 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
2463 /* Setup default profile for this ring */
2464 pring->iotag_max = 4096;
2465 pring->num_mask = 1;
2466 pring->prt[0].profile = 0; /* Mask 0 */
2467 pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
2468 pring->prt[0].type = phba->cfg_multi_ring_type;
2469 pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
2474 lpfc_sli_setup(struct lpfc_hba *phba)
2477 struct lpfc_sli *psli = &phba->sli;
2478 struct lpfc_sli_ring *pring;
2480 psli->num_rings = MAX_CONFIGURED_RINGS;
2482 psli->fcp_ring = LPFC_FCP_RING;
2483 psli->next_ring = LPFC_FCP_NEXT_RING;
2484 psli->extra_ring = LPFC_EXTRA_RING;
2486 psli->iocbq_lookup = NULL;
2487 psli->iocbq_lookup_len = 0;
2488 psli->last_iotag = 0;
2490 for (i = 0; i < psli->num_rings; i++) {
2491 pring = &psli->ring[i];
2493 case LPFC_FCP_RING: /* ring 0 - FCP */
2494 /* numCiocb and numRiocb are used in config_port */
2495 pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
2496 pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
2497 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
2498 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
2499 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
2500 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
2501 pring->iotag_ctr = 0;
2503 (phba->cfg_hba_queue_depth * 2);
2504 pring->fast_iotag = pring->iotag_max;
2505 pring->num_mask = 0;
2507 case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
2508 /* numCiocb and numRiocb are used in config_port */
2509 pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
2510 pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
2511 pring->num_mask = 0;
2513 case LPFC_ELS_RING: /* ring 2 - ELS / CT */
2514 /* numCiocb and numRiocb are used in config_port */
2515 pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
2516 pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
2517 pring->fast_iotag = 0;
2518 pring->iotag_ctr = 0;
2519 pring->iotag_max = 4096;
2520 pring->num_mask = 4;
2521 pring->prt[0].profile = 0; /* Mask 0 */
2522 pring->prt[0].rctl = FC_ELS_REQ;
2523 pring->prt[0].type = FC_ELS_DATA;
2524 pring->prt[0].lpfc_sli_rcv_unsol_event =
2525 lpfc_els_unsol_event;
2526 pring->prt[1].profile = 0; /* Mask 1 */
2527 pring->prt[1].rctl = FC_ELS_RSP;
2528 pring->prt[1].type = FC_ELS_DATA;
2529 pring->prt[1].lpfc_sli_rcv_unsol_event =
2530 lpfc_els_unsol_event;
2531 pring->prt[2].profile = 0; /* Mask 2 */
2532 /* NameServer Inquiry */
2533 pring->prt[2].rctl = FC_UNSOL_CTL;
2535 pring->prt[2].type = FC_COMMON_TRANSPORT_ULP;
2536 pring->prt[2].lpfc_sli_rcv_unsol_event =
2537 lpfc_ct_unsol_event;
2538 pring->prt[3].profile = 0; /* Mask 3 */
2539 /* NameServer response */
2540 pring->prt[3].rctl = FC_SOL_CTL;
2542 pring->prt[3].type = FC_COMMON_TRANSPORT_ULP;
2543 pring->prt[3].lpfc_sli_rcv_unsol_event =
2544 lpfc_ct_unsol_event;
2547 totiocb += (pring->numCiocb + pring->numRiocb);
2549 if (totiocb > MAX_SLI2_IOCB) {
2550 /* Too many cmd / rsp ring entries in SLI2 SLIM */
2551 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2552 "%d:0462 Too many cmd / rsp ring entries in "
2553 "SLI2 SLIM Data: x%x x%x\n",
2554 phba->brd_no, totiocb, MAX_SLI2_IOCB);
2556 if (phba->cfg_multi_ring_support == 2)
2557 lpfc_extra_ring_setup(phba);
2563 lpfc_sli_queue_setup(struct lpfc_hba * phba)
2565 struct lpfc_sli *psli;
2566 struct lpfc_sli_ring *pring;
2570 spin_lock_irq(phba->host->host_lock);
2571 INIT_LIST_HEAD(&psli->mboxq);
2572 /* Initialize list headers for txq and txcmplq as double linked lists */
2573 for (i = 0; i < psli->num_rings; i++) {
2574 pring = &psli->ring[i];
2576 pring->next_cmdidx = 0;
2577 pring->local_getidx = 0;
2579 INIT_LIST_HEAD(&pring->txq);
2580 INIT_LIST_HEAD(&pring->txcmplq);
2581 INIT_LIST_HEAD(&pring->iocb_continueq);
2582 INIT_LIST_HEAD(&pring->postbufq);
2584 spin_unlock_irq(phba->host->host_lock);
2589 lpfc_sli_hba_down(struct lpfc_hba * phba)
2591 LIST_HEAD(completions);
2592 struct lpfc_sli *psli;
2593 struct lpfc_sli_ring *pring;
2595 struct lpfc_iocbq *iocb;
2598 unsigned long flags = 0;
2601 lpfc_hba_down_prep(phba);
2603 spin_lock_irqsave(phba->host->host_lock, flags);
2604 for (i = 0; i < psli->num_rings; i++) {
2605 pring = &psli->ring[i];
2606 pring->flag |= LPFC_DEFERRED_RING_EVENT;
2609 * Error everything on the txq since these iocbs have not been
2610 * given to the FW yet.
2612 list_splice_init(&pring->txq, &completions);
2616 spin_unlock_irqrestore(phba->host->host_lock, flags);
2618 while (!list_empty(&completions)) {
2619 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
2621 list_del(&iocb->list);
2623 if (iocb->iocb_cmpl) {
2624 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2625 cmd->un.ulpWord[4] = IOERR_SLI_DOWN;
2626 (iocb->iocb_cmpl) (phba, iocb, iocb);
2628 lpfc_sli_release_iocbq(phba, iocb);
2631 /* Return any active mbox cmds */
2632 del_timer_sync(&psli->mbox_tmo);
2633 spin_lock_irqsave(phba->host->host_lock, flags);
2634 phba->work_hba_events &= ~WORKER_MBOX_TMO;
2635 if (psli->mbox_active) {
2636 pmb = psli->mbox_active;
2637 pmb->mb.mbxStatus = MBX_NOT_FINISHED;
2638 if (pmb->mbox_cmpl) {
2639 spin_unlock_irqrestore(phba->host->host_lock, flags);
2640 pmb->mbox_cmpl(phba,pmb);
2641 spin_lock_irqsave(phba->host->host_lock, flags);
2644 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2645 psli->mbox_active = NULL;
2647 /* Return any pending mbox cmds */
2648 while ((pmb = lpfc_mbox_get(phba)) != NULL) {
2649 pmb->mb.mbxStatus = MBX_NOT_FINISHED;
2650 if (pmb->mbox_cmpl) {
2651 spin_unlock_irqrestore(phba->host->host_lock, flags);
2652 pmb->mbox_cmpl(phba,pmb);
2653 spin_lock_irqsave(phba->host->host_lock, flags);
2657 INIT_LIST_HEAD(&psli->mboxq);
2659 spin_unlock_irqrestore(phba->host->host_lock, flags);
2665 lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
2667 uint32_t *src = srcp;
2668 uint32_t *dest = destp;
2672 for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
2674 ldata = le32_to_cpu(ldata);
2682 lpfc_sli_ringpostbuf_put(struct lpfc_hba * phba, struct lpfc_sli_ring * pring,
2683 struct lpfc_dmabuf * mp)
2685 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
2687 list_add_tail(&mp->list, &pring->postbufq);
2689 pring->postbufq_cnt++;
2694 struct lpfc_dmabuf *
2695 lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2698 struct lpfc_dmabuf *mp, *next_mp;
2699 struct list_head *slp = &pring->postbufq;
2701 /* Search postbufq, from the begining, looking for a match on phys */
2702 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
2703 if (mp->phys == phys) {
2704 list_del_init(&mp->list);
2705 pring->postbufq_cnt--;
2710 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2711 "%d:0410 Cannot find virtual addr for mapped buf on "
2712 "ring %d Data x%llx x%p x%p x%x\n",
2713 phba->brd_no, pring->ringno, (unsigned long long)phys,
2714 slp->next, slp->prev, pring->postbufq_cnt);
2719 lpfc_sli_abort_els_cmpl(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2720 struct lpfc_iocbq * rspiocb)
2722 spin_lock_irq(phba->host->host_lock);
2723 lpfc_sli_release_iocbq(phba, cmdiocb);
2724 spin_unlock_irq(phba->host->host_lock);
2729 lpfc_sli_issue_abort_iotag(struct lpfc_hba * phba,
2730 struct lpfc_sli_ring * pring,
2731 struct lpfc_iocbq * cmdiocb)
2733 struct lpfc_iocbq *abtsiocbp;
2734 IOCB_t *icmd = NULL;
2735 IOCB_t *iabt = NULL;
2736 int retval = IOCB_ERROR;
2738 /* There are certain command types we don't want
2741 icmd = &cmdiocb->iocb;
2742 if ((icmd->ulpCommand == CMD_ABORT_XRI_CN) ||
2743 (icmd->ulpCommand == CMD_CLOSE_XRI_CN))
2746 /* If we're unloading, interrupts are disabled so we
2747 * need to cleanup the iocb here.
2749 if (phba->fc_flag & FC_UNLOADING)
2750 goto abort_iotag_exit;
2752 /* issue ABTS for this IOCB based on iotag */
2753 abtsiocbp = lpfc_sli_get_iocbq(phba);
2754 if (abtsiocbp == NULL)
2757 /* This signals the response to set the correct status
2758 * before calling the completion handler.
2760 cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
2762 iabt = &abtsiocbp->iocb;
2763 iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
2764 iabt->un.acxri.abortContextTag = icmd->ulpContext;
2765 iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
2767 iabt->ulpClass = icmd->ulpClass;
2769 if (phba->hba_state >= LPFC_LINK_UP)
2770 iabt->ulpCommand = CMD_ABORT_XRI_CN;
2772 iabt->ulpCommand = CMD_CLOSE_XRI_CN;
2774 abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
2775 retval = lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0);
2779 /* If we could not issue an abort dequeue the iocb and handle
2780 * the completion here.
2782 if (retval == IOCB_ERROR) {
2783 list_del(&cmdiocb->list);
2784 pring->txcmplq_cnt--;
2786 if (cmdiocb->iocb_cmpl) {
2787 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2788 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
2789 spin_unlock_irq(phba->host->host_lock);
2790 (cmdiocb->iocb_cmpl) (phba, cmdiocb, cmdiocb);
2791 spin_lock_irq(phba->host->host_lock);
2793 lpfc_sli_release_iocbq(phba, cmdiocb);
2800 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, uint16_t tgt_id,
2801 uint64_t lun_id, uint32_t ctx,
2802 lpfc_ctx_cmd ctx_cmd)
2804 struct lpfc_scsi_buf *lpfc_cmd;
2805 struct scsi_cmnd *cmnd;
2808 if (!(iocbq->iocb_flag & LPFC_IO_FCP))
2811 lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
2812 cmnd = lpfc_cmd->pCmd;
2819 if ((cmnd->device->id == tgt_id) &&
2820 (cmnd->device->lun == lun_id))
2824 if (cmnd->device->id == tgt_id)
2828 if (iocbq->iocb.ulpContext == ctx)
2835 printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
2836 __FUNCTION__, ctx_cmd);
2844 lpfc_sli_sum_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2845 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd ctx_cmd)
2847 struct lpfc_iocbq *iocbq;
2850 for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
2851 iocbq = phba->sli.iocbq_lookup[i];
2853 if (lpfc_sli_validate_fcp_iocb (iocbq, tgt_id, lun_id,
2862 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2863 struct lpfc_iocbq * rspiocb)
2865 spin_lock_irq(phba->host->host_lock);
2866 lpfc_sli_release_iocbq(phba, cmdiocb);
2867 spin_unlock_irq(phba->host->host_lock);
2872 lpfc_sli_abort_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2873 uint16_t tgt_id, uint64_t lun_id, uint32_t ctx,
2874 lpfc_ctx_cmd abort_cmd)
2876 struct lpfc_iocbq *iocbq;
2877 struct lpfc_iocbq *abtsiocb;
2879 int errcnt = 0, ret_val = 0;
2882 for (i = 1; i <= phba->sli.last_iotag; i++) {
2883 iocbq = phba->sli.iocbq_lookup[i];
2885 if (lpfc_sli_validate_fcp_iocb (iocbq, tgt_id, lun_id,
2889 /* issue ABTS for this IOCB based on iotag */
2890 abtsiocb = lpfc_sli_get_iocbq(phba);
2891 if (abtsiocb == NULL) {
2897 abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
2898 abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
2899 abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
2900 abtsiocb->iocb.ulpLe = 1;
2901 abtsiocb->iocb.ulpClass = cmd->ulpClass;
2903 if (phba->hba_state >= LPFC_LINK_UP)
2904 abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
2906 abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
2908 /* Setup callback routine and issue the command. */
2909 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
2910 ret_val = lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0);
2911 if (ret_val == IOCB_ERROR) {
2912 lpfc_sli_release_iocbq(phba, abtsiocb);
2922 lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
2923 struct lpfc_iocbq *cmdiocbq,
2924 struct lpfc_iocbq *rspiocbq)
2926 wait_queue_head_t *pdone_q;
2927 unsigned long iflags;
2929 spin_lock_irqsave(phba->host->host_lock, iflags);
2930 cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
2931 if (cmdiocbq->context2 && rspiocbq)
2932 memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
2933 &rspiocbq->iocb, sizeof(IOCB_t));
2935 pdone_q = cmdiocbq->context_un.wait_queue;
2936 spin_unlock_irqrestore(phba->host->host_lock, iflags);
2943 * Issue the caller's iocb and wait for its completion, but no longer than the
2944 * caller's timeout. Note that iocb_flags is cleared before the
2945 * lpfc_sli_issue_call since the wake routine sets a unique value and by
2946 * definition this is a wait function.
2949 lpfc_sli_issue_iocb_wait(struct lpfc_hba * phba,
2950 struct lpfc_sli_ring * pring,
2951 struct lpfc_iocbq * piocb,
2952 struct lpfc_iocbq * prspiocbq,
2955 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
2956 long timeleft, timeout_req = 0;
2957 int retval = IOCB_SUCCESS;
2961 * If the caller has provided a response iocbq buffer, then context2
2962 * is NULL or its an error.
2965 if (piocb->context2)
2967 piocb->context2 = prspiocbq;
2970 piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
2971 piocb->context_un.wait_queue = &done_q;
2972 piocb->iocb_flag &= ~LPFC_IO_WAKE;
2974 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
2975 creg_val = readl(phba->HCregaddr);
2976 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
2977 writel(creg_val, phba->HCregaddr);
2978 readl(phba->HCregaddr); /* flush */
2981 retval = lpfc_sli_issue_iocb(phba, pring, piocb, 0);
2982 if (retval == IOCB_SUCCESS) {
2983 timeout_req = timeout * HZ;
2984 spin_unlock_irq(phba->host->host_lock);
2985 timeleft = wait_event_timeout(done_q,
2986 piocb->iocb_flag & LPFC_IO_WAKE,
2988 spin_lock_irq(phba->host->host_lock);
2990 if (timeleft == 0) {
2991 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2992 "%d:0338 IOCB wait timeout error - no "
2993 "wake response Data x%x\n",
2994 phba->brd_no, timeout);
2995 retval = IOCB_TIMEDOUT;
2996 } else if (!(piocb->iocb_flag & LPFC_IO_WAKE)) {
2997 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2998 "%d:0330 IOCB wake NOT set, "
2999 "Data x%x x%lx\n", phba->brd_no,
3000 timeout, (timeleft / jiffies));
3001 retval = IOCB_TIMEDOUT;
3003 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3004 "%d:0331 IOCB wake signaled\n",
3008 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3009 "%d:0332 IOCB wait issue failed, Data x%x\n",
3010 phba->brd_no, retval);
3011 retval = IOCB_ERROR;
3014 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
3015 creg_val = readl(phba->HCregaddr);
3016 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
3017 writel(creg_val, phba->HCregaddr);
3018 readl(phba->HCregaddr); /* flush */
3022 piocb->context2 = NULL;
3024 piocb->context_un.wait_queue = NULL;
3025 piocb->iocb_cmpl = NULL;
3030 lpfc_sli_issue_mbox_wait(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq,
3033 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
3034 DECLARE_WAITQUEUE(wq_entry, current);
3035 uint32_t timeleft = 0;
3038 /* The caller must leave context1 empty. */
3039 if (pmboxq->context1 != 0) {
3040 return (MBX_NOT_FINISHED);
3043 /* setup wake call as IOCB callback */
3044 pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
3045 /* setup context field to pass wait_queue pointer to wake function */
3046 pmboxq->context1 = &done_q;
3048 /* start to sleep before we wait, to avoid races */
3049 set_current_state(TASK_INTERRUPTIBLE);
3050 add_wait_queue(&done_q, &wq_entry);
3052 /* now issue the command */
3053 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
3055 if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
3056 timeleft = schedule_timeout(timeout * HZ);
3057 pmboxq->context1 = NULL;
3058 /* if schedule_timeout returns 0, we timed out and were not
3060 if ((timeleft == 0) || signal_pending(current))
3061 retval = MBX_TIMEOUT;
3063 retval = MBX_SUCCESS;
3067 set_current_state(TASK_RUNNING);
3068 remove_wait_queue(&done_q, &wq_entry);
3073 lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba)
3077 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE && !phba->stopped) {
3078 if (i++ > LPFC_MBOX_TMO * 1000)
3081 if (lpfc_sli_handle_mb_event(phba) == 0)
3087 return (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) ? 1 : 0;
3091 lpfc_intr_handler(int irq, void *dev_id)
3093 struct lpfc_hba *phba;
3095 uint32_t work_ha_copy;
3096 unsigned long status;
3101 * Get the driver's phba structure from the dev_id and
3102 * assume the HBA is not interrupting.
3104 phba = (struct lpfc_hba *) dev_id;
3106 if (unlikely(!phba))
3109 /* If the pci channel is offline, ignore all the interrupts. */
3110 if (unlikely(pci_channel_offline(phba->pcidev)))
3113 phba->sli.slistat.sli_intr++;
3116 * Call the HBA to see if it is interrupting. If not, don't claim
3120 /* Ignore all interrupts during initialization. */
3121 if (unlikely(phba->hba_state < LPFC_LINK_DOWN))
3125 * Read host attention register to determine interrupt source
3126 * Clear Attention Sources, except Error Attention (to
3127 * preserve status) and Link Attention
3129 spin_lock(phba->host->host_lock);
3130 ha_copy = readl(phba->HAregaddr);
3131 writel((ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
3132 readl(phba->HAregaddr); /* flush */
3133 spin_unlock(phba->host->host_lock);
3135 if (unlikely(!ha_copy))
3138 work_ha_copy = ha_copy & phba->work_ha_mask;
3140 if (unlikely(work_ha_copy)) {
3141 if (work_ha_copy & HA_LATT) {
3142 if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
3144 * Turn off Link Attention interrupts
3145 * until CLEAR_LA done
3147 spin_lock(phba->host->host_lock);
3148 phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
3149 control = readl(phba->HCregaddr);
3150 control &= ~HC_LAINT_ENA;
3151 writel(control, phba->HCregaddr);
3152 readl(phba->HCregaddr); /* flush */
3153 spin_unlock(phba->host->host_lock);
3156 work_ha_copy &= ~HA_LATT;
3159 if (work_ha_copy & ~(HA_ERATT|HA_MBATT|HA_LATT)) {
3160 for (i = 0; i < phba->sli.num_rings; i++) {
3161 if (work_ha_copy & (HA_RXATT << (4*i))) {
3163 * Turn off Slow Rings interrupts
3165 spin_lock(phba->host->host_lock);
3166 control = readl(phba->HCregaddr);
3167 control &= ~(HC_R0INT_ENA << i);
3168 writel(control, phba->HCregaddr);
3169 readl(phba->HCregaddr); /* flush */
3170 spin_unlock(phba->host->host_lock);
3175 if (work_ha_copy & HA_ERATT) {
3176 phba->hba_state = LPFC_HBA_ERROR;
3178 * There was a link/board error. Read the
3179 * status register to retrieve the error event
3182 phba->sli.slistat.err_attn_event++;
3183 /* Save status info */
3184 phba->work_hs = readl(phba->HSregaddr);
3185 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
3186 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
3188 /* Clear Chip error bit */
3189 writel(HA_ERATT, phba->HAregaddr);
3190 readl(phba->HAregaddr); /* flush */
3194 spin_lock(phba->host->host_lock);
3195 phba->work_ha |= work_ha_copy;
3196 if (phba->work_wait)
3197 wake_up(phba->work_wait);
3198 spin_unlock(phba->host->host_lock);
3201 ha_copy &= ~(phba->work_ha_mask);
3204 * Process all events on FCP ring. Take the optimized path for
3205 * FCP IO. Any other IO is slow path and is handled by
3206 * the worker thread.
3208 status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
3209 status >>= (4*LPFC_FCP_RING);
3210 if (status & HA_RXATT)
3211 lpfc_sli_handle_fast_ring_event(phba,
3212 &phba->sli.ring[LPFC_FCP_RING],
3215 if (phba->cfg_multi_ring_support == 2) {
3217 * Process all events on extra ring. Take the optimized path
3218 * for extra ring IO. Any other IO is slow path and is handled
3219 * by the worker thread.
3221 status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
3222 status >>= (4*LPFC_EXTRA_RING);
3223 if (status & HA_RXATT) {
3224 lpfc_sli_handle_fast_ring_event(phba,
3225 &phba->sli.ring[LPFC_EXTRA_RING],
3231 } /* lpfc_intr_handler */