1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2007 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/interrupt.h>
25 #include <linux/delay.h>
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_cmnd.h>
29 #include <scsi/scsi_device.h>
30 #include <scsi/scsi_host.h>
31 #include <scsi/scsi_transport_fc.h>
35 #include "lpfc_disc.h"
36 #include "lpfc_scsi.h"
38 #include "lpfc_crtn.h"
39 #include "lpfc_logmsg.h"
40 #include "lpfc_compat.h"
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 (%d):0311 Mailbox command x%x cannot " \
53 "issue Data: x%x x%x x%x\n", \
55 pmbox->vport ? pmbox->vport->vpi : 0, \
56 pmbox->mb.mbxCommand, \
57 phba->pport->port_state, \
62 /* There are only four IOCB completion types. */
63 typedef enum _lpfc_iocb_type {
70 /* SLI-2/SLI-3 provide different sized iocbs. Given a pointer
71 * to the start of the ring, and the slot number of the
72 * desired iocb entry, calc a pointer to that entry.
74 static inline IOCB_t *
75 lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
77 return (IOCB_t *) (((char *) pring->cmdringaddr) +
78 pring->cmdidx * phba->iocb_cmd_size);
81 static inline IOCB_t *
82 lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
84 return (IOCB_t *) (((char *) pring->rspringaddr) +
85 pring->rspidx * phba->iocb_rsp_size);
88 static struct lpfc_iocbq *
89 __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
91 struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
92 struct lpfc_iocbq * iocbq = NULL;
94 list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
99 lpfc_sli_get_iocbq(struct lpfc_hba *phba)
101 struct lpfc_iocbq * iocbq = NULL;
102 unsigned long iflags;
104 spin_lock_irqsave(&phba->hbalock, iflags);
105 iocbq = __lpfc_sli_get_iocbq(phba);
106 spin_unlock_irqrestore(&phba->hbalock, iflags);
111 __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
113 size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
116 * Clean all volatile data fields, preserve iotag and node struct.
118 memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
119 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
123 lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
125 unsigned long iflags;
128 * Clean all volatile data fields, preserve iotag and node struct.
130 spin_lock_irqsave(&phba->hbalock, iflags);
131 __lpfc_sli_release_iocbq(phba, iocbq);
132 spin_unlock_irqrestore(&phba->hbalock, iflags);
136 * Translate the iocb command to an iocb command type used to decide the final
137 * disposition of each completed IOCB.
139 static lpfc_iocb_type
140 lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
142 lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
144 if (iocb_cmnd > CMD_MAX_IOCB_CMD)
148 case CMD_XMIT_SEQUENCE_CR:
149 case CMD_XMIT_SEQUENCE_CX:
150 case CMD_XMIT_BCAST_CN:
151 case CMD_XMIT_BCAST_CX:
152 case CMD_ELS_REQUEST_CR:
153 case CMD_ELS_REQUEST_CX:
154 case CMD_CREATE_XRI_CR:
155 case CMD_CREATE_XRI_CX:
157 case CMD_XMIT_ELS_RSP_CX:
159 case CMD_FCP_IWRITE_CR:
160 case CMD_FCP_IWRITE_CX:
161 case CMD_FCP_IREAD_CR:
162 case CMD_FCP_IREAD_CX:
163 case CMD_FCP_ICMND_CR:
164 case CMD_FCP_ICMND_CX:
165 case CMD_FCP_TSEND_CX:
166 case CMD_FCP_TRSP_CX:
167 case CMD_FCP_TRECEIVE_CX:
168 case CMD_FCP_AUTO_TRSP_CX:
169 case CMD_ADAPTER_MSG:
170 case CMD_ADAPTER_DUMP:
171 case CMD_XMIT_SEQUENCE64_CR:
172 case CMD_XMIT_SEQUENCE64_CX:
173 case CMD_XMIT_BCAST64_CN:
174 case CMD_XMIT_BCAST64_CX:
175 case CMD_ELS_REQUEST64_CR:
176 case CMD_ELS_REQUEST64_CX:
177 case CMD_FCP_IWRITE64_CR:
178 case CMD_FCP_IWRITE64_CX:
179 case CMD_FCP_IREAD64_CR:
180 case CMD_FCP_IREAD64_CX:
181 case CMD_FCP_ICMND64_CR:
182 case CMD_FCP_ICMND64_CX:
183 case CMD_FCP_TSEND64_CX:
184 case CMD_FCP_TRSP64_CX:
185 case CMD_FCP_TRECEIVE64_CX:
186 case CMD_GEN_REQUEST64_CR:
187 case CMD_GEN_REQUEST64_CX:
188 case CMD_XMIT_ELS_RSP64_CX:
189 type = LPFC_SOL_IOCB;
191 case CMD_ABORT_XRI_CN:
192 case CMD_ABORT_XRI_CX:
193 case CMD_CLOSE_XRI_CN:
194 case CMD_CLOSE_XRI_CX:
195 case CMD_XRI_ABORTED_CX:
196 case CMD_ABORT_MXRI64_CN:
197 type = LPFC_ABORT_IOCB;
199 case CMD_RCV_SEQUENCE_CX:
200 case CMD_RCV_ELS_REQ_CX:
201 case CMD_RCV_SEQUENCE64_CX:
202 case CMD_RCV_ELS_REQ64_CX:
203 case CMD_IOCB_RCV_SEQ64_CX:
204 case CMD_IOCB_RCV_ELS64_CX:
205 case CMD_IOCB_RCV_CONT64_CX:
206 type = LPFC_UNSOL_IOCB;
209 type = LPFC_UNKNOWN_IOCB;
217 lpfc_sli_ring_map(struct lpfc_hba *phba)
219 struct lpfc_sli *psli = &phba->sli;
224 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
228 phba->link_state = LPFC_INIT_MBX_CMDS;
229 for (i = 0; i < psli->num_rings; i++) {
230 lpfc_config_ring(phba, i, pmb);
231 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
232 if (rc != MBX_SUCCESS) {
233 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
234 "%d:0446 Adapter failed to init (%d), "
235 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
241 phba->link_state = LPFC_HBA_ERROR;
246 mempool_free(pmb, phba->mbox_mem_pool);
251 lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
252 struct lpfc_iocbq *piocb)
254 list_add_tail(&piocb->list, &pring->txcmplq);
255 pring->txcmplq_cnt++;
256 if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
257 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
258 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
262 mod_timer(&piocb->vport->els_tmofunc,
263 jiffies + HZ * (phba->fc_ratov << 1));
270 static struct lpfc_iocbq *
271 lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
273 struct lpfc_iocbq *cmd_iocb;
275 list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
276 if (cmd_iocb != NULL)
282 lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
284 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
285 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
286 &phba->slim2p->mbx.us.s2.port[pring->ringno];
287 uint32_t max_cmd_idx = pring->numCiocb;
289 if ((pring->next_cmdidx == pring->cmdidx) &&
290 (++pring->next_cmdidx >= max_cmd_idx))
291 pring->next_cmdidx = 0;
293 if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
295 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
297 if (unlikely(pring->local_getidx >= max_cmd_idx)) {
298 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
299 "%d:0315 Ring %d issue: portCmdGet %d "
300 "is bigger then cmd ring %d\n",
301 phba->brd_no, pring->ringno,
302 pring->local_getidx, max_cmd_idx);
304 phba->link_state = LPFC_HBA_ERROR;
306 * All error attention handlers are posted to
309 phba->work_ha |= HA_ERATT;
310 phba->work_hs = HS_FFER3;
312 /* hbalock should already be held */
314 lpfc_worker_wake_up(phba);
319 if (pring->local_getidx == pring->next_cmdidx)
323 return lpfc_cmd_iocb(phba, pring);
327 lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
329 struct lpfc_iocbq **new_arr;
330 struct lpfc_iocbq **old_arr;
332 struct lpfc_sli *psli = &phba->sli;
335 spin_lock_irq(&phba->hbalock);
336 iotag = psli->last_iotag;
337 if(++iotag < psli->iocbq_lookup_len) {
338 psli->last_iotag = iotag;
339 psli->iocbq_lookup[iotag] = iocbq;
340 spin_unlock_irq(&phba->hbalock);
341 iocbq->iotag = iotag;
343 } else if (psli->iocbq_lookup_len < (0xffff
344 - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
345 new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
346 spin_unlock_irq(&phba->hbalock);
347 new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
350 spin_lock_irq(&phba->hbalock);
351 old_arr = psli->iocbq_lookup;
352 if (new_len <= psli->iocbq_lookup_len) {
353 /* highly unprobable case */
355 iotag = psli->last_iotag;
356 if(++iotag < psli->iocbq_lookup_len) {
357 psli->last_iotag = iotag;
358 psli->iocbq_lookup[iotag] = iocbq;
359 spin_unlock_irq(&phba->hbalock);
360 iocbq->iotag = iotag;
363 spin_unlock_irq(&phba->hbalock);
366 if (psli->iocbq_lookup)
367 memcpy(new_arr, old_arr,
368 ((psli->last_iotag + 1) *
369 sizeof (struct lpfc_iocbq *)));
370 psli->iocbq_lookup = new_arr;
371 psli->iocbq_lookup_len = new_len;
372 psli->last_iotag = iotag;
373 psli->iocbq_lookup[iotag] = iocbq;
374 spin_unlock_irq(&phba->hbalock);
375 iocbq->iotag = iotag;
380 spin_unlock_irq(&phba->hbalock);
382 lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
383 "%d:0318 Failed to allocate IOTAG.last IOTAG is %d\n",
384 phba->brd_no, psli->last_iotag);
390 lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
391 IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
396 nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
399 * Issue iocb command to adapter
401 lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
403 pring->stats.iocb_cmd++;
406 * If there is no completion routine to call, we can release the
407 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
408 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
410 if (nextiocb->iocb_cmpl)
411 lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
413 __lpfc_sli_release_iocbq(phba, nextiocb);
416 * Let the HBA know what IOCB slot will be the next one the
417 * driver will put a command into.
419 pring->cmdidx = pring->next_cmdidx;
420 writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
424 lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
426 int ringno = pring->ringno;
428 pring->flag |= LPFC_CALL_RING_AVAILABLE;
433 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
434 * The HBA will tell us when an IOCB entry is available.
436 writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
437 readl(phba->CAregaddr); /* flush */
439 pring->stats.iocb_cmd_full++;
443 lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
445 int ringno = pring->ringno;
448 * Tell the HBA that there is work to do in this ring.
451 writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
452 readl(phba->CAregaddr); /* flush */
456 lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
459 struct lpfc_iocbq *nextiocb;
463 * (a) there is anything on the txq to send
465 * (c) link attention events can be processed (fcp ring only)
466 * (d) IOCB processing is not blocked by the outstanding mbox command.
468 if (pring->txq_cnt &&
469 lpfc_is_link_up(phba) &&
470 (pring->ringno != phba->sli.fcp_ring ||
471 phba->sli.sli_flag & LPFC_PROCESS_LA) &&
472 !(pring->flag & LPFC_STOP_IOCB_MBX)) {
474 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
475 (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
476 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
479 lpfc_sli_update_ring(phba, pring);
481 lpfc_sli_update_full_ring(phba, pring);
487 /* lpfc_sli_turn_on_ring is only called by lpfc_sli_handle_mb_event below */
489 lpfc_sli_turn_on_ring(struct lpfc_hba *phba, int ringno)
491 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
492 &phba->slim2p->mbx.us.s3_pgp.port[ringno] :
493 &phba->slim2p->mbx.us.s2.port[ringno];
494 unsigned long iflags;
496 /* If the ring is active, flag it */
497 spin_lock_irqsave(&phba->hbalock, iflags);
498 if (phba->sli.ring[ringno].cmdringaddr) {
499 if (phba->sli.ring[ringno].flag & LPFC_STOP_IOCB_MBX) {
500 phba->sli.ring[ringno].flag &= ~LPFC_STOP_IOCB_MBX;
502 * Force update of the local copy of cmdGetInx
504 phba->sli.ring[ringno].local_getidx
505 = le32_to_cpu(pgp->cmdGetInx);
506 lpfc_sli_resume_iocb(phba, &phba->sli.ring[ringno]);
509 spin_unlock_irqrestore(&phba->hbalock, iflags);
512 struct lpfc_hbq_entry *
513 lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
515 struct hbq_s *hbqp = &phba->hbqs[hbqno];
517 if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
518 ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
519 hbqp->next_hbqPutIdx = 0;
521 if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
522 uint32_t raw_index = phba->hbq_get[hbqno];
523 uint32_t getidx = le32_to_cpu(raw_index);
525 hbqp->local_hbqGetIdx = getidx;
527 if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
528 lpfc_printf_log(phba, KERN_ERR,
530 "%d:1802 HBQ %d: local_hbqGetIdx "
531 "%u is > than hbqp->entry_count %u\n",
533 hbqp->local_hbqGetIdx,
536 phba->link_state = LPFC_HBA_ERROR;
540 if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
544 return (struct lpfc_hbq_entry *) phba->hbqslimp.virt + hbqp->hbqPutIdx;
548 lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
550 struct lpfc_dmabuf *dmabuf, *next_dmabuf;
551 struct hbq_dmabuf *hbq_buf;
553 /* Return all memory used by all HBQs */
554 list_for_each_entry_safe(dmabuf, next_dmabuf,
555 &phba->hbq_buffer_list, list) {
556 hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
557 list_del(&hbq_buf->dbuf.list);
558 lpfc_hbq_free(phba, hbq_buf->dbuf.virt, hbq_buf->dbuf.phys);
564 lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
565 struct hbq_dmabuf *hbq_buf)
567 struct lpfc_hbq_entry *hbqe;
568 dma_addr_t physaddr = hbq_buf->dbuf.phys;
570 /* Get next HBQ entry slot to use */
571 hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
573 struct hbq_s *hbqp = &phba->hbqs[hbqno];
575 hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
576 hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
577 hbqe->bde.tus.f.bdeSize = FCELSSIZE;
578 hbqe->bde.tus.f.bdeFlags = 0;
579 hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
580 hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
582 hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
583 writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
585 readl(phba->hbq_put + hbqno);
586 list_add_tail(&hbq_buf->dbuf.list, &phba->hbq_buffer_list);
590 static struct lpfc_hbq_init lpfc_els_hbq = {
595 .ring_mask = 1 << LPFC_ELS_RING,
601 static struct lpfc_hbq_init *lpfc_hbq_defs[] = {
606 lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
608 uint32_t i, start, end;
609 struct hbq_dmabuf *hbq_buffer;
611 start = lpfc_hbq_defs[hbqno]->buffer_count;
612 end = count + lpfc_hbq_defs[hbqno]->buffer_count;
613 if (end > lpfc_hbq_defs[hbqno]->entry_count) {
614 end = lpfc_hbq_defs[hbqno]->entry_count;
617 /* Populate HBQ entries */
618 for (i = start; i < end; i++) {
619 hbq_buffer = kmalloc(sizeof(struct hbq_dmabuf),
623 hbq_buffer->dbuf.virt = lpfc_hbq_alloc(phba, MEM_PRI,
624 &hbq_buffer->dbuf.phys);
625 if (hbq_buffer->dbuf.virt == NULL)
627 hbq_buffer->tag = (i | (hbqno << 16));
628 lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer);
629 lpfc_hbq_defs[hbqno]->buffer_count++;
635 lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
637 return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
638 lpfc_hbq_defs[qno]->add_count));
642 lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
644 return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
645 lpfc_hbq_defs[qno]->init_count));
649 lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
651 struct lpfc_dmabuf *d_buf;
652 struct hbq_dmabuf *hbq_buf;
654 list_for_each_entry(d_buf, &phba->hbq_buffer_list, list) {
655 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
656 if ((hbq_buf->tag & 0xffff) == tag) {
660 lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
661 "%d:1803 Bad hbq tag. Data: x%x x%x\n",
663 lpfc_hbq_defs[tag >> 16]->buffer_count);
668 lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *sp)
673 hbqno = sp->tag >> 16;
674 lpfc_sli_hbq_to_firmware(phba, hbqno, sp);
679 lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
683 switch (mbxCommand) {
687 case MBX_RUN_BIU_DIAG:
690 case MBX_CONFIG_LINK:
691 case MBX_CONFIG_RING:
693 case MBX_READ_CONFIG:
694 case MBX_READ_RCONFIG:
696 case MBX_READ_STATUS:
700 case MBX_READ_LNK_STAT:
702 case MBX_UNREG_LOGIN:
705 case MBX_DUMP_MEMORY:
706 case MBX_DUMP_CONTEXT:
711 case MBX_DEL_LD_ENTRY:
712 case MBX_RUN_PROGRAM:
717 case MBX_CONFIG_FARP:
720 case MBX_RUN_BIU_DIAG64:
721 case MBX_CONFIG_PORT:
722 case MBX_READ_SPARM64:
724 case MBX_REG_LOGIN64:
726 case MBX_FLASH_WR_ULA:
728 case MBX_LOAD_EXP_ROM:
741 lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
743 wait_queue_head_t *pdone_q;
744 unsigned long drvr_flag;
747 * If pdone_q is empty, the driver thread gave up waiting and
750 pmboxq->mbox_flag |= LPFC_MBX_WAKE;
751 spin_lock_irqsave(&phba->hbalock, drvr_flag);
752 pdone_q = (wait_queue_head_t *) pmboxq->context1;
754 wake_up_interruptible(pdone_q);
755 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
760 lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
762 struct lpfc_dmabuf *mp;
766 mp = (struct lpfc_dmabuf *) (pmb->context1);
769 lpfc_mbuf_free(phba, mp->virt, mp->phys);
774 * If a REG_LOGIN succeeded after node is destroyed or node
775 * is in re-discovery driver need to cleanup the RPI.
777 if (!(phba->pport->load_flag & FC_UNLOADING) &&
778 pmb->mb.mbxCommand == MBX_REG_LOGIN64 &&
779 !pmb->mb.mbxStatus) {
781 rpi = pmb->mb.un.varWords[0];
782 lpfc_unreg_login(phba, pmb->mb.un.varRegLogin.vpi, rpi, pmb);
783 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
784 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
785 if (rc != MBX_NOT_FINISHED)
789 mempool_free(pmb, phba->mbox_mem_pool);
794 lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
801 phba->sli.slistat.mbox_event++;
803 /* Get all completed mailboxe buffers into the cmplq */
804 spin_lock_irq(&phba->hbalock);
805 list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
806 spin_unlock_irq(&phba->hbalock);
808 /* Get a Mailbox buffer to setup mailbox commands for callback */
810 list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
816 if (pmbox->mbxCommand != MBX_HEARTBEAT) {
818 lpfc_debugfs_disc_trc(pmb->vport,
819 LPFC_DISC_TRC_MBOX_VPORT,
820 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
821 (uint32_t)pmbox->mbxCommand,
822 pmbox->un.varWords[0],
823 pmbox->un.varWords[1]);
826 lpfc_debugfs_disc_trc(phba->pport,
828 "MBOX cmpl: cmd:x%x mb:x%x x%x",
829 (uint32_t)pmbox->mbxCommand,
830 pmbox->un.varWords[0],
831 pmbox->un.varWords[1]);
836 * It is a fatal error if unknown mbox command completion.
838 if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
841 /* Unknow mailbox command compl */
842 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
843 "%d (%d):0323 Unknown Mailbox command "
846 pmb->vport ? pmb->vport->vpi : 0,
848 phba->link_state = LPFC_HBA_ERROR;
849 phba->work_hs = HS_FFER3;
850 lpfc_handle_eratt(phba);
854 if (pmbox->mbxStatus) {
855 phba->sli.slistat.mbox_stat_err++;
856 if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
857 /* Mbox cmd cmpl error - RETRYing */
858 lpfc_printf_log(phba, KERN_INFO,
860 "%d (%d):0305 Mbox cmd cmpl "
861 "error - RETRYing Data: x%x "
864 pmb->vport ? pmb->vport->vpi :0,
867 pmbox->un.varWords[0],
868 pmb->vport->port_state);
869 pmbox->mbxStatus = 0;
870 pmbox->mbxOwner = OWN_HOST;
871 spin_lock_irq(&phba->hbalock);
872 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
873 spin_unlock_irq(&phba->hbalock);
874 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
875 if (rc == MBX_SUCCESS)
880 /* Mailbox cmd <cmd> Cmpl <cmpl> */
881 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
882 "%d (%d):0307 Mailbox cmd x%x Cmpl x%p "
883 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
885 pmb->vport ? pmb->vport->vpi : 0,
888 *((uint32_t *) pmbox),
889 pmbox->un.varWords[0],
890 pmbox->un.varWords[1],
891 pmbox->un.varWords[2],
892 pmbox->un.varWords[3],
893 pmbox->un.varWords[4],
894 pmbox->un.varWords[5],
895 pmbox->un.varWords[6],
896 pmbox->un.varWords[7]);
899 pmb->mbox_cmpl(phba,pmb);
904 static struct lpfc_dmabuf *
905 lpfc_sli_replace_hbqbuff(struct lpfc_hba *phba, uint32_t tag)
907 struct hbq_dmabuf *hbq_entry, *new_hbq_entry;
909 hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
910 if (hbq_entry == NULL)
912 list_del(&hbq_entry->dbuf.list);
913 new_hbq_entry = kmalloc(sizeof(struct hbq_dmabuf), GFP_ATOMIC);
914 if (new_hbq_entry == NULL)
915 return &hbq_entry->dbuf;
916 new_hbq_entry->dbuf = hbq_entry->dbuf;
917 new_hbq_entry->tag = -1;
918 hbq_entry->dbuf.virt = lpfc_hbq_alloc(phba, 0, &hbq_entry->dbuf.phys);
919 if (hbq_entry->dbuf.virt == NULL) {
920 kfree(new_hbq_entry);
921 return &hbq_entry->dbuf;
923 lpfc_sli_free_hbq(phba, hbq_entry);
924 return &new_hbq_entry->dbuf;
928 lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
929 struct lpfc_iocbq *saveq)
937 irsp = &(saveq->iocb);
938 if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX)
939 || (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX)
940 || (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)
941 || (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX)) {
946 (WORD5 *) & (saveq->iocb.un.
948 Rctl = w5p->hcsw.Rctl;
949 Type = w5p->hcsw.Type;
951 /* Firmware Workaround */
952 if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
953 (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
954 irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
957 w5p->hcsw.Rctl = Rctl;
958 w5p->hcsw.Type = Type;
962 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
963 if (irsp->ulpBdeCount != 0)
964 saveq->context2 = lpfc_sli_replace_hbqbuff(phba,
965 irsp->un.ulpWord[3]);
966 if (irsp->ulpBdeCount == 2)
967 saveq->context3 = lpfc_sli_replace_hbqbuff(phba,
968 irsp->un.ulpWord[15]);
971 /* unSolicited Responses */
972 if (pring->prt[0].profile) {
973 if (pring->prt[0].lpfc_sli_rcv_unsol_event)
974 (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
978 /* We must search, based on rctl / type
979 for the right routine */
980 for (i = 0; i < pring->num_mask;
982 if ((pring->prt[i].rctl ==
986 if (pring->prt[i].lpfc_sli_rcv_unsol_event)
987 (pring->prt[i].lpfc_sli_rcv_unsol_event)
988 (phba, pring, saveq);
995 /* Unexpected Rctl / Type received */
996 /* Ring <ringno> handler: unexpected
997 Rctl <Rctl> Type <Type> received */
998 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
999 "%d:0313 Ring %d handler: unexpected Rctl x%x "
1000 "Type x%x received\n",
1009 static struct lpfc_iocbq *
1010 lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
1011 struct lpfc_sli_ring *pring,
1012 struct lpfc_iocbq *prspiocb)
1014 struct lpfc_iocbq *cmd_iocb = NULL;
1017 iotag = prspiocb->iocb.ulpIoTag;
1019 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
1020 cmd_iocb = phba->sli.iocbq_lookup[iotag];
1021 list_del_init(&cmd_iocb->list);
1022 pring->txcmplq_cnt--;
1026 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1027 "%d:0317 iotag x%x is out off "
1028 "range: max iotag x%x wd0 x%x\n",
1029 phba->brd_no, iotag,
1030 phba->sli.last_iotag,
1031 *(((uint32_t *) &prspiocb->iocb) + 7));
1036 lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1037 struct lpfc_iocbq *saveq)
1039 struct lpfc_iocbq *cmdiocbp;
1041 unsigned long iflag;
1043 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
1044 spin_lock_irqsave(&phba->hbalock, iflag);
1045 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
1046 spin_unlock_irqrestore(&phba->hbalock, iflag);
1049 if (cmdiocbp->iocb_cmpl) {
1051 * Post all ELS completions to the worker thread.
1052 * All other are passed to the completion callback.
1054 if (pring->ringno == LPFC_ELS_RING) {
1055 if (cmdiocbp->iocb_flag & LPFC_DRIVER_ABORTED) {
1056 cmdiocbp->iocb_flag &=
1057 ~LPFC_DRIVER_ABORTED;
1058 saveq->iocb.ulpStatus =
1059 IOSTAT_LOCAL_REJECT;
1060 saveq->iocb.un.ulpWord[4] =
1064 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
1066 lpfc_sli_release_iocbq(phba, cmdiocbp);
1069 * Unknown initiating command based on the response iotag.
1070 * This could be the case on the ELS ring because of
1073 if (pring->ringno != LPFC_ELS_RING) {
1075 * Ring <ringno> handler: unexpected completion IoTag
1078 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1079 "%d (%d):0322 Ring %d handler: "
1080 "unexpected completion IoTag x%x "
1081 "Data: x%x x%x x%x x%x\n",
1083 cmdiocbp->vport->vpi,
1085 saveq->iocb.ulpIoTag,
1086 saveq->iocb.ulpStatus,
1087 saveq->iocb.un.ulpWord[4],
1088 saveq->iocb.ulpCommand,
1089 saveq->iocb.ulpContext);
1097 lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1099 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
1100 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1101 &phba->slim2p->mbx.us.s2.port[pring->ringno];
1103 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
1104 * rsp ring <portRspMax>
1106 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1107 "%d:0312 Ring %d handler: portRspPut %d "
1108 "is bigger then rsp ring %d\n",
1109 phba->brd_no, pring->ringno,
1110 le32_to_cpu(pgp->rspPutInx),
1113 phba->link_state = LPFC_HBA_ERROR;
1116 * All error attention handlers are posted to
1119 phba->work_ha |= HA_ERATT;
1120 phba->work_hs = HS_FFER3;
1122 /* hbalock should already be held */
1123 if (phba->work_wait)
1124 lpfc_worker_wake_up(phba);
1129 void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba)
1131 struct lpfc_sli *psli = &phba->sli;
1132 struct lpfc_sli_ring *pring = &psli->ring[LPFC_FCP_RING];
1133 IOCB_t *irsp = NULL;
1134 IOCB_t *entry = NULL;
1135 struct lpfc_iocbq *cmdiocbq = NULL;
1136 struct lpfc_iocbq rspiocbq;
1137 struct lpfc_pgp *pgp;
1139 uint32_t portRspPut, portRspMax;
1141 uint32_t rsp_cmpl = 0;
1143 unsigned long iflags;
1145 pring->stats.iocb_event++;
1147 pgp = (phba->sli_rev == 3) ?
1148 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1149 &phba->slim2p->mbx.us.s2.port[pring->ringno];
1153 * The next available response entry should never exceed the maximum
1154 * entries. If it does, treat it as an adapter hardware error.
1156 portRspMax = pring->numRiocb;
1157 portRspPut = le32_to_cpu(pgp->rspPutInx);
1158 if (unlikely(portRspPut >= portRspMax)) {
1159 lpfc_sli_rsp_pointers_error(phba, pring);
1164 while (pring->rspidx != portRspPut) {
1165 entry = lpfc_resp_iocb(phba, pring);
1166 if (++pring->rspidx >= portRspMax)
1169 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
1170 (uint32_t *) &rspiocbq.iocb,
1171 phba->iocb_rsp_size);
1172 irsp = &rspiocbq.iocb;
1173 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
1174 pring->stats.iocb_rsp++;
1177 if (unlikely(irsp->ulpStatus)) {
1178 /* Rsp ring <ringno> error: IOCB */
1179 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1180 "%d:0326 Rsp Ring %d error: IOCB Data: "
1181 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
1182 phba->brd_no, pring->ringno,
1183 irsp->un.ulpWord[0],
1184 irsp->un.ulpWord[1],
1185 irsp->un.ulpWord[2],
1186 irsp->un.ulpWord[3],
1187 irsp->un.ulpWord[4],
1188 irsp->un.ulpWord[5],
1189 *(((uint32_t *) irsp) + 6),
1190 *(((uint32_t *) irsp) + 7));
1194 case LPFC_ABORT_IOCB:
1197 * Idle exchange closed via ABTS from port. No iocb
1198 * resources need to be recovered.
1200 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
1201 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1202 "%d:0314 IOCB cmd 0x%x"
1203 " processed. Skipping"
1204 " completion", phba->brd_no,
1209 spin_lock_irqsave(&phba->hbalock, iflags);
1210 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
1212 spin_unlock_irqrestore(&phba->hbalock, iflags);
1213 if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
1214 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1219 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1220 char adaptermsg[LPFC_MAX_ADPTMSG];
1221 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
1222 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1224 dev_warn(&((phba->pcidev)->dev), "lpfc%d: %s",
1225 phba->brd_no, adaptermsg);
1227 /* Unknown IOCB command */
1228 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1229 "%d:0321 Unknown IOCB command "
1230 "Data: x%x, x%x x%x x%x x%x\n",
1241 * The response IOCB has been processed. Update the ring
1242 * pointer in SLIM. If the port response put pointer has not
1243 * been updated, sync the pgp->rspPutInx and fetch the new port
1244 * response put pointer.
1246 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
1248 if (pring->rspidx == portRspPut)
1249 portRspPut = le32_to_cpu(pgp->rspPutInx);
1252 ha_copy = readl(phba->HAregaddr);
1253 ha_copy >>= (LPFC_FCP_RING * 4);
1255 if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) {
1256 spin_lock_irqsave(&phba->hbalock, iflags);
1257 pring->stats.iocb_rsp_full++;
1258 status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4));
1259 writel(status, phba->CAregaddr);
1260 readl(phba->CAregaddr);
1261 spin_unlock_irqrestore(&phba->hbalock, iflags);
1263 if ((ha_copy & HA_R0CE_RSP) &&
1264 (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1265 spin_lock_irqsave(&phba->hbalock, iflags);
1266 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1267 pring->stats.iocb_cmd_empty++;
1269 /* Force update of the local copy of cmdGetInx */
1270 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1271 lpfc_sli_resume_iocb(phba, pring);
1273 if ((pring->lpfc_sli_cmd_available))
1274 (pring->lpfc_sli_cmd_available) (phba, pring);
1276 spin_unlock_irqrestore(&phba->hbalock, iflags);
1283 * This routine presumes LPFC_FCP_RING handling and doesn't bother
1284 * to check it explicitly.
1287 lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
1288 struct lpfc_sli_ring *pring, uint32_t mask)
1290 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
1291 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1292 &phba->slim2p->mbx.us.s2.port[pring->ringno];
1293 IOCB_t *irsp = NULL;
1294 IOCB_t *entry = NULL;
1295 struct lpfc_iocbq *cmdiocbq = NULL;
1296 struct lpfc_iocbq rspiocbq;
1298 uint32_t portRspPut, portRspMax;
1300 lpfc_iocb_type type;
1301 unsigned long iflag;
1302 uint32_t rsp_cmpl = 0;
1304 spin_lock_irqsave(&phba->hbalock, iflag);
1305 pring->stats.iocb_event++;
1308 * The next available response entry should never exceed the maximum
1309 * entries. If it does, treat it as an adapter hardware error.
1311 portRspMax = pring->numRiocb;
1312 portRspPut = le32_to_cpu(pgp->rspPutInx);
1313 if (unlikely(portRspPut >= portRspMax)) {
1314 lpfc_sli_rsp_pointers_error(phba, pring);
1315 spin_unlock_irqrestore(&phba->hbalock, iflag);
1320 while (pring->rspidx != portRspPut) {
1322 * Fetch an entry off the ring and copy it into a local data
1323 * structure. The copy involves a byte-swap since the
1324 * network byte order and pci byte orders are different.
1326 entry = lpfc_resp_iocb(phba, pring);
1327 phba->last_completion_time = jiffies;
1329 if (++pring->rspidx >= portRspMax)
1332 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
1333 (uint32_t *) &rspiocbq.iocb,
1334 phba->iocb_rsp_size);
1335 INIT_LIST_HEAD(&(rspiocbq.list));
1336 irsp = &rspiocbq.iocb;
1338 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
1339 pring->stats.iocb_rsp++;
1342 if (unlikely(irsp->ulpStatus)) {
1344 * If resource errors reported from HBA, reduce
1345 * queuedepths of the SCSI device.
1347 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1348 (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
1349 spin_unlock_irqrestore(&phba->hbalock, iflag);
1350 lpfc_adjust_queue_depth(phba);
1351 spin_lock_irqsave(&phba->hbalock, iflag);
1354 /* Rsp ring <ringno> error: IOCB */
1355 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1356 "%d:0336 Rsp Ring %d error: IOCB Data: "
1357 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
1358 phba->brd_no, pring->ringno,
1359 irsp->un.ulpWord[0],
1360 irsp->un.ulpWord[1],
1361 irsp->un.ulpWord[2],
1362 irsp->un.ulpWord[3],
1363 irsp->un.ulpWord[4],
1364 irsp->un.ulpWord[5],
1365 *(((uint32_t *) irsp) + 6),
1366 *(((uint32_t *) irsp) + 7));
1370 case LPFC_ABORT_IOCB:
1373 * Idle exchange closed via ABTS from port. No iocb
1374 * resources need to be recovered.
1376 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
1377 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1378 "%d:0333 IOCB cmd 0x%x"
1379 " processed. Skipping"
1386 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
1388 if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
1389 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
1390 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1393 spin_unlock_irqrestore(&phba->hbalock,
1395 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1397 spin_lock_irqsave(&phba->hbalock,
1402 case LPFC_UNSOL_IOCB:
1403 spin_unlock_irqrestore(&phba->hbalock, iflag);
1404 lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
1405 spin_lock_irqsave(&phba->hbalock, iflag);
1408 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1409 char adaptermsg[LPFC_MAX_ADPTMSG];
1410 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
1411 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1413 dev_warn(&((phba->pcidev)->dev), "lpfc%d: %s",
1414 phba->brd_no, adaptermsg);
1416 /* Unknown IOCB command */
1417 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1418 "%d:0334 Unknown IOCB command "
1419 "Data: x%x, x%x x%x x%x x%x\n",
1430 * The response IOCB has been processed. Update the ring
1431 * pointer in SLIM. If the port response put pointer has not
1432 * been updated, sync the pgp->rspPutInx and fetch the new port
1433 * response put pointer.
1435 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
1437 if (pring->rspidx == portRspPut)
1438 portRspPut = le32_to_cpu(pgp->rspPutInx);
1441 if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
1442 pring->stats.iocb_rsp_full++;
1443 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
1444 writel(status, phba->CAregaddr);
1445 readl(phba->CAregaddr);
1447 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1448 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1449 pring->stats.iocb_cmd_empty++;
1451 /* Force update of the local copy of cmdGetInx */
1452 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1453 lpfc_sli_resume_iocb(phba, pring);
1455 if ((pring->lpfc_sli_cmd_available))
1456 (pring->lpfc_sli_cmd_available) (phba, pring);
1460 spin_unlock_irqrestore(&phba->hbalock, iflag);
1465 lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
1466 struct lpfc_sli_ring *pring, uint32_t mask)
1468 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
1469 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1470 &phba->slim2p->mbx.us.s2.port[pring->ringno];
1472 IOCB_t *irsp = NULL;
1473 struct lpfc_iocbq *rspiocbp = NULL;
1474 struct lpfc_iocbq *next_iocb;
1475 struct lpfc_iocbq *cmdiocbp;
1476 struct lpfc_iocbq *saveq;
1477 uint8_t iocb_cmd_type;
1478 lpfc_iocb_type type;
1479 uint32_t status, free_saveq;
1480 uint32_t portRspPut, portRspMax;
1482 unsigned long iflag;
1484 spin_lock_irqsave(&phba->hbalock, iflag);
1485 pring->stats.iocb_event++;
1488 * The next available response entry should never exceed the maximum
1489 * entries. If it does, treat it as an adapter hardware error.
1491 portRspMax = pring->numRiocb;
1492 portRspPut = le32_to_cpu(pgp->rspPutInx);
1493 if (portRspPut >= portRspMax) {
1495 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
1496 * rsp ring <portRspMax>
1498 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1499 "%d:0303 Ring %d handler: portRspPut %d "
1500 "is bigger then rsp ring %d\n",
1501 phba->brd_no, pring->ringno, portRspPut,
1504 phba->link_state = LPFC_HBA_ERROR;
1505 spin_unlock_irqrestore(&phba->hbalock, iflag);
1507 phba->work_hs = HS_FFER3;
1508 lpfc_handle_eratt(phba);
1514 while (pring->rspidx != portRspPut) {
1516 * Build a completion list and call the appropriate handler.
1517 * The process is to get the next available response iocb, get
1518 * a free iocb from the list, copy the response data into the
1519 * free iocb, insert to the continuation list, and update the
1520 * next response index to slim. This process makes response
1521 * iocb's in the ring available to DMA as fast as possible but
1522 * pays a penalty for a copy operation. Since the iocb is
1523 * only 32 bytes, this penalty is considered small relative to
1524 * the PCI reads for register values and a slim write. When
1525 * the ulpLe field is set, the entire Command has been
1528 entry = lpfc_resp_iocb(phba, pring);
1530 phba->last_completion_time = jiffies;
1531 rspiocbp = __lpfc_sli_get_iocbq(phba);
1532 if (rspiocbp == NULL) {
1533 printk(KERN_ERR "%s: out of buffers! Failing "
1534 "completion.\n", __FUNCTION__);
1538 lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
1539 phba->iocb_rsp_size);
1540 irsp = &rspiocbp->iocb;
1542 if (++pring->rspidx >= portRspMax)
1545 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
1547 if (list_empty(&(pring->iocb_continueq))) {
1548 list_add(&rspiocbp->list, &(pring->iocb_continueq));
1550 list_add_tail(&rspiocbp->list,
1551 &(pring->iocb_continueq));
1554 pring->iocb_continueq_cnt++;
1557 * By default, the driver expects to free all resources
1558 * associated with this iocb completion.
1561 saveq = list_get_first(&pring->iocb_continueq,
1562 struct lpfc_iocbq, list);
1563 irsp = &(saveq->iocb);
1564 list_del_init(&pring->iocb_continueq);
1565 pring->iocb_continueq_cnt = 0;
1567 pring->stats.iocb_rsp++;
1570 * If resource errors reported from HBA, reduce
1571 * queuedepths of the SCSI device.
1573 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1574 (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
1575 spin_unlock_irqrestore(&phba->hbalock, iflag);
1576 lpfc_adjust_queue_depth(phba);
1577 spin_lock_irqsave(&phba->hbalock, iflag);
1580 if (irsp->ulpStatus) {
1581 /* Rsp ring <ringno> error: IOCB */
1582 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1583 "%d:0328 Rsp Ring %d error: "
1588 "x%x x%x x%x x%x\n",
1591 irsp->un.ulpWord[0],
1592 irsp->un.ulpWord[1],
1593 irsp->un.ulpWord[2],
1594 irsp->un.ulpWord[3],
1595 irsp->un.ulpWord[4],
1596 irsp->un.ulpWord[5],
1597 *(((uint32_t *) irsp) + 6),
1598 *(((uint32_t *) irsp) + 7),
1599 *(((uint32_t *) irsp) + 8),
1600 *(((uint32_t *) irsp) + 9),
1601 *(((uint32_t *) irsp) + 10),
1602 *(((uint32_t *) irsp) + 11),
1603 *(((uint32_t *) irsp) + 12),
1604 *(((uint32_t *) irsp) + 13),
1605 *(((uint32_t *) irsp) + 14),
1606 *(((uint32_t *) irsp) + 15));
1610 * Fetch the IOCB command type and call the correct
1611 * completion routine. Solicited and Unsolicited
1612 * IOCBs on the ELS ring get freed back to the
1613 * lpfc_iocb_list by the discovery kernel thread.
1615 iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
1616 type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
1617 if (type == LPFC_SOL_IOCB) {
1618 spin_unlock_irqrestore(&phba->hbalock,
1620 rc = lpfc_sli_process_sol_iocb(phba, pring,
1622 spin_lock_irqsave(&phba->hbalock, iflag);
1623 } else if (type == LPFC_UNSOL_IOCB) {
1624 spin_unlock_irqrestore(&phba->hbalock,
1626 rc = lpfc_sli_process_unsol_iocb(phba, pring,
1628 spin_lock_irqsave(&phba->hbalock, iflag);
1629 } else if (type == LPFC_ABORT_IOCB) {
1630 if ((irsp->ulpCommand != CMD_XRI_ABORTED_CX) &&
1632 lpfc_sli_iocbq_lookup(phba, pring,
1634 /* Call the specified completion
1636 if (cmdiocbp->iocb_cmpl) {
1637 spin_unlock_irqrestore(
1640 (cmdiocbp->iocb_cmpl) (phba,
1646 __lpfc_sli_release_iocbq(phba,
1649 } else if (type == LPFC_UNKNOWN_IOCB) {
1650 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1652 char adaptermsg[LPFC_MAX_ADPTMSG];
1654 memset(adaptermsg, 0,
1656 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1658 dev_warn(&((phba->pcidev)->dev),
1660 phba->brd_no, adaptermsg);
1662 /* Unknown IOCB command */
1663 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1664 "%d:0335 Unknown IOCB "
1665 "command Data: x%x "
1676 list_for_each_entry_safe(rspiocbp, next_iocb,
1677 &saveq->list, list) {
1678 list_del(&rspiocbp->list);
1679 __lpfc_sli_release_iocbq(phba,
1682 __lpfc_sli_release_iocbq(phba, saveq);
1688 * If the port response put pointer has not been updated, sync
1689 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
1690 * response put pointer.
1692 if (pring->rspidx == portRspPut) {
1693 portRspPut = le32_to_cpu(pgp->rspPutInx);
1695 } /* while (pring->rspidx != portRspPut) */
1697 if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
1698 /* At least one response entry has been freed */
1699 pring->stats.iocb_rsp_full++;
1700 /* SET RxRE_RSP in Chip Att register */
1701 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
1702 writel(status, phba->CAregaddr);
1703 readl(phba->CAregaddr); /* flush */
1705 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1706 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1707 pring->stats.iocb_cmd_empty++;
1709 /* Force update of the local copy of cmdGetInx */
1710 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1711 lpfc_sli_resume_iocb(phba, pring);
1713 if ((pring->lpfc_sli_cmd_available))
1714 (pring->lpfc_sli_cmd_available) (phba, pring);
1718 spin_unlock_irqrestore(&phba->hbalock, iflag);
1723 lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1725 LIST_HEAD(completions);
1726 struct lpfc_iocbq *iocb, *next_iocb;
1729 if (pring->ringno == LPFC_ELS_RING) {
1730 lpfc_fabric_abort_hba(phba);
1733 /* Error everything on txq and txcmplq
1736 spin_lock_irq(&phba->hbalock);
1737 list_splice_init(&pring->txq, &completions);
1740 /* Next issue ABTS for everything on the txcmplq */
1741 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
1742 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1744 spin_unlock_irq(&phba->hbalock);
1746 while (!list_empty(&completions)) {
1747 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
1749 list_del_init(&iocb->list);
1751 if (!iocb->iocb_cmpl)
1752 lpfc_sli_release_iocbq(phba, iocb);
1754 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
1755 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
1756 (iocb->iocb_cmpl) (phba, iocb, iocb);
1762 lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
1768 /* Read the HBA Host Status Register */
1769 status = readl(phba->HSregaddr);
1772 * Check status register every 100ms for 5 retries, then every
1773 * 500ms for 5, then every 2.5 sec for 5, then reset board and
1774 * every 2.5 sec for 4.
1775 * Break our of the loop if errors occurred during init.
1777 while (((status & mask) != mask) &&
1778 !(status & HS_FFERM) &&
1790 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
1791 lpfc_sli_brdrestart(phba);
1793 /* Read the HBA Host Status Register */
1794 status = readl(phba->HSregaddr);
1797 /* Check to see if any errors occurred during init */
1798 if ((status & HS_FFERM) || (i >= 20)) {
1799 phba->link_state = LPFC_HBA_ERROR;
1806 #define BARRIER_TEST_PATTERN (0xdeadbeef)
1808 void lpfc_reset_barrier(struct lpfc_hba *phba)
1810 uint32_t __iomem *resp_buf;
1811 uint32_t __iomem *mbox_buf;
1812 volatile uint32_t mbox;
1817 pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
1818 if (hdrtype != 0x80 ||
1819 (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
1820 FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
1824 * Tell the other part of the chip to suspend temporarily all
1827 resp_buf = phba->MBslimaddr;
1829 /* Disable the error attention */
1830 hc_copy = readl(phba->HCregaddr);
1831 writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
1832 readl(phba->HCregaddr); /* flush */
1833 phba->link_flag |= LS_IGNORE_ERATT;
1835 if (readl(phba->HAregaddr) & HA_ERATT) {
1836 /* Clear Chip error bit */
1837 writel(HA_ERATT, phba->HAregaddr);
1838 phba->pport->stopped = 1;
1842 ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
1843 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
1845 writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
1846 mbox_buf = phba->MBslimaddr;
1847 writel(mbox, mbox_buf);
1850 readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
1853 if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
1854 if (phba->sli.sli_flag & LPFC_SLI2_ACTIVE ||
1855 phba->pport->stopped)
1861 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
1862 for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
1867 while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
1870 if (readl(phba->HAregaddr) & HA_ERATT) {
1871 writel(HA_ERATT, phba->HAregaddr);
1872 phba->pport->stopped = 1;
1876 phba->link_flag &= ~LS_IGNORE_ERATT;
1877 writel(hc_copy, phba->HCregaddr);
1878 readl(phba->HCregaddr); /* flush */
1882 lpfc_sli_brdkill(struct lpfc_hba *phba)
1884 struct lpfc_sli *psli;
1894 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1895 "%d:0329 Kill HBA Data: x%x x%x\n",
1896 phba->brd_no, phba->pport->port_state, psli->sli_flag);
1898 if ((pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
1902 /* Disable the error attention */
1903 spin_lock_irq(&phba->hbalock);
1904 status = readl(phba->HCregaddr);
1905 status &= ~HC_ERINT_ENA;
1906 writel(status, phba->HCregaddr);
1907 readl(phba->HCregaddr); /* flush */
1908 phba->link_flag |= LS_IGNORE_ERATT;
1909 spin_unlock_irq(&phba->hbalock);
1911 lpfc_kill_board(phba, pmb);
1912 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1913 retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
1915 if (retval != MBX_SUCCESS) {
1916 if (retval != MBX_BUSY)
1917 mempool_free(pmb, phba->mbox_mem_pool);
1918 spin_lock_irq(&phba->hbalock);
1919 phba->link_flag &= ~LS_IGNORE_ERATT;
1920 spin_unlock_irq(&phba->hbalock);
1924 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
1926 mempool_free(pmb, phba->mbox_mem_pool);
1928 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
1929 * attention every 100ms for 3 seconds. If we don't get ERATT after
1930 * 3 seconds we still set HBA_ERROR state because the status of the
1931 * board is now undefined.
1933 ha_copy = readl(phba->HAregaddr);
1935 while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
1937 ha_copy = readl(phba->HAregaddr);
1940 del_timer_sync(&psli->mbox_tmo);
1941 if (ha_copy & HA_ERATT) {
1942 writel(HA_ERATT, phba->HAregaddr);
1943 phba->pport->stopped = 1;
1945 spin_lock_irq(&phba->hbalock);
1946 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
1947 phba->link_flag &= ~LS_IGNORE_ERATT;
1948 spin_unlock_irq(&phba->hbalock);
1950 psli->mbox_active = NULL;
1951 lpfc_hba_down_post(phba);
1952 phba->link_state = LPFC_HBA_ERROR;
1954 return ha_copy & HA_ERATT ? 0 : 1;
1958 lpfc_sli_brdreset(struct lpfc_hba *phba)
1960 struct lpfc_sli *psli;
1961 struct lpfc_sli_ring *pring;
1968 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1969 "%d:0325 Reset HBA Data: x%x x%x\n", phba->brd_no,
1970 phba->pport->port_state, psli->sli_flag);
1972 /* perform board reset */
1973 phba->fc_eventTag = 0;
1974 phba->pport->fc_myDID = 0;
1975 phba->pport->fc_prevDID = 0;
1977 /* Turn off parity checking and serr during the physical reset */
1978 pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
1979 pci_write_config_word(phba->pcidev, PCI_COMMAND,
1981 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
1983 psli->sli_flag &= ~(LPFC_SLI2_ACTIVE | LPFC_PROCESS_LA);
1984 /* Now toggle INITFF bit in the Host Control Register */
1985 writel(HC_INITFF, phba->HCregaddr);
1987 readl(phba->HCregaddr); /* flush */
1988 writel(0, phba->HCregaddr);
1989 readl(phba->HCregaddr); /* flush */
1991 /* Restore PCI cmd register */
1992 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
1994 /* Initialize relevant SLI info */
1995 for (i = 0; i < psli->num_rings; i++) {
1996 pring = &psli->ring[i];
1999 pring->next_cmdidx = 0;
2000 pring->local_getidx = 0;
2002 pring->missbufcnt = 0;
2005 phba->link_state = LPFC_WARM_START;
2010 lpfc_sli_brdrestart(struct lpfc_hba *phba)
2013 struct lpfc_sli *psli;
2015 volatile uint32_t word0;
2016 void __iomem *to_slim;
2018 spin_lock_irq(&phba->hbalock);
2023 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2024 "%d:0337 Restart HBA Data: x%x x%x\n", phba->brd_no,
2025 phba->pport->port_state, psli->sli_flag);
2028 mb = (MAILBOX_t *) &word0;
2029 mb->mbxCommand = MBX_RESTART;
2032 lpfc_reset_barrier(phba);
2034 to_slim = phba->MBslimaddr;
2035 writel(*(uint32_t *) mb, to_slim);
2036 readl(to_slim); /* flush */
2038 /* Only skip post after fc_ffinit is completed */
2039 if (phba->pport->port_state) {
2041 word0 = 1; /* This is really setting up word1 */
2044 word0 = 0; /* This is really setting up word1 */
2046 to_slim = phba->MBslimaddr + sizeof (uint32_t);
2047 writel(*(uint32_t *) mb, to_slim);
2048 readl(to_slim); /* flush */
2050 lpfc_sli_brdreset(phba);
2051 phba->pport->stopped = 0;
2052 phba->link_state = LPFC_INIT_START;
2054 spin_unlock_irq(&phba->hbalock);
2056 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
2057 psli->stats_start = get_seconds();
2064 lpfc_hba_down_post(phba);
2070 lpfc_sli_chipset_init(struct lpfc_hba *phba)
2072 uint32_t status, i = 0;
2074 /* Read the HBA Host Status Register */
2075 status = readl(phba->HSregaddr);
2077 /* Check status register to see what current state is */
2079 while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
2081 /* Check every 100ms for 5 retries, then every 500ms for 5, then
2082 * every 2.5 sec for 5, then reset board and every 2.5 sec for
2086 /* Adapter failed to init, timeout, status reg
2088 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2089 "%d:0436 Adapter failed to init, "
2090 "timeout, status reg x%x\n",
2091 phba->brd_no, status);
2092 phba->link_state = LPFC_HBA_ERROR;
2096 /* Check to see if any errors occurred during init */
2097 if (status & HS_FFERM) {
2098 /* ERROR: During chipset initialization */
2099 /* Adapter failed to init, chipset, status reg
2101 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2102 "%d:0437 Adapter failed to init, "
2103 "chipset, status reg x%x\n",
2106 phba->link_state = LPFC_HBA_ERROR;
2112 } else if (i <= 10) {
2120 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
2121 lpfc_sli_brdrestart(phba);
2123 /* Read the HBA Host Status Register */
2124 status = readl(phba->HSregaddr);
2127 /* Check to see if any errors occurred during init */
2128 if (status & HS_FFERM) {
2129 /* ERROR: During chipset initialization */
2130 /* Adapter failed to init, chipset, status reg <status> */
2131 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2132 "%d:0438 Adapter failed to init, chipset, "
2136 phba->link_state = LPFC_HBA_ERROR;
2140 /* Clear all interrupt enable conditions */
2141 writel(0, phba->HCregaddr);
2142 readl(phba->HCregaddr); /* flush */
2144 /* setup host attn register */
2145 writel(0xffffffff, phba->HAregaddr);
2146 readl(phba->HAregaddr); /* flush */
2151 lpfc_sli_hbq_count(void)
2153 return ARRAY_SIZE(lpfc_hbq_defs);
2157 lpfc_sli_hbq_entry_count(void)
2159 int hbq_count = lpfc_sli_hbq_count();
2163 for (i = 0; i < hbq_count; ++i)
2164 count += lpfc_hbq_defs[i]->entry_count;
2169 lpfc_sli_hbq_size(void)
2171 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
2175 lpfc_sli_hbq_setup(struct lpfc_hba *phba)
2177 int hbq_count = lpfc_sli_hbq_count();
2181 uint32_t hbq_entry_index;
2183 /* Get a Mailbox buffer to setup mailbox
2184 * commands for HBA initialization
2186 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2193 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
2194 phba->link_state = LPFC_INIT_MBX_CMDS;
2196 hbq_entry_index = 0;
2197 for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
2198 phba->hbqs[hbqno].next_hbqPutIdx = 0;
2199 phba->hbqs[hbqno].hbqPutIdx = 0;
2200 phba->hbqs[hbqno].local_hbqGetIdx = 0;
2201 phba->hbqs[hbqno].entry_count =
2202 lpfc_hbq_defs[hbqno]->entry_count;
2203 lpfc_config_hbq(phba, lpfc_hbq_defs[hbqno], hbq_entry_index,
2205 hbq_entry_index += phba->hbqs[hbqno].entry_count;
2207 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
2208 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
2209 mbxStatus <status>, ring <num> */
2211 lpfc_printf_log(phba, KERN_ERR,
2212 LOG_SLI | LOG_VPORT,
2213 "%d:1805 Adapter failed to init. "
2214 "Data: x%x x%x x%x\n",
2215 phba->brd_no, pmbox->mbxCommand,
2216 pmbox->mbxStatus, hbqno);
2218 phba->link_state = LPFC_HBA_ERROR;
2219 mempool_free(pmb, phba->mbox_mem_pool);
2223 phba->hbq_count = hbq_count;
2225 mempool_free(pmb, phba->mbox_mem_pool);
2227 /* Initially populate or replenish the HBQs */
2228 for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
2229 if (lpfc_sli_hbqbuf_init_hbqs(phba, hbqno))
2236 lpfc_do_config_port(struct lpfc_hba *phba, int sli_mode)
2239 uint32_t resetcount = 0, rc = 0, done = 0;
2241 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2243 phba->link_state = LPFC_HBA_ERROR;
2247 phba->sli_rev = sli_mode;
2248 while (resetcount < 2 && !done) {
2249 spin_lock_irq(&phba->hbalock);
2250 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
2251 spin_unlock_irq(&phba->hbalock);
2252 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
2253 lpfc_sli_brdrestart(phba);
2255 rc = lpfc_sli_chipset_init(phba);
2259 spin_lock_irq(&phba->hbalock);
2260 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2261 spin_unlock_irq(&phba->hbalock);
2264 /* Call pre CONFIG_PORT mailbox command initialization. A
2265 * value of 0 means the call was successful. Any other
2266 * nonzero value is a failure, but if ERESTART is returned,
2267 * the driver may reset the HBA and try again.
2269 rc = lpfc_config_port_prep(phba);
2270 if (rc == -ERESTART) {
2271 phba->link_state = LPFC_LINK_UNKNOWN;
2277 phba->link_state = LPFC_INIT_MBX_CMDS;
2278 lpfc_config_port(phba, pmb);
2279 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
2280 if (rc != MBX_SUCCESS) {
2281 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2282 "%d:0442 Adapter failed to init, mbxCmd x%x "
2283 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
2284 phba->brd_no, pmb->mb.mbxCommand,
2285 pmb->mb.mbxStatus, 0);
2286 spin_lock_irq(&phba->hbalock);
2287 phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE;
2288 spin_unlock_irq(&phba->hbalock);
2292 phba->max_vpi = (phba->max_vpi &&
2293 pmb->mb.un.varCfgPort.gmv) != 0
2294 ? pmb->mb.un.varCfgPort.max_vpi
2301 goto do_prep_failed;
2304 if ((pmb->mb.un.varCfgPort.sli_mode == 3) &&
2305 (!pmb->mb.un.varCfgPort.cMA)) {
2307 goto do_prep_failed;
2312 mempool_free(pmb, phba->mbox_mem_pool);
2317 lpfc_sli_hba_setup(struct lpfc_hba *phba)
2322 switch (lpfc_sli_mode) {
2324 if (phba->cfg_npiv_enable) {
2325 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
2326 "%d:1824 NPIV enabled: Override lpfc_sli_mode "
2327 "parameter (%d) to auto (0).\n",
2328 phba->brd_no, lpfc_sli_mode);
2337 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
2338 "%d:1819 Unrecognized lpfc_sli_mode "
2340 phba->brd_no, lpfc_sli_mode);
2345 rc = lpfc_do_config_port(phba, mode);
2346 if (rc && lpfc_sli_mode == 3)
2347 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
2348 "%d:1820 Unable to select SLI-3. "
2349 "Not supported by adapter.\n",
2351 if (rc && mode != 2)
2352 rc = lpfc_do_config_port(phba, 2);
2354 goto lpfc_sli_hba_setup_error;
2356 if (phba->sli_rev == 3) {
2357 phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
2358 phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
2359 phba->sli3_options |= LPFC_SLI3_ENABLED;
2360 phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
2363 phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
2364 phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
2365 phba->sli3_options = 0;
2368 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2369 "%d:0444 Firmware in SLI %x mode. Max_vpi %d\n",
2370 phba->brd_no, phba->sli_rev, phba->max_vpi);
2371 rc = lpfc_sli_ring_map(phba);
2374 goto lpfc_sli_hba_setup_error;
2378 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
2379 rc = lpfc_sli_hbq_setup(phba);
2381 goto lpfc_sli_hba_setup_error;
2384 phba->sli.sli_flag |= LPFC_PROCESS_LA;
2386 rc = lpfc_config_port_post(phba);
2388 goto lpfc_sli_hba_setup_error;
2392 lpfc_sli_hba_setup_error:
2393 phba->link_state = LPFC_HBA_ERROR;
2394 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2395 "%d:0445 Firmware initialization failed\n",
2400 /*! lpfc_mbox_timeout
2404 * \param hba Pointer to per struct lpfc_hba structure
2405 * \param l1 Pointer to the driver's mailbox queue.
2411 * This routine handles mailbox timeout events at timer interrupt context.
2414 lpfc_mbox_timeout(unsigned long ptr)
2416 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
2417 unsigned long iflag;
2418 uint32_t tmo_posted;
2420 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
2421 tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
2423 phba->pport->work_port_events |= WORKER_MBOX_TMO;
2424 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
2427 spin_lock_irqsave(&phba->hbalock, iflag);
2428 if (phba->work_wait)
2429 lpfc_worker_wake_up(phba);
2430 spin_unlock_irqrestore(&phba->hbalock, iflag);
2435 lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
2437 LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
2438 MAILBOX_t *mb = &pmbox->mb;
2439 struct lpfc_sli *psli = &phba->sli;
2440 struct lpfc_sli_ring *pring;
2442 if (!(phba->pport->work_port_events & WORKER_MBOX_TMO)) {
2446 /* Mbox cmd <mbxCommand> timeout */
2447 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
2448 "%d:0310 Mailbox command x%x timeout Data: x%x x%x "
2452 phba->pport->port_state,
2454 phba->sli.mbox_active);
2456 /* Setting state unknown so lpfc_sli_abort_iocb_ring
2457 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
2458 * it to fail all oustanding SCSI IO.
2460 spin_lock_irq(&phba->pport->work_port_lock);
2461 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
2462 spin_unlock_irq(&phba->pport->work_port_lock);
2463 spin_lock_irq(&phba->hbalock);
2464 phba->link_state = LPFC_LINK_UNKNOWN;
2465 phba->pport->fc_flag |= FC_ESTABLISH_LINK;
2466 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
2467 spin_unlock_irq(&phba->hbalock);
2469 pring = &psli->ring[psli->fcp_ring];
2470 lpfc_sli_abort_iocb_ring(phba, pring);
2472 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
2473 "%d:0316 Resetting board due to mailbox timeout\n",
2476 * lpfc_offline calls lpfc_sli_hba_down which will clean up
2477 * on oustanding mailbox commands.
2479 lpfc_offline_prep(phba);
2481 lpfc_sli_brdrestart(phba);
2482 if (lpfc_online(phba) == 0) /* Initialize the HBA */
2483 mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
2484 lpfc_unblock_mgmt_io(phba);
2489 lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
2492 struct lpfc_sli *psli = &phba->sli;
2493 uint32_t status, evtctr;
2496 unsigned long drvr_flag = 0;
2497 volatile uint32_t word0, ldata;
2498 void __iomem *to_slim;
2500 if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
2501 pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
2503 lpfc_printf_log(phba, KERN_ERR,
2504 LOG_MBOX | LOG_VPORT,
2505 "%d:1806 Mbox x%x failed. No vport\n",
2507 pmbox->mb.mbxCommand);
2509 return MBXERR_ERROR;
2514 /* If the PCI channel is in offline state, do not post mbox. */
2515 if (unlikely(pci_channel_offline(phba->pcidev)))
2516 return MBX_NOT_FINISHED;
2518 spin_lock_irqsave(&phba->hbalock, drvr_flag);
2523 status = MBX_SUCCESS;
2525 if (phba->link_state == LPFC_HBA_ERROR) {
2526 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2528 /* Mbox command <mbxCommand> cannot issue */
2529 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag)
2530 return MBX_NOT_FINISHED;
2533 if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
2534 !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
2535 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2536 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag)
2537 return MBX_NOT_FINISHED;
2540 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
2541 /* Polling for a mbox command when another one is already active
2542 * is not allowed in SLI. Also, the driver must have established
2543 * SLI2 mode to queue and process multiple mbox commands.
2546 if (flag & MBX_POLL) {
2547 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2549 /* Mbox command <mbxCommand> cannot issue */
2550 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
2551 return MBX_NOT_FINISHED;
2554 if (!(psli->sli_flag & LPFC_SLI2_ACTIVE)) {
2555 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2556 /* Mbox command <mbxCommand> cannot issue */
2557 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
2558 return MBX_NOT_FINISHED;
2561 /* Handle STOP IOCB processing flag. This is only meaningful
2562 * if we are not polling for mbox completion.
2564 if (flag & MBX_STOP_IOCB) {
2565 flag &= ~MBX_STOP_IOCB;
2566 /* Now flag each ring */
2567 for (i = 0; i < psli->num_rings; i++) {
2568 /* If the ring is active, flag it */
2569 if (psli->ring[i].cmdringaddr) {
2570 psli->ring[i].flag |=
2576 /* Another mailbox command is still being processed, queue this
2577 * command to be processed later.
2579 lpfc_mbox_put(phba, pmbox);
2581 /* Mbox cmd issue - BUSY */
2582 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
2583 "%d (%d):0308 Mbox cmd issue - BUSY Data: "
2584 "x%x x%x x%x x%x\n",
2586 pmbox->vport ? pmbox->vport->vpi : 0xffffff,
2587 mb->mbxCommand, phba->pport->port_state,
2588 psli->sli_flag, flag);
2590 psli->slistat.mbox_busy++;
2591 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2594 lpfc_debugfs_disc_trc(pmbox->vport,
2595 LPFC_DISC_TRC_MBOX_VPORT,
2596 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
2597 (uint32_t)mb->mbxCommand,
2598 mb->un.varWords[0], mb->un.varWords[1]);
2601 lpfc_debugfs_disc_trc(phba->pport,
2603 "MBOX Bsy: cmd:x%x mb:x%x x%x",
2604 (uint32_t)mb->mbxCommand,
2605 mb->un.varWords[0], mb->un.varWords[1]);
2611 /* Handle STOP IOCB processing flag. This is only meaningful
2612 * if we are not polling for mbox completion.
2614 if (flag & MBX_STOP_IOCB) {
2615 flag &= ~MBX_STOP_IOCB;
2616 if (flag == MBX_NOWAIT) {
2617 /* Now flag each ring */
2618 for (i = 0; i < psli->num_rings; i++) {
2619 /* If the ring is active, flag it */
2620 if (psli->ring[i].cmdringaddr) {
2621 psli->ring[i].flag |=
2628 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
2630 /* If we are not polling, we MUST be in SLI2 mode */
2631 if (flag != MBX_POLL) {
2632 if (!(psli->sli_flag & LPFC_SLI2_ACTIVE) &&
2633 (mb->mbxCommand != MBX_KILL_BOARD)) {
2634 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2635 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2636 /* Mbox command <mbxCommand> cannot issue */
2637 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
2638 return MBX_NOT_FINISHED;
2640 /* timeout active mbox command */
2641 mod_timer(&psli->mbox_tmo, (jiffies +
2642 (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
2645 /* Mailbox cmd <cmd> issue */
2646 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
2647 "%d (%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
2649 phba->brd_no, pmbox->vport ? pmbox->vport->vpi : 0,
2650 mb->mbxCommand, phba->pport->port_state,
2651 psli->sli_flag, flag);
2653 if (mb->mbxCommand != MBX_HEARTBEAT) {
2655 lpfc_debugfs_disc_trc(pmbox->vport,
2656 LPFC_DISC_TRC_MBOX_VPORT,
2657 "MBOX Send vport: cmd:x%x mb:x%x x%x",
2658 (uint32_t)mb->mbxCommand,
2659 mb->un.varWords[0], mb->un.varWords[1]);
2662 lpfc_debugfs_disc_trc(phba->pport,
2664 "MBOX Send: cmd:x%x mb:x%x x%x",
2665 (uint32_t)mb->mbxCommand,
2666 mb->un.varWords[0], mb->un.varWords[1]);
2670 psli->slistat.mbox_cmd++;
2671 evtctr = psli->slistat.mbox_event;
2673 /* next set own bit for the adapter and copy over command word */
2674 mb->mbxOwner = OWN_CHIP;
2676 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2677 /* First copy command data to host SLIM area */
2678 lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx, MAILBOX_CMD_SIZE);
2680 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2681 /* copy command data into host mbox for cmpl */
2682 lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx,
2686 /* First copy mbox command data to HBA SLIM, skip past first
2688 to_slim = phba->MBslimaddr + sizeof (uint32_t);
2689 lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
2690 MAILBOX_CMD_SIZE - sizeof (uint32_t));
2692 /* Next copy over first word, with mbxOwner set */
2693 ldata = *((volatile uint32_t *)mb);
2694 to_slim = phba->MBslimaddr;
2695 writel(ldata, to_slim);
2696 readl(to_slim); /* flush */
2698 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2699 /* switch over to host mailbox */
2700 psli->sli_flag |= LPFC_SLI2_ACTIVE;
2705 /* interrupt board to doit right away */
2706 writel(CA_MBATT, phba->CAregaddr);
2707 readl(phba->CAregaddr); /* flush */
2711 /* Don't wait for it to finish, just return */
2712 psli->mbox_active = pmbox;
2716 psli->mbox_active = NULL;
2717 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2718 /* First read mbox status word */
2719 word0 = *((volatile uint32_t *)&phba->slim2p->mbx);
2720 word0 = le32_to_cpu(word0);
2722 /* First read mbox status word */
2723 word0 = readl(phba->MBslimaddr);
2726 /* Read the HBA Host Attention Register */
2727 ha_copy = readl(phba->HAregaddr);
2729 i = lpfc_mbox_tmo_val(phba, mb->mbxCommand);
2730 i *= 1000; /* Convert to ms */
2732 /* Wait for command to complete */
2733 while (((word0 & OWN_CHIP) == OWN_CHIP) ||
2734 (!(ha_copy & HA_MBATT) &&
2735 (phba->link_state > LPFC_WARM_START))) {
2737 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2738 spin_unlock_irqrestore(&phba->hbalock,
2740 return MBX_NOT_FINISHED;
2743 /* Check if we took a mbox interrupt while we were
2745 if (((word0 & OWN_CHIP) != OWN_CHIP)
2746 && (evtctr != psli->slistat.mbox_event))
2749 spin_unlock_irqrestore(&phba->hbalock,
2754 spin_lock_irqsave(&phba->hbalock, drvr_flag);
2756 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2757 /* First copy command data */
2758 word0 = *((volatile uint32_t *)
2759 &phba->slim2p->mbx);
2760 word0 = le32_to_cpu(word0);
2761 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2763 volatile uint32_t slimword0;
2764 /* Check real SLIM for any errors */
2765 slimword0 = readl(phba->MBslimaddr);
2766 slimmb = (MAILBOX_t *) & slimword0;
2767 if (((slimword0 & OWN_CHIP) != OWN_CHIP)
2768 && slimmb->mbxStatus) {
2775 /* First copy command data */
2776 word0 = readl(phba->MBslimaddr);
2778 /* Read the HBA Host Attention Register */
2779 ha_copy = readl(phba->HAregaddr);
2782 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2783 /* copy results back to user */
2784 lpfc_sli_pcimem_bcopy(&phba->slim2p->mbx, mb,
2787 /* First copy command data */
2788 lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
2790 if ((mb->mbxCommand == MBX_DUMP_MEMORY) &&
2792 lpfc_memcpy_from_slim((void *)pmbox->context2,
2793 phba->MBslimaddr + DMP_RSP_OFFSET,
2794 mb->un.varDmp.word_cnt);
2798 writel(HA_MBATT, phba->HAregaddr);
2799 readl(phba->HAregaddr); /* flush */
2801 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2802 status = mb->mbxStatus;
2805 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2810 * Caller needs to hold lock.
2813 __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2814 struct lpfc_iocbq *piocb)
2816 /* Insert the caller's iocb in the txq tail for later processing. */
2817 list_add_tail(&piocb->list, &pring->txq);
2821 static struct lpfc_iocbq *
2822 lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2823 struct lpfc_iocbq **piocb)
2825 struct lpfc_iocbq * nextiocb;
2827 nextiocb = lpfc_sli_ringtx_get(phba, pring);
2837 * Lockless version of lpfc_sli_issue_iocb.
2840 __lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2841 struct lpfc_iocbq *piocb, uint32_t flag)
2843 struct lpfc_iocbq *nextiocb;
2846 if (piocb->iocb_cmpl && (!piocb->vport) &&
2847 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
2848 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
2849 lpfc_printf_log(phba, KERN_ERR,
2850 LOG_SLI | LOG_VPORT,
2851 "%d:1807 IOCB x%x failed. No vport\n",
2853 piocb->iocb.ulpCommand);
2859 /* If the PCI channel is in offline state, do not post iocbs. */
2860 if (unlikely(pci_channel_offline(phba->pcidev)))
2864 * We should never get an IOCB if we are in a < LINK_DOWN state
2866 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
2870 * Check to see if we are blocking IOCB processing because of a
2871 * outstanding mbox command.
2873 if (unlikely(pring->flag & LPFC_STOP_IOCB_MBX))
2876 if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
2878 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
2879 * can be issued if the link is not up.
2881 switch (piocb->iocb.ulpCommand) {
2882 case CMD_QUE_RING_BUF_CN:
2883 case CMD_QUE_RING_BUF64_CN:
2885 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
2886 * completion, iocb_cmpl MUST be 0.
2888 if (piocb->iocb_cmpl)
2889 piocb->iocb_cmpl = NULL;
2891 case CMD_CREATE_XRI_CR:
2892 case CMD_CLOSE_XRI_CN:
2893 case CMD_CLOSE_XRI_CX:
2900 * For FCP commands, we must be in a state where we can process link
2903 } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
2904 !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
2908 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
2909 (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
2910 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
2913 lpfc_sli_update_ring(phba, pring);
2915 lpfc_sli_update_full_ring(phba, pring);
2918 return IOCB_SUCCESS;
2923 pring->stats.iocb_cmd_delay++;
2927 if (!(flag & SLI_IOCB_RET_IOCB)) {
2928 __lpfc_sli_ringtx_put(phba, pring, piocb);
2929 return IOCB_SUCCESS;
2937 lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2938 struct lpfc_iocbq *piocb, uint32_t flag)
2940 unsigned long iflags;
2943 spin_lock_irqsave(&phba->hbalock, iflags);
2944 rc = __lpfc_sli_issue_iocb(phba, pring, piocb, flag);
2945 spin_unlock_irqrestore(&phba->hbalock, iflags);
2951 lpfc_extra_ring_setup( struct lpfc_hba *phba)
2953 struct lpfc_sli *psli;
2954 struct lpfc_sli_ring *pring;
2958 /* Adjust cmd/rsp ring iocb entries more evenly */
2960 /* Take some away from the FCP ring */
2961 pring = &psli->ring[psli->fcp_ring];
2962 pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
2963 pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
2964 pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
2965 pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
2967 /* and give them to the extra ring */
2968 pring = &psli->ring[psli->extra_ring];
2970 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
2971 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
2972 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
2973 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
2975 /* Setup default profile for this ring */
2976 pring->iotag_max = 4096;
2977 pring->num_mask = 1;
2978 pring->prt[0].profile = 0; /* Mask 0 */
2979 pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
2980 pring->prt[0].type = phba->cfg_multi_ring_type;
2981 pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
2986 lpfc_sli_setup(struct lpfc_hba *phba)
2988 int i, totiocbsize = 0;
2989 struct lpfc_sli *psli = &phba->sli;
2990 struct lpfc_sli_ring *pring;
2992 psli->num_rings = MAX_CONFIGURED_RINGS;
2994 psli->fcp_ring = LPFC_FCP_RING;
2995 psli->next_ring = LPFC_FCP_NEXT_RING;
2996 psli->extra_ring = LPFC_EXTRA_RING;
2998 psli->iocbq_lookup = NULL;
2999 psli->iocbq_lookup_len = 0;
3000 psli->last_iotag = 0;
3002 for (i = 0; i < psli->num_rings; i++) {
3003 pring = &psli->ring[i];
3005 case LPFC_FCP_RING: /* ring 0 - FCP */
3006 /* numCiocb and numRiocb are used in config_port */
3007 pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
3008 pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
3009 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
3010 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
3011 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
3012 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
3013 pring->sizeCiocb = (phba->sli_rev == 3) ?
3014 SLI3_IOCB_CMD_SIZE :
3016 pring->sizeRiocb = (phba->sli_rev == 3) ?
3017 SLI3_IOCB_RSP_SIZE :
3019 pring->iotag_ctr = 0;
3021 (phba->cfg_hba_queue_depth * 2);
3022 pring->fast_iotag = pring->iotag_max;
3023 pring->num_mask = 0;
3025 case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
3026 /* numCiocb and numRiocb are used in config_port */
3027 pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
3028 pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
3029 pring->sizeCiocb = (phba->sli_rev == 3) ?
3030 SLI3_IOCB_CMD_SIZE :
3032 pring->sizeRiocb = (phba->sli_rev == 3) ?
3033 SLI3_IOCB_RSP_SIZE :
3035 pring->iotag_max = phba->cfg_hba_queue_depth;
3036 pring->num_mask = 0;
3038 case LPFC_ELS_RING: /* ring 2 - ELS / CT */
3039 /* numCiocb and numRiocb are used in config_port */
3040 pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
3041 pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
3042 pring->sizeCiocb = (phba->sli_rev == 3) ?
3043 SLI3_IOCB_CMD_SIZE :
3045 pring->sizeRiocb = (phba->sli_rev == 3) ?
3046 SLI3_IOCB_RSP_SIZE :
3048 pring->fast_iotag = 0;
3049 pring->iotag_ctr = 0;
3050 pring->iotag_max = 4096;
3051 pring->num_mask = 4;
3052 pring->prt[0].profile = 0; /* Mask 0 */
3053 pring->prt[0].rctl = FC_ELS_REQ;
3054 pring->prt[0].type = FC_ELS_DATA;
3055 pring->prt[0].lpfc_sli_rcv_unsol_event =
3056 lpfc_els_unsol_event;
3057 pring->prt[1].profile = 0; /* Mask 1 */
3058 pring->prt[1].rctl = FC_ELS_RSP;
3059 pring->prt[1].type = FC_ELS_DATA;
3060 pring->prt[1].lpfc_sli_rcv_unsol_event =
3061 lpfc_els_unsol_event;
3062 pring->prt[2].profile = 0; /* Mask 2 */
3063 /* NameServer Inquiry */
3064 pring->prt[2].rctl = FC_UNSOL_CTL;
3066 pring->prt[2].type = FC_COMMON_TRANSPORT_ULP;
3067 pring->prt[2].lpfc_sli_rcv_unsol_event =
3068 lpfc_ct_unsol_event;
3069 pring->prt[3].profile = 0; /* Mask 3 */
3070 /* NameServer response */
3071 pring->prt[3].rctl = FC_SOL_CTL;
3073 pring->prt[3].type = FC_COMMON_TRANSPORT_ULP;
3074 pring->prt[3].lpfc_sli_rcv_unsol_event =
3075 lpfc_ct_unsol_event;
3078 totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
3079 (pring->numRiocb * pring->sizeRiocb);
3081 if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
3082 /* Too many cmd / rsp ring entries in SLI2 SLIM */
3083 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3084 "%d:0462 Too many cmd / rsp ring entries in "
3085 "SLI2 SLIM Data: x%x x%lx\n",
3086 phba->brd_no, totiocbsize,
3087 (unsigned long) MAX_SLIM_IOCB_SIZE);
3089 if (phba->cfg_multi_ring_support == 2)
3090 lpfc_extra_ring_setup(phba);
3096 lpfc_sli_queue_setup(struct lpfc_hba *phba)
3098 struct lpfc_sli *psli;
3099 struct lpfc_sli_ring *pring;
3103 spin_lock_irq(&phba->hbalock);
3104 INIT_LIST_HEAD(&psli->mboxq);
3105 INIT_LIST_HEAD(&psli->mboxq_cmpl);
3106 /* Initialize list headers for txq and txcmplq as double linked lists */
3107 for (i = 0; i < psli->num_rings; i++) {
3108 pring = &psli->ring[i];
3110 pring->next_cmdidx = 0;
3111 pring->local_getidx = 0;
3113 INIT_LIST_HEAD(&pring->txq);
3114 INIT_LIST_HEAD(&pring->txcmplq);
3115 INIT_LIST_HEAD(&pring->iocb_continueq);
3116 INIT_LIST_HEAD(&pring->postbufq);
3118 spin_unlock_irq(&phba->hbalock);
3123 lpfc_sli_host_down(struct lpfc_vport *vport)
3125 LIST_HEAD(completions);
3126 struct lpfc_hba *phba = vport->phba;
3127 struct lpfc_sli *psli = &phba->sli;
3128 struct lpfc_sli_ring *pring;
3129 struct lpfc_iocbq *iocb, *next_iocb;
3131 unsigned long flags = 0;
3132 uint16_t prev_pring_flag;
3134 lpfc_cleanup_discovery_resources(vport);
3136 spin_lock_irqsave(&phba->hbalock, flags);
3137 for (i = 0; i < psli->num_rings; i++) {
3138 pring = &psli->ring[i];
3139 prev_pring_flag = pring->flag;
3140 if (pring->ringno == LPFC_ELS_RING) /* Only slow rings */
3141 pring->flag |= LPFC_DEFERRED_RING_EVENT;
3143 * Error everything on the txq since these iocbs have not been
3144 * given to the FW yet.
3146 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
3147 if (iocb->vport != vport)
3149 list_move_tail(&iocb->list, &completions);
3153 /* Next issue ABTS for everything on the txcmplq */
3154 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
3156 if (iocb->vport != vport)
3158 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
3161 pring->flag = prev_pring_flag;
3164 spin_unlock_irqrestore(&phba->hbalock, flags);
3166 while (!list_empty(&completions)) {
3167 list_remove_head(&completions, iocb, struct lpfc_iocbq, list);
3169 if (!iocb->iocb_cmpl)
3170 lpfc_sli_release_iocbq(phba, iocb);
3172 iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
3173 iocb->iocb.un.ulpWord[4] = IOERR_SLI_DOWN;
3174 (iocb->iocb_cmpl) (phba, iocb, iocb);
3181 lpfc_sli_hba_down(struct lpfc_hba *phba)
3183 LIST_HEAD(completions);
3184 struct lpfc_sli *psli = &phba->sli;
3185 struct lpfc_sli_ring *pring;
3187 struct lpfc_iocbq *iocb;
3190 unsigned long flags = 0;
3192 lpfc_hba_down_prep(phba);
3194 lpfc_fabric_abort_hba(phba);
3196 spin_lock_irqsave(&phba->hbalock, flags);
3197 for (i = 0; i < psli->num_rings; i++) {
3198 pring = &psli->ring[i];
3199 if (pring->ringno == LPFC_ELS_RING) /* Only slow rings */
3200 pring->flag |= LPFC_DEFERRED_RING_EVENT;
3203 * Error everything on the txq since these iocbs have not been
3204 * given to the FW yet.
3206 list_splice_init(&pring->txq, &completions);
3210 spin_unlock_irqrestore(&phba->hbalock, flags);
3212 while (!list_empty(&completions)) {
3213 list_remove_head(&completions, iocb, struct lpfc_iocbq, list);
3216 if (!iocb->iocb_cmpl)
3217 lpfc_sli_release_iocbq(phba, iocb);
3219 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3220 cmd->un.ulpWord[4] = IOERR_SLI_DOWN;
3221 (iocb->iocb_cmpl) (phba, iocb, iocb);
3225 /* Return any active mbox cmds */
3226 del_timer_sync(&psli->mbox_tmo);
3227 spin_lock_irqsave(&phba->hbalock, flags);
3229 spin_lock(&phba->pport->work_port_lock);
3230 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
3231 spin_unlock(&phba->pport->work_port_lock);
3233 if (psli->mbox_active) {
3234 list_add_tail(&psli->mbox_active->list, &completions);
3235 psli->mbox_active = NULL;
3236 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
3239 /* Return any pending or completed mbox cmds */
3240 list_splice_init(&phba->sli.mboxq, &completions);
3241 list_splice_init(&phba->sli.mboxq_cmpl, &completions);
3242 INIT_LIST_HEAD(&psli->mboxq);
3243 INIT_LIST_HEAD(&psli->mboxq_cmpl);
3245 spin_unlock_irqrestore(&phba->hbalock, flags);
3247 while (!list_empty(&completions)) {
3248 list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
3249 pmb->mb.mbxStatus = MBX_NOT_FINISHED;
3250 if (pmb->mbox_cmpl) {
3251 pmb->mbox_cmpl(phba,pmb);
3258 lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
3260 uint32_t *src = srcp;
3261 uint32_t *dest = destp;
3265 for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
3267 ldata = le32_to_cpu(ldata);
3275 lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3276 struct lpfc_dmabuf *mp)
3278 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
3280 spin_lock_irq(&phba->hbalock);
3281 list_add_tail(&mp->list, &pring->postbufq);
3282 pring->postbufq_cnt++;
3283 spin_unlock_irq(&phba->hbalock);
3288 struct lpfc_dmabuf *
3289 lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3292 struct lpfc_dmabuf *mp, *next_mp;
3293 struct list_head *slp = &pring->postbufq;
3295 /* Search postbufq, from the begining, looking for a match on phys */
3296 spin_lock_irq(&phba->hbalock);
3297 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
3298 if (mp->phys == phys) {
3299 list_del_init(&mp->list);
3300 pring->postbufq_cnt--;
3301 spin_unlock_irq(&phba->hbalock);
3306 spin_unlock_irq(&phba->hbalock);
3307 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3308 "%d:0410 Cannot find virtual addr for mapped buf on "
3309 "ring %d Data x%llx x%p x%p x%x\n",
3310 phba->brd_no, pring->ringno, (unsigned long long)phys,
3311 slp->next, slp->prev, pring->postbufq_cnt);
3316 lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3317 struct lpfc_iocbq *rspiocb)
3319 IOCB_t *irsp = &rspiocb->iocb;
3320 uint16_t abort_iotag, abort_context;
3321 struct lpfc_iocbq *abort_iocb;
3322 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
3326 if (irsp->ulpStatus) {
3327 abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
3328 abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
3330 spin_lock_irq(&phba->hbalock);
3331 if (abort_iotag != 0 && abort_iotag <= phba->sli.last_iotag)
3332 abort_iocb = phba->sli.iocbq_lookup[abort_iotag];
3334 lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI,
3335 "%d:0327 Cannot abort els iocb %p "
3336 "with tag %x context %x, abort status %x, "
3338 phba->brd_no, abort_iocb, abort_iotag,
3339 abort_context, irsp->ulpStatus,
3340 irsp->un.ulpWord[4]);
3343 * make sure we have the right iocbq before taking it
3344 * off the txcmplq and try to call completion routine.
3347 abort_iocb->iocb.ulpContext != abort_context ||
3348 (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
3349 spin_unlock_irq(&phba->hbalock);
3351 list_del_init(&abort_iocb->list);
3352 pring->txcmplq_cnt--;
3353 spin_unlock_irq(&phba->hbalock);
3355 abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
3356 abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
3357 abort_iocb->iocb.un.ulpWord[4] = IOERR_SLI_ABORTED;
3358 (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
3362 lpfc_sli_release_iocbq(phba, cmdiocb);
3367 lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3368 struct lpfc_iocbq *rspiocb)
3370 IOCB_t *irsp = &rspiocb->iocb;
3372 /* ELS cmd tag <ulpIoTag> completes */
3373 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
3374 "%d (X):0133 Ignoring ELS cmd tag x%x completion Data: "
3376 phba->brd_no, irsp->ulpIoTag, irsp->ulpStatus,
3377 irsp->un.ulpWord[4], irsp->ulpTimeout);
3378 if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
3379 lpfc_ct_free_iocb(phba, cmdiocb);
3381 lpfc_els_free_iocb(phba, cmdiocb);
3386 lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3387 struct lpfc_iocbq *cmdiocb)
3389 struct lpfc_vport *vport = cmdiocb->vport;
3390 struct lpfc_iocbq *abtsiocbp;
3391 IOCB_t *icmd = NULL;
3392 IOCB_t *iabt = NULL;
3393 int retval = IOCB_ERROR;
3396 * There are certain command types we don't want to abort. And we
3397 * don't want to abort commands that are already in the process of
3400 icmd = &cmdiocb->iocb;
3401 if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
3402 icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
3403 (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
3406 /* If we're unloading, don't abort iocb on the ELS ring, but change the
3407 * callback so that nothing happens when it finishes.
3409 if ((vport->load_flag & FC_UNLOADING) &&
3410 (pring->ringno == LPFC_ELS_RING)) {
3411 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
3412 cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
3414 cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
3415 goto abort_iotag_exit;
3418 /* issue ABTS for this IOCB based on iotag */
3419 abtsiocbp = __lpfc_sli_get_iocbq(phba);
3420 if (abtsiocbp == NULL)
3423 /* This signals the response to set the correct status
3424 * before calling the completion handler.
3426 cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
3428 iabt = &abtsiocbp->iocb;
3429 iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
3430 iabt->un.acxri.abortContextTag = icmd->ulpContext;
3431 iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
3433 iabt->ulpClass = icmd->ulpClass;
3435 if (phba->link_state >= LPFC_LINK_UP)
3436 iabt->ulpCommand = CMD_ABORT_XRI_CN;
3438 iabt->ulpCommand = CMD_CLOSE_XRI_CN;
3440 abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
3442 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3443 "%d (%d):0339 Abort xri x%x, original iotag x%x, "
3444 "abort cmd iotag x%x\n",
3445 phba->brd_no, vport->vpi,
3446 iabt->un.acxri.abortContextTag,
3447 iabt->un.acxri.abortIoTag, abtsiocbp->iotag);
3448 retval = __lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0);
3452 * Caller to this routine should check for IOCB_ERROR
3453 * and handle it properly. This routine no longer removes
3454 * iocb off txcmplq and call compl in case of IOCB_ERROR.
3460 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, uint16_t tgt_id,
3461 uint64_t lun_id, uint32_t ctx,
3462 lpfc_ctx_cmd ctx_cmd)
3464 struct lpfc_scsi_buf *lpfc_cmd;
3465 struct scsi_cmnd *cmnd;
3468 if (!(iocbq->iocb_flag & LPFC_IO_FCP))
3471 lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
3472 cmnd = lpfc_cmd->pCmd;
3479 if ((cmnd->device->id == tgt_id) &&
3480 (cmnd->device->lun == lun_id))
3484 if (cmnd->device->id == tgt_id)
3488 if (iocbq->iocb.ulpContext == ctx)
3495 printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
3496 __FUNCTION__, ctx_cmd);
3504 lpfc_sli_sum_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3505 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd ctx_cmd)
3507 struct lpfc_iocbq *iocbq;
3510 for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
3511 iocbq = phba->sli.iocbq_lookup[i];
3513 if (lpfc_sli_validate_fcp_iocb (iocbq, tgt_id, lun_id,
3522 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3523 struct lpfc_iocbq *rspiocb)
3525 lpfc_sli_release_iocbq(phba, cmdiocb);
3530 lpfc_sli_abort_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3531 uint16_t tgt_id, uint64_t lun_id, uint32_t ctx,
3532 lpfc_ctx_cmd abort_cmd)
3534 struct lpfc_iocbq *iocbq;
3535 struct lpfc_iocbq *abtsiocb;
3537 int errcnt = 0, ret_val = 0;
3540 for (i = 1; i <= phba->sli.last_iotag; i++) {
3541 iocbq = phba->sli.iocbq_lookup[i];
3543 if (lpfc_sli_validate_fcp_iocb(iocbq, tgt_id, lun_id, 0,
3547 /* issue ABTS for this IOCB based on iotag */
3548 abtsiocb = lpfc_sli_get_iocbq(phba);
3549 if (abtsiocb == NULL) {
3555 abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
3556 abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
3557 abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
3558 abtsiocb->iocb.ulpLe = 1;
3559 abtsiocb->iocb.ulpClass = cmd->ulpClass;
3560 abtsiocb->vport = phba->pport;
3562 if (lpfc_is_link_up(phba))
3563 abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
3565 abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
3567 /* Setup callback routine and issue the command. */
3568 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
3569 ret_val = lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0);
3570 if (ret_val == IOCB_ERROR) {
3571 lpfc_sli_release_iocbq(phba, abtsiocb);
3581 lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
3582 struct lpfc_iocbq *cmdiocbq,
3583 struct lpfc_iocbq *rspiocbq)
3585 wait_queue_head_t *pdone_q;
3586 unsigned long iflags;
3588 spin_lock_irqsave(&phba->hbalock, iflags);
3589 cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
3590 if (cmdiocbq->context2 && rspiocbq)
3591 memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
3592 &rspiocbq->iocb, sizeof(IOCB_t));
3594 pdone_q = cmdiocbq->context_un.wait_queue;
3597 spin_unlock_irqrestore(&phba->hbalock, iflags);
3602 * Issue the caller's iocb and wait for its completion, but no longer than the
3603 * caller's timeout. Note that iocb_flags is cleared before the
3604 * lpfc_sli_issue_call since the wake routine sets a unique value and by
3605 * definition this is a wait function.
3609 lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
3610 struct lpfc_sli_ring *pring,
3611 struct lpfc_iocbq *piocb,
3612 struct lpfc_iocbq *prspiocbq,
3615 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
3616 long timeleft, timeout_req = 0;
3617 int retval = IOCB_SUCCESS;
3621 * If the caller has provided a response iocbq buffer, then context2
3622 * is NULL or its an error.
3625 if (piocb->context2)
3627 piocb->context2 = prspiocbq;
3630 piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
3631 piocb->context_un.wait_queue = &done_q;
3632 piocb->iocb_flag &= ~LPFC_IO_WAKE;
3634 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
3635 creg_val = readl(phba->HCregaddr);
3636 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
3637 writel(creg_val, phba->HCregaddr);
3638 readl(phba->HCregaddr); /* flush */
3641 retval = lpfc_sli_issue_iocb(phba, pring, piocb, 0);
3642 if (retval == IOCB_SUCCESS) {
3643 timeout_req = timeout * HZ;
3644 timeleft = wait_event_timeout(done_q,
3645 piocb->iocb_flag & LPFC_IO_WAKE,
3648 if (piocb->iocb_flag & LPFC_IO_WAKE) {
3649 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3650 "%d:0331 IOCB wake signaled\n",
3652 } else if (timeleft == 0) {
3653 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3654 "%d:0338 IOCB wait timeout error - no "
3655 "wake response Data x%x\n",
3656 phba->brd_no, timeout);
3657 retval = IOCB_TIMEDOUT;
3659 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3660 "%d:0330 IOCB wake NOT set, "
3661 "Data x%x x%lx\n", phba->brd_no,
3662 timeout, (timeleft / jiffies));
3663 retval = IOCB_TIMEDOUT;
3666 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3667 "%d:0332 IOCB wait issue failed, Data x%x\n",
3668 phba->brd_no, retval);
3669 retval = IOCB_ERROR;
3672 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
3673 creg_val = readl(phba->HCregaddr);
3674 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
3675 writel(creg_val, phba->HCregaddr);
3676 readl(phba->HCregaddr); /* flush */
3680 piocb->context2 = NULL;
3682 piocb->context_un.wait_queue = NULL;
3683 piocb->iocb_cmpl = NULL;
3688 lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
3691 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
3695 /* The caller must leave context1 empty. */
3696 if (pmboxq->context1 != 0)
3697 return MBX_NOT_FINISHED;
3699 /* setup wake call as IOCB callback */
3700 pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
3701 /* setup context field to pass wait_queue pointer to wake function */
3702 pmboxq->context1 = &done_q;
3704 /* now issue the command */
3705 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
3707 if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
3708 wait_event_interruptible_timeout(done_q,
3709 pmboxq->mbox_flag & LPFC_MBX_WAKE,
3712 spin_lock_irqsave(&phba->hbalock, flag);
3713 pmboxq->context1 = NULL;
3715 * if LPFC_MBX_WAKE flag is set the mailbox is completed
3716 * else do not free the resources.
3718 if (pmboxq->mbox_flag & LPFC_MBX_WAKE)
3719 retval = MBX_SUCCESS;
3721 retval = MBX_TIMEOUT;
3722 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3724 spin_unlock_irqrestore(&phba->hbalock, flag);
3731 lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba)
3733 struct lpfc_vport *vport = phba->pport;
3737 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE && !vport->stopped) {
3738 if (i++ > LPFC_MBOX_TMO * 1000)
3742 * Call lpfc_sli_handle_mb_event only if a mailbox cmd
3743 * did finish. This way we won't get the misleading
3744 * "Stray Mailbox Interrupt" message.
3746 spin_lock_irq(&phba->hbalock);
3747 ha_copy = phba->work_ha;
3748 phba->work_ha &= ~HA_MBATT;
3749 spin_unlock_irq(&phba->hbalock);
3751 if (ha_copy & HA_MBATT)
3752 if (lpfc_sli_handle_mb_event(phba) == 0)
3758 return (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) ? 1 : 0;
3762 lpfc_intr_handler(int irq, void *dev_id)
3764 struct lpfc_hba *phba;
3766 uint32_t work_ha_copy;
3767 unsigned long status;
3771 MAILBOX_t *mbox, *pmbox;
3772 struct lpfc_vport *vport;
3773 struct lpfc_nodelist *ndlp;
3774 struct lpfc_dmabuf *mp;
3779 * Get the driver's phba structure from the dev_id and
3780 * assume the HBA is not interrupting.
3782 phba = (struct lpfc_hba *) dev_id;
3784 if (unlikely(!phba))
3787 /* If the pci channel is offline, ignore all the interrupts. */
3788 if (unlikely(pci_channel_offline(phba->pcidev)))
3791 phba->sli.slistat.sli_intr++;
3794 * Call the HBA to see if it is interrupting. If not, don't claim
3798 /* Ignore all interrupts during initialization. */
3799 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
3803 * Read host attention register to determine interrupt source
3804 * Clear Attention Sources, except Error Attention (to
3805 * preserve status) and Link Attention
3807 spin_lock(&phba->hbalock);
3808 ha_copy = readl(phba->HAregaddr);
3809 /* If somebody is waiting to handle an eratt don't process it
3810 * here. The brdkill function will do this.
3812 if (phba->link_flag & LS_IGNORE_ERATT)
3813 ha_copy &= ~HA_ERATT;
3814 writel((ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
3815 readl(phba->HAregaddr); /* flush */
3816 spin_unlock(&phba->hbalock);
3818 if (unlikely(!ha_copy))
3821 work_ha_copy = ha_copy & phba->work_ha_mask;
3823 if (unlikely(work_ha_copy)) {
3824 if (work_ha_copy & HA_LATT) {
3825 if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
3827 * Turn off Link Attention interrupts
3828 * until CLEAR_LA done
3830 spin_lock(&phba->hbalock);
3831 phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
3832 control = readl(phba->HCregaddr);
3833 control &= ~HC_LAINT_ENA;
3834 writel(control, phba->HCregaddr);
3835 readl(phba->HCregaddr); /* flush */
3836 spin_unlock(&phba->hbalock);
3839 work_ha_copy &= ~HA_LATT;
3842 if (work_ha_copy & ~(HA_ERATT|HA_MBATT|HA_LATT)) {
3844 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
3845 * the only slow ring.
3847 status = (work_ha_copy &
3848 (HA_RXMASK << (4*LPFC_ELS_RING)));
3849 status >>= (4*LPFC_ELS_RING);
3850 if (status & HA_RXMASK) {
3851 spin_lock(&phba->hbalock);
3852 control = readl(phba->HCregaddr);
3853 if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
3855 ~(HC_R0INT_ENA << LPFC_ELS_RING);
3856 writel(control, phba->HCregaddr);
3857 readl(phba->HCregaddr); /* flush */
3859 spin_unlock(&phba->hbalock);
3863 if (work_ha_copy & HA_ERATT) {
3864 phba->link_state = LPFC_HBA_ERROR;
3866 * There was a link/board error. Read the
3867 * status register to retrieve the error event
3870 phba->sli.slistat.err_attn_event++;
3871 /* Save status info */
3872 phba->work_hs = readl(phba->HSregaddr);
3873 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
3874 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
3876 /* Clear Chip error bit */
3877 writel(HA_ERATT, phba->HAregaddr);
3878 readl(phba->HAregaddr); /* flush */
3879 phba->pport->stopped = 1;
3882 if ((work_ha_copy & HA_MBATT) &&
3883 (phba->sli.mbox_active)) {
3884 pmb = phba->sli.mbox_active;
3886 mbox = &phba->slim2p->mbx;
3889 /* First check out the status word */
3890 lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
3891 if (pmbox->mbxOwner != OWN_HOST) {
3893 * Stray Mailbox Interrupt, mbxCommand <cmd>
3894 * mbxStatus <status>
3896 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX |
3898 "%d (%d):0304 Stray Mailbox "
3899 "Interrupt mbxCommand x%x "
3907 phba->last_completion_time = jiffies;
3908 del_timer_sync(&phba->sli.mbox_tmo);
3910 phba->sli.mbox_active = NULL;
3911 if (pmb->mbox_cmpl) {
3912 lpfc_sli_pcimem_bcopy(mbox, pmbox,
3915 if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
3916 pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
3918 lpfc_debugfs_disc_trc(vport,
3919 LPFC_DISC_TRC_MBOX_VPORT,
3920 "MBOX dflt rpi: : status:x%x rpi:x%x",
3921 (uint32_t)pmbox->mbxStatus,
3922 pmbox->un.varWords[0], 0);
3924 if ( !pmbox->mbxStatus) {
3925 mp = (struct lpfc_dmabuf *)
3927 ndlp = (struct lpfc_nodelist *)
3930 /* Reg_LOGIN of dflt RPI was successful.
3931 * new lets get rid of the RPI using the
3934 lpfc_unreg_login(phba, vport->vpi,
3935 pmbox->un.varWords[0], pmb);
3936 pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3938 pmb->context2 = ndlp;
3940 spin_lock(&phba->hbalock);
3941 phba->sli.sli_flag &=
3942 ~LPFC_SLI_MBOX_ACTIVE;
3943 spin_unlock(&phba->hbalock);
3944 goto send_current_mbox;
3947 spin_lock(&phba->pport->work_port_lock);
3948 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
3949 spin_unlock(&phba->pport->work_port_lock);
3950 lpfc_mbox_cmpl_put(phba, pmb);
3952 if ((work_ha_copy & HA_MBATT) &&
3953 (phba->sli.mbox_active == NULL)) {
3955 spin_lock(&phba->hbalock);
3956 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
3957 pmb = lpfc_mbox_get(phba);
3958 spin_unlock(&phba->hbalock);
3960 /* Process next mailbox command if there is one */
3962 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
3963 if (rc == MBX_NOT_FINISHED) {
3964 pmb->mb.mbxStatus = MBX_NOT_FINISHED;
3965 lpfc_mbox_cmpl_put(phba, pmb);
3966 goto send_next_mbox;
3969 /* Turn on IOCB processing */
3970 for (i = 0; i < phba->sli.num_rings; i++)
3971 lpfc_sli_turn_on_ring(phba, i);
3976 spin_lock(&phba->hbalock);
3977 phba->work_ha |= work_ha_copy;
3978 if (phba->work_wait)
3979 lpfc_worker_wake_up(phba);
3980 spin_unlock(&phba->hbalock);
3983 ha_copy &= ~(phba->work_ha_mask);
3986 * Process all events on FCP ring. Take the optimized path for
3987 * FCP IO. Any other IO is slow path and is handled by
3988 * the worker thread.
3990 status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
3991 status >>= (4*LPFC_FCP_RING);
3992 if (status & HA_RXMASK)
3993 lpfc_sli_handle_fast_ring_event(phba,
3994 &phba->sli.ring[LPFC_FCP_RING],
3997 if (phba->cfg_multi_ring_support == 2) {
3999 * Process all events on extra ring. Take the optimized path
4000 * for extra ring IO. Any other IO is slow path and is handled
4001 * by the worker thread.
4003 status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
4004 status >>= (4*LPFC_EXTRA_RING);
4005 if (status & HA_RXMASK) {
4006 lpfc_sli_handle_fast_ring_event(phba,
4007 &phba->sli.ring[LPFC_EXTRA_RING],
4013 } /* lpfc_intr_handler */