1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2008 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"
41 #include "lpfc_debugfs.h"
44 * Define macro to log: Mailbox command x%x cannot issue Data
45 * This allows multiple uses of lpfc_msgBlk0311
46 * w/o perturbing log msg utility.
48 #define LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag) \
49 lpfc_printf_log(phba, \
52 "(%d):0311 Mailbox command x%x cannot " \
53 "issue Data: x%x x%x x%x\n", \
54 pmbox->vport ? pmbox->vport->vpi : 0, \
55 pmbox->mb.mbxCommand, \
56 phba->pport->port_state, \
61 /* There are only four IOCB completion types. */
62 typedef enum _lpfc_iocb_type {
69 /* SLI-2/SLI-3 provide different sized iocbs. Given a pointer
70 * to the start of the ring, and the slot number of the
71 * desired iocb entry, calc a pointer to that entry.
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_ASYNC_STATUS:
203 case CMD_IOCB_RCV_SEQ64_CX:
204 case CMD_IOCB_RCV_ELS64_CX:
205 case CMD_IOCB_RCV_CONT64_CX:
206 case CMD_IOCB_RET_XRI64_CX:
207 type = LPFC_UNSOL_IOCB;
209 case CMD_IOCB_XMIT_MSEQ64_CR:
210 case CMD_IOCB_XMIT_MSEQ64_CX:
211 case CMD_IOCB_RCV_SEQ_LIST64_CX:
212 case CMD_IOCB_RCV_ELS_LIST64_CX:
213 case CMD_IOCB_CLOSE_EXTENDED_CN:
214 case CMD_IOCB_ABORT_EXTENDED_CN:
215 case CMD_IOCB_RET_HBQE64_CN:
216 case CMD_IOCB_FCP_IBIDIR64_CR:
217 case CMD_IOCB_FCP_IBIDIR64_CX:
218 case CMD_IOCB_FCP_ITASKMGT64_CX:
219 case CMD_IOCB_LOGENTRY_CN:
220 case CMD_IOCB_LOGENTRY_ASYNC_CN:
221 printk("%s - Unhandled SLI-3 Command x%x\n",
222 __FUNCTION__, iocb_cmnd);
223 type = LPFC_UNKNOWN_IOCB;
226 type = LPFC_UNKNOWN_IOCB;
234 lpfc_sli_ring_map(struct lpfc_hba *phba)
236 struct lpfc_sli *psli = &phba->sli;
241 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
245 phba->link_state = LPFC_INIT_MBX_CMDS;
246 for (i = 0; i < psli->num_rings; i++) {
247 lpfc_config_ring(phba, i, pmb);
248 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
249 if (rc != MBX_SUCCESS) {
250 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
251 "0446 Adapter failed to init (%d), "
252 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
254 rc, pmbox->mbxCommand,
255 pmbox->mbxStatus, i);
256 phba->link_state = LPFC_HBA_ERROR;
261 mempool_free(pmb, phba->mbox_mem_pool);
266 lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
267 struct lpfc_iocbq *piocb)
269 list_add_tail(&piocb->list, &pring->txcmplq);
270 pring->txcmplq_cnt++;
271 if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
272 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
273 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
277 mod_timer(&piocb->vport->els_tmofunc,
278 jiffies + HZ * (phba->fc_ratov << 1));
285 static struct lpfc_iocbq *
286 lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
288 struct lpfc_iocbq *cmd_iocb;
290 list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
291 if (cmd_iocb != NULL)
297 lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
299 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
300 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
301 &phba->slim2p->mbx.us.s2.port[pring->ringno];
302 uint32_t max_cmd_idx = pring->numCiocb;
304 if ((pring->next_cmdidx == pring->cmdidx) &&
305 (++pring->next_cmdidx >= max_cmd_idx))
306 pring->next_cmdidx = 0;
308 if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
310 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
312 if (unlikely(pring->local_getidx >= max_cmd_idx)) {
313 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
314 "0315 Ring %d issue: portCmdGet %d "
315 "is bigger then cmd ring %d\n",
317 pring->local_getidx, max_cmd_idx);
319 phba->link_state = LPFC_HBA_ERROR;
321 * All error attention handlers are posted to
324 phba->work_ha |= HA_ERATT;
325 phba->work_hs = HS_FFER3;
327 lpfc_worker_wake_up(phba);
332 if (pring->local_getidx == pring->next_cmdidx)
336 return lpfc_cmd_iocb(phba, pring);
340 lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
342 struct lpfc_iocbq **new_arr;
343 struct lpfc_iocbq **old_arr;
345 struct lpfc_sli *psli = &phba->sli;
348 spin_lock_irq(&phba->hbalock);
349 iotag = psli->last_iotag;
350 if(++iotag < psli->iocbq_lookup_len) {
351 psli->last_iotag = iotag;
352 psli->iocbq_lookup[iotag] = iocbq;
353 spin_unlock_irq(&phba->hbalock);
354 iocbq->iotag = iotag;
356 } else if (psli->iocbq_lookup_len < (0xffff
357 - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
358 new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
359 spin_unlock_irq(&phba->hbalock);
360 new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
363 spin_lock_irq(&phba->hbalock);
364 old_arr = psli->iocbq_lookup;
365 if (new_len <= psli->iocbq_lookup_len) {
366 /* highly unprobable case */
368 iotag = psli->last_iotag;
369 if(++iotag < psli->iocbq_lookup_len) {
370 psli->last_iotag = iotag;
371 psli->iocbq_lookup[iotag] = iocbq;
372 spin_unlock_irq(&phba->hbalock);
373 iocbq->iotag = iotag;
376 spin_unlock_irq(&phba->hbalock);
379 if (psli->iocbq_lookup)
380 memcpy(new_arr, old_arr,
381 ((psli->last_iotag + 1) *
382 sizeof (struct lpfc_iocbq *)));
383 psli->iocbq_lookup = new_arr;
384 psli->iocbq_lookup_len = new_len;
385 psli->last_iotag = iotag;
386 psli->iocbq_lookup[iotag] = iocbq;
387 spin_unlock_irq(&phba->hbalock);
388 iocbq->iotag = iotag;
393 spin_unlock_irq(&phba->hbalock);
395 lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
396 "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
403 lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
404 IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
409 nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
411 if (pring->ringno == LPFC_ELS_RING) {
412 lpfc_debugfs_slow_ring_trc(phba,
413 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
414 *(((uint32_t *) &nextiocb->iocb) + 4),
415 *(((uint32_t *) &nextiocb->iocb) + 6),
416 *(((uint32_t *) &nextiocb->iocb) + 7));
420 * Issue iocb command to adapter
422 lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
424 pring->stats.iocb_cmd++;
427 * If there is no completion routine to call, we can release the
428 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
429 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
431 if (nextiocb->iocb_cmpl)
432 lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
434 __lpfc_sli_release_iocbq(phba, nextiocb);
437 * Let the HBA know what IOCB slot will be the next one the
438 * driver will put a command into.
440 pring->cmdidx = pring->next_cmdidx;
441 writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
445 lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
447 int ringno = pring->ringno;
449 pring->flag |= LPFC_CALL_RING_AVAILABLE;
454 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
455 * The HBA will tell us when an IOCB entry is available.
457 writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
458 readl(phba->CAregaddr); /* flush */
460 pring->stats.iocb_cmd_full++;
464 lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
466 int ringno = pring->ringno;
469 * Tell the HBA that there is work to do in this ring.
472 writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
473 readl(phba->CAregaddr); /* flush */
477 lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
480 struct lpfc_iocbq *nextiocb;
484 * (a) there is anything on the txq to send
486 * (c) link attention events can be processed (fcp ring only)
487 * (d) IOCB processing is not blocked by the outstanding mbox command.
489 if (pring->txq_cnt &&
490 lpfc_is_link_up(phba) &&
491 (pring->ringno != phba->sli.fcp_ring ||
492 phba->sli.sli_flag & LPFC_PROCESS_LA)) {
494 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
495 (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
496 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
499 lpfc_sli_update_ring(phba, pring);
501 lpfc_sli_update_full_ring(phba, pring);
507 static struct lpfc_hbq_entry *
508 lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
510 struct hbq_s *hbqp = &phba->hbqs[hbqno];
512 if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
513 ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
514 hbqp->next_hbqPutIdx = 0;
516 if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
517 uint32_t raw_index = phba->hbq_get[hbqno];
518 uint32_t getidx = le32_to_cpu(raw_index);
520 hbqp->local_hbqGetIdx = getidx;
522 if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
523 lpfc_printf_log(phba, KERN_ERR,
525 "1802 HBQ %d: local_hbqGetIdx "
526 "%u is > than hbqp->entry_count %u\n",
527 hbqno, hbqp->local_hbqGetIdx,
530 phba->link_state = LPFC_HBA_ERROR;
534 if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
538 return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
543 lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
545 struct lpfc_dmabuf *dmabuf, *next_dmabuf;
546 struct hbq_dmabuf *hbq_buf;
551 hbq_count = lpfc_sli_hbq_count();
552 /* Return all memory used by all HBQs */
553 spin_lock_irqsave(&phba->hbalock, flags);
554 for (i = 0; i < hbq_count; ++i) {
555 list_for_each_entry_safe(dmabuf, next_dmabuf,
556 &phba->hbqs[i].hbq_buffer_list, list) {
557 hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
558 list_del(&hbq_buf->dbuf.list);
559 (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
561 phba->hbqs[i].buffer_count = 0;
563 /* Return all HBQ buffer that are in-fly */
564 list_for_each_entry_safe(dmabuf, next_dmabuf,
565 &phba->hbqbuf_in_list, list) {
566 hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
567 list_del(&hbq_buf->dbuf.list);
568 if (hbq_buf->tag == -1) {
569 (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
572 hbqno = hbq_buf->tag >> 16;
573 if (hbqno >= LPFC_MAX_HBQS)
574 (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
577 (phba->hbqs[hbqno].hbq_free_buffer)(phba,
582 /* Mark the HBQs not in use */
583 phba->hbq_in_use = 0;
584 spin_unlock_irqrestore(&phba->hbalock, flags);
587 static struct lpfc_hbq_entry *
588 lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
589 struct hbq_dmabuf *hbq_buf)
591 struct lpfc_hbq_entry *hbqe;
592 dma_addr_t physaddr = hbq_buf->dbuf.phys;
594 /* Get next HBQ entry slot to use */
595 hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
597 struct hbq_s *hbqp = &phba->hbqs[hbqno];
599 hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
600 hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
601 hbqe->bde.tus.f.bdeSize = hbq_buf->size;
602 hbqe->bde.tus.f.bdeFlags = 0;
603 hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
604 hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
606 hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
607 writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
609 readl(phba->hbq_put + hbqno);
610 list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
615 static struct lpfc_hbq_init lpfc_els_hbq = {
620 .ring_mask = (1 << LPFC_ELS_RING),
626 static struct lpfc_hbq_init lpfc_extra_hbq = {
631 .ring_mask = (1 << LPFC_EXTRA_RING),
637 struct lpfc_hbq_init *lpfc_hbq_defs[] = {
643 lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
645 uint32_t i, start, end;
647 struct hbq_dmabuf *hbq_buffer;
649 if (!phba->hbqs[hbqno].hbq_alloc_buffer)
652 start = phba->hbqs[hbqno].buffer_count;
654 if (end > lpfc_hbq_defs[hbqno]->entry_count)
655 end = lpfc_hbq_defs[hbqno]->entry_count;
657 /* Check whether HBQ is still in use */
658 spin_lock_irqsave(&phba->hbalock, flags);
659 if (!phba->hbq_in_use)
662 /* Populate HBQ entries */
663 for (i = start; i < end; i++) {
664 hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
667 hbq_buffer->tag = (i | (hbqno << 16));
668 if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
669 phba->hbqs[hbqno].buffer_count++;
671 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
675 spin_unlock_irqrestore(&phba->hbalock, flags);
678 spin_unlock_irqrestore(&phba->hbalock, flags);
683 lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
685 return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
686 lpfc_hbq_defs[qno]->add_count));
690 lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
692 return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
693 lpfc_hbq_defs[qno]->init_count));
696 static struct hbq_dmabuf *
697 lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
699 struct lpfc_dmabuf *d_buf;
700 struct hbq_dmabuf *hbq_buf;
704 if (hbqno >= LPFC_MAX_HBQS)
707 list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
708 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
709 if (hbq_buf->tag == tag) {
713 lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
714 "1803 Bad hbq tag. Data: x%x x%x\n",
715 tag, phba->hbqs[tag >> 16].buffer_count);
720 lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
725 hbqno = hbq_buffer->tag >> 16;
726 if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
727 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
733 lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
737 switch (mbxCommand) {
741 case MBX_WRITE_VPARMS:
742 case MBX_RUN_BIU_DIAG:
745 case MBX_CONFIG_LINK:
746 case MBX_CONFIG_RING:
748 case MBX_READ_CONFIG:
749 case MBX_READ_RCONFIG:
751 case MBX_READ_STATUS:
755 case MBX_READ_LNK_STAT:
757 case MBX_UNREG_LOGIN:
760 case MBX_DUMP_MEMORY:
761 case MBX_DUMP_CONTEXT:
766 case MBX_DEL_LD_ENTRY:
767 case MBX_RUN_PROGRAM:
769 case MBX_SET_VARIABLE:
772 case MBX_CONFIG_FARP:
775 case MBX_RUN_BIU_DIAG64:
776 case MBX_CONFIG_PORT:
777 case MBX_READ_SPARM64:
779 case MBX_REG_LOGIN64:
783 case MBX_LOAD_EXP_ROM:
784 case MBX_ASYNCEVT_ENABLE:
797 lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
799 wait_queue_head_t *pdone_q;
800 unsigned long drvr_flag;
803 * If pdone_q is empty, the driver thread gave up waiting and
806 pmboxq->mbox_flag |= LPFC_MBX_WAKE;
807 spin_lock_irqsave(&phba->hbalock, drvr_flag);
808 pdone_q = (wait_queue_head_t *) pmboxq->context1;
810 wake_up_interruptible(pdone_q);
811 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
816 lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
818 struct lpfc_dmabuf *mp;
822 mp = (struct lpfc_dmabuf *) (pmb->context1);
825 lpfc_mbuf_free(phba, mp->virt, mp->phys);
830 * If a REG_LOGIN succeeded after node is destroyed or node
831 * is in re-discovery driver need to cleanup the RPI.
833 if (!(phba->pport->load_flag & FC_UNLOADING) &&
834 pmb->mb.mbxCommand == MBX_REG_LOGIN64 &&
835 !pmb->mb.mbxStatus) {
837 rpi = pmb->mb.un.varWords[0];
838 lpfc_unreg_login(phba, pmb->mb.un.varRegLogin.vpi, rpi, pmb);
839 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
840 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
841 if (rc != MBX_NOT_FINISHED)
845 mempool_free(pmb, phba->mbox_mem_pool);
850 lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
857 phba->sli.slistat.mbox_event++;
859 /* Get all completed mailboxe buffers into the cmplq */
860 spin_lock_irq(&phba->hbalock);
861 list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
862 spin_unlock_irq(&phba->hbalock);
864 /* Get a Mailbox buffer to setup mailbox commands for callback */
866 list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
872 if (pmbox->mbxCommand != MBX_HEARTBEAT) {
874 lpfc_debugfs_disc_trc(pmb->vport,
875 LPFC_DISC_TRC_MBOX_VPORT,
876 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
877 (uint32_t)pmbox->mbxCommand,
878 pmbox->un.varWords[0],
879 pmbox->un.varWords[1]);
882 lpfc_debugfs_disc_trc(phba->pport,
884 "MBOX cmpl: cmd:x%x mb:x%x x%x",
885 (uint32_t)pmbox->mbxCommand,
886 pmbox->un.varWords[0],
887 pmbox->un.varWords[1]);
892 * It is a fatal error if unknown mbox command completion.
894 if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
896 /* Unknow mailbox command compl */
897 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
898 "(%d):0323 Unknown Mailbox command "
900 pmb->vport ? pmb->vport->vpi : 0,
902 phba->link_state = LPFC_HBA_ERROR;
903 phba->work_hs = HS_FFER3;
904 lpfc_handle_eratt(phba);
908 if (pmbox->mbxStatus) {
909 phba->sli.slistat.mbox_stat_err++;
910 if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
911 /* Mbox cmd cmpl error - RETRYing */
912 lpfc_printf_log(phba, KERN_INFO,
914 "(%d):0305 Mbox cmd cmpl "
915 "error - RETRYing Data: x%x "
917 pmb->vport ? pmb->vport->vpi :0,
920 pmbox->un.varWords[0],
921 pmb->vport->port_state);
922 pmbox->mbxStatus = 0;
923 pmbox->mbxOwner = OWN_HOST;
924 spin_lock_irq(&phba->hbalock);
925 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
926 spin_unlock_irq(&phba->hbalock);
927 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
928 if (rc == MBX_SUCCESS)
933 /* Mailbox cmd <cmd> Cmpl <cmpl> */
934 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
935 "(%d):0307 Mailbox cmd x%x Cmpl x%p "
936 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
937 pmb->vport ? pmb->vport->vpi : 0,
940 *((uint32_t *) pmbox),
941 pmbox->un.varWords[0],
942 pmbox->un.varWords[1],
943 pmbox->un.varWords[2],
944 pmbox->un.varWords[3],
945 pmbox->un.varWords[4],
946 pmbox->un.varWords[5],
947 pmbox->un.varWords[6],
948 pmbox->un.varWords[7]);
951 pmb->mbox_cmpl(phba,pmb);
956 static struct lpfc_dmabuf *
957 lpfc_sli_replace_hbqbuff(struct lpfc_hba *phba, uint32_t tag)
959 struct hbq_dmabuf *hbq_entry, *new_hbq_entry;
961 void *virt; /* virtual address ptr */
962 dma_addr_t phys; /* mapped address */
965 /* Check whether HBQ is still in use */
966 spin_lock_irqsave(&phba->hbalock, flags);
967 if (!phba->hbq_in_use) {
968 spin_unlock_irqrestore(&phba->hbalock, flags);
972 hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
973 if (hbq_entry == NULL) {
974 spin_unlock_irqrestore(&phba->hbalock, flags);
977 list_del(&hbq_entry->dbuf.list);
980 new_hbq_entry = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
981 if (new_hbq_entry == NULL) {
982 list_add_tail(&hbq_entry->dbuf.list, &phba->hbqbuf_in_list);
983 spin_unlock_irqrestore(&phba->hbalock, flags);
984 return &hbq_entry->dbuf;
986 new_hbq_entry->tag = -1;
987 phys = new_hbq_entry->dbuf.phys;
988 virt = new_hbq_entry->dbuf.virt;
989 new_hbq_entry->dbuf.phys = hbq_entry->dbuf.phys;
990 new_hbq_entry->dbuf.virt = hbq_entry->dbuf.virt;
991 hbq_entry->dbuf.phys = phys;
992 hbq_entry->dbuf.virt = virt;
993 lpfc_sli_free_hbq(phba, hbq_entry);
994 list_add_tail(&new_hbq_entry->dbuf.list, &phba->hbqbuf_in_list);
995 spin_unlock_irqrestore(&phba->hbalock, flags);
997 return &new_hbq_entry->dbuf;
1000 static struct lpfc_dmabuf *
1001 lpfc_sli_get_buff(struct lpfc_hba *phba,
1002 struct lpfc_sli_ring *pring,
1005 if (tag & QUE_BUFTAG_BIT)
1006 return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
1008 return lpfc_sli_replace_hbqbuff(phba, tag);
1012 lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1013 struct lpfc_iocbq *saveq)
1017 uint32_t Rctl, Type;
1019 struct lpfc_iocbq *iocbq;
1020 struct lpfc_dmabuf *dmzbuf;
1023 irsp = &(saveq->iocb);
1025 if (irsp->ulpStatus == IOSTAT_NEED_BUFFER)
1027 if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
1028 if (pring->lpfc_sli_rcv_async_status)
1029 pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
1031 lpfc_printf_log(phba,
1034 "0316 Ring %d handler: unexpected "
1035 "ASYNC_STATUS iocb received evt_code "
1038 irsp->un.asyncstat.evt_code);
1042 if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
1043 (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
1044 if (irsp->ulpBdeCount > 0) {
1045 dmzbuf = lpfc_sli_get_buff(phba, pring,
1046 irsp->un.ulpWord[3]);
1047 lpfc_in_buf_free(phba, dmzbuf);
1050 if (irsp->ulpBdeCount > 1) {
1051 dmzbuf = lpfc_sli_get_buff(phba, pring,
1052 irsp->unsli3.sli3Words[3]);
1053 lpfc_in_buf_free(phba, dmzbuf);
1056 if (irsp->ulpBdeCount > 2) {
1057 dmzbuf = lpfc_sli_get_buff(phba, pring,
1058 irsp->unsli3.sli3Words[7]);
1059 lpfc_in_buf_free(phba, dmzbuf);
1065 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
1066 if (irsp->ulpBdeCount != 0) {
1067 saveq->context2 = lpfc_sli_get_buff(phba, pring,
1068 irsp->un.ulpWord[3]);
1069 if (!saveq->context2)
1070 lpfc_printf_log(phba,
1073 "0341 Ring %d Cannot find buffer for "
1074 "an unsolicited iocb. tag 0x%x\n",
1076 irsp->un.ulpWord[3]);
1078 if (irsp->ulpBdeCount == 2) {
1079 saveq->context3 = lpfc_sli_get_buff(phba, pring,
1080 irsp->unsli3.sli3Words[7]);
1081 if (!saveq->context3)
1082 lpfc_printf_log(phba,
1085 "0342 Ring %d Cannot find buffer for an"
1086 " unsolicited iocb. tag 0x%x\n",
1088 irsp->unsli3.sli3Words[7]);
1090 list_for_each_entry(iocbq, &saveq->list, list) {
1091 irsp = &(iocbq->iocb);
1092 if (irsp->ulpBdeCount != 0) {
1093 iocbq->context2 = lpfc_sli_get_buff(phba, pring,
1094 irsp->un.ulpWord[3]);
1095 if (!iocbq->context2)
1096 lpfc_printf_log(phba,
1099 "0343 Ring %d Cannot find "
1100 "buffer for an unsolicited iocb"
1101 ". tag 0x%x\n", pring->ringno,
1102 irsp->un.ulpWord[3]);
1104 if (irsp->ulpBdeCount == 2) {
1105 iocbq->context3 = lpfc_sli_get_buff(phba, pring,
1106 irsp->unsli3.sli3Words[7]);
1107 if (!iocbq->context3)
1108 lpfc_printf_log(phba,
1111 "0344 Ring %d Cannot find "
1112 "buffer for an unsolicited "
1115 irsp->unsli3.sli3Words[7]);
1119 if (irsp->ulpBdeCount != 0 &&
1120 (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
1121 irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
1124 /* search continue save q for same XRI */
1125 list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
1126 if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) {
1127 list_add_tail(&saveq->list, &iocbq->list);
1133 list_add_tail(&saveq->clist,
1134 &pring->iocb_continue_saveq);
1135 if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
1136 list_del_init(&iocbq->clist);
1138 irsp = &(saveq->iocb);
1142 if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
1143 (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
1144 (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
1148 w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
1149 Rctl = w5p->hcsw.Rctl;
1150 Type = w5p->hcsw.Type;
1152 /* Firmware Workaround */
1153 if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
1154 (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
1155 irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
1158 w5p->hcsw.Rctl = Rctl;
1159 w5p->hcsw.Type = Type;
1163 /* unSolicited Responses */
1164 if (pring->prt[0].profile) {
1165 if (pring->prt[0].lpfc_sli_rcv_unsol_event)
1166 (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
1170 /* We must search, based on rctl / type
1171 for the right routine */
1172 for (i = 0; i < pring->num_mask; i++) {
1173 if ((pring->prt[i].rctl == Rctl)
1174 && (pring->prt[i].type == Type)) {
1175 if (pring->prt[i].lpfc_sli_rcv_unsol_event)
1176 (pring->prt[i].lpfc_sli_rcv_unsol_event)
1177 (phba, pring, saveq);
1184 /* Unexpected Rctl / Type received */
1185 /* Ring <ringno> handler: unexpected
1186 Rctl <Rctl> Type <Type> received */
1187 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1188 "0313 Ring %d handler: unexpected Rctl x%x "
1189 "Type x%x received\n",
1190 pring->ringno, Rctl, Type);
1195 static struct lpfc_iocbq *
1196 lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
1197 struct lpfc_sli_ring *pring,
1198 struct lpfc_iocbq *prspiocb)
1200 struct lpfc_iocbq *cmd_iocb = NULL;
1203 iotag = prspiocb->iocb.ulpIoTag;
1205 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
1206 cmd_iocb = phba->sli.iocbq_lookup[iotag];
1207 list_del_init(&cmd_iocb->list);
1208 pring->txcmplq_cnt--;
1212 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1213 "0317 iotag x%x is out off "
1214 "range: max iotag x%x wd0 x%x\n",
1215 iotag, phba->sli.last_iotag,
1216 *(((uint32_t *) &prspiocb->iocb) + 7));
1221 lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1222 struct lpfc_iocbq *saveq)
1224 struct lpfc_iocbq *cmdiocbp;
1226 unsigned long iflag;
1228 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
1229 spin_lock_irqsave(&phba->hbalock, iflag);
1230 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
1231 spin_unlock_irqrestore(&phba->hbalock, iflag);
1234 if (cmdiocbp->iocb_cmpl) {
1236 * Post all ELS completions to the worker thread.
1237 * All other are passed to the completion callback.
1239 if (pring->ringno == LPFC_ELS_RING) {
1240 if (cmdiocbp->iocb_flag & LPFC_DRIVER_ABORTED) {
1241 cmdiocbp->iocb_flag &=
1242 ~LPFC_DRIVER_ABORTED;
1243 saveq->iocb.ulpStatus =
1244 IOSTAT_LOCAL_REJECT;
1245 saveq->iocb.un.ulpWord[4] =
1248 /* Firmware could still be in progress
1249 * of DMAing payload, so don't free data
1250 * buffer till after a hbeat.
1252 saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
1255 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
1257 lpfc_sli_release_iocbq(phba, cmdiocbp);
1260 * Unknown initiating command based on the response iotag.
1261 * This could be the case on the ELS ring because of
1264 if (pring->ringno != LPFC_ELS_RING) {
1266 * Ring <ringno> handler: unexpected completion IoTag
1269 lpfc_printf_vlog(cmdiocbp->vport, KERN_WARNING, LOG_SLI,
1270 "0322 Ring %d handler: "
1271 "unexpected completion IoTag x%x "
1272 "Data: x%x x%x x%x x%x\n",
1274 saveq->iocb.ulpIoTag,
1275 saveq->iocb.ulpStatus,
1276 saveq->iocb.un.ulpWord[4],
1277 saveq->iocb.ulpCommand,
1278 saveq->iocb.ulpContext);
1286 lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1288 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
1289 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1290 &phba->slim2p->mbx.us.s2.port[pring->ringno];
1292 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
1293 * rsp ring <portRspMax>
1295 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1296 "0312 Ring %d handler: portRspPut %d "
1297 "is bigger then rsp ring %d\n",
1298 pring->ringno, le32_to_cpu(pgp->rspPutInx),
1301 phba->link_state = LPFC_HBA_ERROR;
1304 * All error attention handlers are posted to
1307 phba->work_ha |= HA_ERATT;
1308 phba->work_hs = HS_FFER3;
1310 lpfc_worker_wake_up(phba);
1315 void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba)
1317 struct lpfc_sli *psli = &phba->sli;
1318 struct lpfc_sli_ring *pring = &psli->ring[LPFC_FCP_RING];
1319 IOCB_t *irsp = NULL;
1320 IOCB_t *entry = NULL;
1321 struct lpfc_iocbq *cmdiocbq = NULL;
1322 struct lpfc_iocbq rspiocbq;
1323 struct lpfc_pgp *pgp;
1325 uint32_t portRspPut, portRspMax;
1327 uint32_t rsp_cmpl = 0;
1329 unsigned long iflags;
1331 pring->stats.iocb_event++;
1333 pgp = (phba->sli_rev == 3) ?
1334 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1335 &phba->slim2p->mbx.us.s2.port[pring->ringno];
1339 * The next available response entry should never exceed the maximum
1340 * entries. If it does, treat it as an adapter hardware error.
1342 portRspMax = pring->numRiocb;
1343 portRspPut = le32_to_cpu(pgp->rspPutInx);
1344 if (unlikely(portRspPut >= portRspMax)) {
1345 lpfc_sli_rsp_pointers_error(phba, pring);
1350 while (pring->rspidx != portRspPut) {
1351 entry = lpfc_resp_iocb(phba, pring);
1352 if (++pring->rspidx >= portRspMax)
1355 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
1356 (uint32_t *) &rspiocbq.iocb,
1357 phba->iocb_rsp_size);
1358 irsp = &rspiocbq.iocb;
1359 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
1360 pring->stats.iocb_rsp++;
1363 if (unlikely(irsp->ulpStatus)) {
1364 /* Rsp ring <ringno> error: IOCB */
1365 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1366 "0326 Rsp Ring %d error: IOCB Data: "
1367 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
1369 irsp->un.ulpWord[0],
1370 irsp->un.ulpWord[1],
1371 irsp->un.ulpWord[2],
1372 irsp->un.ulpWord[3],
1373 irsp->un.ulpWord[4],
1374 irsp->un.ulpWord[5],
1375 *(((uint32_t *) irsp) + 6),
1376 *(((uint32_t *) irsp) + 7));
1380 case LPFC_ABORT_IOCB:
1383 * Idle exchange closed via ABTS from port. No iocb
1384 * resources need to be recovered.
1386 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
1387 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1388 "0314 IOCB cmd 0x%x "
1389 "processed. Skipping "
1395 spin_lock_irqsave(&phba->hbalock, iflags);
1396 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
1398 spin_unlock_irqrestore(&phba->hbalock, iflags);
1399 if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
1400 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1405 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1406 char adaptermsg[LPFC_MAX_ADPTMSG];
1407 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
1408 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1410 dev_warn(&((phba->pcidev)->dev),
1412 phba->brd_no, adaptermsg);
1414 /* Unknown IOCB command */
1415 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1416 "0321 Unknown IOCB command "
1417 "Data: x%x, x%x x%x x%x x%x\n",
1418 type, irsp->ulpCommand,
1427 * The response IOCB has been processed. Update the ring
1428 * pointer in SLIM. If the port response put pointer has not
1429 * been updated, sync the pgp->rspPutInx and fetch the new port
1430 * response put pointer.
1432 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
1434 if (pring->rspidx == portRspPut)
1435 portRspPut = le32_to_cpu(pgp->rspPutInx);
1438 ha_copy = readl(phba->HAregaddr);
1439 ha_copy >>= (LPFC_FCP_RING * 4);
1441 if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) {
1442 spin_lock_irqsave(&phba->hbalock, iflags);
1443 pring->stats.iocb_rsp_full++;
1444 status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4));
1445 writel(status, phba->CAregaddr);
1446 readl(phba->CAregaddr);
1447 spin_unlock_irqrestore(&phba->hbalock, iflags);
1449 if ((ha_copy & HA_R0CE_RSP) &&
1450 (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1451 spin_lock_irqsave(&phba->hbalock, iflags);
1452 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1453 pring->stats.iocb_cmd_empty++;
1455 /* Force update of the local copy of cmdGetInx */
1456 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1457 lpfc_sli_resume_iocb(phba, pring);
1459 if ((pring->lpfc_sli_cmd_available))
1460 (pring->lpfc_sli_cmd_available) (phba, pring);
1462 spin_unlock_irqrestore(&phba->hbalock, iflags);
1469 * This routine presumes LPFC_FCP_RING handling and doesn't bother
1470 * to check it explicitly.
1473 lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
1474 struct lpfc_sli_ring *pring, uint32_t mask)
1476 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
1477 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1478 &phba->slim2p->mbx.us.s2.port[pring->ringno];
1479 IOCB_t *irsp = NULL;
1480 IOCB_t *entry = NULL;
1481 struct lpfc_iocbq *cmdiocbq = NULL;
1482 struct lpfc_iocbq rspiocbq;
1484 uint32_t portRspPut, portRspMax;
1486 lpfc_iocb_type type;
1487 unsigned long iflag;
1488 uint32_t rsp_cmpl = 0;
1490 spin_lock_irqsave(&phba->hbalock, iflag);
1491 pring->stats.iocb_event++;
1494 * The next available response entry should never exceed the maximum
1495 * entries. If it does, treat it as an adapter hardware error.
1497 portRspMax = pring->numRiocb;
1498 portRspPut = le32_to_cpu(pgp->rspPutInx);
1499 if (unlikely(portRspPut >= portRspMax)) {
1500 lpfc_sli_rsp_pointers_error(phba, pring);
1501 spin_unlock_irqrestore(&phba->hbalock, iflag);
1506 while (pring->rspidx != portRspPut) {
1508 * Fetch an entry off the ring and copy it into a local data
1509 * structure. The copy involves a byte-swap since the
1510 * network byte order and pci byte orders are different.
1512 entry = lpfc_resp_iocb(phba, pring);
1513 phba->last_completion_time = jiffies;
1515 if (++pring->rspidx >= portRspMax)
1518 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
1519 (uint32_t *) &rspiocbq.iocb,
1520 phba->iocb_rsp_size);
1521 INIT_LIST_HEAD(&(rspiocbq.list));
1522 irsp = &rspiocbq.iocb;
1524 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
1525 pring->stats.iocb_rsp++;
1528 if (unlikely(irsp->ulpStatus)) {
1530 * If resource errors reported from HBA, reduce
1531 * queuedepths of the SCSI device.
1533 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1534 (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
1535 spin_unlock_irqrestore(&phba->hbalock, iflag);
1536 lpfc_adjust_queue_depth(phba);
1537 spin_lock_irqsave(&phba->hbalock, iflag);
1540 /* Rsp ring <ringno> error: IOCB */
1541 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1542 "0336 Rsp Ring %d error: IOCB Data: "
1543 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
1545 irsp->un.ulpWord[0],
1546 irsp->un.ulpWord[1],
1547 irsp->un.ulpWord[2],
1548 irsp->un.ulpWord[3],
1549 irsp->un.ulpWord[4],
1550 irsp->un.ulpWord[5],
1551 *(((uint32_t *) irsp) + 6),
1552 *(((uint32_t *) irsp) + 7));
1556 case LPFC_ABORT_IOCB:
1559 * Idle exchange closed via ABTS from port. No iocb
1560 * resources need to be recovered.
1562 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
1563 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1564 "0333 IOCB cmd 0x%x"
1565 " processed. Skipping"
1571 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
1573 if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
1574 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
1575 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1578 spin_unlock_irqrestore(&phba->hbalock,
1580 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1582 spin_lock_irqsave(&phba->hbalock,
1587 case LPFC_UNSOL_IOCB:
1588 spin_unlock_irqrestore(&phba->hbalock, iflag);
1589 lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
1590 spin_lock_irqsave(&phba->hbalock, iflag);
1593 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1594 char adaptermsg[LPFC_MAX_ADPTMSG];
1595 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
1596 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1598 dev_warn(&((phba->pcidev)->dev),
1600 phba->brd_no, adaptermsg);
1602 /* Unknown IOCB command */
1603 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1604 "0334 Unknown IOCB command "
1605 "Data: x%x, x%x x%x x%x x%x\n",
1606 type, irsp->ulpCommand,
1615 * The response IOCB has been processed. Update the ring
1616 * pointer in SLIM. If the port response put pointer has not
1617 * been updated, sync the pgp->rspPutInx and fetch the new port
1618 * response put pointer.
1620 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
1622 if (pring->rspidx == portRspPut)
1623 portRspPut = le32_to_cpu(pgp->rspPutInx);
1626 if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
1627 pring->stats.iocb_rsp_full++;
1628 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
1629 writel(status, phba->CAregaddr);
1630 readl(phba->CAregaddr);
1632 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1633 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1634 pring->stats.iocb_cmd_empty++;
1636 /* Force update of the local copy of cmdGetInx */
1637 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1638 lpfc_sli_resume_iocb(phba, pring);
1640 if ((pring->lpfc_sli_cmd_available))
1641 (pring->lpfc_sli_cmd_available) (phba, pring);
1645 spin_unlock_irqrestore(&phba->hbalock, iflag);
1650 lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
1651 struct lpfc_sli_ring *pring, uint32_t mask)
1653 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
1654 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1655 &phba->slim2p->mbx.us.s2.port[pring->ringno];
1657 IOCB_t *irsp = NULL;
1658 struct lpfc_iocbq *rspiocbp = NULL;
1659 struct lpfc_iocbq *next_iocb;
1660 struct lpfc_iocbq *cmdiocbp;
1661 struct lpfc_iocbq *saveq;
1662 uint8_t iocb_cmd_type;
1663 lpfc_iocb_type type;
1664 uint32_t status, free_saveq;
1665 uint32_t portRspPut, portRspMax;
1667 unsigned long iflag;
1669 spin_lock_irqsave(&phba->hbalock, iflag);
1670 pring->stats.iocb_event++;
1673 * The next available response entry should never exceed the maximum
1674 * entries. If it does, treat it as an adapter hardware error.
1676 portRspMax = pring->numRiocb;
1677 portRspPut = le32_to_cpu(pgp->rspPutInx);
1678 if (portRspPut >= portRspMax) {
1680 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
1681 * rsp ring <portRspMax>
1683 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1684 "0303 Ring %d handler: portRspPut %d "
1685 "is bigger then rsp ring %d\n",
1686 pring->ringno, portRspPut, portRspMax);
1688 phba->link_state = LPFC_HBA_ERROR;
1689 spin_unlock_irqrestore(&phba->hbalock, iflag);
1691 phba->work_hs = HS_FFER3;
1692 lpfc_handle_eratt(phba);
1698 while (pring->rspidx != portRspPut) {
1700 * Build a completion list and call the appropriate handler.
1701 * The process is to get the next available response iocb, get
1702 * a free iocb from the list, copy the response data into the
1703 * free iocb, insert to the continuation list, and update the
1704 * next response index to slim. This process makes response
1705 * iocb's in the ring available to DMA as fast as possible but
1706 * pays a penalty for a copy operation. Since the iocb is
1707 * only 32 bytes, this penalty is considered small relative to
1708 * the PCI reads for register values and a slim write. When
1709 * the ulpLe field is set, the entire Command has been
1712 entry = lpfc_resp_iocb(phba, pring);
1714 phba->last_completion_time = jiffies;
1715 rspiocbp = __lpfc_sli_get_iocbq(phba);
1716 if (rspiocbp == NULL) {
1717 printk(KERN_ERR "%s: out of buffers! Failing "
1718 "completion.\n", __FUNCTION__);
1722 lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
1723 phba->iocb_rsp_size);
1724 irsp = &rspiocbp->iocb;
1726 if (++pring->rspidx >= portRspMax)
1729 if (pring->ringno == LPFC_ELS_RING) {
1730 lpfc_debugfs_slow_ring_trc(phba,
1731 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
1732 *(((uint32_t *) irsp) + 4),
1733 *(((uint32_t *) irsp) + 6),
1734 *(((uint32_t *) irsp) + 7));
1737 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
1739 list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
1741 pring->iocb_continueq_cnt++;
1744 * By default, the driver expects to free all resources
1745 * associated with this iocb completion.
1748 saveq = list_get_first(&pring->iocb_continueq,
1749 struct lpfc_iocbq, list);
1750 irsp = &(saveq->iocb);
1751 list_del_init(&pring->iocb_continueq);
1752 pring->iocb_continueq_cnt = 0;
1754 pring->stats.iocb_rsp++;
1757 * If resource errors reported from HBA, reduce
1758 * queuedepths of the SCSI device.
1760 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1761 (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
1762 spin_unlock_irqrestore(&phba->hbalock, iflag);
1763 lpfc_adjust_queue_depth(phba);
1764 spin_lock_irqsave(&phba->hbalock, iflag);
1767 if (irsp->ulpStatus) {
1768 /* Rsp ring <ringno> error: IOCB */
1769 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1770 "0328 Rsp Ring %d error: "
1775 "x%x x%x x%x x%x\n",
1777 irsp->un.ulpWord[0],
1778 irsp->un.ulpWord[1],
1779 irsp->un.ulpWord[2],
1780 irsp->un.ulpWord[3],
1781 irsp->un.ulpWord[4],
1782 irsp->un.ulpWord[5],
1783 *(((uint32_t *) irsp) + 6),
1784 *(((uint32_t *) irsp) + 7),
1785 *(((uint32_t *) irsp) + 8),
1786 *(((uint32_t *) irsp) + 9),
1787 *(((uint32_t *) irsp) + 10),
1788 *(((uint32_t *) irsp) + 11),
1789 *(((uint32_t *) irsp) + 12),
1790 *(((uint32_t *) irsp) + 13),
1791 *(((uint32_t *) irsp) + 14),
1792 *(((uint32_t *) irsp) + 15));
1796 * Fetch the IOCB command type and call the correct
1797 * completion routine. Solicited and Unsolicited
1798 * IOCBs on the ELS ring get freed back to the
1799 * lpfc_iocb_list by the discovery kernel thread.
1801 iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
1802 type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
1803 if (type == LPFC_SOL_IOCB) {
1804 spin_unlock_irqrestore(&phba->hbalock, iflag);
1805 rc = lpfc_sli_process_sol_iocb(phba, pring,
1807 spin_lock_irqsave(&phba->hbalock, iflag);
1808 } else if (type == LPFC_UNSOL_IOCB) {
1809 spin_unlock_irqrestore(&phba->hbalock, iflag);
1810 rc = lpfc_sli_process_unsol_iocb(phba, pring,
1812 spin_lock_irqsave(&phba->hbalock, iflag);
1815 } else if (type == LPFC_ABORT_IOCB) {
1816 if ((irsp->ulpCommand != CMD_XRI_ABORTED_CX) &&
1818 lpfc_sli_iocbq_lookup(phba, pring,
1820 /* Call the specified completion
1822 if (cmdiocbp->iocb_cmpl) {
1823 spin_unlock_irqrestore(
1826 (cmdiocbp->iocb_cmpl) (phba,
1832 __lpfc_sli_release_iocbq(phba,
1835 } else if (type == LPFC_UNKNOWN_IOCB) {
1836 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1838 char adaptermsg[LPFC_MAX_ADPTMSG];
1840 memset(adaptermsg, 0,
1842 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1844 dev_warn(&((phba->pcidev)->dev),
1846 phba->brd_no, adaptermsg);
1848 /* Unknown IOCB command */
1849 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1850 "0335 Unknown IOCB "
1851 "command Data: x%x "
1861 list_for_each_entry_safe(rspiocbp, next_iocb,
1862 &saveq->list, list) {
1863 list_del(&rspiocbp->list);
1864 __lpfc_sli_release_iocbq(phba,
1867 __lpfc_sli_release_iocbq(phba, saveq);
1873 * If the port response put pointer has not been updated, sync
1874 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
1875 * response put pointer.
1877 if (pring->rspidx == portRspPut) {
1878 portRspPut = le32_to_cpu(pgp->rspPutInx);
1880 } /* while (pring->rspidx != portRspPut) */
1882 if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
1883 /* At least one response entry has been freed */
1884 pring->stats.iocb_rsp_full++;
1885 /* SET RxRE_RSP in Chip Att register */
1886 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
1887 writel(status, phba->CAregaddr);
1888 readl(phba->CAregaddr); /* flush */
1890 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1891 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1892 pring->stats.iocb_cmd_empty++;
1894 /* Force update of the local copy of cmdGetInx */
1895 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1896 lpfc_sli_resume_iocb(phba, pring);
1898 if ((pring->lpfc_sli_cmd_available))
1899 (pring->lpfc_sli_cmd_available) (phba, pring);
1903 spin_unlock_irqrestore(&phba->hbalock, iflag);
1908 lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1910 LIST_HEAD(completions);
1911 struct lpfc_iocbq *iocb, *next_iocb;
1914 if (pring->ringno == LPFC_ELS_RING) {
1915 lpfc_fabric_abort_hba(phba);
1918 /* Error everything on txq and txcmplq
1921 spin_lock_irq(&phba->hbalock);
1922 list_splice_init(&pring->txq, &completions);
1925 /* Next issue ABTS for everything on the txcmplq */
1926 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
1927 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1929 spin_unlock_irq(&phba->hbalock);
1931 while (!list_empty(&completions)) {
1932 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
1934 list_del_init(&iocb->list);
1936 if (!iocb->iocb_cmpl)
1937 lpfc_sli_release_iocbq(phba, iocb);
1939 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
1940 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
1941 (iocb->iocb_cmpl) (phba, iocb, iocb);
1947 lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
1953 /* Read the HBA Host Status Register */
1954 status = readl(phba->HSregaddr);
1957 * Check status register every 100ms for 5 retries, then every
1958 * 500ms for 5, then every 2.5 sec for 5, then reset board and
1959 * every 2.5 sec for 4.
1960 * Break our of the loop if errors occurred during init.
1962 while (((status & mask) != mask) &&
1963 !(status & HS_FFERM) &&
1975 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
1976 lpfc_sli_brdrestart(phba);
1978 /* Read the HBA Host Status Register */
1979 status = readl(phba->HSregaddr);
1982 /* Check to see if any errors occurred during init */
1983 if ((status & HS_FFERM) || (i >= 20)) {
1984 phba->link_state = LPFC_HBA_ERROR;
1991 #define BARRIER_TEST_PATTERN (0xdeadbeef)
1993 void lpfc_reset_barrier(struct lpfc_hba *phba)
1995 uint32_t __iomem *resp_buf;
1996 uint32_t __iomem *mbox_buf;
1997 volatile uint32_t mbox;
2002 pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
2003 if (hdrtype != 0x80 ||
2004 (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
2005 FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
2009 * Tell the other part of the chip to suspend temporarily all
2012 resp_buf = phba->MBslimaddr;
2014 /* Disable the error attention */
2015 hc_copy = readl(phba->HCregaddr);
2016 writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
2017 readl(phba->HCregaddr); /* flush */
2018 phba->link_flag |= LS_IGNORE_ERATT;
2020 if (readl(phba->HAregaddr) & HA_ERATT) {
2021 /* Clear Chip error bit */
2022 writel(HA_ERATT, phba->HAregaddr);
2023 phba->pport->stopped = 1;
2027 ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
2028 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
2030 writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
2031 mbox_buf = phba->MBslimaddr;
2032 writel(mbox, mbox_buf);
2035 readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
2038 if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
2039 if (phba->sli.sli_flag & LPFC_SLI2_ACTIVE ||
2040 phba->pport->stopped)
2046 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
2047 for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
2052 while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
2055 if (readl(phba->HAregaddr) & HA_ERATT) {
2056 writel(HA_ERATT, phba->HAregaddr);
2057 phba->pport->stopped = 1;
2061 phba->link_flag &= ~LS_IGNORE_ERATT;
2062 writel(hc_copy, phba->HCregaddr);
2063 readl(phba->HCregaddr); /* flush */
2067 lpfc_sli_brdkill(struct lpfc_hba *phba)
2069 struct lpfc_sli *psli;
2079 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2080 "0329 Kill HBA Data: x%x x%x\n",
2081 phba->pport->port_state, psli->sli_flag);
2083 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2087 /* Disable the error attention */
2088 spin_lock_irq(&phba->hbalock);
2089 status = readl(phba->HCregaddr);
2090 status &= ~HC_ERINT_ENA;
2091 writel(status, phba->HCregaddr);
2092 readl(phba->HCregaddr); /* flush */
2093 phba->link_flag |= LS_IGNORE_ERATT;
2094 spin_unlock_irq(&phba->hbalock);
2096 lpfc_kill_board(phba, pmb);
2097 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2098 retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
2100 if (retval != MBX_SUCCESS) {
2101 if (retval != MBX_BUSY)
2102 mempool_free(pmb, phba->mbox_mem_pool);
2103 spin_lock_irq(&phba->hbalock);
2104 phba->link_flag &= ~LS_IGNORE_ERATT;
2105 spin_unlock_irq(&phba->hbalock);
2109 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
2111 mempool_free(pmb, phba->mbox_mem_pool);
2113 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
2114 * attention every 100ms for 3 seconds. If we don't get ERATT after
2115 * 3 seconds we still set HBA_ERROR state because the status of the
2116 * board is now undefined.
2118 ha_copy = readl(phba->HAregaddr);
2120 while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
2122 ha_copy = readl(phba->HAregaddr);
2125 del_timer_sync(&psli->mbox_tmo);
2126 if (ha_copy & HA_ERATT) {
2127 writel(HA_ERATT, phba->HAregaddr);
2128 phba->pport->stopped = 1;
2130 spin_lock_irq(&phba->hbalock);
2131 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2132 phba->link_flag &= ~LS_IGNORE_ERATT;
2133 spin_unlock_irq(&phba->hbalock);
2135 psli->mbox_active = NULL;
2136 lpfc_hba_down_post(phba);
2137 phba->link_state = LPFC_HBA_ERROR;
2139 return ha_copy & HA_ERATT ? 0 : 1;
2143 lpfc_sli_brdreset(struct lpfc_hba *phba)
2145 struct lpfc_sli *psli;
2146 struct lpfc_sli_ring *pring;
2153 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2154 "0325 Reset HBA Data: x%x x%x\n",
2155 phba->pport->port_state, psli->sli_flag);
2157 /* perform board reset */
2158 phba->fc_eventTag = 0;
2159 phba->pport->fc_myDID = 0;
2160 phba->pport->fc_prevDID = 0;
2162 /* Turn off parity checking and serr during the physical reset */
2163 pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
2164 pci_write_config_word(phba->pcidev, PCI_COMMAND,
2166 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
2168 psli->sli_flag &= ~(LPFC_SLI2_ACTIVE | LPFC_PROCESS_LA);
2169 /* Now toggle INITFF bit in the Host Control Register */
2170 writel(HC_INITFF, phba->HCregaddr);
2172 readl(phba->HCregaddr); /* flush */
2173 writel(0, phba->HCregaddr);
2174 readl(phba->HCregaddr); /* flush */
2176 /* Restore PCI cmd register */
2177 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
2179 /* Initialize relevant SLI info */
2180 for (i = 0; i < psli->num_rings; i++) {
2181 pring = &psli->ring[i];
2184 pring->next_cmdidx = 0;
2185 pring->local_getidx = 0;
2187 pring->missbufcnt = 0;
2190 phba->link_state = LPFC_WARM_START;
2195 lpfc_sli_brdrestart(struct lpfc_hba *phba)
2198 struct lpfc_sli *psli;
2200 volatile uint32_t word0;
2201 void __iomem *to_slim;
2203 spin_lock_irq(&phba->hbalock);
2208 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2209 "0337 Restart HBA Data: x%x x%x\n",
2210 phba->pport->port_state, psli->sli_flag);
2213 mb = (MAILBOX_t *) &word0;
2214 mb->mbxCommand = MBX_RESTART;
2217 lpfc_reset_barrier(phba);
2219 to_slim = phba->MBslimaddr;
2220 writel(*(uint32_t *) mb, to_slim);
2221 readl(to_slim); /* flush */
2223 /* Only skip post after fc_ffinit is completed */
2224 if (phba->pport->port_state) {
2226 word0 = 1; /* This is really setting up word1 */
2229 word0 = 0; /* This is really setting up word1 */
2231 to_slim = phba->MBslimaddr + sizeof (uint32_t);
2232 writel(*(uint32_t *) mb, to_slim);
2233 readl(to_slim); /* flush */
2235 lpfc_sli_brdreset(phba);
2236 phba->pport->stopped = 0;
2237 phba->link_state = LPFC_INIT_START;
2239 spin_unlock_irq(&phba->hbalock);
2241 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
2242 psli->stats_start = get_seconds();
2249 lpfc_hba_down_post(phba);
2255 lpfc_sli_chipset_init(struct lpfc_hba *phba)
2257 uint32_t status, i = 0;
2259 /* Read the HBA Host Status Register */
2260 status = readl(phba->HSregaddr);
2262 /* Check status register to see what current state is */
2264 while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
2266 /* Check every 100ms for 5 retries, then every 500ms for 5, then
2267 * every 2.5 sec for 5, then reset board and every 2.5 sec for
2271 /* Adapter failed to init, timeout, status reg
2273 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2274 "0436 Adapter failed to init, "
2275 "timeout, status reg x%x, "
2276 "FW Data: A8 x%x AC x%x\n", status,
2277 readl(phba->MBslimaddr + 0xa8),
2278 readl(phba->MBslimaddr + 0xac));
2279 phba->link_state = LPFC_HBA_ERROR;
2283 /* Check to see if any errors occurred during init */
2284 if (status & HS_FFERM) {
2285 /* ERROR: During chipset initialization */
2286 /* Adapter failed to init, chipset, status reg
2288 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2289 "0437 Adapter failed to init, "
2290 "chipset, status reg x%x, "
2291 "FW Data: A8 x%x AC x%x\n", status,
2292 readl(phba->MBslimaddr + 0xa8),
2293 readl(phba->MBslimaddr + 0xac));
2294 phba->link_state = LPFC_HBA_ERROR;
2300 } else if (i <= 10) {
2308 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
2309 lpfc_sli_brdrestart(phba);
2311 /* Read the HBA Host Status Register */
2312 status = readl(phba->HSregaddr);
2315 /* Check to see if any errors occurred during init */
2316 if (status & HS_FFERM) {
2317 /* ERROR: During chipset initialization */
2318 /* Adapter failed to init, chipset, status reg <status> */
2319 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2320 "0438 Adapter failed to init, chipset, "
2322 "FW Data: A8 x%x AC x%x\n", status,
2323 readl(phba->MBslimaddr + 0xa8),
2324 readl(phba->MBslimaddr + 0xac));
2325 phba->link_state = LPFC_HBA_ERROR;
2329 /* Clear all interrupt enable conditions */
2330 writel(0, phba->HCregaddr);
2331 readl(phba->HCregaddr); /* flush */
2333 /* setup host attn register */
2334 writel(0xffffffff, phba->HAregaddr);
2335 readl(phba->HAregaddr); /* flush */
2340 lpfc_sli_hbq_count(void)
2342 return ARRAY_SIZE(lpfc_hbq_defs);
2346 lpfc_sli_hbq_entry_count(void)
2348 int hbq_count = lpfc_sli_hbq_count();
2352 for (i = 0; i < hbq_count; ++i)
2353 count += lpfc_hbq_defs[i]->entry_count;
2358 lpfc_sli_hbq_size(void)
2360 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
2364 lpfc_sli_hbq_setup(struct lpfc_hba *phba)
2366 int hbq_count = lpfc_sli_hbq_count();
2370 uint32_t hbq_entry_index;
2372 /* Get a Mailbox buffer to setup mailbox
2373 * commands for HBA initialization
2375 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2382 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
2383 phba->link_state = LPFC_INIT_MBX_CMDS;
2384 phba->hbq_in_use = 1;
2386 hbq_entry_index = 0;
2387 for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
2388 phba->hbqs[hbqno].next_hbqPutIdx = 0;
2389 phba->hbqs[hbqno].hbqPutIdx = 0;
2390 phba->hbqs[hbqno].local_hbqGetIdx = 0;
2391 phba->hbqs[hbqno].entry_count =
2392 lpfc_hbq_defs[hbqno]->entry_count;
2393 lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
2394 hbq_entry_index, pmb);
2395 hbq_entry_index += phba->hbqs[hbqno].entry_count;
2397 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
2398 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
2399 mbxStatus <status>, ring <num> */
2401 lpfc_printf_log(phba, KERN_ERR,
2402 LOG_SLI | LOG_VPORT,
2403 "1805 Adapter failed to init. "
2404 "Data: x%x x%x x%x\n",
2406 pmbox->mbxStatus, hbqno);
2408 phba->link_state = LPFC_HBA_ERROR;
2409 mempool_free(pmb, phba->mbox_mem_pool);
2413 phba->hbq_count = hbq_count;
2415 mempool_free(pmb, phba->mbox_mem_pool);
2417 /* Initially populate or replenish the HBQs */
2418 for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
2419 if (lpfc_sli_hbqbuf_init_hbqs(phba, hbqno))
2426 lpfc_do_config_port(struct lpfc_hba *phba, int sli_mode)
2429 uint32_t resetcount = 0, rc = 0, done = 0;
2431 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2433 phba->link_state = LPFC_HBA_ERROR;
2437 phba->sli_rev = sli_mode;
2438 while (resetcount < 2 && !done) {
2439 spin_lock_irq(&phba->hbalock);
2440 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
2441 spin_unlock_irq(&phba->hbalock);
2442 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
2443 lpfc_sli_brdrestart(phba);
2445 rc = lpfc_sli_chipset_init(phba);
2449 spin_lock_irq(&phba->hbalock);
2450 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2451 spin_unlock_irq(&phba->hbalock);
2454 /* Call pre CONFIG_PORT mailbox command initialization. A
2455 * value of 0 means the call was successful. Any other
2456 * nonzero value is a failure, but if ERESTART is returned,
2457 * the driver may reset the HBA and try again.
2459 rc = lpfc_config_port_prep(phba);
2460 if (rc == -ERESTART) {
2461 phba->link_state = LPFC_LINK_UNKNOWN;
2467 phba->link_state = LPFC_INIT_MBX_CMDS;
2468 lpfc_config_port(phba, pmb);
2469 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
2470 if (rc != MBX_SUCCESS) {
2471 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2472 "0442 Adapter failed to init, mbxCmd x%x "
2473 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
2474 pmb->mb.mbxCommand, pmb->mb.mbxStatus, 0);
2475 spin_lock_irq(&phba->hbalock);
2476 phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE;
2477 spin_unlock_irq(&phba->hbalock);
2481 phba->max_vpi = (phba->max_vpi &&
2482 pmb->mb.un.varCfgPort.gmv) != 0
2483 ? pmb->mb.un.varCfgPort.max_vpi
2490 goto do_prep_failed;
2493 if ((pmb->mb.un.varCfgPort.sli_mode == 3) &&
2494 (!pmb->mb.un.varCfgPort.cMA)) {
2499 mempool_free(pmb, phba->mbox_mem_pool);
2504 lpfc_sli_hba_setup(struct lpfc_hba *phba)
2509 switch (lpfc_sli_mode) {
2511 if (phba->cfg_enable_npiv) {
2512 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
2513 "1824 NPIV enabled: Override lpfc_sli_mode "
2514 "parameter (%d) to auto (0).\n",
2524 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
2525 "1819 Unrecognized lpfc_sli_mode "
2526 "parameter: %d.\n", lpfc_sli_mode);
2531 rc = lpfc_do_config_port(phba, mode);
2532 if (rc && lpfc_sli_mode == 3)
2533 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
2534 "1820 Unable to select SLI-3. "
2535 "Not supported by adapter.\n");
2536 if (rc && mode != 2)
2537 rc = lpfc_do_config_port(phba, 2);
2539 goto lpfc_sli_hba_setup_error;
2541 if (phba->sli_rev == 3) {
2542 phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
2543 phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
2544 phba->sli3_options |= LPFC_SLI3_ENABLED;
2545 phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
2548 phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
2549 phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
2550 phba->sli3_options = 0;
2553 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2554 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
2555 phba->sli_rev, phba->max_vpi);
2556 rc = lpfc_sli_ring_map(phba);
2559 goto lpfc_sli_hba_setup_error;
2563 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
2564 rc = lpfc_sli_hbq_setup(phba);
2566 goto lpfc_sli_hba_setup_error;
2569 phba->sli.sli_flag |= LPFC_PROCESS_LA;
2571 rc = lpfc_config_port_post(phba);
2573 goto lpfc_sli_hba_setup_error;
2577 lpfc_sli_hba_setup_error:
2578 phba->link_state = LPFC_HBA_ERROR;
2579 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2580 "0445 Firmware initialization failed\n");
2584 /*! lpfc_mbox_timeout
2588 * \param hba Pointer to per struct lpfc_hba structure
2589 * \param l1 Pointer to the driver's mailbox queue.
2595 * This routine handles mailbox timeout events at timer interrupt context.
2598 lpfc_mbox_timeout(unsigned long ptr)
2600 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
2601 unsigned long iflag;
2602 uint32_t tmo_posted;
2604 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
2605 tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
2607 phba->pport->work_port_events |= WORKER_MBOX_TMO;
2608 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
2611 lpfc_worker_wake_up(phba);
2616 lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
2618 LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
2619 MAILBOX_t *mb = &pmbox->mb;
2620 struct lpfc_sli *psli = &phba->sli;
2621 struct lpfc_sli_ring *pring;
2623 if (!(phba->pport->work_port_events & WORKER_MBOX_TMO)) {
2627 /* Mbox cmd <mbxCommand> timeout */
2628 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
2629 "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
2631 phba->pport->port_state,
2633 phba->sli.mbox_active);
2635 /* Setting state unknown so lpfc_sli_abort_iocb_ring
2636 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
2637 * it to fail all oustanding SCSI IO.
2639 spin_lock_irq(&phba->pport->work_port_lock);
2640 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
2641 spin_unlock_irq(&phba->pport->work_port_lock);
2642 spin_lock_irq(&phba->hbalock);
2643 phba->link_state = LPFC_LINK_UNKNOWN;
2644 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
2645 spin_unlock_irq(&phba->hbalock);
2647 pring = &psli->ring[psli->fcp_ring];
2648 lpfc_sli_abort_iocb_ring(phba, pring);
2650 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
2651 "0345 Resetting board due to mailbox timeout\n");
2653 * lpfc_offline calls lpfc_sli_hba_down which will clean up
2654 * on oustanding mailbox commands.
2656 /* If resets are disabled then set error state and return. */
2657 if (!phba->cfg_enable_hba_reset) {
2658 phba->link_state = LPFC_HBA_ERROR;
2661 lpfc_offline_prep(phba);
2663 lpfc_sli_brdrestart(phba);
2665 lpfc_unblock_mgmt_io(phba);
2670 lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
2673 struct lpfc_sli *psli = &phba->sli;
2674 uint32_t status, evtctr;
2677 unsigned long timeout;
2678 unsigned long drvr_flag = 0;
2679 volatile uint32_t word0, ldata;
2680 void __iomem *to_slim;
2681 int processing_queue = 0;
2683 spin_lock_irqsave(&phba->hbalock, drvr_flag);
2685 /* processing mbox queue from intr_handler */
2686 processing_queue = 1;
2687 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2688 pmbox = lpfc_mbox_get(phba);
2690 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2695 if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
2696 pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
2698 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2699 lpfc_printf_log(phba, KERN_ERR,
2700 LOG_MBOX | LOG_VPORT,
2701 "1806 Mbox x%x failed. No vport\n",
2702 pmbox->mb.mbxCommand);
2704 goto out_not_finished;
2708 /* If the PCI channel is in offline state, do not post mbox. */
2709 if (unlikely(pci_channel_offline(phba->pcidev))) {
2710 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2711 goto out_not_finished;
2717 status = MBX_SUCCESS;
2719 if (phba->link_state == LPFC_HBA_ERROR) {
2720 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2722 /* Mbox command <mbxCommand> cannot issue */
2723 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
2724 goto out_not_finished;
2727 if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
2728 !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
2729 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2730 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
2731 goto out_not_finished;
2734 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
2735 /* Polling for a mbox command when another one is already active
2736 * is not allowed in SLI. Also, the driver must have established
2737 * SLI2 mode to queue and process multiple mbox commands.
2740 if (flag & MBX_POLL) {
2741 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2743 /* Mbox command <mbxCommand> cannot issue */
2744 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
2745 goto out_not_finished;
2748 if (!(psli->sli_flag & LPFC_SLI2_ACTIVE)) {
2749 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2750 /* Mbox command <mbxCommand> cannot issue */
2751 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
2752 goto out_not_finished;
2755 /* Another mailbox command is still being processed, queue this
2756 * command to be processed later.
2758 lpfc_mbox_put(phba, pmbox);
2760 /* Mbox cmd issue - BUSY */
2761 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
2762 "(%d):0308 Mbox cmd issue - BUSY Data: "
2763 "x%x x%x x%x x%x\n",
2764 pmbox->vport ? pmbox->vport->vpi : 0xffffff,
2765 mb->mbxCommand, phba->pport->port_state,
2766 psli->sli_flag, flag);
2768 psli->slistat.mbox_busy++;
2769 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2772 lpfc_debugfs_disc_trc(pmbox->vport,
2773 LPFC_DISC_TRC_MBOX_VPORT,
2774 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
2775 (uint32_t)mb->mbxCommand,
2776 mb->un.varWords[0], mb->un.varWords[1]);
2779 lpfc_debugfs_disc_trc(phba->pport,
2781 "MBOX Bsy: cmd:x%x mb:x%x x%x",
2782 (uint32_t)mb->mbxCommand,
2783 mb->un.varWords[0], mb->un.varWords[1]);
2789 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
2791 /* If we are not polling, we MUST be in SLI2 mode */
2792 if (flag != MBX_POLL) {
2793 if (!(psli->sli_flag & LPFC_SLI2_ACTIVE) &&
2794 (mb->mbxCommand != MBX_KILL_BOARD)) {
2795 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2796 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2797 /* Mbox command <mbxCommand> cannot issue */
2798 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
2799 goto out_not_finished;
2801 /* timeout active mbox command */
2802 mod_timer(&psli->mbox_tmo, (jiffies +
2803 (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
2806 /* Mailbox cmd <cmd> issue */
2807 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
2808 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
2810 pmbox->vport ? pmbox->vport->vpi : 0,
2811 mb->mbxCommand, phba->pport->port_state,
2812 psli->sli_flag, flag);
2814 if (mb->mbxCommand != MBX_HEARTBEAT) {
2816 lpfc_debugfs_disc_trc(pmbox->vport,
2817 LPFC_DISC_TRC_MBOX_VPORT,
2818 "MBOX Send vport: cmd:x%x mb:x%x x%x",
2819 (uint32_t)mb->mbxCommand,
2820 mb->un.varWords[0], mb->un.varWords[1]);
2823 lpfc_debugfs_disc_trc(phba->pport,
2825 "MBOX Send: cmd:x%x mb:x%x x%x",
2826 (uint32_t)mb->mbxCommand,
2827 mb->un.varWords[0], mb->un.varWords[1]);
2831 psli->slistat.mbox_cmd++;
2832 evtctr = psli->slistat.mbox_event;
2834 /* next set own bit for the adapter and copy over command word */
2835 mb->mbxOwner = OWN_CHIP;
2837 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2838 /* First copy command data to host SLIM area */
2839 lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx, MAILBOX_CMD_SIZE);
2841 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2842 /* copy command data into host mbox for cmpl */
2843 lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx,
2847 /* First copy mbox command data to HBA SLIM, skip past first
2849 to_slim = phba->MBslimaddr + sizeof (uint32_t);
2850 lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
2851 MAILBOX_CMD_SIZE - sizeof (uint32_t));
2853 /* Next copy over first word, with mbxOwner set */
2854 ldata = *((volatile uint32_t *)mb);
2855 to_slim = phba->MBslimaddr;
2856 writel(ldata, to_slim);
2857 readl(to_slim); /* flush */
2859 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2860 /* switch over to host mailbox */
2861 psli->sli_flag |= LPFC_SLI2_ACTIVE;
2869 /* Set up reference to mailbox command */
2870 psli->mbox_active = pmbox;
2871 /* Interrupt board to do it */
2872 writel(CA_MBATT, phba->CAregaddr);
2873 readl(phba->CAregaddr); /* flush */
2874 /* Don't wait for it to finish, just return */
2878 /* Set up null reference to mailbox command */
2879 psli->mbox_active = NULL;
2880 /* Interrupt board to do it */
2881 writel(CA_MBATT, phba->CAregaddr);
2882 readl(phba->CAregaddr); /* flush */
2884 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2885 /* First read mbox status word */
2886 word0 = *((volatile uint32_t *)&phba->slim2p->mbx);
2887 word0 = le32_to_cpu(word0);
2889 /* First read mbox status word */
2890 word0 = readl(phba->MBslimaddr);
2893 /* Read the HBA Host Attention Register */
2894 ha_copy = readl(phba->HAregaddr);
2895 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
2899 /* Wait for command to complete */
2900 while (((word0 & OWN_CHIP) == OWN_CHIP) ||
2901 (!(ha_copy & HA_MBATT) &&
2902 (phba->link_state > LPFC_WARM_START))) {
2903 if (time_after(jiffies, timeout)) {
2904 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2905 spin_unlock_irqrestore(&phba->hbalock,
2907 goto out_not_finished;
2910 /* Check if we took a mbox interrupt while we were
2912 if (((word0 & OWN_CHIP) != OWN_CHIP)
2913 && (evtctr != psli->slistat.mbox_event))
2917 spin_unlock_irqrestore(&phba->hbalock,
2920 spin_lock_irqsave(&phba->hbalock, drvr_flag);
2923 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2924 /* First copy command data */
2925 word0 = *((volatile uint32_t *)
2926 &phba->slim2p->mbx);
2927 word0 = le32_to_cpu(word0);
2928 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2930 volatile uint32_t slimword0;
2931 /* Check real SLIM for any errors */
2932 slimword0 = readl(phba->MBslimaddr);
2933 slimmb = (MAILBOX_t *) & slimword0;
2934 if (((slimword0 & OWN_CHIP) != OWN_CHIP)
2935 && slimmb->mbxStatus) {
2942 /* First copy command data */
2943 word0 = readl(phba->MBslimaddr);
2945 /* Read the HBA Host Attention Register */
2946 ha_copy = readl(phba->HAregaddr);
2949 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2950 /* copy results back to user */
2951 lpfc_sli_pcimem_bcopy(&phba->slim2p->mbx, mb,
2954 /* First copy command data */
2955 lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
2957 if ((mb->mbxCommand == MBX_DUMP_MEMORY) &&
2959 lpfc_memcpy_from_slim((void *)pmbox->context2,
2960 phba->MBslimaddr + DMP_RSP_OFFSET,
2961 mb->un.varDmp.word_cnt);
2965 writel(HA_MBATT, phba->HAregaddr);
2966 readl(phba->HAregaddr); /* flush */
2968 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2969 status = mb->mbxStatus;
2972 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2976 if (processing_queue) {
2977 pmbox->mb.mbxStatus = MBX_NOT_FINISHED;
2978 lpfc_mbox_cmpl_put(phba, pmbox);
2980 return MBX_NOT_FINISHED;
2984 * Caller needs to hold lock.
2987 __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2988 struct lpfc_iocbq *piocb)
2990 /* Insert the caller's iocb in the txq tail for later processing. */
2991 list_add_tail(&piocb->list, &pring->txq);
2995 static struct lpfc_iocbq *
2996 lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2997 struct lpfc_iocbq **piocb)
2999 struct lpfc_iocbq * nextiocb;
3001 nextiocb = lpfc_sli_ringtx_get(phba, pring);
3011 * Lockless version of lpfc_sli_issue_iocb.
3014 __lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3015 struct lpfc_iocbq *piocb, uint32_t flag)
3017 struct lpfc_iocbq *nextiocb;
3020 if (piocb->iocb_cmpl && (!piocb->vport) &&
3021 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
3022 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
3023 lpfc_printf_log(phba, KERN_ERR,
3024 LOG_SLI | LOG_VPORT,
3025 "1807 IOCB x%x failed. No vport\n",
3026 piocb->iocb.ulpCommand);
3032 /* If the PCI channel is in offline state, do not post iocbs. */
3033 if (unlikely(pci_channel_offline(phba->pcidev)))
3037 * We should never get an IOCB if we are in a < LINK_DOWN state
3039 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
3043 * Check to see if we are blocking IOCB processing because of a
3044 * outstanding event.
3046 if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
3049 if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
3051 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
3052 * can be issued if the link is not up.
3054 switch (piocb->iocb.ulpCommand) {
3055 case CMD_QUE_RING_BUF_CN:
3056 case CMD_QUE_RING_BUF64_CN:
3058 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
3059 * completion, iocb_cmpl MUST be 0.
3061 if (piocb->iocb_cmpl)
3062 piocb->iocb_cmpl = NULL;
3064 case CMD_CREATE_XRI_CR:
3065 case CMD_CLOSE_XRI_CN:
3066 case CMD_CLOSE_XRI_CX:
3073 * For FCP commands, we must be in a state where we can process link
3076 } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
3077 !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
3081 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
3082 (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
3083 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
3086 lpfc_sli_update_ring(phba, pring);
3088 lpfc_sli_update_full_ring(phba, pring);
3091 return IOCB_SUCCESS;
3096 pring->stats.iocb_cmd_delay++;
3100 if (!(flag & SLI_IOCB_RET_IOCB)) {
3101 __lpfc_sli_ringtx_put(phba, pring, piocb);
3102 return IOCB_SUCCESS;
3110 lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3111 struct lpfc_iocbq *piocb, uint32_t flag)
3113 unsigned long iflags;
3116 spin_lock_irqsave(&phba->hbalock, iflags);
3117 rc = __lpfc_sli_issue_iocb(phba, pring, piocb, flag);
3118 spin_unlock_irqrestore(&phba->hbalock, iflags);
3124 lpfc_extra_ring_setup( struct lpfc_hba *phba)
3126 struct lpfc_sli *psli;
3127 struct lpfc_sli_ring *pring;
3131 /* Adjust cmd/rsp ring iocb entries more evenly */
3133 /* Take some away from the FCP ring */
3134 pring = &psli->ring[psli->fcp_ring];
3135 pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
3136 pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
3137 pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
3138 pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
3140 /* and give them to the extra ring */
3141 pring = &psli->ring[psli->extra_ring];
3143 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
3144 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
3145 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
3146 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
3148 /* Setup default profile for this ring */
3149 pring->iotag_max = 4096;
3150 pring->num_mask = 1;
3151 pring->prt[0].profile = 0; /* Mask 0 */
3152 pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
3153 pring->prt[0].type = phba->cfg_multi_ring_type;
3154 pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
3159 lpfc_sli_async_event_handler(struct lpfc_hba * phba,
3160 struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
3165 struct temp_event temp_event_data;
3166 struct Scsi_Host *shost;
3168 icmd = &iocbq->iocb;
3169 evt_code = icmd->un.asyncstat.evt_code;
3170 temp = icmd->ulpContext;
3172 if ((evt_code != ASYNC_TEMP_WARN) &&
3173 (evt_code != ASYNC_TEMP_SAFE)) {
3174 lpfc_printf_log(phba,
3177 "0346 Ring %d handler: unexpected ASYNC_STATUS"
3180 icmd->un.asyncstat.evt_code);
3183 temp_event_data.data = (uint32_t)temp;
3184 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
3185 if (evt_code == ASYNC_TEMP_WARN) {
3186 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
3187 lpfc_printf_log(phba,
3190 "0347 Adapter is very hot, please take "
3191 "corrective action. temperature : %d Celsius\n",
3194 if (evt_code == ASYNC_TEMP_SAFE) {
3195 temp_event_data.event_code = LPFC_NORMAL_TEMP;
3196 lpfc_printf_log(phba,
3199 "0340 Adapter temperature is OK now. "
3200 "temperature : %d Celsius\n",
3204 /* Send temperature change event to applications */
3205 shost = lpfc_shost_from_vport(phba->pport);
3206 fc_host_post_vendor_event(shost, fc_get_event_number(),
3207 sizeof(temp_event_data), (char *) &temp_event_data,
3208 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
3214 lpfc_sli_setup(struct lpfc_hba *phba)
3216 int i, totiocbsize = 0;
3217 struct lpfc_sli *psli = &phba->sli;
3218 struct lpfc_sli_ring *pring;
3220 psli->num_rings = MAX_CONFIGURED_RINGS;
3222 psli->fcp_ring = LPFC_FCP_RING;
3223 psli->next_ring = LPFC_FCP_NEXT_RING;
3224 psli->extra_ring = LPFC_EXTRA_RING;
3226 psli->iocbq_lookup = NULL;
3227 psli->iocbq_lookup_len = 0;
3228 psli->last_iotag = 0;
3230 for (i = 0; i < psli->num_rings; i++) {
3231 pring = &psli->ring[i];
3233 case LPFC_FCP_RING: /* ring 0 - FCP */
3234 /* numCiocb and numRiocb are used in config_port */
3235 pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
3236 pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
3237 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
3238 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
3239 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
3240 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
3241 pring->sizeCiocb = (phba->sli_rev == 3) ?
3242 SLI3_IOCB_CMD_SIZE :
3244 pring->sizeRiocb = (phba->sli_rev == 3) ?
3245 SLI3_IOCB_RSP_SIZE :
3247 pring->iotag_ctr = 0;
3249 (phba->cfg_hba_queue_depth * 2);
3250 pring->fast_iotag = pring->iotag_max;
3251 pring->num_mask = 0;
3253 case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
3254 /* numCiocb and numRiocb are used in config_port */
3255 pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
3256 pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
3257 pring->sizeCiocb = (phba->sli_rev == 3) ?
3258 SLI3_IOCB_CMD_SIZE :
3260 pring->sizeRiocb = (phba->sli_rev == 3) ?
3261 SLI3_IOCB_RSP_SIZE :
3263 pring->iotag_max = phba->cfg_hba_queue_depth;
3264 pring->num_mask = 0;
3266 case LPFC_ELS_RING: /* ring 2 - ELS / CT */
3267 /* numCiocb and numRiocb are used in config_port */
3268 pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
3269 pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
3270 pring->sizeCiocb = (phba->sli_rev == 3) ?
3271 SLI3_IOCB_CMD_SIZE :
3273 pring->sizeRiocb = (phba->sli_rev == 3) ?
3274 SLI3_IOCB_RSP_SIZE :
3276 pring->fast_iotag = 0;
3277 pring->iotag_ctr = 0;
3278 pring->iotag_max = 4096;
3279 pring->lpfc_sli_rcv_async_status =
3280 lpfc_sli_async_event_handler;
3281 pring->num_mask = 4;
3282 pring->prt[0].profile = 0; /* Mask 0 */
3283 pring->prt[0].rctl = FC_ELS_REQ;
3284 pring->prt[0].type = FC_ELS_DATA;
3285 pring->prt[0].lpfc_sli_rcv_unsol_event =
3286 lpfc_els_unsol_event;
3287 pring->prt[1].profile = 0; /* Mask 1 */
3288 pring->prt[1].rctl = FC_ELS_RSP;
3289 pring->prt[1].type = FC_ELS_DATA;
3290 pring->prt[1].lpfc_sli_rcv_unsol_event =
3291 lpfc_els_unsol_event;
3292 pring->prt[2].profile = 0; /* Mask 2 */
3293 /* NameServer Inquiry */
3294 pring->prt[2].rctl = FC_UNSOL_CTL;
3296 pring->prt[2].type = FC_COMMON_TRANSPORT_ULP;
3297 pring->prt[2].lpfc_sli_rcv_unsol_event =
3298 lpfc_ct_unsol_event;
3299 pring->prt[3].profile = 0; /* Mask 3 */
3300 /* NameServer response */
3301 pring->prt[3].rctl = FC_SOL_CTL;
3303 pring->prt[3].type = FC_COMMON_TRANSPORT_ULP;
3304 pring->prt[3].lpfc_sli_rcv_unsol_event =
3305 lpfc_ct_unsol_event;
3308 totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
3309 (pring->numRiocb * pring->sizeRiocb);
3311 if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
3312 /* Too many cmd / rsp ring entries in SLI2 SLIM */
3313 printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
3314 "SLI2 SLIM Data: x%x x%lx\n",
3315 phba->brd_no, totiocbsize,
3316 (unsigned long) MAX_SLIM_IOCB_SIZE);
3318 if (phba->cfg_multi_ring_support == 2)
3319 lpfc_extra_ring_setup(phba);
3325 lpfc_sli_queue_setup(struct lpfc_hba *phba)
3327 struct lpfc_sli *psli;
3328 struct lpfc_sli_ring *pring;
3332 spin_lock_irq(&phba->hbalock);
3333 INIT_LIST_HEAD(&psli->mboxq);
3334 INIT_LIST_HEAD(&psli->mboxq_cmpl);
3335 /* Initialize list headers for txq and txcmplq as double linked lists */
3336 for (i = 0; i < psli->num_rings; i++) {
3337 pring = &psli->ring[i];
3339 pring->next_cmdidx = 0;
3340 pring->local_getidx = 0;
3342 INIT_LIST_HEAD(&pring->txq);
3343 INIT_LIST_HEAD(&pring->txcmplq);
3344 INIT_LIST_HEAD(&pring->iocb_continueq);
3345 INIT_LIST_HEAD(&pring->iocb_continue_saveq);
3346 INIT_LIST_HEAD(&pring->postbufq);
3348 spin_unlock_irq(&phba->hbalock);
3353 lpfc_sli_host_down(struct lpfc_vport *vport)
3355 LIST_HEAD(completions);
3356 struct lpfc_hba *phba = vport->phba;
3357 struct lpfc_sli *psli = &phba->sli;
3358 struct lpfc_sli_ring *pring;
3359 struct lpfc_iocbq *iocb, *next_iocb;
3361 unsigned long flags = 0;
3362 uint16_t prev_pring_flag;
3364 lpfc_cleanup_discovery_resources(vport);
3366 spin_lock_irqsave(&phba->hbalock, flags);
3367 for (i = 0; i < psli->num_rings; i++) {
3368 pring = &psli->ring[i];
3369 prev_pring_flag = pring->flag;
3370 /* Only slow rings */
3371 if (pring->ringno == LPFC_ELS_RING) {
3372 pring->flag |= LPFC_DEFERRED_RING_EVENT;
3373 /* Set the lpfc data pending flag */
3374 set_bit(LPFC_DATA_READY, &phba->data_flags);
3377 * Error everything on the txq since these iocbs have not been
3378 * given to the FW yet.
3380 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
3381 if (iocb->vport != vport)
3383 list_move_tail(&iocb->list, &completions);
3387 /* Next issue ABTS for everything on the txcmplq */
3388 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
3390 if (iocb->vport != vport)
3392 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
3395 pring->flag = prev_pring_flag;
3398 spin_unlock_irqrestore(&phba->hbalock, flags);
3400 while (!list_empty(&completions)) {
3401 list_remove_head(&completions, iocb, struct lpfc_iocbq, list);
3403 if (!iocb->iocb_cmpl)
3404 lpfc_sli_release_iocbq(phba, iocb);
3406 iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
3407 iocb->iocb.un.ulpWord[4] = IOERR_SLI_DOWN;
3408 (iocb->iocb_cmpl) (phba, iocb, iocb);
3415 lpfc_sli_hba_down(struct lpfc_hba *phba)
3417 LIST_HEAD(completions);
3418 struct lpfc_sli *psli = &phba->sli;
3419 struct lpfc_sli_ring *pring;
3420 struct lpfc_dmabuf *buf_ptr;
3422 struct lpfc_iocbq *iocb;
3425 unsigned long flags = 0;
3427 lpfc_hba_down_prep(phba);
3429 lpfc_fabric_abort_hba(phba);
3431 spin_lock_irqsave(&phba->hbalock, flags);
3432 for (i = 0; i < psli->num_rings; i++) {
3433 pring = &psli->ring[i];
3434 /* Only slow rings */
3435 if (pring->ringno == LPFC_ELS_RING) {
3436 pring->flag |= LPFC_DEFERRED_RING_EVENT;
3437 /* Set the lpfc data pending flag */
3438 set_bit(LPFC_DATA_READY, &phba->data_flags);
3442 * Error everything on the txq since these iocbs have not been
3443 * given to the FW yet.
3445 list_splice_init(&pring->txq, &completions);
3449 spin_unlock_irqrestore(&phba->hbalock, flags);
3451 while (!list_empty(&completions)) {
3452 list_remove_head(&completions, iocb, struct lpfc_iocbq, list);
3455 if (!iocb->iocb_cmpl)
3456 lpfc_sli_release_iocbq(phba, iocb);
3458 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3459 cmd->un.ulpWord[4] = IOERR_SLI_DOWN;
3460 (iocb->iocb_cmpl) (phba, iocb, iocb);
3464 spin_lock_irqsave(&phba->hbalock, flags);
3465 list_splice_init(&phba->elsbuf, &completions);
3466 phba->elsbuf_cnt = 0;
3467 phba->elsbuf_prev_cnt = 0;
3468 spin_unlock_irqrestore(&phba->hbalock, flags);
3470 while (!list_empty(&completions)) {
3471 list_remove_head(&completions, buf_ptr,
3472 struct lpfc_dmabuf, list);
3473 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3477 /* Return any active mbox cmds */
3478 del_timer_sync(&psli->mbox_tmo);
3479 spin_lock_irqsave(&phba->hbalock, flags);
3481 spin_lock(&phba->pport->work_port_lock);
3482 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
3483 spin_unlock(&phba->pport->work_port_lock);
3485 /* Return any pending or completed mbox cmds */
3486 list_splice_init(&phba->sli.mboxq, &completions);
3487 if (psli->mbox_active) {
3488 list_add_tail(&psli->mbox_active->list, &completions);
3489 psli->mbox_active = NULL;
3490 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
3492 list_splice_init(&phba->sli.mboxq_cmpl, &completions);
3493 spin_unlock_irqrestore(&phba->hbalock, flags);
3495 while (!list_empty(&completions)) {
3496 list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
3497 pmb->mb.mbxStatus = MBX_NOT_FINISHED;
3499 pmb->mbox_cmpl(phba,pmb);
3505 lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
3507 uint32_t *src = srcp;
3508 uint32_t *dest = destp;
3512 for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
3514 ldata = le32_to_cpu(ldata);
3522 lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3523 struct lpfc_dmabuf *mp)
3525 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
3527 spin_lock_irq(&phba->hbalock);
3528 list_add_tail(&mp->list, &pring->postbufq);
3529 pring->postbufq_cnt++;
3530 spin_unlock_irq(&phba->hbalock);
3535 lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
3537 spin_lock_irq(&phba->hbalock);
3538 phba->buffer_tag_count++;
3540 * Always set the QUE_BUFTAG_BIT to distiguish between
3541 * a tag assigned by HBQ.
3543 phba->buffer_tag_count |= QUE_BUFTAG_BIT;
3544 spin_unlock_irq(&phba->hbalock);
3545 return phba->buffer_tag_count;
3548 struct lpfc_dmabuf *
3549 lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3552 struct lpfc_dmabuf *mp, *next_mp;
3553 struct list_head *slp = &pring->postbufq;
3555 /* Search postbufq, from the begining, looking for a match on tag */
3556 spin_lock_irq(&phba->hbalock);
3557 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
3558 if (mp->buffer_tag == tag) {
3559 list_del_init(&mp->list);
3560 pring->postbufq_cnt--;
3561 spin_unlock_irq(&phba->hbalock);
3566 spin_unlock_irq(&phba->hbalock);
3567 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3568 "0410 Cannot find virtual addr for buffer tag on "
3569 "ring %d Data x%lx x%p x%p x%x\n",
3570 pring->ringno, (unsigned long) tag,
3571 slp->next, slp->prev, pring->postbufq_cnt);
3576 struct lpfc_dmabuf *
3577 lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3580 struct lpfc_dmabuf *mp, *next_mp;
3581 struct list_head *slp = &pring->postbufq;
3583 /* Search postbufq, from the begining, looking for a match on phys */
3584 spin_lock_irq(&phba->hbalock);
3585 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
3586 if (mp->phys == phys) {
3587 list_del_init(&mp->list);
3588 pring->postbufq_cnt--;
3589 spin_unlock_irq(&phba->hbalock);
3594 spin_unlock_irq(&phba->hbalock);
3595 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3596 "0410 Cannot find virtual addr for mapped buf on "
3597 "ring %d Data x%llx x%p x%p x%x\n",
3598 pring->ringno, (unsigned long long)phys,
3599 slp->next, slp->prev, pring->postbufq_cnt);
3604 lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3605 struct lpfc_iocbq *rspiocb)
3607 IOCB_t *irsp = &rspiocb->iocb;
3608 uint16_t abort_iotag, abort_context;
3609 struct lpfc_iocbq *abort_iocb;
3610 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
3614 if (irsp->ulpStatus) {
3615 abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
3616 abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
3618 spin_lock_irq(&phba->hbalock);
3619 if (abort_iotag != 0 && abort_iotag <= phba->sli.last_iotag)
3620 abort_iocb = phba->sli.iocbq_lookup[abort_iotag];
3622 lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI,
3623 "0327 Cannot abort els iocb %p "
3624 "with tag %x context %x, abort status %x, "
3626 abort_iocb, abort_iotag, abort_context,
3627 irsp->ulpStatus, irsp->un.ulpWord[4]);
3630 * If the iocb is not found in Firmware queue the iocb
3631 * might have completed already. Do not free it again.
3633 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
3634 spin_unlock_irq(&phba->hbalock);
3635 lpfc_sli_release_iocbq(phba, cmdiocb);
3639 * make sure we have the right iocbq before taking it
3640 * off the txcmplq and try to call completion routine.
3643 abort_iocb->iocb.ulpContext != abort_context ||
3644 (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
3645 spin_unlock_irq(&phba->hbalock);
3647 list_del_init(&abort_iocb->list);
3648 pring->txcmplq_cnt--;
3649 spin_unlock_irq(&phba->hbalock);
3651 /* Firmware could still be in progress of DMAing
3652 * payload, so don't free data buffer till after
3655 abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
3657 abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
3658 abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
3659 abort_iocb->iocb.un.ulpWord[4] = IOERR_SLI_ABORTED;
3660 (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
3664 lpfc_sli_release_iocbq(phba, cmdiocb);
3669 lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3670 struct lpfc_iocbq *rspiocb)
3672 IOCB_t *irsp = &rspiocb->iocb;
3674 /* ELS cmd tag <ulpIoTag> completes */
3675 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
3676 "0133 Ignoring ELS cmd tag x%x completion Data: "
3678 irsp->ulpIoTag, irsp->ulpStatus,
3679 irsp->un.ulpWord[4], irsp->ulpTimeout);
3680 if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
3681 lpfc_ct_free_iocb(phba, cmdiocb);
3683 lpfc_els_free_iocb(phba, cmdiocb);
3688 lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3689 struct lpfc_iocbq *cmdiocb)
3691 struct lpfc_vport *vport = cmdiocb->vport;
3692 struct lpfc_iocbq *abtsiocbp;
3693 IOCB_t *icmd = NULL;
3694 IOCB_t *iabt = NULL;
3695 int retval = IOCB_ERROR;
3698 * There are certain command types we don't want to abort. And we
3699 * don't want to abort commands that are already in the process of
3702 icmd = &cmdiocb->iocb;
3703 if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
3704 icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
3705 (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
3708 /* If we're unloading, don't abort iocb on the ELS ring, but change the
3709 * callback so that nothing happens when it finishes.
3711 if ((vport->load_flag & FC_UNLOADING) &&
3712 (pring->ringno == LPFC_ELS_RING)) {
3713 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
3714 cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
3716 cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
3717 goto abort_iotag_exit;
3720 /* issue ABTS for this IOCB based on iotag */
3721 abtsiocbp = __lpfc_sli_get_iocbq(phba);
3722 if (abtsiocbp == NULL)
3725 /* This signals the response to set the correct status
3726 * before calling the completion handler.
3728 cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
3730 iabt = &abtsiocbp->iocb;
3731 iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
3732 iabt->un.acxri.abortContextTag = icmd->ulpContext;
3733 iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
3735 iabt->ulpClass = icmd->ulpClass;
3737 if (phba->link_state >= LPFC_LINK_UP)
3738 iabt->ulpCommand = CMD_ABORT_XRI_CN;
3740 iabt->ulpCommand = CMD_CLOSE_XRI_CN;
3742 abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
3744 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
3745 "0339 Abort xri x%x, original iotag x%x, "
3746 "abort cmd iotag x%x\n",
3747 iabt->un.acxri.abortContextTag,
3748 iabt->un.acxri.abortIoTag, abtsiocbp->iotag);
3749 retval = __lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0);
3753 * Caller to this routine should check for IOCB_ERROR
3754 * and handle it properly. This routine no longer removes
3755 * iocb off txcmplq and call compl in case of IOCB_ERROR.
3761 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
3762 uint16_t tgt_id, uint64_t lun_id,
3763 lpfc_ctx_cmd ctx_cmd)
3765 struct lpfc_scsi_buf *lpfc_cmd;
3768 if (!(iocbq->iocb_flag & LPFC_IO_FCP))
3771 if (iocbq->vport != vport)
3774 lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
3776 if (lpfc_cmd->pCmd == NULL)
3781 if ((lpfc_cmd->rdata->pnode) &&
3782 (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
3783 (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
3787 if ((lpfc_cmd->rdata->pnode) &&
3788 (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
3795 printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
3796 __FUNCTION__, ctx_cmd);
3804 lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
3805 lpfc_ctx_cmd ctx_cmd)
3807 struct lpfc_hba *phba = vport->phba;
3808 struct lpfc_iocbq *iocbq;
3811 for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
3812 iocbq = phba->sli.iocbq_lookup[i];
3814 if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
3823 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3824 struct lpfc_iocbq *rspiocb)
3826 lpfc_sli_release_iocbq(phba, cmdiocb);
3831 lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
3832 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
3834 struct lpfc_hba *phba = vport->phba;
3835 struct lpfc_iocbq *iocbq;
3836 struct lpfc_iocbq *abtsiocb;
3838 int errcnt = 0, ret_val = 0;
3841 for (i = 1; i <= phba->sli.last_iotag; i++) {
3842 iocbq = phba->sli.iocbq_lookup[i];
3844 if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
3848 /* issue ABTS for this IOCB based on iotag */
3849 abtsiocb = lpfc_sli_get_iocbq(phba);
3850 if (abtsiocb == NULL) {
3856 abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
3857 abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
3858 abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
3859 abtsiocb->iocb.ulpLe = 1;
3860 abtsiocb->iocb.ulpClass = cmd->ulpClass;
3861 abtsiocb->vport = phba->pport;
3863 if (lpfc_is_link_up(phba))
3864 abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
3866 abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
3868 /* Setup callback routine and issue the command. */
3869 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
3870 ret_val = lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0);
3871 if (ret_val == IOCB_ERROR) {
3872 lpfc_sli_release_iocbq(phba, abtsiocb);
3882 lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
3883 struct lpfc_iocbq *cmdiocbq,
3884 struct lpfc_iocbq *rspiocbq)
3886 wait_queue_head_t *pdone_q;
3887 unsigned long iflags;
3889 spin_lock_irqsave(&phba->hbalock, iflags);
3890 cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
3891 if (cmdiocbq->context2 && rspiocbq)
3892 memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
3893 &rspiocbq->iocb, sizeof(IOCB_t));
3895 pdone_q = cmdiocbq->context_un.wait_queue;
3898 spin_unlock_irqrestore(&phba->hbalock, iflags);
3903 * Issue the caller's iocb and wait for its completion, but no longer than the
3904 * caller's timeout. Note that iocb_flags is cleared before the
3905 * lpfc_sli_issue_call since the wake routine sets a unique value and by
3906 * definition this is a wait function.
3910 lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
3911 struct lpfc_sli_ring *pring,
3912 struct lpfc_iocbq *piocb,
3913 struct lpfc_iocbq *prspiocbq,
3916 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
3917 long timeleft, timeout_req = 0;
3918 int retval = IOCB_SUCCESS;
3922 * If the caller has provided a response iocbq buffer, then context2
3923 * is NULL or its an error.
3926 if (piocb->context2)
3928 piocb->context2 = prspiocbq;
3931 piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
3932 piocb->context_un.wait_queue = &done_q;
3933 piocb->iocb_flag &= ~LPFC_IO_WAKE;
3935 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
3936 creg_val = readl(phba->HCregaddr);
3937 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
3938 writel(creg_val, phba->HCregaddr);
3939 readl(phba->HCregaddr); /* flush */
3942 retval = lpfc_sli_issue_iocb(phba, pring, piocb, 0);
3943 if (retval == IOCB_SUCCESS) {
3944 timeout_req = timeout * HZ;
3945 timeleft = wait_event_timeout(done_q,
3946 piocb->iocb_flag & LPFC_IO_WAKE,
3949 if (piocb->iocb_flag & LPFC_IO_WAKE) {
3950 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3951 "0331 IOCB wake signaled\n");
3952 } else if (timeleft == 0) {
3953 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3954 "0338 IOCB wait timeout error - no "
3955 "wake response Data x%x\n", timeout);
3956 retval = IOCB_TIMEDOUT;
3958 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3959 "0330 IOCB wake NOT set, "
3961 timeout, (timeleft / jiffies));
3962 retval = IOCB_TIMEDOUT;
3965 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3966 ":0332 IOCB wait issue failed, Data x%x\n",
3968 retval = IOCB_ERROR;
3971 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
3972 creg_val = readl(phba->HCregaddr);
3973 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
3974 writel(creg_val, phba->HCregaddr);
3975 readl(phba->HCregaddr); /* flush */
3979 piocb->context2 = NULL;
3981 piocb->context_un.wait_queue = NULL;
3982 piocb->iocb_cmpl = NULL;
3987 lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
3990 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
3994 /* The caller must leave context1 empty. */
3995 if (pmboxq->context1)
3996 return MBX_NOT_FINISHED;
3998 pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
3999 /* setup wake call as IOCB callback */
4000 pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
4001 /* setup context field to pass wait_queue pointer to wake function */
4002 pmboxq->context1 = &done_q;
4004 /* now issue the command */
4005 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
4007 if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
4008 wait_event_interruptible_timeout(done_q,
4009 pmboxq->mbox_flag & LPFC_MBX_WAKE,
4012 spin_lock_irqsave(&phba->hbalock, flag);
4013 pmboxq->context1 = NULL;
4015 * if LPFC_MBX_WAKE flag is set the mailbox is completed
4016 * else do not free the resources.
4018 if (pmboxq->mbox_flag & LPFC_MBX_WAKE)
4019 retval = MBX_SUCCESS;
4021 retval = MBX_TIMEOUT;
4022 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4024 spin_unlock_irqrestore(&phba->hbalock, flag);
4031 lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba)
4033 struct lpfc_vport *vport = phba->pport;
4037 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE && !vport->stopped) {
4038 if (i++ > LPFC_MBOX_TMO * 1000)
4042 * Call lpfc_sli_handle_mb_event only if a mailbox cmd
4043 * did finish. This way we won't get the misleading
4044 * "Stray Mailbox Interrupt" message.
4046 spin_lock_irq(&phba->hbalock);
4047 ha_copy = phba->work_ha;
4048 phba->work_ha &= ~HA_MBATT;
4049 spin_unlock_irq(&phba->hbalock);
4051 if (ha_copy & HA_MBATT)
4052 if (lpfc_sli_handle_mb_event(phba) == 0)
4058 return (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) ? 1 : 0;
4062 lpfc_intr_handler(int irq, void *dev_id)
4064 struct lpfc_hba *phba;
4066 uint32_t work_ha_copy;
4067 unsigned long status;
4070 MAILBOX_t *mbox, *pmbox;
4071 struct lpfc_vport *vport;
4072 struct lpfc_nodelist *ndlp;
4073 struct lpfc_dmabuf *mp;
4078 * Get the driver's phba structure from the dev_id and
4079 * assume the HBA is not interrupting.
4081 phba = (struct lpfc_hba *) dev_id;
4083 if (unlikely(!phba))
4086 /* If the pci channel is offline, ignore all the interrupts. */
4087 if (unlikely(pci_channel_offline(phba->pcidev)))
4090 phba->sli.slistat.sli_intr++;
4093 * Call the HBA to see if it is interrupting. If not, don't claim
4097 /* Ignore all interrupts during initialization. */
4098 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
4102 * Read host attention register to determine interrupt source
4103 * Clear Attention Sources, except Error Attention (to
4104 * preserve status) and Link Attention
4106 spin_lock(&phba->hbalock);
4107 ha_copy = readl(phba->HAregaddr);
4108 /* If somebody is waiting to handle an eratt don't process it
4109 * here. The brdkill function will do this.
4111 if (phba->link_flag & LS_IGNORE_ERATT)
4112 ha_copy &= ~HA_ERATT;
4113 writel((ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
4114 readl(phba->HAregaddr); /* flush */
4115 spin_unlock(&phba->hbalock);
4117 if (unlikely(!ha_copy))
4120 work_ha_copy = ha_copy & phba->work_ha_mask;
4122 if (unlikely(work_ha_copy)) {
4123 if (work_ha_copy & HA_LATT) {
4124 if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
4126 * Turn off Link Attention interrupts
4127 * until CLEAR_LA done
4129 spin_lock(&phba->hbalock);
4130 phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
4131 control = readl(phba->HCregaddr);
4132 control &= ~HC_LAINT_ENA;
4133 writel(control, phba->HCregaddr);
4134 readl(phba->HCregaddr); /* flush */
4135 spin_unlock(&phba->hbalock);
4138 work_ha_copy &= ~HA_LATT;
4141 if (work_ha_copy & ~(HA_ERATT|HA_MBATT|HA_LATT)) {
4143 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
4144 * the only slow ring.
4146 status = (work_ha_copy &
4147 (HA_RXMASK << (4*LPFC_ELS_RING)));
4148 status >>= (4*LPFC_ELS_RING);
4149 if (status & HA_RXMASK) {
4150 spin_lock(&phba->hbalock);
4151 control = readl(phba->HCregaddr);
4153 lpfc_debugfs_slow_ring_trc(phba,
4154 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
4156 (uint32_t)phba->sli.slistat.sli_intr);
4158 if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
4159 lpfc_debugfs_slow_ring_trc(phba,
4161 "pwork:x%x hawork:x%x wait:x%x",
4162 phba->work_ha, work_ha_copy,
4163 (uint32_t)((unsigned long)
4164 &phba->work_waitq));
4167 ~(HC_R0INT_ENA << LPFC_ELS_RING);
4168 writel(control, phba->HCregaddr);
4169 readl(phba->HCregaddr); /* flush */
4172 lpfc_debugfs_slow_ring_trc(phba,
4173 "ISR slow ring: pwork:"
4174 "x%x hawork:x%x wait:x%x",
4175 phba->work_ha, work_ha_copy,
4176 (uint32_t)((unsigned long)
4177 &phba->work_waitq));
4179 spin_unlock(&phba->hbalock);
4183 if (work_ha_copy & HA_ERATT) {
4185 * There was a link/board error. Read the
4186 * status register to retrieve the error event
4189 phba->sli.slistat.err_attn_event++;
4190 /* Save status info */
4191 phba->work_hs = readl(phba->HSregaddr);
4192 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
4193 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
4195 /* Clear Chip error bit */
4196 writel(HA_ERATT, phba->HAregaddr);
4197 readl(phba->HAregaddr); /* flush */
4198 phba->pport->stopped = 1;
4201 spin_lock(&phba->hbalock);
4202 if ((work_ha_copy & HA_MBATT) &&
4203 (phba->sli.mbox_active)) {
4204 pmb = phba->sli.mbox_active;
4206 mbox = &phba->slim2p->mbx;
4209 /* First check out the status word */
4210 lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
4211 if (pmbox->mbxOwner != OWN_HOST) {
4212 spin_unlock(&phba->hbalock);
4214 * Stray Mailbox Interrupt, mbxCommand <cmd>
4215 * mbxStatus <status>
4217 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
4219 "(%d):0304 Stray Mailbox "
4220 "Interrupt mbxCommand x%x "
4222 (vport ? vport->vpi : 0),
4225 /* clear mailbox attention bit */
4226 work_ha_copy &= ~HA_MBATT;
4228 phba->sli.mbox_active = NULL;
4229 spin_unlock(&phba->hbalock);
4230 phba->last_completion_time = jiffies;
4231 del_timer(&phba->sli.mbox_tmo);
4232 if (pmb->mbox_cmpl) {
4233 lpfc_sli_pcimem_bcopy(mbox, pmbox,
4236 if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
4237 pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
4239 lpfc_debugfs_disc_trc(vport,
4240 LPFC_DISC_TRC_MBOX_VPORT,
4242 "status:x%x rpi:x%x",
4243 (uint32_t)pmbox->mbxStatus,
4244 pmbox->un.varWords[0], 0);
4246 if (!pmbox->mbxStatus) {
4247 mp = (struct lpfc_dmabuf *)
4249 ndlp = (struct lpfc_nodelist *)
4252 /* Reg_LOGIN of dflt RPI was
4253 * successful. new lets get
4254 * rid of the RPI using the
4257 lpfc_unreg_login(phba,
4259 pmbox->un.varWords[0],
4262 lpfc_mbx_cmpl_dflt_rpi;
4264 pmb->context2 = ndlp;
4266 rc = lpfc_sli_issue_mbox(phba,
4270 lpfc_printf_log(phba,
4273 "0306 rc should have"
4275 goto send_current_mbox;
4278 spin_lock(&phba->pport->work_port_lock);
4279 phba->pport->work_port_events &=
4281 spin_unlock(&phba->pport->work_port_lock);
4282 lpfc_mbox_cmpl_put(phba, pmb);
4285 spin_unlock(&phba->hbalock);
4286 if ((work_ha_copy & HA_MBATT) &&
4287 (phba->sli.mbox_active == NULL)) {
4289 /* Process next mailbox command if there is one */
4291 rc = lpfc_sli_issue_mbox(phba, NULL,
4293 } while (rc == MBX_NOT_FINISHED);
4294 if (rc != MBX_SUCCESS)
4295 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
4296 LOG_SLI, "0349 rc should be "
4300 spin_lock(&phba->hbalock);
4301 phba->work_ha |= work_ha_copy;
4302 spin_unlock(&phba->hbalock);
4303 lpfc_worker_wake_up(phba);
4306 ha_copy &= ~(phba->work_ha_mask);
4309 * Process all events on FCP ring. Take the optimized path for
4310 * FCP IO. Any other IO is slow path and is handled by
4311 * the worker thread.
4313 status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
4314 status >>= (4*LPFC_FCP_RING);
4315 if (status & HA_RXMASK)
4316 lpfc_sli_handle_fast_ring_event(phba,
4317 &phba->sli.ring[LPFC_FCP_RING],
4320 if (phba->cfg_multi_ring_support == 2) {
4322 * Process all events on extra ring. Take the optimized path
4323 * for extra ring IO. Any other IO is slow path and is handled
4324 * by the worker thread.
4326 status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
4327 status >>= (4*LPFC_EXTRA_RING);
4328 if (status & HA_RXMASK) {
4329 lpfc_sli_handle_fast_ring_event(phba,
4330 &phba->sli.ring[LPFC_EXTRA_RING],
4336 } /* lpfc_intr_handler */