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", \
55 phba->pport->port_state, \
60 /* There are only four IOCB completion types. */
61 typedef enum _lpfc_iocb_type {
69 * SLI-2/SLI-3 provide different sized iocbs. Given a pointer to the start of
70 * the ring, and the slot number of the desired iocb entry, calc a pointer to
73 static inline IOCB_t *
74 lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
76 return (IOCB_t *) (((char *) pring->cmdringaddr) +
77 pring->cmdidx * phba->iocb_cmd_size);
80 static inline IOCB_t *
81 lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
83 return (IOCB_t *) (((char *) pring->rspringaddr) +
84 pring->rspidx * phba->iocb_rsp_size);
87 static struct lpfc_iocbq *
88 __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
90 struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
91 struct lpfc_iocbq * iocbq = NULL;
93 list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
98 lpfc_sli_get_iocbq(struct lpfc_hba *phba)
100 struct lpfc_iocbq * iocbq = NULL;
101 unsigned long iflags;
103 spin_lock_irqsave(&phba->hbalock, iflags);
104 iocbq = __lpfc_sli_get_iocbq(phba);
105 spin_unlock_irqrestore(&phba->hbalock, iflags);
110 __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
112 size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
115 * Clean all volatile data fields, preserve iotag and node struct.
117 memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
118 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
122 lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
124 unsigned long iflags;
127 * Clean all volatile data fields, preserve iotag and node struct.
129 spin_lock_irqsave(&phba->hbalock, iflags);
130 __lpfc_sli_release_iocbq(phba, iocbq);
131 spin_unlock_irqrestore(&phba->hbalock, iflags);
135 * Translate the iocb command to an iocb command type used to decide the final
136 * disposition of each completed IOCB.
138 static lpfc_iocb_type
139 lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
141 lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
143 if (iocb_cmnd > CMD_MAX_IOCB_CMD)
147 case CMD_XMIT_SEQUENCE_CR:
148 case CMD_XMIT_SEQUENCE_CX:
149 case CMD_XMIT_BCAST_CN:
150 case CMD_XMIT_BCAST_CX:
151 case CMD_ELS_REQUEST_CR:
152 case CMD_ELS_REQUEST_CX:
153 case CMD_CREATE_XRI_CR:
154 case CMD_CREATE_XRI_CX:
156 case CMD_XMIT_ELS_RSP_CX:
158 case CMD_FCP_IWRITE_CR:
159 case CMD_FCP_IWRITE_CX:
160 case CMD_FCP_IREAD_CR:
161 case CMD_FCP_IREAD_CX:
162 case CMD_FCP_ICMND_CR:
163 case CMD_FCP_ICMND_CX:
164 case CMD_FCP_TSEND_CX:
165 case CMD_FCP_TRSP_CX:
166 case CMD_FCP_TRECEIVE_CX:
167 case CMD_FCP_AUTO_TRSP_CX:
168 case CMD_ADAPTER_MSG:
169 case CMD_ADAPTER_DUMP:
170 case CMD_XMIT_SEQUENCE64_CR:
171 case CMD_XMIT_SEQUENCE64_CX:
172 case CMD_XMIT_BCAST64_CN:
173 case CMD_XMIT_BCAST64_CX:
174 case CMD_ELS_REQUEST64_CR:
175 case CMD_ELS_REQUEST64_CX:
176 case CMD_FCP_IWRITE64_CR:
177 case CMD_FCP_IWRITE64_CX:
178 case CMD_FCP_IREAD64_CR:
179 case CMD_FCP_IREAD64_CX:
180 case CMD_FCP_ICMND64_CR:
181 case CMD_FCP_ICMND64_CX:
182 case CMD_FCP_TSEND64_CX:
183 case CMD_FCP_TRSP64_CX:
184 case CMD_FCP_TRECEIVE64_CX:
185 case CMD_GEN_REQUEST64_CR:
186 case CMD_GEN_REQUEST64_CX:
187 case CMD_XMIT_ELS_RSP64_CX:
188 type = LPFC_SOL_IOCB;
190 case CMD_ABORT_XRI_CN:
191 case CMD_ABORT_XRI_CX:
192 case CMD_CLOSE_XRI_CN:
193 case CMD_CLOSE_XRI_CX:
194 case CMD_XRI_ABORTED_CX:
195 case CMD_ABORT_MXRI64_CN:
196 type = LPFC_ABORT_IOCB;
198 case CMD_RCV_SEQUENCE_CX:
199 case CMD_RCV_ELS_REQ_CX:
200 case CMD_RCV_SEQUENCE64_CX:
201 case CMD_RCV_ELS_REQ64_CX:
202 case CMD_IOCB_RCV_SEQ64_CX:
203 case CMD_IOCB_RCV_ELS64_CX:
204 case CMD_IOCB_RCV_CONT64_CX:
205 type = LPFC_UNSOL_IOCB;
208 type = LPFC_UNKNOWN_IOCB;
216 lpfc_sli_ring_map(struct lpfc_hba *phba)
218 struct lpfc_sli *psli = &phba->sli;
223 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
227 phba->link_state = LPFC_INIT_MBX_CMDS;
228 for (i = 0; i < psli->num_rings; i++) {
229 lpfc_config_ring(phba, i, pmb);
230 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
231 if (rc != MBX_SUCCESS) {
232 lpfc_printf_log(phba,
235 "%d:0446 Adapter failed to init, "
236 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
242 phba->link_state = LPFC_HBA_ERROR;
247 mempool_free(pmb, phba->mbox_mem_pool);
252 lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
253 struct lpfc_iocbq *piocb)
255 list_add_tail(&piocb->list, &pring->txcmplq);
256 pring->txcmplq_cnt++;
257 if (unlikely(pring->ringno == LPFC_ELS_RING))
258 mod_timer(&piocb->vport->els_tmofunc,
259 jiffies + HZ * (phba->fc_ratov << 1));
264 static struct lpfc_iocbq *
265 lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
267 struct list_head *dlp;
268 struct lpfc_iocbq *cmd_iocb;
272 list_remove_head((&pring->txq), cmd_iocb,
276 /* If the first ptr is not equal to the list header,
277 * deque the IOCBQ_t and return it.
285 lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
287 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
288 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
289 &phba->slim2p->mbx.us.s2.port[pring->ringno];
290 uint32_t max_cmd_idx = pring->numCiocb;
292 if ((pring->next_cmdidx == pring->cmdidx) &&
293 (++pring->next_cmdidx >= max_cmd_idx))
294 pring->next_cmdidx = 0;
296 if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
298 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
300 if (unlikely(pring->local_getidx >= max_cmd_idx)) {
301 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
302 "%d:0315 Ring %d issue: portCmdGet %d "
303 "is bigger then cmd ring %d\n",
304 phba->brd_no, pring->ringno,
305 pring->local_getidx, max_cmd_idx);
307 phba->link_state = LPFC_HBA_ERROR;
309 * All error attention handlers are posted to
312 phba->work_ha |= HA_ERATT;
313 phba->work_hs = HS_FFER3;
315 wake_up(phba->work_wait);
320 if (pring->local_getidx == pring->next_cmdidx)
324 return lpfc_cmd_iocb(phba, pring);
328 lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
330 struct lpfc_iocbq **new_arr;
331 struct lpfc_iocbq **old_arr;
333 struct lpfc_sli *psli = &phba->sli;
336 spin_lock_irq(&phba->hbalock);
337 iotag = psli->last_iotag;
338 if(++iotag < psli->iocbq_lookup_len) {
339 psli->last_iotag = iotag;
340 psli->iocbq_lookup[iotag] = iocbq;
341 spin_unlock_irq(&phba->hbalock);
342 iocbq->iotag = iotag;
344 } else if (psli->iocbq_lookup_len < (0xffff
345 - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
346 new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
347 spin_unlock_irq(&phba->hbalock);
348 new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
351 spin_lock_irq(&phba->hbalock);
352 old_arr = psli->iocbq_lookup;
353 if (new_len <= psli->iocbq_lookup_len) {
354 /* highly unprobable case */
356 iotag = psli->last_iotag;
357 if(++iotag < psli->iocbq_lookup_len) {
358 psli->last_iotag = iotag;
359 psli->iocbq_lookup[iotag] = iocbq;
360 spin_unlock_irq(&phba->hbalock);
361 iocbq->iotag = iotag;
364 spin_unlock_irq(&phba->hbalock);
367 if (psli->iocbq_lookup)
368 memcpy(new_arr, old_arr,
369 ((psli->last_iotag + 1) *
370 sizeof (struct lpfc_iocbq *)));
371 psli->iocbq_lookup = new_arr;
372 psli->iocbq_lookup_len = new_len;
373 psli->last_iotag = iotag;
374 psli->iocbq_lookup[iotag] = iocbq;
375 spin_unlock_irq(&phba->hbalock);
376 iocbq->iotag = iotag;
381 spin_unlock_irq(&phba->hbalock);
383 lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
384 "%d:0318 Failed to allocate IOTAG.last IOTAG is %d\n",
385 phba->brd_no, psli->last_iotag);
391 lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
392 IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
397 nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
400 * Issue iocb command to adapter
402 lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, sizeof (IOCB_t));
404 pring->stats.iocb_cmd++;
407 * If there is no completion routine to call, we can release the
408 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
409 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
411 if (nextiocb->iocb_cmpl)
412 lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
414 __lpfc_sli_release_iocbq(phba, nextiocb);
417 * Let the HBA know what IOCB slot will be the next one the
418 * driver will put a command into.
420 pring->cmdidx = pring->next_cmdidx;
421 writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
425 lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
427 int ringno = pring->ringno;
429 pring->flag |= LPFC_CALL_RING_AVAILABLE;
434 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
435 * The HBA will tell us when an IOCB entry is available.
437 writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
438 readl(phba->CAregaddr); /* flush */
440 pring->stats.iocb_cmd_full++;
444 lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
446 int ringno = pring->ringno;
449 * Tell the HBA that there is work to do in this ring.
452 writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
453 readl(phba->CAregaddr); /* flush */
457 lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
460 struct lpfc_iocbq *nextiocb;
464 * (a) there is anything on the txq to send
466 * (c) link attention events can be processed (fcp ring only)
467 * (d) IOCB processing is not blocked by the outstanding mbox command.
469 if (pring->txq_cnt &&
470 lpfc_is_link_up(phba) &&
471 (pring->ringno != phba->sli.fcp_ring ||
472 phba->sli.sli_flag & LPFC_PROCESS_LA) &&
473 !(pring->flag & LPFC_STOP_IOCB_MBX)) {
475 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
476 (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
477 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
480 lpfc_sli_update_ring(phba, pring);
482 lpfc_sli_update_full_ring(phba, pring);
488 /* lpfc_sli_turn_on_ring is only called by lpfc_sli_handle_mb_event below */
490 lpfc_sli_turn_on_ring(struct lpfc_hba *phba, int ringno)
492 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
493 &phba->slim2p->mbx.us.s3_pgp.port[ringno] :
494 &phba->slim2p->mbx.us.s2.port[ringno];
495 unsigned long iflags;
497 /* If the ring is active, flag it */
498 spin_lock_irqsave(&phba->hbalock, iflags);
499 if (phba->sli.ring[ringno].cmdringaddr) {
500 if (phba->sli.ring[ringno].flag & LPFC_STOP_IOCB_MBX) {
501 phba->sli.ring[ringno].flag &= ~LPFC_STOP_IOCB_MBX;
503 * Force update of the local copy of cmdGetInx
505 phba->sli.ring[ringno].local_getidx
506 = le32_to_cpu(pgp->cmdGetInx);
507 lpfc_sli_resume_iocb(phba, &phba->sli.ring[ringno]);
510 spin_unlock_irqrestore(&phba->hbalock, iflags);
513 struct lpfc_hbq_entry *
514 lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
516 struct hbq_s *hbqp = &phba->hbqs[hbqno];
518 if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
519 ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
520 hbqp->next_hbqPutIdx = 0;
522 if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
523 uint32_t raw_index = readl(&phba->hbq_get[hbqno]);
524 uint32_t getidx = le32_to_cpu(raw_index);
526 hbqp->local_hbqGetIdx = getidx;
528 if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
529 lpfc_printf_log(phba, KERN_ERR,
531 "%d:1802 HBQ %d: local_hbqGetIdx "
532 "%u is > than hbqp->entry_count %u\n",
534 hbqp->local_hbqGetIdx,
537 phba->link_state = LPFC_HBA_ERROR;
541 if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
545 return (struct lpfc_hbq_entry *) phba->hbqslimp.virt + hbqp->hbqPutIdx;
549 lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
553 if (!phba->hbq_buffer_pool)
555 /* Return all memory used by all HBQs */
556 for (i = 0; i < phba->hbq_buffer_count; i++) {
557 lpfc_hbq_free(phba, phba->hbq_buffer_pool[i].dbuf.virt,
558 phba->hbq_buffer_pool[i].dbuf.phys);
560 kfree(phba->hbq_buffer_pool);
561 phba->hbq_buffer_pool = NULL;
565 lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
566 struct hbq_dmabuf *hbq_buf_desc)
568 struct lpfc_hbq_entry *hbqe;
570 /* Get next HBQ entry slot to use */
571 hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
573 struct hbq_s *hbqp = &phba->hbqs[hbqno];
575 hbqe->bde.addrHigh = putPaddrHigh(hbq_buf_desc->dbuf.phys);
576 hbqe->bde.addrLow = putPaddrLow(hbq_buf_desc->dbuf.phys);
577 hbqe->bde.tus.f.bdeSize = FCELSSIZE;
578 hbqe->bde.tus.f.bdeFlags = 0;
579 hbqe->buffer_tag = hbq_buf_desc->tag;
581 hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
582 writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
584 readl(phba->hbq_put + hbqno);
585 phba->hbq_buff_count++;
590 lpfc_sli_fill_hbq(struct lpfc_hba *phba, uint32_t hbqno, uint32_t buffer_index)
592 struct hbq_dmabuf *hbq_buf_desc;
595 for (i = 0; i < phba->hbqs[hbqno].entry_count; i++) {
596 /* Search hbqbufq, from the begining,
597 * looking for an unused entry
599 phba->hbq_buffer_pool[buffer_index + i].tag |= hbqno << 16;
600 hbq_buf_desc = phba->hbq_buffer_pool + buffer_index + i;
601 lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf_desc);
606 lpfc_sli_hbqbuf_fill_hbq(struct lpfc_hba *phba)
612 lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba)
614 uint32_t buffer_index = 0;
617 /* Populate HBQ entries */
618 for (hbqno = 0; hbqno < phba->hbq_count; ++hbqno) {
619 /* Find ring associated with HBQ */
621 lpfc_sli_fill_hbq(phba, hbqno, buffer_index);
622 buffer_index += phba->hbqs[hbqno].entry_count;
628 lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
630 if ((tag & 0xffff) < phba->hbq_buffer_count)
631 return phba->hbq_buffer_pool + (tag & 0xffff);
633 lpfc_printf_log(phba, KERN_ERR,
635 "%d:1803 Bad hbq tag. Data: x%x x%x\n",
637 phba->hbq_buffer_count);
642 lpfc_sli_hbqbuf_free(struct lpfc_hba *phba, void *virt, dma_addr_t phys)
646 for (i = 0; i < phba->hbq_buffer_count; i++) {
647 /* Search hbqbufq, from the begining, looking for a match on
649 if (phba->hbq_buffer_pool[i].dbuf.phys == phys) {
650 hbqno = phba->hbq_buffer_pool[i].tag >> 16;
651 lpfc_sli_hbq_to_firmware(phba, hbqno,
652 phba->hbq_buffer_pool + i);
657 lpfc_printf_log(phba, KERN_ERR,
659 "%d:1804 Cannot find virtual addr for "
660 "mapped buf. Data x%llx\n",
661 phba->brd_no, (unsigned long long) phys);
665 lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *sp)
670 hbqno = sp->tag >> 16;
671 lpfc_sli_hbq_to_firmware(phba, hbqno, sp);
676 lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
680 switch (mbxCommand) {
684 case MBX_RUN_BIU_DIAG:
687 case MBX_CONFIG_LINK:
688 case MBX_CONFIG_RING:
690 case MBX_READ_CONFIG:
691 case MBX_READ_RCONFIG:
693 case MBX_READ_STATUS:
697 case MBX_READ_LNK_STAT:
699 case MBX_UNREG_LOGIN:
702 case MBX_DUMP_MEMORY:
703 case MBX_DUMP_CONTEXT:
708 case MBX_DEL_LD_ENTRY:
709 case MBX_RUN_PROGRAM:
714 case MBX_CONFIG_FARP:
717 case MBX_RUN_BIU_DIAG64:
718 case MBX_CONFIG_PORT:
719 case MBX_READ_SPARM64:
721 case MBX_REG_LOGIN64:
723 case MBX_FLASH_WR_ULA:
725 case MBX_LOAD_EXP_ROM:
735 lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
737 wait_queue_head_t *pdone_q;
740 * If pdone_q is empty, the driver thread gave up waiting and
743 pmboxq->mbox_flag |= LPFC_MBX_WAKE;
744 pdone_q = (wait_queue_head_t *) pmboxq->context1;
746 wake_up_interruptible(pdone_q);
751 lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
753 struct lpfc_dmabuf *mp;
757 mp = (struct lpfc_dmabuf *) (pmb->context1);
760 lpfc_mbuf_free(phba, mp->virt, mp->phys);
765 * If a REG_LOGIN succeeded after node is destroyed or node
766 * is in re-discovery driver need to cleanup the RPI.
768 if (!(phba->pport->load_flag & FC_UNLOADING) &&
769 pmb->mb.mbxCommand == MBX_REG_LOGIN64 &&
770 !pmb->mb.mbxStatus) {
772 rpi = pmb->mb.un.varWords[0];
773 lpfc_unreg_login(phba, rpi, pmb);
774 pmb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
775 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
776 if (rc != MBX_NOT_FINISHED)
780 mempool_free(pmb, phba->mbox_mem_pool);
785 lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
787 MAILBOX_t *mbox, *pmbox;
790 uint32_t process_next;
791 unsigned long iflags;
793 /* We should only get here if we are in SLI2 mode */
794 if (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE)) {
798 phba->sli.slistat.mbox_event++;
800 /* Get a Mailbox buffer to setup mailbox commands for callback */
801 if ((pmb = phba->sli.mbox_active)) {
803 mbox = &phba->slim2p->mbx;
805 /* First check out the status word */
806 lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof (uint32_t));
808 /* Sanity check to ensure the host owns the mailbox */
809 if (pmbox->mbxOwner != OWN_HOST) {
810 /* Lets try for a while */
811 for (i = 0; i < 10240; i++) {
812 /* First copy command data */
813 lpfc_sli_pcimem_bcopy(mbox, pmbox,
815 if (pmbox->mbxOwner == OWN_HOST)
818 /* Stray Mailbox Interrupt, mbxCommand <cmd> mbxStatus
820 lpfc_printf_log(phba,
823 "%d:0304 Stray Mailbox Interrupt "
824 "mbxCommand x%x mbxStatus x%x\n",
829 spin_lock_irq(&phba->hbalock);
830 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
831 spin_unlock_irq(&phba->hbalock);
836 del_timer_sync(&phba->sli.mbox_tmo);
838 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
839 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
840 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
843 * It is a fatal error if unknown mbox command completion.
845 if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
848 /* Unknow mailbox command compl */
849 lpfc_printf_log(phba,
852 "%d:0323 Unknown Mailbox command %x Cmpl\n",
855 phba->link_state = LPFC_HBA_ERROR;
856 phba->work_hs = HS_FFER3;
857 lpfc_handle_eratt(phba);
861 phba->sli.mbox_active = NULL;
862 if (pmbox->mbxStatus) {
863 phba->sli.slistat.mbox_stat_err++;
864 if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
865 /* Mbox cmd cmpl error - RETRYing */
866 lpfc_printf_log(phba,
869 "%d:0305 Mbox cmd cmpl error - "
870 "RETRYing Data: x%x x%x x%x x%x\n",
874 pmbox->un.varWords[0],
875 phba->pport->port_state);
876 pmbox->mbxStatus = 0;
877 pmbox->mbxOwner = OWN_HOST;
878 spin_lock_irq(&phba->hbalock);
879 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
880 spin_unlock_irq(&phba->hbalock);
881 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
882 if (rc == MBX_SUCCESS)
887 /* Mailbox cmd <cmd> Cmpl <cmpl> */
888 lpfc_printf_log(phba,
891 "%d:0307 Mailbox cmd x%x Cmpl x%p "
892 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
896 *((uint32_t *) pmbox),
897 pmbox->un.varWords[0],
898 pmbox->un.varWords[1],
899 pmbox->un.varWords[2],
900 pmbox->un.varWords[3],
901 pmbox->un.varWords[4],
902 pmbox->un.varWords[5],
903 pmbox->un.varWords[6],
904 pmbox->un.varWords[7]);
906 if (pmb->mbox_cmpl) {
907 lpfc_sli_pcimem_bcopy(mbox, pmbox, MAILBOX_CMD_SIZE);
908 pmb->mbox_cmpl(phba,pmb);
914 process_next = 0; /* by default don't loop */
915 spin_lock_irq(&phba->hbalock);
916 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
918 /* Process next mailbox command if there is one */
919 if ((pmb = lpfc_mbox_get(phba))) {
920 spin_unlock_irq(&phba->hbalock);
921 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
922 if (rc == MBX_NOT_FINISHED) {
923 pmb->mb.mbxStatus = MBX_NOT_FINISHED;
924 pmb->mbox_cmpl(phba,pmb);
926 continue; /* loop back */
929 spin_unlock_irq(&phba->hbalock);
930 /* Turn on IOCB processing */
931 for (i = 0; i < phba->sli.num_rings; i++)
932 lpfc_sli_turn_on_ring(phba, i);
935 } while (process_next);
940 lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
941 struct lpfc_iocbq *saveq)
949 irsp = &(saveq->iocb);
950 if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX)
951 || (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX)
952 || (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)
953 || (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX)) {
958 (WORD5 *) & (saveq->iocb.un.
960 Rctl = w5p->hcsw.Rctl;
961 Type = w5p->hcsw.Type;
963 /* Firmware Workaround */
964 if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
965 (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
966 irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
969 w5p->hcsw.Rctl = Rctl;
970 w5p->hcsw.Type = Type;
973 /* unSolicited Responses */
974 if (pring->prt[0].profile) {
975 if (pring->prt[0].lpfc_sli_rcv_unsol_event)
976 (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
980 /* We must search, based on rctl / type
981 for the right routine */
982 for (i = 0; i < pring->num_mask;
984 if ((pring->prt[i].rctl ==
988 if (pring->prt[i].lpfc_sli_rcv_unsol_event)
989 (pring->prt[i].lpfc_sli_rcv_unsol_event)
990 (phba, pring, saveq);
997 /* Unexpected Rctl / Type received */
998 /* Ring <ringno> handler: unexpected
999 Rctl <Rctl> Type <Type> received */
1000 lpfc_printf_log(phba,
1003 "%d:0313 Ring %d handler: unexpected Rctl x%x "
1004 "Type x%x received \n",
1013 static struct lpfc_iocbq *
1014 lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
1015 struct lpfc_sli_ring *pring,
1016 struct lpfc_iocbq *prspiocb)
1018 struct lpfc_iocbq *cmd_iocb = NULL;
1021 iotag = prspiocb->iocb.ulpIoTag;
1023 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
1024 cmd_iocb = phba->sli.iocbq_lookup[iotag];
1025 list_del(&cmd_iocb->list);
1026 pring->txcmplq_cnt--;
1030 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1031 "%d:0317 iotag x%x is out off "
1032 "range: max iotag x%x wd0 x%x\n",
1033 phba->brd_no, iotag,
1034 phba->sli.last_iotag,
1035 *(((uint32_t *) &prspiocb->iocb) + 7));
1040 lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1041 struct lpfc_iocbq *saveq)
1043 struct lpfc_iocbq *cmdiocbp;
1045 unsigned long iflag;
1047 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
1048 spin_lock_irqsave(&phba->hbalock, iflag);
1049 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
1050 spin_unlock_irqrestore(&phba->hbalock, iflag);
1053 if (cmdiocbp->iocb_cmpl) {
1055 * Post all ELS completions to the worker thread.
1056 * All other are passed to the completion callback.
1058 if (pring->ringno == LPFC_ELS_RING) {
1059 if (cmdiocbp->iocb_flag & LPFC_DRIVER_ABORTED) {
1060 cmdiocbp->iocb_flag &=
1061 ~LPFC_DRIVER_ABORTED;
1062 saveq->iocb.ulpStatus =
1063 IOSTAT_LOCAL_REJECT;
1064 saveq->iocb.un.ulpWord[4] =
1068 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
1070 lpfc_sli_release_iocbq(phba, cmdiocbp);
1073 * Unknown initiating command based on the response iotag.
1074 * This could be the case on the ELS ring because of
1077 if (pring->ringno != LPFC_ELS_RING) {
1079 * Ring <ringno> handler: unexpected completion IoTag
1082 lpfc_printf_log(phba,
1085 "%d:0322 Ring %d handler: unexpected "
1086 "completion IoTag x%x Data: x%x x%x x%x x%x\n",
1089 saveq->iocb.ulpIoTag,
1090 saveq->iocb.ulpStatus,
1091 saveq->iocb.un.ulpWord[4],
1092 saveq->iocb.ulpCommand,
1093 saveq->iocb.ulpContext);
1101 lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1103 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
1104 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1105 &phba->slim2p->mbx.us.s2.port[pring->ringno];
1108 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
1109 * rsp ring <portRspMax>
1111 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1112 "%d:0312 Ring %d handler: portRspPut %d "
1113 "is bigger then rsp ring %d\n",
1114 phba->brd_no, pring->ringno,
1115 le32_to_cpu(pgp->rspPutInx),
1118 phba->link_state = LPFC_HBA_ERROR;
1121 * All error attention handlers are posted to
1124 phba->work_ha |= HA_ERATT;
1125 phba->work_hs = HS_FFER3;
1126 if (phba->work_wait)
1127 wake_up(phba->work_wait);
1132 void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba)
1134 struct lpfc_sli *psli = &phba->sli;
1135 struct lpfc_sli_ring *pring = &psli->ring[LPFC_FCP_RING];
1136 IOCB_t *irsp = NULL;
1137 IOCB_t *entry = NULL;
1138 struct lpfc_iocbq *cmdiocbq = NULL;
1139 struct lpfc_iocbq rspiocbq;
1140 struct lpfc_pgp *pgp;
1142 uint32_t portRspPut, portRspMax;
1144 uint32_t rsp_cmpl = 0;
1146 unsigned long iflags;
1148 pring->stats.iocb_event++;
1150 pgp = (phba->sli_rev == 3) ?
1151 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1152 &phba->slim2p->mbx.us.s2.port[pring->ringno];
1156 * The next available response entry should never exceed the maximum
1157 * entries. If it does, treat it as an adapter hardware error.
1159 portRspMax = pring->numRiocb;
1160 portRspPut = le32_to_cpu(pgp->rspPutInx);
1161 if (unlikely(portRspPut >= portRspMax)) {
1162 lpfc_sli_rsp_pointers_error(phba, pring);
1167 while (pring->rspidx != portRspPut) {
1168 entry = lpfc_resp_iocb(phba, pring);
1169 if (++pring->rspidx >= portRspMax)
1172 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
1173 (uint32_t *) &rspiocbq.iocb,
1175 irsp = &rspiocbq.iocb;
1176 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
1177 pring->stats.iocb_rsp++;
1180 if (unlikely(irsp->ulpStatus)) {
1181 /* Rsp ring <ringno> error: IOCB */
1182 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1183 "%d:0326 Rsp Ring %d error: IOCB Data: "
1184 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
1185 phba->brd_no, pring->ringno,
1186 irsp->un.ulpWord[0],
1187 irsp->un.ulpWord[1],
1188 irsp->un.ulpWord[2],
1189 irsp->un.ulpWord[3],
1190 irsp->un.ulpWord[4],
1191 irsp->un.ulpWord[5],
1192 *(((uint32_t *) irsp) + 6),
1193 *(((uint32_t *) irsp) + 7));
1197 case LPFC_ABORT_IOCB:
1200 * Idle exchange closed via ABTS from port. No iocb
1201 * resources need to be recovered.
1203 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
1204 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1205 "%d:0314 IOCB cmd 0x%x"
1206 " processed. Skipping"
1207 " completion", phba->brd_no,
1212 spin_lock_irqsave(&phba->hbalock, iflags);
1213 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
1215 spin_unlock_irqrestore(&phba->hbalock, iflags);
1216 if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
1217 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1222 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1223 char adaptermsg[LPFC_MAX_ADPTMSG];
1224 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
1225 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1227 dev_warn(&((phba->pcidev)->dev), "lpfc%d: %s",
1228 phba->brd_no, adaptermsg);
1230 /* Unknown IOCB command */
1231 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1232 "%d:0321 Unknown IOCB command "
1233 "Data: x%x, x%x x%x x%x x%x\n",
1244 * The response IOCB has been processed. Update the ring
1245 * pointer in SLIM. If the port response put pointer has not
1246 * been updated, sync the pgp->rspPutInx and fetch the new port
1247 * response put pointer.
1249 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
1251 if (pring->rspidx == portRspPut)
1252 portRspPut = le32_to_cpu(pgp->rspPutInx);
1255 ha_copy = readl(phba->HAregaddr);
1256 ha_copy >>= (LPFC_FCP_RING * 4);
1258 if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) {
1259 spin_lock_irqsave(&phba->hbalock, iflags);
1260 pring->stats.iocb_rsp_full++;
1261 status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4));
1262 writel(status, phba->CAregaddr);
1263 readl(phba->CAregaddr);
1264 spin_unlock_irqrestore(&phba->hbalock, iflags);
1266 if ((ha_copy & HA_R0CE_RSP) &&
1267 (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1268 spin_lock_irqsave(&phba->hbalock, iflags);
1269 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1270 pring->stats.iocb_cmd_empty++;
1272 /* Force update of the local copy of cmdGetInx */
1273 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1274 lpfc_sli_resume_iocb(phba, pring);
1276 if ((pring->lpfc_sli_cmd_available))
1277 (pring->lpfc_sli_cmd_available) (phba, pring);
1279 spin_unlock_irqrestore(&phba->hbalock, iflags);
1286 * This routine presumes LPFC_FCP_RING handling and doesn't bother
1287 * to check it explicitly.
1290 lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
1291 struct lpfc_sli_ring *pring, uint32_t mask)
1293 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
1294 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1295 &phba->slim2p->mbx.us.s2.port[pring->ringno];
1296 IOCB_t *irsp = NULL;
1297 IOCB_t *entry = NULL;
1298 struct lpfc_iocbq *cmdiocbq = NULL;
1299 struct lpfc_iocbq rspiocbq;
1301 uint32_t portRspPut, portRspMax;
1303 lpfc_iocb_type type;
1304 unsigned long iflag;
1305 uint32_t rsp_cmpl = 0;
1307 spin_lock_irqsave(&phba->hbalock, iflag);
1308 pring->stats.iocb_event++;
1311 * The next available response entry should never exceed the maximum
1312 * entries. If it does, treat it as an adapter hardware error.
1314 portRspMax = pring->numRiocb;
1315 portRspPut = le32_to_cpu(pgp->rspPutInx);
1316 if (unlikely(portRspPut >= portRspMax)) {
1317 lpfc_sli_rsp_pointers_error(phba, pring);
1318 spin_unlock_irqrestore(&phba->hbalock, iflag);
1323 while (pring->rspidx != portRspPut) {
1325 * Fetch an entry off the ring and copy it into a local data
1326 * structure. The copy involves a byte-swap since the
1327 * network byte order and pci byte orders are different.
1329 entry = lpfc_resp_iocb(phba, pring);
1331 if (++pring->rspidx >= portRspMax)
1334 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
1335 (uint32_t *) &rspiocbq.iocb,
1336 phba->iocb_rsp_size);
1337 INIT_LIST_HEAD(&(rspiocbq.list));
1338 irsp = &rspiocbq.iocb;
1340 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
1341 pring->stats.iocb_rsp++;
1344 if (unlikely(irsp->ulpStatus)) {
1345 /* Rsp ring <ringno> error: IOCB */
1346 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1347 "%d:0336 Rsp Ring %d error: IOCB Data: "
1348 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
1349 phba->brd_no, pring->ringno,
1350 irsp->un.ulpWord[0], irsp->un.ulpWord[1],
1351 irsp->un.ulpWord[2], irsp->un.ulpWord[3],
1352 irsp->un.ulpWord[4], irsp->un.ulpWord[5],
1353 *(((uint32_t *) irsp) + 6),
1354 *(((uint32_t *) irsp) + 7));
1358 case LPFC_ABORT_IOCB:
1361 * Idle exchange closed via ABTS from port. No iocb
1362 * resources need to be recovered.
1364 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
1365 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1366 "%d:0333 IOCB cmd 0x%x"
1367 " processed. Skipping"
1368 " completion\n", phba->brd_no,
1373 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
1375 if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
1376 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
1377 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1380 spin_unlock_irqrestore(&phba->hbalock,
1382 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1384 spin_lock_irqsave(&phba->hbalock,
1389 case LPFC_UNSOL_IOCB:
1390 spin_unlock_irqrestore(&phba->hbalock, iflag);
1391 lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
1392 spin_lock_irqsave(&phba->hbalock, iflag);
1395 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1396 char adaptermsg[LPFC_MAX_ADPTMSG];
1397 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
1398 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1400 dev_warn(&((phba->pcidev)->dev), "lpfc%d: %s",
1401 phba->brd_no, adaptermsg);
1403 /* Unknown IOCB command */
1404 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1405 "%d:0334 Unknown IOCB command "
1406 "Data: x%x, x%x x%x x%x x%x\n",
1407 phba->brd_no, type, irsp->ulpCommand,
1408 irsp->ulpStatus, irsp->ulpIoTag,
1415 * The response IOCB has been processed. Update the ring
1416 * pointer in SLIM. If the port response put pointer has not
1417 * been updated, sync the pgp->rspPutInx and fetch the new port
1418 * response put pointer.
1420 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
1422 if (pring->rspidx == portRspPut)
1423 portRspPut = le32_to_cpu(pgp->rspPutInx);
1426 if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
1427 pring->stats.iocb_rsp_full++;
1428 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
1429 writel(status, phba->CAregaddr);
1430 readl(phba->CAregaddr);
1432 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1433 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1434 pring->stats.iocb_cmd_empty++;
1436 /* Force update of the local copy of cmdGetInx */
1437 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1438 lpfc_sli_resume_iocb(phba, pring);
1440 if ((pring->lpfc_sli_cmd_available))
1441 (pring->lpfc_sli_cmd_available) (phba, pring);
1445 spin_unlock_irqrestore(&phba->hbalock, iflag);
1451 lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
1452 struct lpfc_sli_ring *pring, uint32_t mask)
1454 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
1455 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1456 &phba->slim2p->mbx.us.s2.port[pring->ringno];
1458 IOCB_t *irsp = NULL;
1459 struct lpfc_iocbq *rspiocbp = NULL;
1460 struct lpfc_iocbq *next_iocb;
1461 struct lpfc_iocbq *cmdiocbp;
1462 struct lpfc_iocbq *saveq;
1463 uint8_t iocb_cmd_type;
1464 lpfc_iocb_type type;
1465 uint32_t status, free_saveq;
1466 uint32_t portRspPut, portRspMax;
1468 unsigned long iflag;
1470 spin_lock_irqsave(&phba->hbalock, iflag);
1471 pring->stats.iocb_event++;
1474 * The next available response entry should never exceed the maximum
1475 * entries. If it does, treat it as an adapter hardware error.
1477 portRspMax = pring->numRiocb;
1478 portRspPut = le32_to_cpu(pgp->rspPutInx);
1479 if (portRspPut >= portRspMax) {
1481 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
1482 * rsp ring <portRspMax>
1484 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1485 "%d:0303 Ring %d handler: portRspPut %d "
1486 "is bigger then rsp ring %d\n",
1488 pring->ringno, portRspPut, portRspMax);
1490 phba->link_state = LPFC_HBA_ERROR;
1491 spin_unlock_irqrestore(&phba->hbalock, iflag);
1493 phba->work_hs = HS_FFER3;
1494 lpfc_handle_eratt(phba);
1500 while (pring->rspidx != portRspPut) {
1502 * Build a completion list and call the appropriate handler.
1503 * The process is to get the next available response iocb, get
1504 * a free iocb from the list, copy the response data into the
1505 * free iocb, insert to the continuation list, and update the
1506 * next response index to slim. This process makes response
1507 * iocb's in the ring available to DMA as fast as possible but
1508 * pays a penalty for a copy operation. Since the iocb is
1509 * only 32 bytes, this penalty is considered small relative to
1510 * the PCI reads for register values and a slim write. When
1511 * the ulpLe field is set, the entire Command has been
1514 entry = lpfc_resp_iocb(phba, pring);
1516 rspiocbp = __lpfc_sli_get_iocbq(phba);
1517 if (rspiocbp == NULL) {
1518 printk(KERN_ERR "%s: out of buffers! Failing "
1519 "completion.\n", __FUNCTION__);
1523 lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
1524 phba->iocb_rsp_size);
1525 irsp = &rspiocbp->iocb;
1527 if (++pring->rspidx >= portRspMax)
1530 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
1532 if (list_empty(&(pring->iocb_continueq))) {
1533 list_add(&rspiocbp->list, &(pring->iocb_continueq));
1535 list_add_tail(&rspiocbp->list,
1536 &(pring->iocb_continueq));
1539 pring->iocb_continueq_cnt++;
1542 * By default, the driver expects to free all resources
1543 * associated with this iocb completion.
1546 saveq = list_get_first(&pring->iocb_continueq,
1547 struct lpfc_iocbq, list);
1548 irsp = &(saveq->iocb);
1549 list_del_init(&pring->iocb_continueq);
1550 pring->iocb_continueq_cnt = 0;
1552 pring->stats.iocb_rsp++;
1554 if (irsp->ulpStatus) {
1555 /* Rsp ring <ringno> error: IOCB */
1556 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1557 "%d:0328 Rsp Ring %d error: "
1562 "x%x x%x x%x x%x\n",
1565 irsp->un.ulpWord[0],
1566 irsp->un.ulpWord[1],
1567 irsp->un.ulpWord[2],
1568 irsp->un.ulpWord[3],
1569 irsp->un.ulpWord[4],
1570 irsp->un.ulpWord[5],
1571 *(((uint32_t *) irsp) + 6),
1572 *(((uint32_t *) irsp) + 7),
1573 *(((uint32_t *) irsp) + 8),
1574 *(((uint32_t *) irsp) + 9),
1575 *(((uint32_t *) irsp) + 10),
1576 *(((uint32_t *) irsp) + 11),
1577 *(((uint32_t *) irsp) + 12),
1578 *(((uint32_t *) irsp) + 13),
1579 *(((uint32_t *) irsp) + 14),
1580 *(((uint32_t *) irsp) + 15));
1584 * Fetch the IOCB command type and call the correct
1585 * completion routine. Solicited and Unsolicited
1586 * IOCBs on the ELS ring get freed back to the
1587 * lpfc_iocb_list by the discovery kernel thread.
1589 iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
1590 type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
1591 if (type == LPFC_SOL_IOCB) {
1592 spin_unlock_irqrestore(&phba->hbalock,
1594 rc = lpfc_sli_process_sol_iocb(phba, pring,
1596 spin_lock_irqsave(&phba->hbalock, iflag);
1597 } else if (type == LPFC_UNSOL_IOCB) {
1598 spin_unlock_irqrestore(&phba->hbalock,
1600 rc = lpfc_sli_process_unsol_iocb(phba, pring,
1602 spin_lock_irqsave(&phba->hbalock, iflag);
1603 } else if (type == LPFC_ABORT_IOCB) {
1604 if ((irsp->ulpCommand != CMD_XRI_ABORTED_CX) &&
1606 lpfc_sli_iocbq_lookup(phba, pring,
1608 /* Call the specified completion
1610 if (cmdiocbp->iocb_cmpl) {
1611 spin_unlock_irqrestore(
1614 (cmdiocbp->iocb_cmpl) (phba,
1620 __lpfc_sli_release_iocbq(phba,
1623 } else if (type == LPFC_UNKNOWN_IOCB) {
1624 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1626 char adaptermsg[LPFC_MAX_ADPTMSG];
1628 memset(adaptermsg, 0,
1630 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1632 dev_warn(&((phba->pcidev)->dev),
1634 phba->brd_no, adaptermsg);
1636 /* Unknown IOCB command */
1637 lpfc_printf_log(phba,
1640 "%d:0335 Unknown IOCB command "
1641 "Data: x%x x%x x%x x%x\n",
1651 list_for_each_entry_safe(rspiocbp, next_iocb,
1652 &saveq->list, list) {
1653 list_del(&rspiocbp->list);
1654 __lpfc_sli_release_iocbq(phba,
1657 __lpfc_sli_release_iocbq(phba, saveq);
1662 * If the port response put pointer has not been updated, sync
1663 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
1664 * response put pointer.
1666 if (pring->rspidx == portRspPut) {
1667 portRspPut = le32_to_cpu(pgp->rspPutInx);
1669 } /* while (pring->rspidx != portRspPut) */
1671 if ((rspiocbp != 0) && (mask & HA_R0RE_REQ)) {
1672 /* At least one response entry has been freed */
1673 pring->stats.iocb_rsp_full++;
1674 /* SET RxRE_RSP in Chip Att register */
1675 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
1676 writel(status, phba->CAregaddr);
1677 readl(phba->CAregaddr); /* flush */
1679 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1680 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1681 pring->stats.iocb_cmd_empty++;
1683 /* Force update of the local copy of cmdGetInx */
1684 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1685 lpfc_sli_resume_iocb(phba, pring);
1687 if ((pring->lpfc_sli_cmd_available))
1688 (pring->lpfc_sli_cmd_available) (phba, pring);
1692 spin_unlock_irqrestore(&phba->hbalock, iflag);
1697 lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1699 LIST_HEAD(completions);
1700 struct lpfc_iocbq *iocb, *next_iocb;
1703 /* Error everything on txq and txcmplq
1706 spin_lock_irq(&phba->hbalock);
1707 list_splice_init(&pring->txq, &completions);
1710 /* Next issue ABTS for everything on the txcmplq */
1711 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
1712 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1714 spin_unlock_irq(&phba->hbalock);
1716 while (!list_empty(&completions)) {
1717 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
1719 list_del(&iocb->list);
1721 if (!iocb->iocb_cmpl)
1722 lpfc_sli_release_iocbq(phba, iocb);
1724 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
1725 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
1726 (iocb->iocb_cmpl) (phba, iocb, iocb);
1732 lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
1738 /* Read the HBA Host Status Register */
1739 status = readl(phba->HSregaddr);
1742 * Check status register every 100ms for 5 retries, then every
1743 * 500ms for 5, then every 2.5 sec for 5, then reset board and
1744 * every 2.5 sec for 4.
1745 * Break our of the loop if errors occurred during init.
1747 while (((status & mask) != mask) &&
1748 !(status & HS_FFERM) &&
1760 phba->pport->port_state = LPFC_STATE_UNKNOWN;
1761 lpfc_sli_brdrestart(phba);
1763 /* Read the HBA Host Status Register */
1764 status = readl(phba->HSregaddr);
1767 /* Check to see if any errors occurred during init */
1768 if ((status & HS_FFERM) || (i >= 20)) {
1769 phba->link_state = LPFC_HBA_ERROR;
1776 #define BARRIER_TEST_PATTERN (0xdeadbeef)
1778 void lpfc_reset_barrier(struct lpfc_hba *phba)
1780 uint32_t __iomem *resp_buf;
1781 uint32_t __iomem *mbox_buf;
1782 volatile uint32_t mbox;
1787 pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
1788 if (hdrtype != 0x80 ||
1789 (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
1790 FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
1794 * Tell the other part of the chip to suspend temporarily all
1797 resp_buf = phba->MBslimaddr;
1799 /* Disable the error attention */
1800 hc_copy = readl(phba->HCregaddr);
1801 writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
1802 readl(phba->HCregaddr); /* flush */
1803 phba->link_flag |= LS_IGNORE_ERATT;
1805 if (readl(phba->HAregaddr) & HA_ERATT) {
1806 /* Clear Chip error bit */
1807 writel(HA_ERATT, phba->HAregaddr);
1808 phba->pport->stopped = 1;
1812 ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
1813 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
1815 writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
1816 mbox_buf = phba->MBslimaddr;
1817 writel(mbox, mbox_buf);
1820 readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
1823 if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
1824 if (phba->sli.sli_flag & LPFC_SLI2_ACTIVE ||
1825 phba->pport->stopped)
1831 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
1832 for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
1837 while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
1840 if (readl(phba->HAregaddr) & HA_ERATT) {
1841 writel(HA_ERATT, phba->HAregaddr);
1842 phba->pport->stopped = 1;
1846 phba->link_flag &= ~LS_IGNORE_ERATT;
1847 writel(hc_copy, phba->HCregaddr);
1848 readl(phba->HCregaddr); /* flush */
1852 lpfc_sli_brdkill(struct lpfc_hba *phba)
1854 struct lpfc_sli *psli;
1864 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1865 "%d:0329 Kill HBA Data: x%x x%x\n",
1866 phba->brd_no, phba->pport->port_state, psli->sli_flag);
1868 if ((pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
1872 /* Disable the error attention */
1873 spin_lock_irq(&phba->hbalock);
1874 status = readl(phba->HCregaddr);
1875 status &= ~HC_ERINT_ENA;
1876 writel(status, phba->HCregaddr);
1877 readl(phba->HCregaddr); /* flush */
1878 phba->link_flag |= LS_IGNORE_ERATT;
1879 spin_unlock_irq(&phba->hbalock);
1881 lpfc_kill_board(phba, pmb);
1882 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1883 retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
1885 if (retval != MBX_SUCCESS) {
1886 if (retval != MBX_BUSY)
1887 mempool_free(pmb, phba->mbox_mem_pool);
1888 spin_lock_irq(&phba->hbalock);
1889 phba->link_flag &= ~LS_IGNORE_ERATT;
1890 spin_unlock_irq(&phba->hbalock);
1894 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
1896 mempool_free(pmb, phba->mbox_mem_pool);
1898 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
1899 * attention every 100ms for 3 seconds. If we don't get ERATT after
1900 * 3 seconds we still set HBA_ERROR state because the status of the
1901 * board is now undefined.
1903 ha_copy = readl(phba->HAregaddr);
1905 while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
1907 ha_copy = readl(phba->HAregaddr);
1910 del_timer_sync(&psli->mbox_tmo);
1911 if (ha_copy & HA_ERATT) {
1912 writel(HA_ERATT, phba->HAregaddr);
1913 phba->pport->stopped = 1;
1915 spin_lock_irq(&phba->hbalock);
1916 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
1917 phba->link_flag &= ~LS_IGNORE_ERATT;
1918 spin_unlock_irq(&phba->hbalock);
1920 psli->mbox_active = NULL;
1921 lpfc_hba_down_post(phba);
1922 phba->link_state = LPFC_HBA_ERROR;
1924 return ha_copy & HA_ERATT ? 0 : 1;
1928 lpfc_sli_brdreset(struct lpfc_hba *phba)
1930 struct lpfc_sli *psli;
1931 struct lpfc_sli_ring *pring;
1938 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1939 "%d:0325 Reset HBA Data: x%x x%x\n", phba->brd_no,
1940 phba->pport->port_state, psli->sli_flag);
1942 /* perform board reset */
1943 phba->fc_eventTag = 0;
1944 phba->pport->fc_myDID = 0;
1945 phba->pport->fc_prevDID = 0;
1947 /* Turn off parity checking and serr during the physical reset */
1948 pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
1949 pci_write_config_word(phba->pcidev, PCI_COMMAND,
1951 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
1953 psli->sli_flag &= ~(LPFC_SLI2_ACTIVE | LPFC_PROCESS_LA);
1954 /* Now toggle INITFF bit in the Host Control Register */
1955 writel(HC_INITFF, phba->HCregaddr);
1957 readl(phba->HCregaddr); /* flush */
1958 writel(0, phba->HCregaddr);
1959 readl(phba->HCregaddr); /* flush */
1961 /* Restore PCI cmd register */
1962 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
1964 /* Initialize relevant SLI info */
1965 for (i = 0; i < psli->num_rings; i++) {
1966 pring = &psli->ring[i];
1969 pring->next_cmdidx = 0;
1970 pring->local_getidx = 0;
1972 pring->missbufcnt = 0;
1975 phba->link_state = LPFC_WARM_START;
1980 lpfc_sli_brdrestart(struct lpfc_hba *phba)
1983 struct lpfc_sli *psli;
1985 volatile uint32_t word0;
1986 void __iomem *to_slim;
1988 spin_lock_irq(&phba->hbalock);
1993 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1994 "%d:0337 Restart HBA Data: x%x x%x\n", phba->brd_no,
1995 phba->pport->port_state, psli->sli_flag);
1998 mb = (MAILBOX_t *) &word0;
1999 mb->mbxCommand = MBX_RESTART;
2002 lpfc_reset_barrier(phba);
2004 to_slim = phba->MBslimaddr;
2005 writel(*(uint32_t *) mb, to_slim);
2006 readl(to_slim); /* flush */
2008 /* Only skip post after fc_ffinit is completed */
2009 if (phba->pport->port_state) {
2011 word0 = 1; /* This is really setting up word1 */
2014 word0 = 0; /* This is really setting up word1 */
2016 to_slim = phba->MBslimaddr + sizeof (uint32_t);
2017 writel(*(uint32_t *) mb, to_slim);
2018 readl(to_slim); /* flush */
2020 lpfc_sli_brdreset(phba);
2021 phba->pport->stopped = 0;
2022 phba->link_state = LPFC_INIT_START;
2024 spin_unlock_irq(&phba->hbalock);
2026 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
2027 psli->stats_start = get_seconds();
2034 lpfc_hba_down_post(phba);
2040 lpfc_sli_chipset_init(struct lpfc_hba *phba)
2042 uint32_t status, i = 0;
2044 /* Read the HBA Host Status Register */
2045 status = readl(phba->HSregaddr);
2047 /* Check status register to see what current state is */
2049 while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
2051 /* Check every 100ms for 5 retries, then every 500ms for 5, then
2052 * every 2.5 sec for 5, then reset board and every 2.5 sec for
2056 /* Adapter failed to init, timeout, status reg
2058 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2059 "%d:0436 Adapter failed to init, "
2060 "timeout, status reg x%x\n",
2061 phba->brd_no, status);
2062 phba->link_state = LPFC_HBA_ERROR;
2066 /* Check to see if any errors occurred during init */
2067 if (status & HS_FFERM) {
2068 /* ERROR: During chipset initialization */
2069 /* Adapter failed to init, chipset, status reg
2071 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2072 "%d:0437 Adapter failed to init, "
2073 "chipset, status reg x%x\n",
2076 phba->link_state = LPFC_HBA_ERROR;
2082 } else if (i <= 10) {
2090 phba->pport->port_state = LPFC_STATE_UNKNOWN;
2091 lpfc_sli_brdrestart(phba);
2093 /* Read the HBA Host Status Register */
2094 status = readl(phba->HSregaddr);
2097 /* Check to see if any errors occurred during init */
2098 if (status & HS_FFERM) {
2099 /* ERROR: During chipset initialization */
2100 /* Adapter failed to init, chipset, status reg <status> */
2101 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2102 "%d:0438 Adapter failed to init, chipset, "
2106 phba->link_state = LPFC_HBA_ERROR;
2110 /* Clear all interrupt enable conditions */
2111 writel(0, phba->HCregaddr);
2112 readl(phba->HCregaddr); /* flush */
2114 /* setup host attn register */
2115 writel(0xffffffff, phba->HAregaddr);
2116 readl(phba->HAregaddr); /* flush */
2120 static struct hbq_dmabuf *
2121 lpfc_alloc_hbq_buffers(struct lpfc_hba *phba, int count)
2123 struct hbq_dmabuf *hbq_buffer_pool;
2126 hbq_buffer_pool = kmalloc(count * sizeof(struct hbq_dmabuf),
2128 if (!hbq_buffer_pool)
2131 for (i = 0; i < count; ++i) {
2132 hbq_buffer_pool[i].dbuf.virt =
2133 lpfc_hbq_alloc(phba, MEM_PRI,
2134 &hbq_buffer_pool[i].dbuf.phys);
2135 if (hbq_buffer_pool[i].dbuf.virt == NULL)
2137 hbq_buffer_pool[i].tag = i;
2143 lpfc_hbq_free(phba, hbq_buffer_pool[i].dbuf.virt,
2144 hbq_buffer_pool[i].dbuf.phys);
2145 kfree(hbq_buffer_pool);
2146 hbq_buffer_pool = NULL;
2149 phba->hbq_buffer_pool = hbq_buffer_pool;
2150 return hbq_buffer_pool;
2153 static struct lpfc_hbq_init lpfc_els_hbq = {
2155 .entry_count = 1200,
2158 .ring_mask = 1 << LPFC_ELS_RING,
2161 static struct lpfc_hbq_init *lpfc_hbq_definitions[] = {
2166 lpfc_sli_hbq_count(void)
2168 return ARRAY_SIZE(lpfc_hbq_definitions);
2172 lpfc_sli_hbq_entry_count(void)
2174 int hbq_count = lpfc_sli_hbq_count();
2178 for (i = 0; i < hbq_count; ++i)
2179 count += lpfc_hbq_definitions[i]->entry_count;
2184 lpfc_sli_hbq_size(void)
2186 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
2190 lpfc_sli_hbq_setup(struct lpfc_hba *phba)
2192 int hbq_count = lpfc_sli_hbq_count();
2196 uint32_t hbq_entry_index;
2197 uint32_t hbq_buffer_count;
2199 /* count hbq buffers */
2200 hbq_buffer_count = lpfc_sli_hbq_entry_count();
2201 if (!lpfc_alloc_hbq_buffers(phba, hbq_buffer_count))
2204 phba->hbq_buffer_count = hbq_buffer_count;
2206 /* Get a Mailbox buffer to setup mailbox
2207 * commands for HBA initialization
2209 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2216 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
2217 phba->link_state = LPFC_INIT_MBX_CMDS;
2219 hbq_entry_index = 0;
2220 for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
2221 phba->hbqs[hbqno].next_hbqPutIdx = 0;
2222 phba->hbqs[hbqno].hbqPutIdx = 0;
2223 phba->hbqs[hbqno].local_hbqGetIdx = 0;
2224 phba->hbqs[hbqno].entry_count =
2225 lpfc_hbq_definitions[hbqno]->entry_count;
2226 lpfc_config_hbq(phba, lpfc_hbq_definitions[hbqno],
2227 hbq_entry_index, pmb);
2228 hbq_entry_index += phba->hbqs[hbqno].entry_count;
2230 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
2231 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
2232 mbxStatus <status>, ring <num> */
2234 lpfc_printf_log(phba, KERN_ERR,
2236 "%d:1805 Adapter failed to init. "
2237 "Data: x%x x%x x%x\n",
2238 phba->brd_no, pmbox->mbxCommand,
2239 pmbox->mbxStatus, hbqno);
2241 phba->link_state = LPFC_HBA_ERROR;
2242 mempool_free(pmb, phba->mbox_mem_pool);
2243 /* Free all HBQ memory */
2244 lpfc_sli_hbqbuf_free_all(phba);
2248 phba->hbq_count = hbq_count;
2250 /* Initially populate or replenish the HBQs */
2251 lpfc_sli_hbqbuf_fill_hbqs(phba);
2252 mempool_free(pmb, phba->mbox_mem_pool);
2258 lpfc_do_config_port(struct lpfc_hba *phba, int sli_mode)
2261 uint32_t resetcount = 0, rc = 0, done = 0;
2263 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2265 phba->link_state = LPFC_HBA_ERROR;
2269 phba->sli_rev = sli_mode;
2270 while (resetcount < 2 && !done) {
2271 spin_lock_irq(&phba->hbalock);
2272 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
2273 spin_unlock_irq(&phba->hbalock);
2274 phba->pport->port_state = LPFC_STATE_UNKNOWN;
2275 lpfc_sli_brdrestart(phba);
2277 rc = lpfc_sli_chipset_init(phba);
2281 spin_lock_irq(&phba->hbalock);
2282 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2283 spin_unlock_irq(&phba->hbalock);
2286 /* Call pre CONFIG_PORT mailbox command initialization. A
2287 * value of 0 means the call was successful. Any other
2288 * nonzero value is a failure, but if ERESTART is returned,
2289 * the driver may reset the HBA and try again.
2291 rc = lpfc_config_port_prep(phba);
2292 if (rc == -ERESTART) {
2293 phba->link_state = LPFC_LINK_UNKNOWN;
2299 phba->link_state = LPFC_INIT_MBX_CMDS;
2300 lpfc_config_port(phba, pmb);
2301 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
2302 if (rc != MBX_SUCCESS) {
2303 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2304 "%d:0442 Adapter failed to init, "
2305 "mbxCmd x%x CONFIG_PORT, mbxStatus "
2307 phba->brd_no, pmb->mb.mbxCommand,
2308 pmb->mb.mbxStatus, 0);
2309 spin_lock_irq(&phba->hbalock);
2310 phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE;
2311 spin_unlock_irq(&phba->hbalock);
2315 /* DBG: Do we need max_vpi, reg_vpi for that matter
2323 goto do_prep_failed;
2326 if ((pmb->mb.un.varCfgPort.sli_mode == 3) &&
2327 (!pmb->mb.un.varCfgPort.cMA)) {
2329 goto do_prep_failed;
2334 mempool_free(pmb, phba->mbox_mem_pool);
2339 lpfc_sli_hba_setup(struct lpfc_hba *phba)
2344 switch (lpfc_sli_mode) {
2352 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
2353 "%d:1819 Unrecognized lpfc_sli_mode "
2355 phba->brd_no, lpfc_sli_mode);
2360 rc = lpfc_do_config_port(phba, mode);
2361 if (rc && lpfc_sli_mode == 3)
2362 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
2363 "%d:1820 Unable to select SLI-3. "
2364 "Not supported by adapter.\n",
2366 if (rc && mode != 2)
2367 rc = lpfc_do_config_port(phba, 2);
2369 goto lpfc_sli_hba_setup_error;
2371 if (phba->sli_rev == 3) {
2372 phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
2373 phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
2374 phba->sli3_options |= LPFC_SLI3_ENABLED;
2375 phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
2378 phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
2379 phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
2380 phba->sli3_options = 0x0;
2383 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2384 "%d:0444 Firmware in SLI %x mode.\n",
2385 phba->brd_no, phba->sli_rev);
2386 rc = lpfc_sli_ring_map(phba);
2389 goto lpfc_sli_hba_setup_error;
2393 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
2394 rc = lpfc_sli_hbq_setup(phba);
2396 goto lpfc_sli_hba_setup_error;
2399 phba->sli.sli_flag |= LPFC_PROCESS_LA;
2401 rc = lpfc_config_port_post(phba);
2403 goto lpfc_sli_hba_setup_error;
2407 lpfc_sli_hba_setup_error:
2408 phba->link_state = LPFC_HBA_ERROR;
2409 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2410 "%d:0445 Firmware initialization failed\n",
2415 /*! lpfc_mbox_timeout
2419 * \param hba Pointer to per struct lpfc_hba structure
2420 * \param l1 Pointer to the driver's mailbox queue.
2426 * This routine handles mailbox timeout events at timer interrupt context.
2429 lpfc_mbox_timeout(unsigned long ptr)
2431 struct lpfc_hba *phba = (struct lpfc_hba *) phba;
2432 unsigned long iflag;
2433 uint32_t tmo_posted;
2435 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
2436 tmo_posted = (phba->pport->work_port_events & WORKER_MBOX_TMO);
2438 phba->pport->work_port_events |= WORKER_MBOX_TMO;
2439 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
2442 if (phba->work_wait)
2443 wake_up(phba->work_wait);
2448 lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
2450 LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
2451 MAILBOX_t *mb = &pmbox->mb;
2452 struct lpfc_sli *psli = &phba->sli;
2453 struct lpfc_sli_ring *pring;
2455 if (!(phba->pport->work_port_events & WORKER_MBOX_TMO)) {
2459 /* Mbox cmd <mbxCommand> timeout */
2460 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
2461 "%d:0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
2464 phba->pport->port_state,
2466 phba->sli.mbox_active);
2468 /* Setting state unknown so lpfc_sli_abort_iocb_ring
2469 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
2470 * it to fail all oustanding SCSI IO.
2472 spin_lock_irq(&phba->pport->work_port_lock);
2473 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
2474 spin_unlock_irq(&phba->pport->work_port_lock);
2475 spin_lock_irq(&phba->hbalock);
2476 phba->link_state = LPFC_LINK_UNKNOWN;
2477 phba->pport->fc_flag |= FC_ESTABLISH_LINK;
2478 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
2479 spin_unlock_irq(&phba->hbalock);
2481 pring = &psli->ring[psli->fcp_ring];
2482 lpfc_sli_abort_iocb_ring(phba, pring);
2484 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
2485 "%d:0316 Resetting board due to mailbox timeout\n",
2488 * lpfc_offline calls lpfc_sli_hba_down which will clean up
2489 * on oustanding mailbox commands.
2491 lpfc_offline_prep(phba);
2493 lpfc_sli_brdrestart(phba);
2494 if (lpfc_online(phba) == 0) /* Initialize the HBA */
2495 mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
2496 lpfc_unblock_mgmt_io(phba);
2501 lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
2504 struct lpfc_sli *psli = &phba->sli;
2505 uint32_t status, evtctr;
2508 unsigned long drvr_flag = 0;
2509 volatile uint32_t word0, ldata;
2510 void __iomem *to_slim;
2512 if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
2513 pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
2515 lpfc_printf_log(phba, KERN_ERR,
2517 "%d:1806 Mbox x%x failed. No vport\n",
2519 pmbox->mb.mbxCommand);
2521 return MBXERR_ERROR;
2525 /* If the PCI channel is in offline state, do not post mbox. */
2526 if (unlikely(pci_channel_offline(phba->pcidev)))
2527 return MBX_NOT_FINISHED;
2529 spin_lock_irqsave(&phba->hbalock, drvr_flag);
2532 status = MBX_SUCCESS;
2534 if (phba->link_state == LPFC_HBA_ERROR) {
2535 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2537 /* Mbox command <mbxCommand> cannot issue */
2538 LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag)
2539 return MBX_NOT_FINISHED;
2542 if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
2543 !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
2544 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2545 LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag)
2546 return MBX_NOT_FINISHED;
2549 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
2550 /* Polling for a mbox command when another one is already active
2551 * is not allowed in SLI. Also, the driver must have established
2552 * SLI2 mode to queue and process multiple mbox commands.
2555 if (flag & MBX_POLL) {
2556 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2558 /* Mbox command <mbxCommand> cannot issue */
2559 LOG_MBOX_CANNOT_ISSUE_DATA(phba, mb, psli, flag);
2560 return MBX_NOT_FINISHED;
2563 if (!(psli->sli_flag & LPFC_SLI2_ACTIVE)) {
2564 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2565 /* Mbox command <mbxCommand> cannot issue */
2566 LOG_MBOX_CANNOT_ISSUE_DATA(phba, mb, psli, flag);
2567 return MBX_NOT_FINISHED;
2570 /* Handle STOP IOCB processing flag. This is only meaningful
2571 * if we are not polling for mbox completion.
2573 if (flag & MBX_STOP_IOCB) {
2574 flag &= ~MBX_STOP_IOCB;
2575 /* Now flag each ring */
2576 for (i = 0; i < psli->num_rings; i++) {
2577 /* If the ring is active, flag it */
2578 if (psli->ring[i].cmdringaddr) {
2579 psli->ring[i].flag |=
2585 /* Another mailbox command is still being processed, queue this
2586 * command to be processed later.
2588 lpfc_mbox_put(phba, pmbox);
2590 /* Mbox cmd issue - BUSY */
2591 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
2592 "%d:0308 Mbox cmd issue - BUSY Data: x%x x%x x%x x%x\n",
2594 mb->mbxCommand, phba->pport->port_state,
2595 psli->sli_flag, flag);
2597 psli->slistat.mbox_busy++;
2598 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2603 /* Handle STOP IOCB processing flag. This is only meaningful
2604 * if we are not polling for mbox completion.
2606 if (flag & MBX_STOP_IOCB) {
2607 flag &= ~MBX_STOP_IOCB;
2608 if (flag == MBX_NOWAIT) {
2609 /* Now flag each ring */
2610 for (i = 0; i < psli->num_rings; i++) {
2611 /* If the ring is active, flag it */
2612 if (psli->ring[i].cmdringaddr) {
2613 psli->ring[i].flag |=
2620 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
2622 /* If we are not polling, we MUST be in SLI2 mode */
2623 if (flag != MBX_POLL) {
2624 if (!(psli->sli_flag & LPFC_SLI2_ACTIVE) &&
2625 (mb->mbxCommand != MBX_KILL_BOARD)) {
2626 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2627 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2628 /* Mbox command <mbxCommand> cannot issue */
2629 LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag);
2630 return MBX_NOT_FINISHED;
2632 /* timeout active mbox command */
2633 mod_timer(&psli->mbox_tmo, (jiffies +
2634 (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
2637 /* Mailbox cmd <cmd> issue */
2638 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
2639 "%d:0309 Mailbox cmd x%x issue Data: x%x x%x x%x\n",
2641 mb->mbxCommand, phba->pport->port_state,
2642 psli->sli_flag, flag);
2644 psli->slistat.mbox_cmd++;
2645 evtctr = psli->slistat.mbox_event;
2647 /* next set own bit for the adapter and copy over command word */
2648 mb->mbxOwner = OWN_CHIP;
2650 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2651 /* First copy command data to host SLIM area */
2652 lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx, MAILBOX_CMD_SIZE);
2654 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2655 /* copy command data into host mbox for cmpl */
2656 lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx,
2660 /* First copy mbox command data to HBA SLIM, skip past first
2662 to_slim = phba->MBslimaddr + sizeof (uint32_t);
2663 lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
2664 MAILBOX_CMD_SIZE - sizeof (uint32_t));
2666 /* Next copy over first word, with mbxOwner set */
2667 ldata = *((volatile uint32_t *)mb);
2668 to_slim = phba->MBslimaddr;
2669 writel(ldata, to_slim);
2670 readl(to_slim); /* flush */
2672 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2673 /* switch over to host mailbox */
2674 psli->sli_flag |= LPFC_SLI2_ACTIVE;
2679 /* interrupt board to doit right away */
2680 writel(CA_MBATT, phba->CAregaddr);
2681 readl(phba->CAregaddr); /* flush */
2685 /* Don't wait for it to finish, just return */
2686 psli->mbox_active = pmbox;
2690 psli->mbox_active = NULL;
2691 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2692 /* First read mbox status word */
2693 word0 = *((volatile uint32_t *)&phba->slim2p->mbx);
2694 word0 = le32_to_cpu(word0);
2696 /* First read mbox status word */
2697 word0 = readl(phba->MBslimaddr);
2700 /* Read the HBA Host Attention Register */
2701 ha_copy = readl(phba->HAregaddr);
2703 i = lpfc_mbox_tmo_val(phba, mb->mbxCommand);
2704 i *= 1000; /* Convert to ms */
2706 /* Wait for command to complete */
2707 while (((word0 & OWN_CHIP) == OWN_CHIP) ||
2708 (!(ha_copy & HA_MBATT) &&
2709 (phba->link_state > LPFC_WARM_START))) {
2711 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2712 spin_unlock_irqrestore(&phba->hbalock,
2714 return MBX_NOT_FINISHED;
2717 /* Check if we took a mbox interrupt while we were
2719 if (((word0 & OWN_CHIP) != OWN_CHIP)
2720 && (evtctr != psli->slistat.mbox_event))
2723 spin_unlock_irqrestore(&phba->hbalock,
2728 spin_lock_irqsave(&phba->hbalock, drvr_flag);
2730 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2731 /* First copy command data */
2732 word0 = *((volatile uint32_t *)
2733 &phba->slim2p->mbx);
2734 word0 = le32_to_cpu(word0);
2735 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2737 volatile uint32_t slimword0;
2738 /* Check real SLIM for any errors */
2739 slimword0 = readl(phba->MBslimaddr);
2740 slimmb = (MAILBOX_t *) & slimword0;
2741 if (((slimword0 & OWN_CHIP) != OWN_CHIP)
2742 && slimmb->mbxStatus) {
2749 /* First copy command data */
2750 word0 = readl(phba->MBslimaddr);
2752 /* Read the HBA Host Attention Register */
2753 ha_copy = readl(phba->HAregaddr);
2756 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2757 /* copy results back to user */
2758 lpfc_sli_pcimem_bcopy(&phba->slim2p->mbx, mb,
2761 /* First copy command data */
2762 lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
2764 if ((mb->mbxCommand == MBX_DUMP_MEMORY) &&
2766 lpfc_memcpy_from_slim((void *) pmbox->context2,
2767 phba->MBslimaddr + DMP_RSP_OFFSET,
2768 mb->un.varDmp.word_cnt);
2772 writel(HA_MBATT, phba->HAregaddr);
2773 readl(phba->HAregaddr); /* flush */
2775 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2776 status = mb->mbxStatus;
2779 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2784 lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2785 struct lpfc_iocbq *piocb)
2787 unsigned long iflags;
2789 /* Insert the caller's iocb in the txq tail for later processing. */
2790 spin_lock_irqsave(&phba->hbalock, iflags);
2791 list_add_tail(&piocb->list, &pring->txq);
2793 spin_unlock_irqrestore(&phba->hbalock, iflags);
2797 static struct lpfc_iocbq *
2798 lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2799 struct lpfc_iocbq **piocb)
2801 struct lpfc_iocbq * nextiocb;
2803 nextiocb = lpfc_sli_ringtx_get(phba, pring);
2813 lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2814 struct lpfc_iocbq *piocb, uint32_t flag)
2816 struct lpfc_iocbq *nextiocb;
2817 unsigned long iflags;
2820 /* If the PCI channel is in offline state, do not post iocbs. */
2821 if (unlikely(pci_channel_offline(phba->pcidev)))
2825 * We should never get an IOCB if we are in a < LINK_DOWN state
2827 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
2831 * Check to see if we are blocking IOCB processing because of a
2832 * outstanding mbox command.
2834 if (unlikely(pring->flag & LPFC_STOP_IOCB_MBX))
2837 if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
2839 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
2840 * can be issued if the link is not up.
2842 switch (piocb->iocb.ulpCommand) {
2843 case CMD_QUE_RING_BUF_CN:
2844 case CMD_QUE_RING_BUF64_CN:
2846 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
2847 * completion, iocb_cmpl MUST be 0.
2849 if (piocb->iocb_cmpl)
2850 piocb->iocb_cmpl = NULL;
2852 case CMD_CREATE_XRI_CR:
2853 case CMD_CLOSE_XRI_CN:
2854 case CMD_CLOSE_XRI_CX:
2861 * For FCP commands, we must be in a state where we can process link
2864 } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
2865 !(phba->sli.sli_flag & LPFC_PROCESS_LA)))
2868 spin_lock_irqsave(&phba->hbalock, iflags);
2869 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
2870 (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
2871 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
2874 lpfc_sli_update_ring(phba, pring);
2876 lpfc_sli_update_full_ring(phba, pring);
2877 spin_unlock_irqrestore(&phba->hbalock, iflags);
2880 return IOCB_SUCCESS;
2885 spin_lock_irqsave(&phba->hbalock, iflags);
2886 pring->stats.iocb_cmd_delay++;
2887 spin_unlock_irqrestore(&phba->hbalock, iflags);
2891 if (!(flag & SLI_IOCB_RET_IOCB)) {
2892 lpfc_sli_ringtx_put(phba, pring, piocb);
2893 return IOCB_SUCCESS;
2900 lpfc_extra_ring_setup( struct lpfc_hba *phba)
2902 struct lpfc_sli *psli;
2903 struct lpfc_sli_ring *pring;
2907 /* Adjust cmd/rsp ring iocb entries more evenly */
2909 /* Take some away from the FCP ring */
2910 pring = &psli->ring[psli->fcp_ring];
2911 pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
2912 pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
2913 pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
2914 pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
2916 /* and give them to the extra ring */
2917 pring = &psli->ring[psli->extra_ring];
2919 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
2920 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
2921 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
2922 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
2924 /* Setup default profile for this ring */
2925 pring->iotag_max = 4096;
2926 pring->num_mask = 1;
2927 pring->prt[0].profile = 0; /* Mask 0 */
2928 pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
2929 pring->prt[0].type = phba->cfg_multi_ring_type;
2930 pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
2935 lpfc_sli_setup(struct lpfc_hba *phba)
2937 int i, totiocbsize = 0;
2938 struct lpfc_sli *psli = &phba->sli;
2939 struct lpfc_sli_ring *pring;
2941 psli->num_rings = MAX_CONFIGURED_RINGS;
2943 psli->fcp_ring = LPFC_FCP_RING;
2944 psli->next_ring = LPFC_FCP_NEXT_RING;
2945 psli->extra_ring = LPFC_EXTRA_RING;
2947 psli->iocbq_lookup = NULL;
2948 psli->iocbq_lookup_len = 0;
2949 psli->last_iotag = 0;
2951 for (i = 0; i < psli->num_rings; i++) {
2952 pring = &psli->ring[i];
2954 case LPFC_FCP_RING: /* ring 0 - FCP */
2955 /* numCiocb and numRiocb are used in config_port */
2956 pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
2957 pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
2958 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
2959 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
2960 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
2961 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
2962 pring->sizeCiocb = (phba->sli_rev == 3) ?
2963 SLI3_IOCB_CMD_SIZE :
2965 pring->sizeRiocb = (phba->sli_rev == 3) ?
2966 SLI3_IOCB_RSP_SIZE :
2968 pring->iotag_ctr = 0;
2970 (phba->cfg_hba_queue_depth * 2);
2971 pring->fast_iotag = pring->iotag_max;
2972 pring->num_mask = 0;
2974 case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
2975 /* numCiocb and numRiocb are used in config_port */
2976 pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
2977 pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
2978 pring->sizeCiocb = (phba->sli_rev == 3) ?
2979 SLI3_IOCB_CMD_SIZE :
2981 pring->sizeRiocb = (phba->sli_rev == 3) ?
2982 SLI3_IOCB_RSP_SIZE :
2984 pring->iotag_max = phba->cfg_hba_queue_depth;
2985 pring->num_mask = 0;
2987 case LPFC_ELS_RING: /* ring 2 - ELS / CT */
2988 /* numCiocb and numRiocb are used in config_port */
2989 pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
2990 pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
2991 pring->sizeCiocb = (phba->sli_rev == 3) ?
2992 SLI3_IOCB_CMD_SIZE :
2994 pring->sizeRiocb = (phba->sli_rev == 3) ?
2995 SLI3_IOCB_RSP_SIZE :
2997 pring->fast_iotag = 0;
2998 pring->iotag_ctr = 0;
2999 pring->iotag_max = 4096;
3000 pring->num_mask = 4;
3001 pring->prt[0].profile = 0; /* Mask 0 */
3002 pring->prt[0].rctl = FC_ELS_REQ;
3003 pring->prt[0].type = FC_ELS_DATA;
3004 pring->prt[0].lpfc_sli_rcv_unsol_event =
3005 lpfc_els_unsol_event;
3006 pring->prt[1].profile = 0; /* Mask 1 */
3007 pring->prt[1].rctl = FC_ELS_RSP;
3008 pring->prt[1].type = FC_ELS_DATA;
3009 pring->prt[1].lpfc_sli_rcv_unsol_event =
3010 lpfc_els_unsol_event;
3011 pring->prt[2].profile = 0; /* Mask 2 */
3012 /* NameServer Inquiry */
3013 pring->prt[2].rctl = FC_UNSOL_CTL;
3015 pring->prt[2].type = FC_COMMON_TRANSPORT_ULP;
3016 pring->prt[2].lpfc_sli_rcv_unsol_event =
3017 lpfc_ct_unsol_event;
3018 pring->prt[3].profile = 0; /* Mask 3 */
3019 /* NameServer response */
3020 pring->prt[3].rctl = FC_SOL_CTL;
3022 pring->prt[3].type = FC_COMMON_TRANSPORT_ULP;
3023 pring->prt[3].lpfc_sli_rcv_unsol_event =
3024 lpfc_ct_unsol_event;
3027 totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
3028 (pring->numRiocb * pring->sizeRiocb);
3030 if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
3031 /* Too many cmd / rsp ring entries in SLI2 SLIM */
3032 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3033 "%d:0462 Too many cmd / rsp ring entries in "
3034 "SLI2 SLIM Data: x%x x%lx\n",
3035 phba->brd_no, totiocbsize,
3036 (unsigned long) MAX_SLIM_IOCB_SIZE);
3038 if (phba->cfg_multi_ring_support == 2)
3039 lpfc_extra_ring_setup(phba);
3045 lpfc_sli_queue_setup(struct lpfc_hba *phba)
3047 struct lpfc_sli *psli;
3048 struct lpfc_sli_ring *pring;
3052 spin_lock_irq(&phba->hbalock);
3053 INIT_LIST_HEAD(&psli->mboxq);
3054 /* Initialize list headers for txq and txcmplq as double linked lists */
3055 for (i = 0; i < psli->num_rings; i++) {
3056 pring = &psli->ring[i];
3058 pring->next_cmdidx = 0;
3059 pring->local_getidx = 0;
3061 INIT_LIST_HEAD(&pring->txq);
3062 INIT_LIST_HEAD(&pring->txcmplq);
3063 INIT_LIST_HEAD(&pring->iocb_continueq);
3064 INIT_LIST_HEAD(&pring->postbufq);
3066 spin_unlock_irq(&phba->hbalock);
3071 lpfc_sli_hba_down(struct lpfc_hba *phba)
3073 LIST_HEAD(completions);
3074 struct lpfc_sli *psli = &phba->sli;
3075 struct lpfc_sli_ring *pring;
3077 struct lpfc_iocbq *iocb;
3080 unsigned long flags = 0;
3082 lpfc_hba_down_prep(phba);
3084 spin_lock_irqsave(&phba->hbalock, flags);
3085 for (i = 0; i < psli->num_rings; i++) {
3086 pring = &psli->ring[i];
3087 pring->flag |= LPFC_DEFERRED_RING_EVENT;
3090 * Error everything on the txq since these iocbs have not been
3091 * given to the FW yet.
3093 list_splice_init(&pring->txq, &completions);
3097 spin_unlock_irqrestore(&phba->hbalock, flags);
3099 while (!list_empty(&completions)) {
3100 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
3102 list_del(&iocb->list);
3104 if (!iocb->iocb_cmpl)
3105 lpfc_sli_release_iocbq(phba, iocb);
3107 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3108 cmd->un.ulpWord[4] = IOERR_SLI_DOWN;
3109 (iocb->iocb_cmpl) (phba, iocb, iocb);
3113 /* Return any active mbox cmds */
3114 del_timer_sync(&psli->mbox_tmo);
3116 spin_lock_irqsave(&phba->pport->work_port_lock, flags);
3117 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
3118 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
3120 spin_lock_irqsave(&phba->hbalock, flags);
3121 pmb = psli->mbox_active;
3123 psli->mbox_active = NULL;
3124 pmb->mb.mbxStatus = MBX_NOT_FINISHED;
3125 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
3126 if (pmb->mbox_cmpl) {
3127 pmb->mbox_cmpl(phba,pmb);
3131 /* Return any pending mbox cmds */
3132 while ((pmb = lpfc_mbox_get(phba)) != NULL) {
3133 pmb->mb.mbxStatus = MBX_NOT_FINISHED;
3134 if (pmb->mbox_cmpl) {
3135 pmb->mbox_cmpl(phba,pmb);
3138 INIT_LIST_HEAD(&psli->mboxq);
3140 /* Free all HBQ memory */
3141 lpfc_sli_hbqbuf_free_all(phba);
3147 lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
3149 uint32_t *src = srcp;
3150 uint32_t *dest = destp;
3154 for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
3156 ldata = le32_to_cpu(ldata);
3164 lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3165 struct lpfc_dmabuf *mp)
3167 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
3169 spin_lock_irq(&phba->hbalock);
3170 list_add_tail(&mp->list, &pring->postbufq);
3171 pring->postbufq_cnt++;
3172 spin_unlock_irq(&phba->hbalock);
3177 struct lpfc_dmabuf *
3178 lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3181 struct lpfc_dmabuf *mp, *next_mp;
3182 struct list_head *slp = &pring->postbufq;
3184 /* Search postbufq, from the begining, looking for a match on phys */
3185 spin_lock_irq(&phba->hbalock);
3186 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
3187 if (mp->phys == phys) {
3188 list_del_init(&mp->list);
3189 pring->postbufq_cnt--;
3190 spin_unlock_irq(&phba->hbalock);
3195 spin_unlock_irq(&phba->hbalock);
3196 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3197 "%d:0410 Cannot find virtual addr for mapped buf on "
3198 "ring %d Data x%llx x%p x%p x%x\n",
3199 phba->brd_no, pring->ringno, (unsigned long long) phys,
3200 slp->next, slp->prev, pring->postbufq_cnt);
3205 lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3206 struct lpfc_iocbq *rspiocb)
3208 IOCB_t *irsp = &rspiocb->iocb;
3209 uint16_t abort_iotag, abort_context;
3210 struct lpfc_iocbq *abort_iocb, *rsp_ab_iocb;
3211 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
3215 if (irsp->ulpStatus) {
3216 abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
3217 abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
3219 spin_lock_irq(&phba->hbalock);
3220 if (abort_iotag != 0 && abort_iotag <= phba->sli.last_iotag)
3221 abort_iocb = phba->sli.iocbq_lookup[abort_iotag];
3223 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3224 "%d:0327 Cannot abort els iocb %p"
3225 " with tag %x context %x\n",
3226 phba->brd_no, abort_iocb,
3227 abort_iotag, abort_context);
3230 * make sure we have the right iocbq before taking it
3231 * off the txcmplq and try to call completion routine.
3234 abort_iocb->iocb.ulpContext != abort_context ||
3235 (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
3236 spin_unlock_irq(&phba->hbalock);
3238 list_del(&abort_iocb->list);
3239 pring->txcmplq_cnt--;
3240 spin_unlock_irq(&phba->hbalock);
3242 rsp_ab_iocb = lpfc_sli_get_iocbq(phba);
3243 if (rsp_ab_iocb == NULL)
3244 lpfc_sli_release_iocbq(phba, abort_iocb);
3246 abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
3247 rsp_ab_iocb->iocb.ulpStatus =
3248 IOSTAT_LOCAL_REJECT;
3249 rsp_ab_iocb->iocb.un.ulpWord[4] =
3251 (abort_iocb->iocb_cmpl)(phba, abort_iocb,
3253 lpfc_sli_release_iocbq(phba, rsp_ab_iocb);
3258 lpfc_sli_release_iocbq(phba, cmdiocb);
3263 lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3264 struct lpfc_iocbq *cmdiocb)
3266 struct lpfc_vport *vport = cmdiocb->vport;
3267 struct lpfc_iocbq *abtsiocbp;
3268 IOCB_t *icmd = NULL;
3269 IOCB_t *iabt = NULL;
3270 int retval = IOCB_ERROR;
3272 /* There are certain command types we don't want
3275 icmd = &cmdiocb->iocb;
3276 if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
3277 icmd->ulpCommand == CMD_CLOSE_XRI_CN)
3280 /* If we're unloading, interrupts are disabled so we
3281 * need to cleanup the iocb here.
3283 if (vport->load_flag & FC_UNLOADING)
3284 goto abort_iotag_exit;
3286 /* issue ABTS for this IOCB based on iotag */
3287 abtsiocbp = lpfc_sli_get_iocbq(phba);
3288 if (abtsiocbp == NULL)
3291 /* This signals the response to set the correct status
3292 * before calling the completion handler.
3294 cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
3296 iabt = &abtsiocbp->iocb;
3297 iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
3298 iabt->un.acxri.abortContextTag = icmd->ulpContext;
3299 iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
3301 iabt->ulpClass = icmd->ulpClass;
3303 if (phba->link_state >= LPFC_LINK_UP)
3304 iabt->ulpCommand = CMD_ABORT_XRI_CN;
3306 iabt->ulpCommand = CMD_CLOSE_XRI_CN;
3308 abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
3310 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3311 "%d:0339 Abort xri x%x, original iotag x%x, abort "
3313 phba->brd_no, iabt->un.acxri.abortContextTag,
3314 iabt->un.acxri.abortIoTag, abtsiocbp->iotag);
3315 retval = lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0);
3319 * Caller to this routine should check for IOCB_ERROR
3320 * and handle it properly. This routine no longer removes
3321 * iocb off txcmplq and call compl in case of IOCB_ERROR.
3327 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, uint16_t tgt_id,
3328 uint64_t lun_id, uint32_t ctx,
3329 lpfc_ctx_cmd ctx_cmd)
3331 struct lpfc_scsi_buf *lpfc_cmd;
3332 struct scsi_cmnd *cmnd;
3335 if (!(iocbq->iocb_flag & LPFC_IO_FCP))
3338 lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
3339 cmnd = lpfc_cmd->pCmd;
3346 if ((cmnd->device->id == tgt_id) &&
3347 (cmnd->device->lun == lun_id))
3351 if (cmnd->device->id == tgt_id)
3355 if (iocbq->iocb.ulpContext == ctx)
3362 printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
3363 __FUNCTION__, ctx_cmd);
3371 lpfc_sli_sum_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3372 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd ctx_cmd)
3374 struct lpfc_iocbq *iocbq;
3377 for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
3378 iocbq = phba->sli.iocbq_lookup[i];
3380 if (lpfc_sli_validate_fcp_iocb (iocbq, tgt_id, lun_id,
3389 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3390 struct lpfc_iocbq *rspiocb)
3392 lpfc_sli_release_iocbq(phba, cmdiocb);
3397 lpfc_sli_abort_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3398 uint16_t tgt_id, uint64_t lun_id, uint32_t ctx,
3399 lpfc_ctx_cmd abort_cmd)
3401 struct lpfc_iocbq *iocbq;
3402 struct lpfc_iocbq *abtsiocb;
3404 int errcnt = 0, ret_val = 0;
3407 for (i = 1; i <= phba->sli.last_iotag; i++) {
3408 iocbq = phba->sli.iocbq_lookup[i];
3410 if (lpfc_sli_validate_fcp_iocb(iocbq, tgt_id, lun_id, 0,
3414 /* issue ABTS for this IOCB based on iotag */
3415 abtsiocb = lpfc_sli_get_iocbq(phba);
3416 if (abtsiocb == NULL) {
3422 abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
3423 abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
3424 abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
3425 abtsiocb->iocb.ulpLe = 1;
3426 abtsiocb->iocb.ulpClass = cmd->ulpClass;
3427 abtsiocb->vport = phba->pport;
3429 if (lpfc_is_link_up(phba))
3430 abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
3432 abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
3434 /* Setup callback routine and issue the command. */
3435 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
3436 ret_val = lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0);
3437 if (ret_val == IOCB_ERROR) {
3438 lpfc_sli_release_iocbq(phba, abtsiocb);
3448 lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
3449 struct lpfc_iocbq *cmdiocbq,
3450 struct lpfc_iocbq *rspiocbq)
3452 wait_queue_head_t *pdone_q;
3453 unsigned long iflags;
3455 spin_lock_irqsave(&phba->hbalock, iflags);
3456 cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
3457 if (cmdiocbq->context2 && rspiocbq)
3458 memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
3459 &rspiocbq->iocb, sizeof(IOCB_t));
3461 pdone_q = cmdiocbq->context_un.wait_queue;
3462 spin_unlock_irqrestore(&phba->hbalock, iflags);
3469 * Issue the caller's iocb and wait for its completion, but no longer than the
3470 * caller's timeout. Note that iocb_flags is cleared before the
3471 * lpfc_sli_issue_call since the wake routine sets a unique value and by
3472 * definition this is a wait function.
3475 lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
3476 struct lpfc_sli_ring *pring,
3477 struct lpfc_iocbq *piocb,
3478 struct lpfc_iocbq *prspiocbq,
3481 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
3482 long timeleft, timeout_req = 0;
3483 int retval = IOCB_SUCCESS;
3487 * If the caller has provided a response iocbq buffer, then context2
3488 * is NULL or its an error.
3491 if (piocb->context2)
3493 piocb->context2 = prspiocbq;
3496 piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
3497 piocb->context_un.wait_queue = &done_q;
3498 piocb->iocb_flag &= ~LPFC_IO_WAKE;
3500 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
3501 creg_val = readl(phba->HCregaddr);
3502 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
3503 writel(creg_val, phba->HCregaddr);
3504 readl(phba->HCregaddr); /* flush */
3507 retval = lpfc_sli_issue_iocb(phba, pring, piocb, 0);
3508 if (retval == IOCB_SUCCESS) {
3509 timeout_req = timeout * HZ;
3510 timeleft = wait_event_timeout(done_q,
3511 piocb->iocb_flag & LPFC_IO_WAKE,
3514 if (piocb->iocb_flag & LPFC_IO_WAKE) {
3515 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3516 "%d:0331 IOCB wake signaled\n",
3518 } else if (timeleft == 0) {
3519 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3520 "%d:0338 IOCB wait timeout error - no "
3521 "wake response Data x%x\n",
3522 phba->brd_no, timeout);
3523 retval = IOCB_TIMEDOUT;
3525 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3526 "%d:0330 IOCB wake NOT set, "
3527 "Data x%x x%lx\n", phba->brd_no,
3528 timeout, (timeleft / jiffies));
3529 retval = IOCB_TIMEDOUT;
3532 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3533 "%d:0332 IOCB wait issue failed, Data x%x\n",
3534 phba->brd_no, retval);
3535 retval = IOCB_ERROR;
3538 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
3539 creg_val = readl(phba->HCregaddr);
3540 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
3541 writel(creg_val, phba->HCregaddr);
3542 readl(phba->HCregaddr); /* flush */
3546 piocb->context2 = NULL;
3548 piocb->context_un.wait_queue = NULL;
3549 piocb->iocb_cmpl = NULL;
3554 lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
3557 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
3560 /* The caller must leave context1 empty. */
3561 if (pmboxq->context1 != 0) {
3562 return MBX_NOT_FINISHED;
3565 /* setup wake call as IOCB callback */
3566 pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
3567 /* setup context field to pass wait_queue pointer to wake function */
3568 pmboxq->context1 = &done_q;
3570 /* now issue the command */
3571 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
3573 if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
3574 wait_event_interruptible_timeout(done_q,
3575 pmboxq->mbox_flag & LPFC_MBX_WAKE,
3578 pmboxq->context1 = NULL;
3580 * if LPFC_MBX_WAKE flag is set the mailbox is completed
3581 * else do not free the resources.
3583 if (pmboxq->mbox_flag & LPFC_MBX_WAKE)
3584 retval = MBX_SUCCESS;
3586 retval = MBX_TIMEOUT;
3593 lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba)
3595 struct lpfc_vport *vport = phba->pport;
3599 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE && !vport->stopped) {
3600 if (i++ > LPFC_MBOX_TMO * 1000)
3604 * Call lpfc_sli_handle_mb_event only if a mailbox cmd
3605 * did finish. This way we won't get the misleading
3606 * "Stray Mailbox Interrupt" message.
3608 spin_lock_irq(&phba->hbalock);
3609 ha_copy = phba->work_ha;
3610 phba->work_ha &= ~HA_MBATT;
3611 spin_unlock_irq(&phba->hbalock);
3613 if (ha_copy & HA_MBATT)
3614 if (lpfc_sli_handle_mb_event(phba) == 0)
3620 return (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) ? 1 : 0;
3624 lpfc_intr_handler(int irq, void *dev_id)
3626 struct lpfc_hba *phba;
3628 uint32_t work_ha_copy;
3629 unsigned long status;
3634 * Get the driver's phba structure from the dev_id and
3635 * assume the HBA is not interrupting.
3637 phba = (struct lpfc_hba *) dev_id;
3639 if (unlikely(!phba))
3642 /* If the pci channel is offline, ignore all the interrupts. */
3643 if (unlikely(pci_channel_offline(phba->pcidev)))
3646 phba->sli.slistat.sli_intr++;
3649 * Call the HBA to see if it is interrupting. If not, don't claim
3653 /* Ignore all interrupts during initialization. */
3654 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
3658 * Read host attention register to determine interrupt source
3659 * Clear Attention Sources, except Error Attention (to
3660 * preserve status) and Link Attention
3662 spin_lock(&phba->hbalock);
3663 ha_copy = readl(phba->HAregaddr);
3664 /* If somebody is waiting to handle an eratt don't process it
3665 * here. The brdkill function will do this.
3667 if (phba->link_flag & LS_IGNORE_ERATT)
3668 ha_copy &= ~HA_ERATT;
3669 writel((ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
3670 readl(phba->HAregaddr); /* flush */
3671 spin_unlock(&phba->hbalock);
3673 if (unlikely(!ha_copy))
3676 work_ha_copy = ha_copy & phba->work_ha_mask;
3678 if (unlikely(work_ha_copy)) {
3679 if (work_ha_copy & HA_LATT) {
3680 if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
3682 * Turn off Link Attention interrupts
3683 * until CLEAR_LA done
3685 spin_lock(&phba->hbalock);
3686 phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
3687 control = readl(phba->HCregaddr);
3688 control &= ~HC_LAINT_ENA;
3689 writel(control, phba->HCregaddr);
3690 readl(phba->HCregaddr); /* flush */
3691 spin_unlock(&phba->hbalock);
3694 work_ha_copy &= ~HA_LATT;
3697 if (work_ha_copy & ~(HA_ERATT|HA_MBATT|HA_LATT)) {
3698 for (i = 0; i < phba->sli.num_rings; i++) {
3699 if (work_ha_copy & (HA_RXATT << (4*i))) {
3701 * Turn off Slow Rings interrupts
3703 spin_lock(&phba->hbalock);
3704 control = readl(phba->HCregaddr);
3705 control &= ~(HC_R0INT_ENA << i);
3706 writel(control, phba->HCregaddr);
3707 readl(phba->HCregaddr); /* flush */
3708 spin_unlock(&phba->hbalock);
3713 if (work_ha_copy & HA_ERATT) {
3714 phba->link_state = LPFC_HBA_ERROR;
3716 * There was a link/board error. Read the
3717 * status register to retrieve the error event
3720 phba->sli.slistat.err_attn_event++;
3721 /* Save status info */
3722 phba->work_hs = readl(phba->HSregaddr);
3723 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
3724 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
3726 /* Clear Chip error bit */
3727 writel(HA_ERATT, phba->HAregaddr);
3728 readl(phba->HAregaddr); /* flush */
3729 phba->pport->stopped = 1;
3732 spin_lock(&phba->hbalock);
3733 phba->work_ha |= work_ha_copy;
3734 if (phba->work_wait)
3735 wake_up(phba->work_wait);
3736 spin_unlock(&phba->hbalock);
3739 ha_copy &= ~(phba->work_ha_mask);
3742 * Process all events on FCP ring. Take the optimized path for
3743 * FCP IO. Any other IO is slow path and is handled by
3744 * the worker thread.
3746 status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
3747 status >>= (4*LPFC_FCP_RING);
3748 if (status & HA_RXATT)
3749 lpfc_sli_handle_fast_ring_event(phba,
3750 &phba->sli.ring[LPFC_FCP_RING],
3753 if (phba->cfg_multi_ring_support == 2) {
3755 * Process all events on extra ring. Take the optimized path
3756 * for extra ring IO. Any other IO is slow path and is handled
3757 * by the worker thread.
3759 status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
3760 status >>= (4*LPFC_EXTRA_RING);
3761 if (status & HA_RXATT) {
3762 lpfc_sli_handle_fast_ring_event(phba,
3763 &phba->sli.ring[LPFC_EXTRA_RING],
3769 } /* lpfc_intr_handler */