1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2007 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 pmboxq->mbox_flag |= LPFC_MBX_WAKE;
532 pdone_q = (wait_queue_head_t *) pmboxq->context1;
534 wake_up_interruptible(pdone_q);
539 lpfc_sli_def_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
541 struct lpfc_dmabuf *mp;
545 mp = (struct lpfc_dmabuf *) (pmb->context1);
548 lpfc_mbuf_free(phba, mp->virt, mp->phys);
553 * If a REG_LOGIN succeeded after node is destroyed or node
554 * is in re-discovery driver need to cleanup the RPI.
556 if (!(phba->fc_flag & FC_UNLOADING) &&
557 (pmb->mb.mbxCommand == MBX_REG_LOGIN64) &&
558 (!pmb->mb.mbxStatus)) {
560 rpi = pmb->mb.un.varWords[0];
561 lpfc_unreg_login(phba, rpi, pmb);
562 pmb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
563 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
564 if (rc != MBX_NOT_FINISHED)
568 mempool_free( pmb, phba->mbox_mem_pool);
573 lpfc_sli_handle_mb_event(struct lpfc_hba * phba)
578 struct lpfc_sli *psli;
580 uint32_t process_next;
583 /* We should only get here if we are in SLI2 mode */
584 if (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE)) {
588 phba->sli.slistat.mbox_event++;
590 /* Get a Mailbox buffer to setup mailbox commands for callback */
591 if ((pmb = phba->sli.mbox_active)) {
593 mbox = &phba->slim2p->mbx;
595 /* First check out the status word */
596 lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof (uint32_t));
598 /* Sanity check to ensure the host owns the mailbox */
599 if (pmbox->mbxOwner != OWN_HOST) {
600 /* Lets try for a while */
601 for (i = 0; i < 10240; i++) {
602 /* First copy command data */
603 lpfc_sli_pcimem_bcopy(mbox, pmbox,
605 if (pmbox->mbxOwner == OWN_HOST)
608 /* Stray Mailbox Interrupt, mbxCommand <cmd> mbxStatus
610 lpfc_printf_log(phba,
613 "%d:0304 Stray Mailbox Interrupt "
614 "mbxCommand x%x mbxStatus x%x\n",
619 spin_lock_irq(phba->host->host_lock);
620 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
621 spin_unlock_irq(phba->host->host_lock);
626 del_timer_sync(&phba->sli.mbox_tmo);
627 phba->work_hba_events &= ~WORKER_MBOX_TMO;
630 * It is a fatal error if unknown mbox command completion.
632 if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
635 /* Unknow mailbox command compl */
636 lpfc_printf_log(phba,
639 "%d:0323 Unknown Mailbox command %x Cmpl\n",
642 phba->hba_state = LPFC_HBA_ERROR;
643 phba->work_hs = HS_FFER3;
644 lpfc_handle_eratt(phba);
648 phba->sli.mbox_active = NULL;
649 if (pmbox->mbxStatus) {
650 phba->sli.slistat.mbox_stat_err++;
651 if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
652 /* Mbox cmd cmpl error - RETRYing */
653 lpfc_printf_log(phba,
656 "%d:0305 Mbox cmd cmpl error - "
657 "RETRYing Data: x%x x%x x%x x%x\n",
661 pmbox->un.varWords[0],
663 pmbox->mbxStatus = 0;
664 pmbox->mbxOwner = OWN_HOST;
665 spin_lock_irq(phba->host->host_lock);
666 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
667 spin_unlock_irq(phba->host->host_lock);
668 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
669 if (rc == MBX_SUCCESS)
674 /* Mailbox cmd <cmd> Cmpl <cmpl> */
675 lpfc_printf_log(phba,
678 "%d:0307 Mailbox cmd x%x Cmpl x%p "
679 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
683 *((uint32_t *) pmbox),
684 pmbox->un.varWords[0],
685 pmbox->un.varWords[1],
686 pmbox->un.varWords[2],
687 pmbox->un.varWords[3],
688 pmbox->un.varWords[4],
689 pmbox->un.varWords[5],
690 pmbox->un.varWords[6],
691 pmbox->un.varWords[7]);
693 if (pmb->mbox_cmpl) {
694 lpfc_sli_pcimem_bcopy(mbox, pmbox, MAILBOX_CMD_SIZE);
695 pmb->mbox_cmpl(phba,pmb);
701 process_next = 0; /* by default don't loop */
702 spin_lock_irq(phba->host->host_lock);
703 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
705 /* Process next mailbox command if there is one */
706 if ((pmb = lpfc_mbox_get(phba))) {
707 spin_unlock_irq(phba->host->host_lock);
708 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
709 if (rc == MBX_NOT_FINISHED) {
710 pmb->mb.mbxStatus = MBX_NOT_FINISHED;
711 pmb->mbox_cmpl(phba,pmb);
713 continue; /* loop back */
716 spin_unlock_irq(phba->host->host_lock);
717 /* Turn on IOCB processing */
718 for (i = 0; i < phba->sli.num_rings; i++)
719 lpfc_sli_turn_on_ring(phba, i);
722 } while (process_next);
727 lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
728 struct lpfc_iocbq *saveq)
736 irsp = &(saveq->iocb);
737 if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX)
738 || (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX)) {
743 (WORD5 *) & (saveq->iocb.un.
745 Rctl = w5p->hcsw.Rctl;
746 Type = w5p->hcsw.Type;
748 /* Firmware Workaround */
749 if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
750 (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX)) {
753 w5p->hcsw.Rctl = Rctl;
754 w5p->hcsw.Type = Type;
757 /* unSolicited Responses */
758 if (pring->prt[0].profile) {
759 if (pring->prt[0].lpfc_sli_rcv_unsol_event)
760 (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
764 /* We must search, based on rctl / type
765 for the right routine */
766 for (i = 0; i < pring->num_mask;
768 if ((pring->prt[i].rctl ==
772 if (pring->prt[i].lpfc_sli_rcv_unsol_event)
773 (pring->prt[i].lpfc_sli_rcv_unsol_event)
774 (phba, pring, saveq);
781 /* Unexpected Rctl / Type received */
782 /* Ring <ringno> handler: unexpected
783 Rctl <Rctl> Type <Type> received */
784 lpfc_printf_log(phba,
787 "%d:0313 Ring %d handler: unexpected Rctl x%x "
788 "Type x%x received \n",
797 static struct lpfc_iocbq *
798 lpfc_sli_iocbq_lookup(struct lpfc_hba * phba,
799 struct lpfc_sli_ring * pring,
800 struct lpfc_iocbq * prspiocb)
802 struct lpfc_iocbq *cmd_iocb = NULL;
805 iotag = prspiocb->iocb.ulpIoTag;
807 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
808 cmd_iocb = phba->sli.iocbq_lookup[iotag];
809 list_del(&cmd_iocb->list);
810 pring->txcmplq_cnt--;
814 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
815 "%d:0317 iotag x%x is out off "
816 "range: max iotag x%x wd0 x%x\n",
818 phba->sli.last_iotag,
819 *(((uint32_t *) &prspiocb->iocb) + 7));
824 lpfc_sli_process_sol_iocb(struct lpfc_hba * phba, struct lpfc_sli_ring * pring,
825 struct lpfc_iocbq *saveq)
827 struct lpfc_iocbq * cmdiocbp;
831 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
832 spin_lock_irqsave(phba->host->host_lock, iflag);
833 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
835 if (cmdiocbp->iocb_cmpl) {
837 * Post all ELS completions to the worker thread.
838 * All other are passed to the completion callback.
840 if (pring->ringno == LPFC_ELS_RING) {
841 if (cmdiocbp->iocb_flag & LPFC_DRIVER_ABORTED) {
842 cmdiocbp->iocb_flag &=
843 ~LPFC_DRIVER_ABORTED;
844 saveq->iocb.ulpStatus =
846 saveq->iocb.un.ulpWord[4] =
849 spin_unlock_irqrestore(phba->host->host_lock,
851 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
852 spin_lock_irqsave(phba->host->host_lock, iflag);
855 spin_unlock_irqrestore(phba->host->host_lock,
857 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
858 spin_lock_irqsave(phba->host->host_lock, iflag);
861 lpfc_sli_release_iocbq(phba, cmdiocbp);
864 * Unknown initiating command based on the response iotag.
865 * This could be the case on the ELS ring because of
868 if (pring->ringno != LPFC_ELS_RING) {
870 * Ring <ringno> handler: unexpected completion IoTag
873 lpfc_printf_log(phba,
876 "%d:0322 Ring %d handler: unexpected "
877 "completion IoTag x%x Data: x%x x%x x%x x%x\n",
880 saveq->iocb.ulpIoTag,
881 saveq->iocb.ulpStatus,
882 saveq->iocb.un.ulpWord[4],
883 saveq->iocb.ulpCommand,
884 saveq->iocb.ulpContext);
888 spin_unlock_irqrestore(phba->host->host_lock, iflag);
892 static void lpfc_sli_rsp_pointers_error(struct lpfc_hba * phba,
893 struct lpfc_sli_ring * pring)
895 struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno];
897 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
898 * rsp ring <portRspMax>
900 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
901 "%d:0312 Ring %d handler: portRspPut %d "
902 "is bigger then rsp ring %d\n",
903 phba->brd_no, pring->ringno,
904 le32_to_cpu(pgp->rspPutInx),
907 phba->hba_state = LPFC_HBA_ERROR;
910 * All error attention handlers are posted to
913 phba->work_ha |= HA_ERATT;
914 phba->work_hs = HS_FFER3;
916 wake_up(phba->work_wait);
921 void lpfc_sli_poll_fcp_ring(struct lpfc_hba * phba)
923 struct lpfc_sli * psli = &phba->sli;
924 struct lpfc_sli_ring * pring = &psli->ring[LPFC_FCP_RING];
926 IOCB_t *entry = NULL;
927 struct lpfc_iocbq *cmdiocbq = NULL;
928 struct lpfc_iocbq rspiocbq;
929 struct lpfc_pgp *pgp;
931 uint32_t portRspPut, portRspMax;
933 uint32_t rsp_cmpl = 0;
934 void __iomem *to_slim;
937 pring->stats.iocb_event++;
939 /* The driver assumes SLI-2 mode */
940 pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno];
943 * The next available response entry should never exceed the maximum
944 * entries. If it does, treat it as an adapter hardware error.
946 portRspMax = pring->numRiocb;
947 portRspPut = le32_to_cpu(pgp->rspPutInx);
948 if (unlikely(portRspPut >= portRspMax)) {
949 lpfc_sli_rsp_pointers_error(phba, pring);
954 while (pring->rspidx != portRspPut) {
956 entry = IOCB_ENTRY(pring->rspringaddr, pring->rspidx);
958 if (++pring->rspidx >= portRspMax)
961 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
962 (uint32_t *) &rspiocbq.iocb,
964 irsp = &rspiocbq.iocb;
965 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
966 pring->stats.iocb_rsp++;
969 if (unlikely(irsp->ulpStatus)) {
970 /* Rsp ring <ringno> error: IOCB */
971 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
972 "%d:0326 Rsp Ring %d error: IOCB Data: "
973 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
974 phba->brd_no, pring->ringno,
981 *(((uint32_t *) irsp) + 6),
982 *(((uint32_t *) irsp) + 7));
986 case LPFC_ABORT_IOCB:
989 * Idle exchange closed via ABTS from port. No iocb
990 * resources need to be recovered.
992 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
993 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
994 "%d:0314 IOCB cmd 0x%x"
995 " processed. Skipping"
996 " completion", phba->brd_no,
1001 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
1003 if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
1004 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1009 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1010 char adaptermsg[LPFC_MAX_ADPTMSG];
1011 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
1012 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1014 dev_warn(&((phba->pcidev)->dev), "lpfc%d: %s",
1015 phba->brd_no, adaptermsg);
1017 /* Unknown IOCB command */
1018 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1019 "%d:0321 Unknown IOCB command "
1020 "Data: x%x, x%x x%x x%x x%x\n",
1031 * The response IOCB has been processed. Update the ring
1032 * pointer in SLIM. If the port response put pointer has not
1033 * been updated, sync the pgp->rspPutInx and fetch the new port
1034 * response put pointer.
1036 to_slim = phba->MBslimaddr +
1037 (SLIMOFF + (pring->ringno * 2) + 1) * 4;
1038 writeb(pring->rspidx, to_slim);
1040 if (pring->rspidx == portRspPut)
1041 portRspPut = le32_to_cpu(pgp->rspPutInx);
1044 ha_copy = readl(phba->HAregaddr);
1045 ha_copy >>= (LPFC_FCP_RING * 4);
1047 if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) {
1048 pring->stats.iocb_rsp_full++;
1049 status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4));
1050 writel(status, phba->CAregaddr);
1051 readl(phba->CAregaddr);
1053 if ((ha_copy & HA_R0CE_RSP) &&
1054 (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1055 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1056 pring->stats.iocb_cmd_empty++;
1058 /* Force update of the local copy of cmdGetInx */
1059 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1060 lpfc_sli_resume_iocb(phba, pring);
1062 if ((pring->lpfc_sli_cmd_available))
1063 (pring->lpfc_sli_cmd_available) (phba, pring);
1071 * This routine presumes LPFC_FCP_RING handling and doesn't bother
1072 * to check it explicitly.
1075 lpfc_sli_handle_fast_ring_event(struct lpfc_hba * phba,
1076 struct lpfc_sli_ring * pring, uint32_t mask)
1078 struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno];
1079 IOCB_t *irsp = NULL;
1080 IOCB_t *entry = NULL;
1081 struct lpfc_iocbq *cmdiocbq = NULL;
1082 struct lpfc_iocbq rspiocbq;
1084 uint32_t portRspPut, portRspMax;
1086 lpfc_iocb_type type;
1087 unsigned long iflag;
1088 uint32_t rsp_cmpl = 0;
1089 void __iomem *to_slim;
1091 spin_lock_irqsave(phba->host->host_lock, iflag);
1092 pring->stats.iocb_event++;
1095 * The next available response entry should never exceed the maximum
1096 * entries. If it does, treat it as an adapter hardware error.
1098 portRspMax = pring->numRiocb;
1099 portRspPut = le32_to_cpu(pgp->rspPutInx);
1100 if (unlikely(portRspPut >= portRspMax)) {
1101 lpfc_sli_rsp_pointers_error(phba, pring);
1102 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1107 while (pring->rspidx != portRspPut) {
1109 * Fetch an entry off the ring and copy it into a local data
1110 * structure. The copy involves a byte-swap since the
1111 * network byte order and pci byte orders are different.
1113 entry = IOCB_ENTRY(pring->rspringaddr, pring->rspidx);
1115 if (++pring->rspidx >= portRspMax)
1118 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
1119 (uint32_t *) &rspiocbq.iocb,
1121 INIT_LIST_HEAD(&(rspiocbq.list));
1122 irsp = &rspiocbq.iocb;
1124 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
1125 pring->stats.iocb_rsp++;
1128 if (unlikely(irsp->ulpStatus)) {
1129 /* Rsp ring <ringno> error: IOCB */
1130 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1131 "%d:0336 Rsp Ring %d error: IOCB Data: "
1132 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
1133 phba->brd_no, pring->ringno,
1134 irsp->un.ulpWord[0], irsp->un.ulpWord[1],
1135 irsp->un.ulpWord[2], irsp->un.ulpWord[3],
1136 irsp->un.ulpWord[4], irsp->un.ulpWord[5],
1137 *(((uint32_t *) irsp) + 6),
1138 *(((uint32_t *) irsp) + 7));
1142 case LPFC_ABORT_IOCB:
1145 * Idle exchange closed via ABTS from port. No iocb
1146 * resources need to be recovered.
1148 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
1149 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1150 "%d:0333 IOCB cmd 0x%x"
1151 " processed. Skipping"
1152 " completion\n", phba->brd_no,
1157 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
1159 if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
1160 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
1161 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1164 spin_unlock_irqrestore(
1165 phba->host->host_lock, iflag);
1166 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1168 spin_lock_irqsave(phba->host->host_lock,
1173 case LPFC_UNSOL_IOCB:
1174 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1175 lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
1176 spin_lock_irqsave(phba->host->host_lock, iflag);
1179 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1180 char adaptermsg[LPFC_MAX_ADPTMSG];
1181 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
1182 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1184 dev_warn(&((phba->pcidev)->dev), "lpfc%d: %s",
1185 phba->brd_no, adaptermsg);
1187 /* Unknown IOCB command */
1188 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1189 "%d:0334 Unknown IOCB command "
1190 "Data: x%x, x%x x%x x%x x%x\n",
1191 phba->brd_no, type, irsp->ulpCommand,
1192 irsp->ulpStatus, irsp->ulpIoTag,
1199 * The response IOCB has been processed. Update the ring
1200 * pointer in SLIM. If the port response put pointer has not
1201 * been updated, sync the pgp->rspPutInx and fetch the new port
1202 * response put pointer.
1204 to_slim = phba->MBslimaddr +
1205 (SLIMOFF + (pring->ringno * 2) + 1) * 4;
1206 writel(pring->rspidx, to_slim);
1208 if (pring->rspidx == portRspPut)
1209 portRspPut = le32_to_cpu(pgp->rspPutInx);
1212 if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
1213 pring->stats.iocb_rsp_full++;
1214 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
1215 writel(status, phba->CAregaddr);
1216 readl(phba->CAregaddr);
1218 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1219 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1220 pring->stats.iocb_cmd_empty++;
1222 /* Force update of the local copy of cmdGetInx */
1223 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1224 lpfc_sli_resume_iocb(phba, pring);
1226 if ((pring->lpfc_sli_cmd_available))
1227 (pring->lpfc_sli_cmd_available) (phba, pring);
1231 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1237 lpfc_sli_handle_slow_ring_event(struct lpfc_hba * phba,
1238 struct lpfc_sli_ring * pring, uint32_t mask)
1241 IOCB_t *irsp = NULL;
1242 struct lpfc_iocbq *rspiocbp = NULL;
1243 struct lpfc_iocbq *next_iocb;
1244 struct lpfc_iocbq *cmdiocbp;
1245 struct lpfc_iocbq *saveq;
1246 struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno];
1247 uint8_t iocb_cmd_type;
1248 lpfc_iocb_type type;
1249 uint32_t status, free_saveq;
1250 uint32_t portRspPut, portRspMax;
1252 unsigned long iflag;
1253 void __iomem *to_slim;
1255 spin_lock_irqsave(phba->host->host_lock, iflag);
1256 pring->stats.iocb_event++;
1259 * The next available response entry should never exceed the maximum
1260 * entries. If it does, treat it as an adapter hardware error.
1262 portRspMax = pring->numRiocb;
1263 portRspPut = le32_to_cpu(pgp->rspPutInx);
1264 if (portRspPut >= portRspMax) {
1266 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
1267 * rsp ring <portRspMax>
1269 lpfc_printf_log(phba,
1272 "%d:0303 Ring %d handler: portRspPut %d "
1273 "is bigger then rsp ring %d\n",
1275 pring->ringno, portRspPut, portRspMax);
1277 phba->hba_state = LPFC_HBA_ERROR;
1278 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1280 phba->work_hs = HS_FFER3;
1281 lpfc_handle_eratt(phba);
1287 while (pring->rspidx != portRspPut) {
1289 * Build a completion list and call the appropriate handler.
1290 * The process is to get the next available response iocb, get
1291 * a free iocb from the list, copy the response data into the
1292 * free iocb, insert to the continuation list, and update the
1293 * next response index to slim. This process makes response
1294 * iocb's in the ring available to DMA as fast as possible but
1295 * pays a penalty for a copy operation. Since the iocb is
1296 * only 32 bytes, this penalty is considered small relative to
1297 * the PCI reads for register values and a slim write. When
1298 * the ulpLe field is set, the entire Command has been
1301 entry = IOCB_ENTRY(pring->rspringaddr, pring->rspidx);
1302 rspiocbp = lpfc_sli_get_iocbq(phba);
1303 if (rspiocbp == NULL) {
1304 printk(KERN_ERR "%s: out of buffers! Failing "
1305 "completion.\n", __FUNCTION__);
1309 lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, sizeof (IOCB_t));
1310 irsp = &rspiocbp->iocb;
1312 if (++pring->rspidx >= portRspMax)
1315 to_slim = phba->MBslimaddr + (SLIMOFF + (pring->ringno * 2)
1317 writel(pring->rspidx, to_slim);
1319 if (list_empty(&(pring->iocb_continueq))) {
1320 list_add(&rspiocbp->list, &(pring->iocb_continueq));
1322 list_add_tail(&rspiocbp->list,
1323 &(pring->iocb_continueq));
1326 pring->iocb_continueq_cnt++;
1329 * By default, the driver expects to free all resources
1330 * associated with this iocb completion.
1333 saveq = list_get_first(&pring->iocb_continueq,
1334 struct lpfc_iocbq, list);
1335 irsp = &(saveq->iocb);
1336 list_del_init(&pring->iocb_continueq);
1337 pring->iocb_continueq_cnt = 0;
1339 pring->stats.iocb_rsp++;
1341 if (irsp->ulpStatus) {
1342 /* Rsp ring <ringno> error: IOCB */
1343 lpfc_printf_log(phba,
1346 "%d:0328 Rsp Ring %d error: IOCB Data: "
1347 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
1350 irsp->un.ulpWord[0],
1351 irsp->un.ulpWord[1],
1352 irsp->un.ulpWord[2],
1353 irsp->un.ulpWord[3],
1354 irsp->un.ulpWord[4],
1355 irsp->un.ulpWord[5],
1356 *(((uint32_t *) irsp) + 6),
1357 *(((uint32_t *) irsp) + 7));
1361 * Fetch the IOCB command type and call the correct
1362 * completion routine. Solicited and Unsolicited
1363 * IOCBs on the ELS ring get freed back to the
1364 * lpfc_iocb_list by the discovery kernel thread.
1366 iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
1367 type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
1368 if (type == LPFC_SOL_IOCB) {
1369 spin_unlock_irqrestore(phba->host->host_lock,
1371 rc = lpfc_sli_process_sol_iocb(phba, pring,
1373 spin_lock_irqsave(phba->host->host_lock, iflag);
1374 } else if (type == LPFC_UNSOL_IOCB) {
1375 spin_unlock_irqrestore(phba->host->host_lock,
1377 rc = lpfc_sli_process_unsol_iocb(phba, pring,
1379 spin_lock_irqsave(phba->host->host_lock, iflag);
1380 } else if (type == LPFC_ABORT_IOCB) {
1381 if ((irsp->ulpCommand != CMD_XRI_ABORTED_CX) &&
1383 lpfc_sli_iocbq_lookup(phba, pring,
1385 /* Call the specified completion
1387 if (cmdiocbp->iocb_cmpl) {
1388 spin_unlock_irqrestore(
1389 phba->host->host_lock,
1391 (cmdiocbp->iocb_cmpl) (phba,
1394 phba->host->host_lock,
1397 lpfc_sli_release_iocbq(phba,
1400 } else if (type == LPFC_UNKNOWN_IOCB) {
1401 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1403 char adaptermsg[LPFC_MAX_ADPTMSG];
1405 memset(adaptermsg, 0,
1407 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1409 dev_warn(&((phba->pcidev)->dev),
1411 phba->brd_no, adaptermsg);
1413 /* Unknown IOCB command */
1414 lpfc_printf_log(phba,
1417 "%d:0335 Unknown IOCB command "
1418 "Data: x%x x%x x%x x%x\n",
1428 if (!list_empty(&saveq->list)) {
1429 list_for_each_entry_safe(rspiocbp,
1433 list_del(&rspiocbp->list);
1434 lpfc_sli_release_iocbq(phba,
1438 lpfc_sli_release_iocbq(phba, saveq);
1443 * If the port response put pointer has not been updated, sync
1444 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
1445 * response put pointer.
1447 if (pring->rspidx == portRspPut) {
1448 portRspPut = le32_to_cpu(pgp->rspPutInx);
1450 } /* while (pring->rspidx != portRspPut) */
1452 if ((rspiocbp != 0) && (mask & HA_R0RE_REQ)) {
1453 /* At least one response entry has been freed */
1454 pring->stats.iocb_rsp_full++;
1455 /* SET RxRE_RSP in Chip Att register */
1456 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
1457 writel(status, phba->CAregaddr);
1458 readl(phba->CAregaddr); /* flush */
1460 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1461 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1462 pring->stats.iocb_cmd_empty++;
1464 /* Force update of the local copy of cmdGetInx */
1465 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1466 lpfc_sli_resume_iocb(phba, pring);
1468 if ((pring->lpfc_sli_cmd_available))
1469 (pring->lpfc_sli_cmd_available) (phba, pring);
1473 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1478 lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1480 LIST_HEAD(completions);
1481 struct lpfc_iocbq *iocb, *next_iocb;
1487 /* Error everything on txq and txcmplq
1490 spin_lock_irq(phba->host->host_lock);
1491 list_splice_init(&pring->txq, &completions);
1494 /* Next issue ABTS for everything on the txcmplq */
1495 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
1496 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1498 spin_unlock_irq(phba->host->host_lock);
1500 while (!list_empty(&completions)) {
1501 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
1503 list_del(&iocb->list);
1505 if (iocb->iocb_cmpl) {
1506 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
1507 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
1508 (iocb->iocb_cmpl) (phba, iocb, iocb);
1510 lpfc_sli_release_iocbq(phba, iocb);
1517 lpfc_sli_brdready(struct lpfc_hba * phba, uint32_t mask)
1523 /* Read the HBA Host Status Register */
1524 status = readl(phba->HSregaddr);
1527 * Check status register every 100ms for 5 retries, then every
1528 * 500ms for 5, then every 2.5 sec for 5, then reset board and
1529 * every 2.5 sec for 4.
1530 * Break our of the loop if errors occurred during init.
1532 while (((status & mask) != mask) &&
1533 !(status & HS_FFERM) &&
1544 phba->hba_state = LPFC_STATE_UNKNOWN; /* Do post */
1545 lpfc_sli_brdrestart(phba);
1547 /* Read the HBA Host Status Register */
1548 status = readl(phba->HSregaddr);
1551 /* Check to see if any errors occurred during init */
1552 if ((status & HS_FFERM) || (i >= 20)) {
1553 phba->hba_state = LPFC_HBA_ERROR;
1560 #define BARRIER_TEST_PATTERN (0xdeadbeef)
1562 void lpfc_reset_barrier(struct lpfc_hba * phba)
1564 uint32_t __iomem *resp_buf;
1565 uint32_t __iomem *mbox_buf;
1566 volatile uint32_t mbox;
1571 pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
1572 if (hdrtype != 0x80 ||
1573 (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
1574 FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
1578 * Tell the other part of the chip to suspend temporarily all
1581 resp_buf = phba->MBslimaddr;
1583 /* Disable the error attention */
1584 hc_copy = readl(phba->HCregaddr);
1585 writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
1586 readl(phba->HCregaddr); /* flush */
1587 phba->fc_flag |= FC_IGNORE_ERATT;
1589 if (readl(phba->HAregaddr) & HA_ERATT) {
1590 /* Clear Chip error bit */
1591 writel(HA_ERATT, phba->HAregaddr);
1596 ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
1597 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
1599 writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
1600 mbox_buf = phba->MBslimaddr;
1601 writel(mbox, mbox_buf);
1604 readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
1607 if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
1608 if (phba->sli.sli_flag & LPFC_SLI2_ACTIVE ||
1615 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
1616 for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
1621 while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
1624 if (readl(phba->HAregaddr) & HA_ERATT) {
1625 writel(HA_ERATT, phba->HAregaddr);
1630 phba->fc_flag &= ~FC_IGNORE_ERATT;
1631 writel(hc_copy, phba->HCregaddr);
1632 readl(phba->HCregaddr); /* flush */
1636 lpfc_sli_brdkill(struct lpfc_hba * phba)
1638 struct lpfc_sli *psli;
1648 lpfc_printf_log(phba,
1651 "%d:0329 Kill HBA Data: x%x x%x\n",
1656 if ((pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
1660 /* Disable the error attention */
1661 spin_lock_irq(phba->host->host_lock);
1662 status = readl(phba->HCregaddr);
1663 status &= ~HC_ERINT_ENA;
1664 writel(status, phba->HCregaddr);
1665 readl(phba->HCregaddr); /* flush */
1666 phba->fc_flag |= FC_IGNORE_ERATT;
1667 spin_unlock_irq(phba->host->host_lock);
1669 lpfc_kill_board(phba, pmb);
1670 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1671 retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
1673 if (retval != MBX_SUCCESS) {
1674 if (retval != MBX_BUSY)
1675 mempool_free(pmb, phba->mbox_mem_pool);
1676 spin_lock_irq(phba->host->host_lock);
1677 phba->fc_flag &= ~FC_IGNORE_ERATT;
1678 spin_unlock_irq(phba->host->host_lock);
1682 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
1684 mempool_free(pmb, phba->mbox_mem_pool);
1686 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
1687 * attention every 100ms for 3 seconds. If we don't get ERATT after
1688 * 3 seconds we still set HBA_ERROR state because the status of the
1689 * board is now undefined.
1691 ha_copy = readl(phba->HAregaddr);
1693 while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
1695 ha_copy = readl(phba->HAregaddr);
1698 del_timer_sync(&psli->mbox_tmo);
1699 if (ha_copy & HA_ERATT) {
1700 writel(HA_ERATT, phba->HAregaddr);
1703 spin_lock_irq(phba->host->host_lock);
1704 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
1705 phba->fc_flag &= ~FC_IGNORE_ERATT;
1706 spin_unlock_irq(phba->host->host_lock);
1708 psli->mbox_active = NULL;
1709 lpfc_hba_down_post(phba);
1710 phba->hba_state = LPFC_HBA_ERROR;
1712 return (ha_copy & HA_ERATT ? 0 : 1);
1716 lpfc_sli_brdreset(struct lpfc_hba * phba)
1718 struct lpfc_sli *psli;
1719 struct lpfc_sli_ring *pring;
1726 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1727 "%d:0325 Reset HBA Data: x%x x%x\n", phba->brd_no,
1728 phba->hba_state, psli->sli_flag);
1730 /* perform board reset */
1731 phba->fc_eventTag = 0;
1733 phba->fc_prevDID = 0;
1735 /* Turn off parity checking and serr during the physical reset */
1736 pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
1737 pci_write_config_word(phba->pcidev, PCI_COMMAND,
1739 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
1741 psli->sli_flag &= ~(LPFC_SLI2_ACTIVE | LPFC_PROCESS_LA);
1742 /* Now toggle INITFF bit in the Host Control Register */
1743 writel(HC_INITFF, phba->HCregaddr);
1745 readl(phba->HCregaddr); /* flush */
1746 writel(0, phba->HCregaddr);
1747 readl(phba->HCregaddr); /* flush */
1749 /* Restore PCI cmd register */
1750 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
1752 /* Initialize relevant SLI info */
1753 for (i = 0; i < psli->num_rings; i++) {
1754 pring = &psli->ring[i];
1757 pring->next_cmdidx = 0;
1758 pring->local_getidx = 0;
1760 pring->missbufcnt = 0;
1763 phba->hba_state = LPFC_WARM_START;
1768 lpfc_sli_brdrestart(struct lpfc_hba * phba)
1771 struct lpfc_sli *psli;
1773 volatile uint32_t word0;
1774 void __iomem *to_slim;
1776 spin_lock_irq(phba->host->host_lock);
1781 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1782 "%d:0337 Restart HBA Data: x%x x%x\n", phba->brd_no,
1783 phba->hba_state, psli->sli_flag);
1786 mb = (MAILBOX_t *) &word0;
1787 mb->mbxCommand = MBX_RESTART;
1790 lpfc_reset_barrier(phba);
1792 to_slim = phba->MBslimaddr;
1793 writel(*(uint32_t *) mb, to_slim);
1794 readl(to_slim); /* flush */
1796 /* Only skip post after fc_ffinit is completed */
1797 if (phba->hba_state) {
1799 word0 = 1; /* This is really setting up word1 */
1802 word0 = 0; /* This is really setting up word1 */
1804 to_slim = phba->MBslimaddr + sizeof (uint32_t);
1805 writel(*(uint32_t *) mb, to_slim);
1806 readl(to_slim); /* flush */
1808 lpfc_sli_brdreset(phba);
1810 phba->hba_state = LPFC_INIT_START;
1812 spin_unlock_irq(phba->host->host_lock);
1814 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
1815 psli->stats_start = get_seconds();
1822 lpfc_hba_down_post(phba);
1828 lpfc_sli_chipset_init(struct lpfc_hba *phba)
1830 uint32_t status, i = 0;
1832 /* Read the HBA Host Status Register */
1833 status = readl(phba->HSregaddr);
1835 /* Check status register to see what current state is */
1837 while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
1839 /* Check every 100ms for 5 retries, then every 500ms for 5, then
1840 * every 2.5 sec for 5, then reset board and every 2.5 sec for
1844 /* Adapter failed to init, timeout, status reg
1846 lpfc_printf_log(phba,
1849 "%d:0436 Adapter failed to init, "
1850 "timeout, status reg x%x\n",
1853 phba->hba_state = LPFC_HBA_ERROR;
1857 /* Check to see if any errors occurred during init */
1858 if (status & HS_FFERM) {
1859 /* ERROR: During chipset initialization */
1860 /* Adapter failed to init, chipset, status reg
1862 lpfc_printf_log(phba,
1865 "%d:0437 Adapter failed to init, "
1866 "chipset, status reg x%x\n",
1869 phba->hba_state = LPFC_HBA_ERROR;
1875 } else if (i <= 10) {
1882 phba->hba_state = LPFC_STATE_UNKNOWN; /* Do post */
1883 lpfc_sli_brdrestart(phba);
1885 /* Read the HBA Host Status Register */
1886 status = readl(phba->HSregaddr);
1889 /* Check to see if any errors occurred during init */
1890 if (status & HS_FFERM) {
1891 /* ERROR: During chipset initialization */
1892 /* Adapter failed to init, chipset, status reg <status> */
1893 lpfc_printf_log(phba,
1896 "%d:0438 Adapter failed to init, chipset, "
1900 phba->hba_state = LPFC_HBA_ERROR;
1904 /* Clear all interrupt enable conditions */
1905 writel(0, phba->HCregaddr);
1906 readl(phba->HCregaddr); /* flush */
1908 /* setup host attn register */
1909 writel(0xffffffff, phba->HAregaddr);
1910 readl(phba->HAregaddr); /* flush */
1915 lpfc_sli_hba_setup(struct lpfc_hba * phba)
1918 uint32_t resetcount = 0, rc = 0, done = 0;
1920 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1922 phba->hba_state = LPFC_HBA_ERROR;
1926 while (resetcount < 2 && !done) {
1927 spin_lock_irq(phba->host->host_lock);
1928 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
1929 spin_unlock_irq(phba->host->host_lock);
1930 phba->hba_state = LPFC_STATE_UNKNOWN;
1931 lpfc_sli_brdrestart(phba);
1933 rc = lpfc_sli_chipset_init(phba);
1937 spin_lock_irq(phba->host->host_lock);
1938 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
1939 spin_unlock_irq(phba->host->host_lock);
1942 /* Call pre CONFIG_PORT mailbox command initialization. A value of 0
1943 * means the call was successful. Any other nonzero value is a failure,
1944 * but if ERESTART is returned, the driver may reset the HBA and try
1947 rc = lpfc_config_port_prep(phba);
1948 if (rc == -ERESTART) {
1949 phba->hba_state = 0;
1955 phba->hba_state = LPFC_INIT_MBX_CMDS;
1956 lpfc_config_port(phba, pmb);
1957 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
1958 if (rc == MBX_SUCCESS)
1961 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1962 "%d:0442 Adapter failed to init, mbxCmd x%x "
1963 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
1964 phba->brd_no, pmb->mb.mbxCommand,
1965 pmb->mb.mbxStatus, 0);
1966 phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE;
1970 goto lpfc_sli_hba_setup_error;
1972 rc = lpfc_sli_ring_map(phba, pmb);
1975 goto lpfc_sli_hba_setup_error;
1977 phba->sli.sli_flag |= LPFC_PROCESS_LA;
1979 rc = lpfc_config_port_post(phba);
1981 goto lpfc_sli_hba_setup_error;
1983 goto lpfc_sli_hba_setup_exit;
1984 lpfc_sli_hba_setup_error:
1985 phba->hba_state = LPFC_HBA_ERROR;
1986 lpfc_sli_hba_setup_exit:
1987 mempool_free(pmb, phba->mbox_mem_pool);
1991 /*! lpfc_mbox_timeout
1995 * \param hba Pointer to per struct lpfc_hba structure
1996 * \param l1 Pointer to the driver's mailbox queue.
2002 * This routine handles mailbox timeout events at timer interrupt context.
2005 lpfc_mbox_timeout(unsigned long ptr)
2007 struct lpfc_hba *phba;
2008 unsigned long iflag;
2010 phba = (struct lpfc_hba *)ptr;
2011 spin_lock_irqsave(phba->host->host_lock, iflag);
2012 if (!(phba->work_hba_events & WORKER_MBOX_TMO)) {
2013 phba->work_hba_events |= WORKER_MBOX_TMO;
2014 if (phba->work_wait)
2015 wake_up(phba->work_wait);
2017 spin_unlock_irqrestore(phba->host->host_lock, iflag);
2021 lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
2023 LPFC_MBOXQ_t *pmbox;
2025 struct lpfc_sli *psli = &phba->sli;
2026 struct lpfc_sli_ring *pring;
2028 spin_lock_irq(phba->host->host_lock);
2029 if (!(phba->work_hba_events & WORKER_MBOX_TMO)) {
2030 spin_unlock_irq(phba->host->host_lock);
2034 pmbox = phba->sli.mbox_active;
2037 /* Mbox cmd <mbxCommand> timeout */
2038 lpfc_printf_log(phba,
2041 "%d:0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
2046 phba->sli.mbox_active);
2048 /* Setting state unknown so lpfc_sli_abort_iocb_ring
2049 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
2050 * it to fail all oustanding SCSI IO.
2052 phba->hba_state = LPFC_STATE_UNKNOWN;
2053 phba->work_hba_events &= ~WORKER_MBOX_TMO;
2054 phba->fc_flag |= FC_ESTABLISH_LINK;
2055 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
2056 spin_unlock_irq(phba->host->host_lock);
2058 pring = &psli->ring[psli->fcp_ring];
2059 lpfc_sli_abort_iocb_ring(phba, pring);
2061 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
2062 "%d:0316 Resetting board due to mailbox timeout\n",
2065 * lpfc_offline calls lpfc_sli_hba_down which will clean up
2066 * on oustanding mailbox commands.
2068 lpfc_offline_prep(phba);
2070 lpfc_sli_brdrestart(phba);
2071 if (lpfc_online(phba) == 0) /* Initialize the HBA */
2072 mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
2073 lpfc_unblock_mgmt_io(phba);
2078 lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag)
2081 struct lpfc_sli *psli;
2082 uint32_t status, evtctr;
2085 unsigned long drvr_flag = 0;
2086 volatile uint32_t word0, ldata;
2087 void __iomem *to_slim;
2089 /* If the PCI channel is in offline state, do not post mbox. */
2090 if (unlikely(pci_channel_offline(phba->pcidev)))
2091 return MBX_NOT_FINISHED;
2095 spin_lock_irqsave(phba->host->host_lock, drvr_flag);
2099 status = MBX_SUCCESS;
2101 if (phba->hba_state == LPFC_HBA_ERROR) {
2102 spin_unlock_irqrestore(phba->host->host_lock, drvr_flag);
2104 /* Mbox command <mbxCommand> cannot issue */
2105 LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag)
2106 return (MBX_NOT_FINISHED);
2109 if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
2110 !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
2111 spin_unlock_irqrestore(phba->host->host_lock, drvr_flag);
2112 LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag)
2113 return (MBX_NOT_FINISHED);
2116 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
2117 /* Polling for a mbox command when another one is already active
2118 * is not allowed in SLI. Also, the driver must have established
2119 * SLI2 mode to queue and process multiple mbox commands.
2122 if (flag & MBX_POLL) {
2123 spin_unlock_irqrestore(phba->host->host_lock,
2126 /* Mbox command <mbxCommand> cannot issue */
2127 LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag)
2128 return (MBX_NOT_FINISHED);
2131 if (!(psli->sli_flag & LPFC_SLI2_ACTIVE)) {
2132 spin_unlock_irqrestore(phba->host->host_lock,
2134 /* Mbox command <mbxCommand> cannot issue */
2135 LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag)
2136 return (MBX_NOT_FINISHED);
2139 /* Handle STOP IOCB processing flag. This is only meaningful
2140 * if we are not polling for mbox completion.
2142 if (flag & MBX_STOP_IOCB) {
2143 flag &= ~MBX_STOP_IOCB;
2144 /* Now flag each ring */
2145 for (i = 0; i < psli->num_rings; i++) {
2146 /* If the ring is active, flag it */
2147 if (psli->ring[i].cmdringaddr) {
2148 psli->ring[i].flag |=
2154 /* Another mailbox command is still being processed, queue this
2155 * command to be processed later.
2157 lpfc_mbox_put(phba, pmbox);
2159 /* Mbox cmd issue - BUSY */
2160 lpfc_printf_log(phba,
2163 "%d:0308 Mbox cmd issue - BUSY Data: x%x x%x x%x x%x\n",
2170 psli->slistat.mbox_busy++;
2171 spin_unlock_irqrestore(phba->host->host_lock,
2177 /* Handle STOP IOCB processing flag. This is only meaningful
2178 * if we are not polling for mbox completion.
2180 if (flag & MBX_STOP_IOCB) {
2181 flag &= ~MBX_STOP_IOCB;
2182 if (flag == MBX_NOWAIT) {
2183 /* Now flag each ring */
2184 for (i = 0; i < psli->num_rings; i++) {
2185 /* If the ring is active, flag it */
2186 if (psli->ring[i].cmdringaddr) {
2187 psli->ring[i].flag |=
2194 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
2196 /* If we are not polling, we MUST be in SLI2 mode */
2197 if (flag != MBX_POLL) {
2198 if (!(psli->sli_flag & LPFC_SLI2_ACTIVE) &&
2199 (mb->mbxCommand != MBX_KILL_BOARD)) {
2200 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2201 spin_unlock_irqrestore(phba->host->host_lock,
2203 /* Mbox command <mbxCommand> cannot issue */
2204 LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag);
2205 return (MBX_NOT_FINISHED);
2207 /* timeout active mbox command */
2208 mod_timer(&psli->mbox_tmo, (jiffies +
2209 (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
2212 /* Mailbox cmd <cmd> issue */
2213 lpfc_printf_log(phba,
2216 "%d:0309 Mailbox cmd x%x issue Data: x%x x%x x%x\n",
2223 psli->slistat.mbox_cmd++;
2224 evtctr = psli->slistat.mbox_event;
2226 /* next set own bit for the adapter and copy over command word */
2227 mb->mbxOwner = OWN_CHIP;
2229 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2230 /* First copy command data to host SLIM area */
2231 lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx, MAILBOX_CMD_SIZE);
2233 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2234 /* copy command data into host mbox for cmpl */
2235 lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx,
2239 /* First copy mbox command data to HBA SLIM, skip past first
2241 to_slim = phba->MBslimaddr + sizeof (uint32_t);
2242 lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
2243 MAILBOX_CMD_SIZE - sizeof (uint32_t));
2245 /* Next copy over first word, with mbxOwner set */
2246 ldata = *((volatile uint32_t *)mb);
2247 to_slim = phba->MBslimaddr;
2248 writel(ldata, to_slim);
2249 readl(to_slim); /* flush */
2251 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2252 /* switch over to host mailbox */
2253 psli->sli_flag |= LPFC_SLI2_ACTIVE;
2258 /* interrupt board to doit right away */
2259 writel(CA_MBATT, phba->CAregaddr);
2260 readl(phba->CAregaddr); /* flush */
2264 /* Don't wait for it to finish, just return */
2265 psli->mbox_active = pmbox;
2269 psli->mbox_active = NULL;
2270 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2271 /* First read mbox status word */
2272 word0 = *((volatile uint32_t *)&phba->slim2p->mbx);
2273 word0 = le32_to_cpu(word0);
2275 /* First read mbox status word */
2276 word0 = readl(phba->MBslimaddr);
2279 /* Read the HBA Host Attention Register */
2280 ha_copy = readl(phba->HAregaddr);
2282 i = lpfc_mbox_tmo_val(phba, mb->mbxCommand);
2283 i *= 1000; /* Convert to ms */
2285 /* Wait for command to complete */
2286 while (((word0 & OWN_CHIP) == OWN_CHIP) ||
2287 (!(ha_copy & HA_MBATT) &&
2288 (phba->hba_state > LPFC_WARM_START))) {
2290 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2291 spin_unlock_irqrestore(phba->host->host_lock,
2293 return (MBX_NOT_FINISHED);
2296 /* Check if we took a mbox interrupt while we were
2298 if (((word0 & OWN_CHIP) != OWN_CHIP)
2299 && (evtctr != psli->slistat.mbox_event))
2302 spin_unlock_irqrestore(phba->host->host_lock,
2307 spin_lock_irqsave(phba->host->host_lock, drvr_flag);
2309 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2310 /* First copy command data */
2311 word0 = *((volatile uint32_t *)
2312 &phba->slim2p->mbx);
2313 word0 = le32_to_cpu(word0);
2314 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2316 volatile uint32_t slimword0;
2317 /* Check real SLIM for any errors */
2318 slimword0 = readl(phba->MBslimaddr);
2319 slimmb = (MAILBOX_t *) & slimword0;
2320 if (((slimword0 & OWN_CHIP) != OWN_CHIP)
2321 && slimmb->mbxStatus) {
2328 /* First copy command data */
2329 word0 = readl(phba->MBslimaddr);
2331 /* Read the HBA Host Attention Register */
2332 ha_copy = readl(phba->HAregaddr);
2335 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2336 /* copy results back to user */
2337 lpfc_sli_pcimem_bcopy(&phba->slim2p->mbx, mb,
2340 /* First copy command data */
2341 lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
2343 if ((mb->mbxCommand == MBX_DUMP_MEMORY) &&
2345 lpfc_memcpy_from_slim((void *)pmbox->context2,
2346 phba->MBslimaddr + DMP_RSP_OFFSET,
2347 mb->un.varDmp.word_cnt);
2351 writel(HA_MBATT, phba->HAregaddr);
2352 readl(phba->HAregaddr); /* flush */
2354 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2355 status = mb->mbxStatus;
2358 spin_unlock_irqrestore(phba->host->host_lock, drvr_flag);
2363 lpfc_sli_ringtx_put(struct lpfc_hba * phba, struct lpfc_sli_ring * pring,
2364 struct lpfc_iocbq * piocb)
2366 /* Insert the caller's iocb in the txq tail for later processing. */
2367 list_add_tail(&piocb->list, &pring->txq);
2372 static struct lpfc_iocbq *
2373 lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2374 struct lpfc_iocbq ** piocb)
2376 struct lpfc_iocbq * nextiocb;
2378 nextiocb = lpfc_sli_ringtx_get(phba, pring);
2388 lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2389 struct lpfc_iocbq *piocb, uint32_t flag)
2391 struct lpfc_iocbq *nextiocb;
2394 /* If the PCI channel is in offline state, do not post iocbs. */
2395 if (unlikely(pci_channel_offline(phba->pcidev)))
2399 * We should never get an IOCB if we are in a < LINK_DOWN state
2401 if (unlikely(phba->hba_state < LPFC_LINK_DOWN))
2405 * Check to see if we are blocking IOCB processing because of a
2406 * outstanding mbox command.
2408 if (unlikely(pring->flag & LPFC_STOP_IOCB_MBX))
2411 if (unlikely(phba->hba_state == LPFC_LINK_DOWN)) {
2413 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
2414 * can be issued if the link is not up.
2416 switch (piocb->iocb.ulpCommand) {
2417 case CMD_QUE_RING_BUF_CN:
2418 case CMD_QUE_RING_BUF64_CN:
2420 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
2421 * completion, iocb_cmpl MUST be 0.
2423 if (piocb->iocb_cmpl)
2424 piocb->iocb_cmpl = NULL;
2426 case CMD_CREATE_XRI_CR:
2427 case CMD_CLOSE_XRI_CN:
2428 case CMD_CLOSE_XRI_CX:
2435 * For FCP commands, we must be in a state where we can process link
2438 } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
2439 !(phba->sli.sli_flag & LPFC_PROCESS_LA)))
2442 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
2443 (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
2444 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
2447 lpfc_sli_update_ring(phba, pring);
2449 lpfc_sli_update_full_ring(phba, pring);
2452 return IOCB_SUCCESS;
2457 pring->stats.iocb_cmd_delay++;
2461 if (!(flag & SLI_IOCB_RET_IOCB)) {
2462 lpfc_sli_ringtx_put(phba, pring, piocb);
2463 return IOCB_SUCCESS;
2470 lpfc_extra_ring_setup( struct lpfc_hba *phba)
2472 struct lpfc_sli *psli;
2473 struct lpfc_sli_ring *pring;
2477 /* Adjust cmd/rsp ring iocb entries more evenly */
2479 /* Take some away from the FCP ring */
2480 pring = &psli->ring[psli->fcp_ring];
2481 pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
2482 pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
2483 pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
2484 pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
2486 /* and give them to the extra ring */
2487 pring = &psli->ring[psli->extra_ring];
2489 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
2490 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
2491 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
2492 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
2494 /* Setup default profile for this ring */
2495 pring->iotag_max = 4096;
2496 pring->num_mask = 1;
2497 pring->prt[0].profile = 0; /* Mask 0 */
2498 pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
2499 pring->prt[0].type = phba->cfg_multi_ring_type;
2500 pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
2505 lpfc_sli_setup(struct lpfc_hba *phba)
2508 struct lpfc_sli *psli = &phba->sli;
2509 struct lpfc_sli_ring *pring;
2511 psli->num_rings = MAX_CONFIGURED_RINGS;
2513 psli->fcp_ring = LPFC_FCP_RING;
2514 psli->next_ring = LPFC_FCP_NEXT_RING;
2515 psli->extra_ring = LPFC_EXTRA_RING;
2517 psli->iocbq_lookup = NULL;
2518 psli->iocbq_lookup_len = 0;
2519 psli->last_iotag = 0;
2521 for (i = 0; i < psli->num_rings; i++) {
2522 pring = &psli->ring[i];
2524 case LPFC_FCP_RING: /* ring 0 - FCP */
2525 /* numCiocb and numRiocb are used in config_port */
2526 pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
2527 pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
2528 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
2529 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
2530 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
2531 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
2532 pring->iotag_ctr = 0;
2534 (phba->cfg_hba_queue_depth * 2);
2535 pring->fast_iotag = pring->iotag_max;
2536 pring->num_mask = 0;
2538 case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
2539 /* numCiocb and numRiocb are used in config_port */
2540 pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
2541 pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
2542 pring->num_mask = 0;
2544 case LPFC_ELS_RING: /* ring 2 - ELS / CT */
2545 /* numCiocb and numRiocb are used in config_port */
2546 pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
2547 pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
2548 pring->fast_iotag = 0;
2549 pring->iotag_ctr = 0;
2550 pring->iotag_max = 4096;
2551 pring->num_mask = 4;
2552 pring->prt[0].profile = 0; /* Mask 0 */
2553 pring->prt[0].rctl = FC_ELS_REQ;
2554 pring->prt[0].type = FC_ELS_DATA;
2555 pring->prt[0].lpfc_sli_rcv_unsol_event =
2556 lpfc_els_unsol_event;
2557 pring->prt[1].profile = 0; /* Mask 1 */
2558 pring->prt[1].rctl = FC_ELS_RSP;
2559 pring->prt[1].type = FC_ELS_DATA;
2560 pring->prt[1].lpfc_sli_rcv_unsol_event =
2561 lpfc_els_unsol_event;
2562 pring->prt[2].profile = 0; /* Mask 2 */
2563 /* NameServer Inquiry */
2564 pring->prt[2].rctl = FC_UNSOL_CTL;
2566 pring->prt[2].type = FC_COMMON_TRANSPORT_ULP;
2567 pring->prt[2].lpfc_sli_rcv_unsol_event =
2568 lpfc_ct_unsol_event;
2569 pring->prt[3].profile = 0; /* Mask 3 */
2570 /* NameServer response */
2571 pring->prt[3].rctl = FC_SOL_CTL;
2573 pring->prt[3].type = FC_COMMON_TRANSPORT_ULP;
2574 pring->prt[3].lpfc_sli_rcv_unsol_event =
2575 lpfc_ct_unsol_event;
2578 totiocb += (pring->numCiocb + pring->numRiocb);
2580 if (totiocb > MAX_SLI2_IOCB) {
2581 /* Too many cmd / rsp ring entries in SLI2 SLIM */
2582 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2583 "%d:0462 Too many cmd / rsp ring entries in "
2584 "SLI2 SLIM Data: x%x x%x\n",
2585 phba->brd_no, totiocb, MAX_SLI2_IOCB);
2587 if (phba->cfg_multi_ring_support == 2)
2588 lpfc_extra_ring_setup(phba);
2594 lpfc_sli_queue_setup(struct lpfc_hba * phba)
2596 struct lpfc_sli *psli;
2597 struct lpfc_sli_ring *pring;
2601 spin_lock_irq(phba->host->host_lock);
2602 INIT_LIST_HEAD(&psli->mboxq);
2603 /* Initialize list headers for txq and txcmplq as double linked lists */
2604 for (i = 0; i < psli->num_rings; i++) {
2605 pring = &psli->ring[i];
2607 pring->next_cmdidx = 0;
2608 pring->local_getidx = 0;
2610 INIT_LIST_HEAD(&pring->txq);
2611 INIT_LIST_HEAD(&pring->txcmplq);
2612 INIT_LIST_HEAD(&pring->iocb_continueq);
2613 INIT_LIST_HEAD(&pring->postbufq);
2615 spin_unlock_irq(phba->host->host_lock);
2620 lpfc_sli_hba_down(struct lpfc_hba * phba)
2622 LIST_HEAD(completions);
2623 struct lpfc_sli *psli;
2624 struct lpfc_sli_ring *pring;
2626 struct lpfc_iocbq *iocb;
2629 unsigned long flags = 0;
2632 lpfc_hba_down_prep(phba);
2634 spin_lock_irqsave(phba->host->host_lock, flags);
2635 for (i = 0; i < psli->num_rings; i++) {
2636 pring = &psli->ring[i];
2637 pring->flag |= LPFC_DEFERRED_RING_EVENT;
2640 * Error everything on the txq since these iocbs have not been
2641 * given to the FW yet.
2643 list_splice_init(&pring->txq, &completions);
2647 spin_unlock_irqrestore(phba->host->host_lock, flags);
2649 while (!list_empty(&completions)) {
2650 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
2652 list_del(&iocb->list);
2654 if (iocb->iocb_cmpl) {
2655 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2656 cmd->un.ulpWord[4] = IOERR_SLI_DOWN;
2657 (iocb->iocb_cmpl) (phba, iocb, iocb);
2659 lpfc_sli_release_iocbq(phba, iocb);
2662 /* Return any active mbox cmds */
2663 del_timer_sync(&psli->mbox_tmo);
2664 spin_lock_irqsave(phba->host->host_lock, flags);
2665 phba->work_hba_events &= ~WORKER_MBOX_TMO;
2666 if (psli->mbox_active) {
2667 pmb = psli->mbox_active;
2668 pmb->mb.mbxStatus = MBX_NOT_FINISHED;
2669 if (pmb->mbox_cmpl) {
2670 spin_unlock_irqrestore(phba->host->host_lock, flags);
2671 pmb->mbox_cmpl(phba,pmb);
2672 spin_lock_irqsave(phba->host->host_lock, flags);
2675 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2676 psli->mbox_active = NULL;
2678 /* Return any pending mbox cmds */
2679 while ((pmb = lpfc_mbox_get(phba)) != NULL) {
2680 pmb->mb.mbxStatus = MBX_NOT_FINISHED;
2681 if (pmb->mbox_cmpl) {
2682 spin_unlock_irqrestore(phba->host->host_lock, flags);
2683 pmb->mbox_cmpl(phba,pmb);
2684 spin_lock_irqsave(phba->host->host_lock, flags);
2688 INIT_LIST_HEAD(&psli->mboxq);
2690 spin_unlock_irqrestore(phba->host->host_lock, flags);
2696 lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
2698 uint32_t *src = srcp;
2699 uint32_t *dest = destp;
2703 for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
2705 ldata = le32_to_cpu(ldata);
2713 lpfc_sli_ringpostbuf_put(struct lpfc_hba * phba, struct lpfc_sli_ring * pring,
2714 struct lpfc_dmabuf * mp)
2716 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
2718 list_add_tail(&mp->list, &pring->postbufq);
2720 pring->postbufq_cnt++;
2725 struct lpfc_dmabuf *
2726 lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2729 struct lpfc_dmabuf *mp, *next_mp;
2730 struct list_head *slp = &pring->postbufq;
2732 /* Search postbufq, from the begining, looking for a match on phys */
2733 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
2734 if (mp->phys == phys) {
2735 list_del_init(&mp->list);
2736 pring->postbufq_cnt--;
2741 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2742 "%d:0410 Cannot find virtual addr for mapped buf on "
2743 "ring %d Data x%llx x%p x%p x%x\n",
2744 phba->brd_no, pring->ringno, (unsigned long long)phys,
2745 slp->next, slp->prev, pring->postbufq_cnt);
2750 lpfc_sli_abort_els_cmpl(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2751 struct lpfc_iocbq * rspiocb)
2754 uint16_t abort_iotag, abort_context;
2755 struct lpfc_iocbq *abort_iocb, *rsp_ab_iocb;
2756 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
2759 irsp = &rspiocb->iocb;
2761 spin_lock_irq(phba->host->host_lock);
2763 if (irsp->ulpStatus) {
2764 abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
2765 abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
2767 if (abort_iotag != 0 && abort_iotag <= phba->sli.last_iotag)
2768 abort_iocb = phba->sli.iocbq_lookup[abort_iotag];
2770 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2771 "%d:0327 Cannot abort els iocb %p"
2772 " with tag %x context %x\n",
2773 phba->brd_no, abort_iocb,
2774 abort_iotag, abort_context);
2777 * make sure we have the right iocbq before taking it
2778 * off the txcmplq and try to call completion routine.
2781 abort_iocb->iocb.ulpContext == abort_context &&
2782 abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) {
2783 list_del(&abort_iocb->list);
2784 pring->txcmplq_cnt--;
2786 rsp_ab_iocb = lpfc_sli_get_iocbq(phba);
2787 if (rsp_ab_iocb == NULL)
2788 lpfc_sli_release_iocbq(phba, abort_iocb);
2790 abort_iocb->iocb_flag &=
2791 ~LPFC_DRIVER_ABORTED;
2792 rsp_ab_iocb->iocb.ulpStatus =
2793 IOSTAT_LOCAL_REJECT;
2794 rsp_ab_iocb->iocb.un.ulpWord[4] =
2796 spin_unlock_irq(phba->host->host_lock);
2797 (abort_iocb->iocb_cmpl)
2798 (phba, abort_iocb, rsp_ab_iocb);
2799 spin_lock_irq(phba->host->host_lock);
2800 lpfc_sli_release_iocbq(phba, rsp_ab_iocb);
2805 lpfc_sli_release_iocbq(phba, cmdiocb);
2806 spin_unlock_irq(phba->host->host_lock);
2811 lpfc_sli_issue_abort_iotag(struct lpfc_hba * phba,
2812 struct lpfc_sli_ring * pring,
2813 struct lpfc_iocbq * cmdiocb)
2815 struct lpfc_iocbq *abtsiocbp;
2816 IOCB_t *icmd = NULL;
2817 IOCB_t *iabt = NULL;
2818 int retval = IOCB_ERROR;
2820 /* There are certain command types we don't want
2823 icmd = &cmdiocb->iocb;
2824 if ((icmd->ulpCommand == CMD_ABORT_XRI_CN) ||
2825 (icmd->ulpCommand == CMD_CLOSE_XRI_CN))
2828 /* If we're unloading, interrupts are disabled so we
2829 * need to cleanup the iocb here.
2831 if (phba->fc_flag & FC_UNLOADING)
2832 goto abort_iotag_exit;
2834 /* issue ABTS for this IOCB based on iotag */
2835 abtsiocbp = lpfc_sli_get_iocbq(phba);
2836 if (abtsiocbp == NULL)
2839 /* This signals the response to set the correct status
2840 * before calling the completion handler.
2842 cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
2844 iabt = &abtsiocbp->iocb;
2845 iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
2846 iabt->un.acxri.abortContextTag = icmd->ulpContext;
2847 iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
2849 iabt->ulpClass = icmd->ulpClass;
2851 if (phba->hba_state >= LPFC_LINK_UP)
2852 iabt->ulpCommand = CMD_ABORT_XRI_CN;
2854 iabt->ulpCommand = CMD_CLOSE_XRI_CN;
2856 abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
2858 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2859 "%d:0339 Abort xri x%x, original iotag x%x, abort "
2861 phba->brd_no, iabt->un.acxri.abortContextTag,
2862 iabt->un.acxri.abortIoTag, abtsiocbp->iotag);
2863 retval = lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0);
2867 /* If we could not issue an abort dequeue the iocb and handle
2868 * the completion here.
2870 if (retval == IOCB_ERROR) {
2871 list_del(&cmdiocb->list);
2872 pring->txcmplq_cnt--;
2874 if (cmdiocb->iocb_cmpl) {
2875 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2876 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
2877 spin_unlock_irq(phba->host->host_lock);
2878 (cmdiocb->iocb_cmpl) (phba, cmdiocb, cmdiocb);
2879 spin_lock_irq(phba->host->host_lock);
2881 lpfc_sli_release_iocbq(phba, cmdiocb);
2888 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, uint16_t tgt_id,
2889 uint64_t lun_id, uint32_t ctx,
2890 lpfc_ctx_cmd ctx_cmd)
2892 struct lpfc_scsi_buf *lpfc_cmd;
2893 struct scsi_cmnd *cmnd;
2896 if (!(iocbq->iocb_flag & LPFC_IO_FCP))
2899 lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
2900 cmnd = lpfc_cmd->pCmd;
2907 if ((cmnd->device->id == tgt_id) &&
2908 (cmnd->device->lun == lun_id))
2912 if (cmnd->device->id == tgt_id)
2916 if (iocbq->iocb.ulpContext == ctx)
2923 printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
2924 __FUNCTION__, ctx_cmd);
2932 lpfc_sli_sum_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2933 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd ctx_cmd)
2935 struct lpfc_iocbq *iocbq;
2938 for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
2939 iocbq = phba->sli.iocbq_lookup[i];
2941 if (lpfc_sli_validate_fcp_iocb (iocbq, tgt_id, lun_id,
2950 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2951 struct lpfc_iocbq * rspiocb)
2953 unsigned long iflags;
2955 spin_lock_irqsave(phba->host->host_lock, iflags);
2956 lpfc_sli_release_iocbq(phba, cmdiocb);
2957 spin_unlock_irqrestore(phba->host->host_lock, iflags);
2962 lpfc_sli_abort_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2963 uint16_t tgt_id, uint64_t lun_id, uint32_t ctx,
2964 lpfc_ctx_cmd abort_cmd)
2966 struct lpfc_iocbq *iocbq;
2967 struct lpfc_iocbq *abtsiocb;
2969 int errcnt = 0, ret_val = 0;
2972 for (i = 1; i <= phba->sli.last_iotag; i++) {
2973 iocbq = phba->sli.iocbq_lookup[i];
2975 if (lpfc_sli_validate_fcp_iocb (iocbq, tgt_id, lun_id,
2979 /* issue ABTS for this IOCB based on iotag */
2980 abtsiocb = lpfc_sli_get_iocbq(phba);
2981 if (abtsiocb == NULL) {
2987 abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
2988 abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
2989 abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
2990 abtsiocb->iocb.ulpLe = 1;
2991 abtsiocb->iocb.ulpClass = cmd->ulpClass;
2993 if (phba->hba_state >= LPFC_LINK_UP)
2994 abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
2996 abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
2998 /* Setup callback routine and issue the command. */
2999 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
3000 ret_val = lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0);
3001 if (ret_val == IOCB_ERROR) {
3002 lpfc_sli_release_iocbq(phba, abtsiocb);
3012 lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
3013 struct lpfc_iocbq *cmdiocbq,
3014 struct lpfc_iocbq *rspiocbq)
3016 wait_queue_head_t *pdone_q;
3017 unsigned long iflags;
3019 spin_lock_irqsave(phba->host->host_lock, iflags);
3020 cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
3021 if (cmdiocbq->context2 && rspiocbq)
3022 memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
3023 &rspiocbq->iocb, sizeof(IOCB_t));
3025 pdone_q = cmdiocbq->context_un.wait_queue;
3026 spin_unlock_irqrestore(phba->host->host_lock, iflags);
3033 * Issue the caller's iocb and wait for its completion, but no longer than the
3034 * caller's timeout. Note that iocb_flags is cleared before the
3035 * lpfc_sli_issue_call since the wake routine sets a unique value and by
3036 * definition this is a wait function.
3039 lpfc_sli_issue_iocb_wait(struct lpfc_hba * phba,
3040 struct lpfc_sli_ring * pring,
3041 struct lpfc_iocbq * piocb,
3042 struct lpfc_iocbq * prspiocbq,
3045 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
3046 long timeleft, timeout_req = 0;
3047 int retval = IOCB_SUCCESS;
3051 * If the caller has provided a response iocbq buffer, then context2
3052 * is NULL or its an error.
3055 if (piocb->context2)
3057 piocb->context2 = prspiocbq;
3060 piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
3061 piocb->context_un.wait_queue = &done_q;
3062 piocb->iocb_flag &= ~LPFC_IO_WAKE;
3064 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
3065 creg_val = readl(phba->HCregaddr);
3066 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
3067 writel(creg_val, phba->HCregaddr);
3068 readl(phba->HCregaddr); /* flush */
3071 retval = lpfc_sli_issue_iocb(phba, pring, piocb, 0);
3072 if (retval == IOCB_SUCCESS) {
3073 timeout_req = timeout * HZ;
3074 spin_unlock_irq(phba->host->host_lock);
3075 timeleft = wait_event_timeout(done_q,
3076 piocb->iocb_flag & LPFC_IO_WAKE,
3078 spin_lock_irq(phba->host->host_lock);
3080 if (piocb->iocb_flag & LPFC_IO_WAKE) {
3081 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3082 "%d:0331 IOCB wake signaled\n",
3084 } else if (timeleft == 0) {
3085 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3086 "%d:0338 IOCB wait timeout error - no "
3087 "wake response Data x%x\n",
3088 phba->brd_no, timeout);
3089 retval = IOCB_TIMEDOUT;
3091 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3092 "%d:0330 IOCB wake NOT set, "
3093 "Data x%x x%lx\n", phba->brd_no,
3094 timeout, (timeleft / jiffies));
3095 retval = IOCB_TIMEDOUT;
3098 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3099 "%d:0332 IOCB wait issue failed, Data x%x\n",
3100 phba->brd_no, retval);
3101 retval = IOCB_ERROR;
3104 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
3105 creg_val = readl(phba->HCregaddr);
3106 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
3107 writel(creg_val, phba->HCregaddr);
3108 readl(phba->HCregaddr); /* flush */
3112 piocb->context2 = NULL;
3114 piocb->context_un.wait_queue = NULL;
3115 piocb->iocb_cmpl = NULL;
3120 lpfc_sli_issue_mbox_wait(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq,
3123 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
3126 /* The caller must leave context1 empty. */
3127 if (pmboxq->context1 != 0) {
3128 return (MBX_NOT_FINISHED);
3131 /* setup wake call as IOCB callback */
3132 pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
3133 /* setup context field to pass wait_queue pointer to wake function */
3134 pmboxq->context1 = &done_q;
3136 /* now issue the command */
3137 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
3139 if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
3140 wait_event_interruptible_timeout(done_q,
3141 pmboxq->mbox_flag & LPFC_MBX_WAKE,
3144 pmboxq->context1 = NULL;
3146 * if LPFC_MBX_WAKE flag is set the mailbox is completed
3147 * else do not free the resources.
3149 if (pmboxq->mbox_flag & LPFC_MBX_WAKE)
3150 retval = MBX_SUCCESS;
3152 retval = MBX_TIMEOUT;
3159 lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba)
3163 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE && !phba->stopped) {
3164 if (i++ > LPFC_MBOX_TMO * 1000)
3167 if (lpfc_sli_handle_mb_event(phba) == 0)
3173 return (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) ? 1 : 0;
3177 lpfc_intr_handler(int irq, void *dev_id)
3179 struct lpfc_hba *phba;
3181 uint32_t work_ha_copy;
3182 unsigned long status;
3187 * Get the driver's phba structure from the dev_id and
3188 * assume the HBA is not interrupting.
3190 phba = (struct lpfc_hba *) dev_id;
3192 if (unlikely(!phba))
3195 /* If the pci channel is offline, ignore all the interrupts. */
3196 if (unlikely(pci_channel_offline(phba->pcidev)))
3199 phba->sli.slistat.sli_intr++;
3202 * Call the HBA to see if it is interrupting. If not, don't claim
3206 /* Ignore all interrupts during initialization. */
3207 if (unlikely(phba->hba_state < LPFC_LINK_DOWN))
3211 * Read host attention register to determine interrupt source
3212 * Clear Attention Sources, except Error Attention (to
3213 * preserve status) and Link Attention
3215 spin_lock(phba->host->host_lock);
3216 ha_copy = readl(phba->HAregaddr);
3217 /* If somebody is waiting to handle an eratt don't process it
3218 * here. The brdkill function will do this.
3220 if (phba->fc_flag & FC_IGNORE_ERATT)
3221 ha_copy &= ~HA_ERATT;
3222 writel((ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
3223 readl(phba->HAregaddr); /* flush */
3224 spin_unlock(phba->host->host_lock);
3226 if (unlikely(!ha_copy))
3229 work_ha_copy = ha_copy & phba->work_ha_mask;
3231 if (unlikely(work_ha_copy)) {
3232 if (work_ha_copy & HA_LATT) {
3233 if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
3235 * Turn off Link Attention interrupts
3236 * until CLEAR_LA done
3238 spin_lock(phba->host->host_lock);
3239 phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
3240 control = readl(phba->HCregaddr);
3241 control &= ~HC_LAINT_ENA;
3242 writel(control, phba->HCregaddr);
3243 readl(phba->HCregaddr); /* flush */
3244 spin_unlock(phba->host->host_lock);
3247 work_ha_copy &= ~HA_LATT;
3250 if (work_ha_copy & ~(HA_ERATT|HA_MBATT|HA_LATT)) {
3251 for (i = 0; i < phba->sli.num_rings; i++) {
3252 if (work_ha_copy & (HA_RXATT << (4*i))) {
3254 * Turn off Slow Rings interrupts
3256 spin_lock(phba->host->host_lock);
3257 control = readl(phba->HCregaddr);
3258 control &= ~(HC_R0INT_ENA << i);
3259 writel(control, phba->HCregaddr);
3260 readl(phba->HCregaddr); /* flush */
3261 spin_unlock(phba->host->host_lock);
3266 if (work_ha_copy & HA_ERATT) {
3267 phba->hba_state = LPFC_HBA_ERROR;
3269 * There was a link/board error. Read the
3270 * status register to retrieve the error event
3273 phba->sli.slistat.err_attn_event++;
3274 /* Save status info */
3275 phba->work_hs = readl(phba->HSregaddr);
3276 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
3277 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
3279 /* Clear Chip error bit */
3280 writel(HA_ERATT, phba->HAregaddr);
3281 readl(phba->HAregaddr); /* flush */
3285 spin_lock(phba->host->host_lock);
3286 phba->work_ha |= work_ha_copy;
3287 if (phba->work_wait)
3288 wake_up(phba->work_wait);
3289 spin_unlock(phba->host->host_lock);
3292 ha_copy &= ~(phba->work_ha_mask);
3295 * Process all events on FCP ring. Take the optimized path for
3296 * FCP IO. Any other IO is slow path and is handled by
3297 * the worker thread.
3299 status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
3300 status >>= (4*LPFC_FCP_RING);
3301 if (status & HA_RXATT)
3302 lpfc_sli_handle_fast_ring_event(phba,
3303 &phba->sli.ring[LPFC_FCP_RING],
3306 if (phba->cfg_multi_ring_support == 2) {
3308 * Process all events on extra ring. Take the optimized path
3309 * for extra ring IO. Any other IO is slow path and is handled
3310 * by the worker thread.
3312 status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
3313 status >>= (4*LPFC_EXTRA_RING);
3314 if (status & HA_RXATT) {
3315 lpfc_sli_handle_fast_ring_event(phba,
3316 &phba->sli.ring[LPFC_EXTRA_RING],
3322 } /* lpfc_intr_handler */