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;
398 if (pring->ringno == LPFC_ELS_RING) {
399 lpfc_debugfs_slow_ring_trc(phba,
400 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
401 *(((uint32_t *) &nextiocb->iocb) + 4),
402 *(((uint32_t *) &nextiocb->iocb) + 6),
403 *(((uint32_t *) &nextiocb->iocb) + 7));
407 * Issue iocb command to adapter
409 lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
411 pring->stats.iocb_cmd++;
414 * If there is no completion routine to call, we can release the
415 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
416 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
418 if (nextiocb->iocb_cmpl)
419 lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
421 __lpfc_sli_release_iocbq(phba, nextiocb);
424 * Let the HBA know what IOCB slot will be the next one the
425 * driver will put a command into.
427 pring->cmdidx = pring->next_cmdidx;
428 writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
432 lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
434 int ringno = pring->ringno;
436 pring->flag |= LPFC_CALL_RING_AVAILABLE;
441 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
442 * The HBA will tell us when an IOCB entry is available.
444 writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
445 readl(phba->CAregaddr); /* flush */
447 pring->stats.iocb_cmd_full++;
451 lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
453 int ringno = pring->ringno;
456 * Tell the HBA that there is work to do in this ring.
459 writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
460 readl(phba->CAregaddr); /* flush */
464 lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
467 struct lpfc_iocbq *nextiocb;
471 * (a) there is anything on the txq to send
473 * (c) link attention events can be processed (fcp ring only)
474 * (d) IOCB processing is not blocked by the outstanding mbox command.
476 if (pring->txq_cnt &&
477 lpfc_is_link_up(phba) &&
478 (pring->ringno != phba->sli.fcp_ring ||
479 phba->sli.sli_flag & LPFC_PROCESS_LA) &&
480 !(pring->flag & LPFC_STOP_IOCB_MBX)) {
482 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
483 (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
484 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
487 lpfc_sli_update_ring(phba, pring);
489 lpfc_sli_update_full_ring(phba, pring);
495 /* lpfc_sli_turn_on_ring is only called by lpfc_sli_handle_mb_event below */
497 lpfc_sli_turn_on_ring(struct lpfc_hba *phba, int ringno)
499 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
500 &phba->slim2p->mbx.us.s3_pgp.port[ringno] :
501 &phba->slim2p->mbx.us.s2.port[ringno];
502 unsigned long iflags;
504 /* If the ring is active, flag it */
505 spin_lock_irqsave(&phba->hbalock, iflags);
506 if (phba->sli.ring[ringno].cmdringaddr) {
507 if (phba->sli.ring[ringno].flag & LPFC_STOP_IOCB_MBX) {
508 phba->sli.ring[ringno].flag &= ~LPFC_STOP_IOCB_MBX;
510 * Force update of the local copy of cmdGetInx
512 phba->sli.ring[ringno].local_getidx
513 = le32_to_cpu(pgp->cmdGetInx);
514 lpfc_sli_resume_iocb(phba, &phba->sli.ring[ringno]);
517 spin_unlock_irqrestore(&phba->hbalock, iflags);
520 struct lpfc_hbq_entry *
521 lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
523 struct hbq_s *hbqp = &phba->hbqs[hbqno];
525 if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
526 ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
527 hbqp->next_hbqPutIdx = 0;
529 if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
530 uint32_t raw_index = phba->hbq_get[hbqno];
531 uint32_t getidx = le32_to_cpu(raw_index);
533 hbqp->local_hbqGetIdx = getidx;
535 if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
536 lpfc_printf_log(phba, KERN_ERR,
538 "%d:1802 HBQ %d: local_hbqGetIdx "
539 "%u is > than hbqp->entry_count %u\n",
541 hbqp->local_hbqGetIdx,
544 phba->link_state = LPFC_HBA_ERROR;
548 if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
552 return (struct lpfc_hbq_entry *) phba->hbqslimp.virt + hbqp->hbqPutIdx;
556 lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
558 struct lpfc_dmabuf *dmabuf, *next_dmabuf;
559 struct hbq_dmabuf *hbq_buf;
561 /* Return all memory used by all HBQs */
562 list_for_each_entry_safe(dmabuf, next_dmabuf,
563 &phba->hbq_buffer_list, list) {
564 hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
565 list_del(&hbq_buf->dbuf.list);
566 lpfc_hbq_free(phba, hbq_buf->dbuf.virt, hbq_buf->dbuf.phys);
572 lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
573 struct hbq_dmabuf *hbq_buf)
575 struct lpfc_hbq_entry *hbqe;
576 dma_addr_t physaddr = hbq_buf->dbuf.phys;
578 /* Get next HBQ entry slot to use */
579 hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
581 struct hbq_s *hbqp = &phba->hbqs[hbqno];
583 hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
584 hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
585 hbqe->bde.tus.f.bdeSize = FCELSSIZE;
586 hbqe->bde.tus.f.bdeFlags = 0;
587 hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
588 hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
590 hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
591 writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
593 readl(phba->hbq_put + hbqno);
594 list_add_tail(&hbq_buf->dbuf.list, &phba->hbq_buffer_list);
598 static struct lpfc_hbq_init lpfc_els_hbq = {
603 .ring_mask = 1 << LPFC_ELS_RING,
609 static struct lpfc_hbq_init *lpfc_hbq_defs[] = {
614 lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
616 uint32_t i, start, end;
617 struct hbq_dmabuf *hbq_buffer;
619 start = lpfc_hbq_defs[hbqno]->buffer_count;
620 end = count + lpfc_hbq_defs[hbqno]->buffer_count;
621 if (end > lpfc_hbq_defs[hbqno]->entry_count) {
622 end = lpfc_hbq_defs[hbqno]->entry_count;
625 /* Populate HBQ entries */
626 for (i = start; i < end; i++) {
627 hbq_buffer = kmalloc(sizeof(struct hbq_dmabuf),
631 hbq_buffer->dbuf.virt = lpfc_hbq_alloc(phba, MEM_PRI,
632 &hbq_buffer->dbuf.phys);
633 if (hbq_buffer->dbuf.virt == NULL)
635 hbq_buffer->tag = (i | (hbqno << 16));
636 lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer);
637 lpfc_hbq_defs[hbqno]->buffer_count++;
643 lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
645 return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
646 lpfc_hbq_defs[qno]->add_count));
650 lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
652 return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
653 lpfc_hbq_defs[qno]->init_count));
657 lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
659 struct lpfc_dmabuf *d_buf;
660 struct hbq_dmabuf *hbq_buf;
662 list_for_each_entry(d_buf, &phba->hbq_buffer_list, list) {
663 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
664 if ((hbq_buf->tag & 0xffff) == tag) {
668 lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
669 "%d:1803 Bad hbq tag. Data: x%x x%x\n",
671 lpfc_hbq_defs[tag >> 16]->buffer_count);
676 lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *sp)
681 hbqno = sp->tag >> 16;
682 lpfc_sli_hbq_to_firmware(phba, hbqno, sp);
687 lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
691 switch (mbxCommand) {
695 case MBX_RUN_BIU_DIAG:
698 case MBX_CONFIG_LINK:
699 case MBX_CONFIG_RING:
701 case MBX_READ_CONFIG:
702 case MBX_READ_RCONFIG:
704 case MBX_READ_STATUS:
708 case MBX_READ_LNK_STAT:
710 case MBX_UNREG_LOGIN:
713 case MBX_DUMP_MEMORY:
714 case MBX_DUMP_CONTEXT:
719 case MBX_DEL_LD_ENTRY:
720 case MBX_RUN_PROGRAM:
725 case MBX_CONFIG_FARP:
728 case MBX_RUN_BIU_DIAG64:
729 case MBX_CONFIG_PORT:
730 case MBX_READ_SPARM64:
732 case MBX_REG_LOGIN64:
734 case MBX_FLASH_WR_ULA:
736 case MBX_LOAD_EXP_ROM:
749 lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
751 wait_queue_head_t *pdone_q;
752 unsigned long drvr_flag;
755 * If pdone_q is empty, the driver thread gave up waiting and
758 pmboxq->mbox_flag |= LPFC_MBX_WAKE;
759 spin_lock_irqsave(&phba->hbalock, drvr_flag);
760 pdone_q = (wait_queue_head_t *) pmboxq->context1;
762 wake_up_interruptible(pdone_q);
763 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
768 lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
770 struct lpfc_dmabuf *mp;
774 mp = (struct lpfc_dmabuf *) (pmb->context1);
777 lpfc_mbuf_free(phba, mp->virt, mp->phys);
782 * If a REG_LOGIN succeeded after node is destroyed or node
783 * is in re-discovery driver need to cleanup the RPI.
785 if (!(phba->pport->load_flag & FC_UNLOADING) &&
786 pmb->mb.mbxCommand == MBX_REG_LOGIN64 &&
787 !pmb->mb.mbxStatus) {
789 rpi = pmb->mb.un.varWords[0];
790 lpfc_unreg_login(phba, pmb->mb.un.varRegLogin.vpi, rpi, pmb);
791 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
792 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
793 if (rc != MBX_NOT_FINISHED)
797 mempool_free(pmb, phba->mbox_mem_pool);
802 lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
809 phba->sli.slistat.mbox_event++;
811 /* Get all completed mailboxe buffers into the cmplq */
812 spin_lock_irq(&phba->hbalock);
813 list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
814 spin_unlock_irq(&phba->hbalock);
816 /* Get a Mailbox buffer to setup mailbox commands for callback */
818 list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
824 if (pmbox->mbxCommand != MBX_HEARTBEAT) {
826 lpfc_debugfs_disc_trc(pmb->vport,
827 LPFC_DISC_TRC_MBOX_VPORT,
828 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
829 (uint32_t)pmbox->mbxCommand,
830 pmbox->un.varWords[0],
831 pmbox->un.varWords[1]);
834 lpfc_debugfs_disc_trc(phba->pport,
836 "MBOX cmpl: cmd:x%x mb:x%x x%x",
837 (uint32_t)pmbox->mbxCommand,
838 pmbox->un.varWords[0],
839 pmbox->un.varWords[1]);
844 * It is a fatal error if unknown mbox command completion.
846 if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
849 /* Unknow mailbox command compl */
850 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
851 "%d (%d):0323 Unknown Mailbox command "
854 pmb->vport ? pmb->vport->vpi : 0,
856 phba->link_state = LPFC_HBA_ERROR;
857 phba->work_hs = HS_FFER3;
858 lpfc_handle_eratt(phba);
862 if (pmbox->mbxStatus) {
863 phba->sli.slistat.mbox_stat_err++;
864 if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
865 /* Mbox cmd cmpl error - RETRYing */
866 lpfc_printf_log(phba, KERN_INFO,
868 "%d (%d):0305 Mbox cmd cmpl "
869 "error - RETRYing Data: x%x "
872 pmb->vport ? pmb->vport->vpi :0,
875 pmbox->un.varWords[0],
876 pmb->vport->port_state);
877 pmbox->mbxStatus = 0;
878 pmbox->mbxOwner = OWN_HOST;
879 spin_lock_irq(&phba->hbalock);
880 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
881 spin_unlock_irq(&phba->hbalock);
882 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
883 if (rc == MBX_SUCCESS)
888 /* Mailbox cmd <cmd> Cmpl <cmpl> */
889 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
890 "%d (%d):0307 Mailbox cmd x%x Cmpl x%p "
891 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
893 pmb->vport ? pmb->vport->vpi : 0,
896 *((uint32_t *) pmbox),
897 pmbox->un.varWords[0],
898 pmbox->un.varWords[1],
899 pmbox->un.varWords[2],
900 pmbox->un.varWords[3],
901 pmbox->un.varWords[4],
902 pmbox->un.varWords[5],
903 pmbox->un.varWords[6],
904 pmbox->un.varWords[7]);
907 pmb->mbox_cmpl(phba,pmb);
912 static struct lpfc_dmabuf *
913 lpfc_sli_replace_hbqbuff(struct lpfc_hba *phba, uint32_t tag)
915 struct hbq_dmabuf *hbq_entry, *new_hbq_entry;
917 hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
918 if (hbq_entry == NULL)
920 list_del(&hbq_entry->dbuf.list);
921 new_hbq_entry = kmalloc(sizeof(struct hbq_dmabuf), GFP_ATOMIC);
922 if (new_hbq_entry == NULL)
923 return &hbq_entry->dbuf;
924 new_hbq_entry->dbuf = hbq_entry->dbuf;
925 new_hbq_entry->tag = -1;
926 hbq_entry->dbuf.virt = lpfc_hbq_alloc(phba, 0, &hbq_entry->dbuf.phys);
927 if (hbq_entry->dbuf.virt == NULL) {
928 kfree(new_hbq_entry);
929 return &hbq_entry->dbuf;
931 lpfc_sli_free_hbq(phba, hbq_entry);
932 return &new_hbq_entry->dbuf;
936 lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
937 struct lpfc_iocbq *saveq)
945 irsp = &(saveq->iocb);
946 if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX)
947 || (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX)
948 || (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)
949 || (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX)) {
954 (WORD5 *) & (saveq->iocb.un.
956 Rctl = w5p->hcsw.Rctl;
957 Type = w5p->hcsw.Type;
959 /* Firmware Workaround */
960 if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
961 (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
962 irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
965 w5p->hcsw.Rctl = Rctl;
966 w5p->hcsw.Type = Type;
970 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
971 if (irsp->ulpBdeCount != 0)
972 saveq->context2 = lpfc_sli_replace_hbqbuff(phba,
973 irsp->un.ulpWord[3]);
974 if (irsp->ulpBdeCount == 2)
975 saveq->context3 = lpfc_sli_replace_hbqbuff(phba,
976 irsp->un.ulpWord[15]);
979 /* unSolicited Responses */
980 if (pring->prt[0].profile) {
981 if (pring->prt[0].lpfc_sli_rcv_unsol_event)
982 (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
986 /* We must search, based on rctl / type
987 for the right routine */
988 for (i = 0; i < pring->num_mask;
990 if ((pring->prt[i].rctl ==
994 if (pring->prt[i].lpfc_sli_rcv_unsol_event)
995 (pring->prt[i].lpfc_sli_rcv_unsol_event)
996 (phba, pring, saveq);
1003 /* Unexpected Rctl / Type received */
1004 /* Ring <ringno> handler: unexpected
1005 Rctl <Rctl> Type <Type> received */
1006 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1007 "%d:0313 Ring %d handler: unexpected Rctl x%x "
1008 "Type x%x received\n",
1017 static struct lpfc_iocbq *
1018 lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
1019 struct lpfc_sli_ring *pring,
1020 struct lpfc_iocbq *prspiocb)
1022 struct lpfc_iocbq *cmd_iocb = NULL;
1025 iotag = prspiocb->iocb.ulpIoTag;
1027 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
1028 cmd_iocb = phba->sli.iocbq_lookup[iotag];
1029 list_del_init(&cmd_iocb->list);
1030 pring->txcmplq_cnt--;
1034 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1035 "%d:0317 iotag x%x is out off "
1036 "range: max iotag x%x wd0 x%x\n",
1037 phba->brd_no, iotag,
1038 phba->sli.last_iotag,
1039 *(((uint32_t *) &prspiocb->iocb) + 7));
1044 lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1045 struct lpfc_iocbq *saveq)
1047 struct lpfc_iocbq *cmdiocbp;
1049 unsigned long iflag;
1051 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
1052 spin_lock_irqsave(&phba->hbalock, iflag);
1053 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
1054 spin_unlock_irqrestore(&phba->hbalock, iflag);
1057 if (cmdiocbp->iocb_cmpl) {
1059 * Post all ELS completions to the worker thread.
1060 * All other are passed to the completion callback.
1062 if (pring->ringno == LPFC_ELS_RING) {
1063 if (cmdiocbp->iocb_flag & LPFC_DRIVER_ABORTED) {
1064 cmdiocbp->iocb_flag &=
1065 ~LPFC_DRIVER_ABORTED;
1066 saveq->iocb.ulpStatus =
1067 IOSTAT_LOCAL_REJECT;
1068 saveq->iocb.un.ulpWord[4] =
1072 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
1074 lpfc_sli_release_iocbq(phba, cmdiocbp);
1077 * Unknown initiating command based on the response iotag.
1078 * This could be the case on the ELS ring because of
1081 if (pring->ringno != LPFC_ELS_RING) {
1083 * Ring <ringno> handler: unexpected completion IoTag
1086 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1087 "%d (%d):0322 Ring %d handler: "
1088 "unexpected completion IoTag x%x "
1089 "Data: x%x x%x x%x x%x\n",
1091 cmdiocbp->vport->vpi,
1093 saveq->iocb.ulpIoTag,
1094 saveq->iocb.ulpStatus,
1095 saveq->iocb.un.ulpWord[4],
1096 saveq->iocb.ulpCommand,
1097 saveq->iocb.ulpContext);
1105 lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1107 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
1108 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1109 &phba->slim2p->mbx.us.s2.port[pring->ringno];
1111 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
1112 * rsp ring <portRspMax>
1114 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1115 "%d:0312 Ring %d handler: portRspPut %d "
1116 "is bigger then rsp ring %d\n",
1117 phba->brd_no, pring->ringno,
1118 le32_to_cpu(pgp->rspPutInx),
1121 phba->link_state = LPFC_HBA_ERROR;
1124 * All error attention handlers are posted to
1127 phba->work_ha |= HA_ERATT;
1128 phba->work_hs = HS_FFER3;
1130 /* hbalock should already be held */
1131 if (phba->work_wait)
1132 lpfc_worker_wake_up(phba);
1137 void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba)
1139 struct lpfc_sli *psli = &phba->sli;
1140 struct lpfc_sli_ring *pring = &psli->ring[LPFC_FCP_RING];
1141 IOCB_t *irsp = NULL;
1142 IOCB_t *entry = NULL;
1143 struct lpfc_iocbq *cmdiocbq = NULL;
1144 struct lpfc_iocbq rspiocbq;
1145 struct lpfc_pgp *pgp;
1147 uint32_t portRspPut, portRspMax;
1149 uint32_t rsp_cmpl = 0;
1151 unsigned long iflags;
1153 pring->stats.iocb_event++;
1155 pgp = (phba->sli_rev == 3) ?
1156 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1157 &phba->slim2p->mbx.us.s2.port[pring->ringno];
1161 * The next available response entry should never exceed the maximum
1162 * entries. If it does, treat it as an adapter hardware error.
1164 portRspMax = pring->numRiocb;
1165 portRspPut = le32_to_cpu(pgp->rspPutInx);
1166 if (unlikely(portRspPut >= portRspMax)) {
1167 lpfc_sli_rsp_pointers_error(phba, pring);
1172 while (pring->rspidx != portRspPut) {
1173 entry = lpfc_resp_iocb(phba, pring);
1174 if (++pring->rspidx >= portRspMax)
1177 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
1178 (uint32_t *) &rspiocbq.iocb,
1179 phba->iocb_rsp_size);
1180 irsp = &rspiocbq.iocb;
1181 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
1182 pring->stats.iocb_rsp++;
1185 if (unlikely(irsp->ulpStatus)) {
1186 /* Rsp ring <ringno> error: IOCB */
1187 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1188 "%d:0326 Rsp Ring %d error: IOCB Data: "
1189 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
1190 phba->brd_no, pring->ringno,
1191 irsp->un.ulpWord[0],
1192 irsp->un.ulpWord[1],
1193 irsp->un.ulpWord[2],
1194 irsp->un.ulpWord[3],
1195 irsp->un.ulpWord[4],
1196 irsp->un.ulpWord[5],
1197 *(((uint32_t *) irsp) + 6),
1198 *(((uint32_t *) irsp) + 7));
1202 case LPFC_ABORT_IOCB:
1205 * Idle exchange closed via ABTS from port. No iocb
1206 * resources need to be recovered.
1208 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
1209 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1210 "%d:0314 IOCB cmd 0x%x"
1211 " processed. Skipping"
1212 " completion", phba->brd_no,
1217 spin_lock_irqsave(&phba->hbalock, iflags);
1218 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
1220 spin_unlock_irqrestore(&phba->hbalock, iflags);
1221 if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
1222 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1227 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1228 char adaptermsg[LPFC_MAX_ADPTMSG];
1229 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
1230 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1232 dev_warn(&((phba->pcidev)->dev), "lpfc%d: %s",
1233 phba->brd_no, adaptermsg);
1235 /* Unknown IOCB command */
1236 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1237 "%d:0321 Unknown IOCB command "
1238 "Data: x%x, x%x x%x x%x x%x\n",
1249 * The response IOCB has been processed. Update the ring
1250 * pointer in SLIM. If the port response put pointer has not
1251 * been updated, sync the pgp->rspPutInx and fetch the new port
1252 * response put pointer.
1254 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
1256 if (pring->rspidx == portRspPut)
1257 portRspPut = le32_to_cpu(pgp->rspPutInx);
1260 ha_copy = readl(phba->HAregaddr);
1261 ha_copy >>= (LPFC_FCP_RING * 4);
1263 if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) {
1264 spin_lock_irqsave(&phba->hbalock, iflags);
1265 pring->stats.iocb_rsp_full++;
1266 status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4));
1267 writel(status, phba->CAregaddr);
1268 readl(phba->CAregaddr);
1269 spin_unlock_irqrestore(&phba->hbalock, iflags);
1271 if ((ha_copy & HA_R0CE_RSP) &&
1272 (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1273 spin_lock_irqsave(&phba->hbalock, iflags);
1274 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1275 pring->stats.iocb_cmd_empty++;
1277 /* Force update of the local copy of cmdGetInx */
1278 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1279 lpfc_sli_resume_iocb(phba, pring);
1281 if ((pring->lpfc_sli_cmd_available))
1282 (pring->lpfc_sli_cmd_available) (phba, pring);
1284 spin_unlock_irqrestore(&phba->hbalock, iflags);
1291 * This routine presumes LPFC_FCP_RING handling and doesn't bother
1292 * to check it explicitly.
1295 lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
1296 struct lpfc_sli_ring *pring, uint32_t mask)
1298 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
1299 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1300 &phba->slim2p->mbx.us.s2.port[pring->ringno];
1301 IOCB_t *irsp = NULL;
1302 IOCB_t *entry = NULL;
1303 struct lpfc_iocbq *cmdiocbq = NULL;
1304 struct lpfc_iocbq rspiocbq;
1306 uint32_t portRspPut, portRspMax;
1308 lpfc_iocb_type type;
1309 unsigned long iflag;
1310 uint32_t rsp_cmpl = 0;
1312 spin_lock_irqsave(&phba->hbalock, iflag);
1313 pring->stats.iocb_event++;
1316 * The next available response entry should never exceed the maximum
1317 * entries. If it does, treat it as an adapter hardware error.
1319 portRspMax = pring->numRiocb;
1320 portRspPut = le32_to_cpu(pgp->rspPutInx);
1321 if (unlikely(portRspPut >= portRspMax)) {
1322 lpfc_sli_rsp_pointers_error(phba, pring);
1323 spin_unlock_irqrestore(&phba->hbalock, iflag);
1328 while (pring->rspidx != portRspPut) {
1330 * Fetch an entry off the ring and copy it into a local data
1331 * structure. The copy involves a byte-swap since the
1332 * network byte order and pci byte orders are different.
1334 entry = lpfc_resp_iocb(phba, pring);
1335 phba->last_completion_time = jiffies;
1337 if (++pring->rspidx >= portRspMax)
1340 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
1341 (uint32_t *) &rspiocbq.iocb,
1342 phba->iocb_rsp_size);
1343 INIT_LIST_HEAD(&(rspiocbq.list));
1344 irsp = &rspiocbq.iocb;
1346 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
1347 pring->stats.iocb_rsp++;
1350 if (unlikely(irsp->ulpStatus)) {
1352 * If resource errors reported from HBA, reduce
1353 * queuedepths of the SCSI device.
1355 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1356 (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
1357 spin_unlock_irqrestore(&phba->hbalock, iflag);
1358 lpfc_adjust_queue_depth(phba);
1359 spin_lock_irqsave(&phba->hbalock, iflag);
1362 /* Rsp ring <ringno> error: IOCB */
1363 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1364 "%d:0336 Rsp Ring %d error: IOCB Data: "
1365 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
1366 phba->brd_no, pring->ringno,
1367 irsp->un.ulpWord[0],
1368 irsp->un.ulpWord[1],
1369 irsp->un.ulpWord[2],
1370 irsp->un.ulpWord[3],
1371 irsp->un.ulpWord[4],
1372 irsp->un.ulpWord[5],
1373 *(((uint32_t *) irsp) + 6),
1374 *(((uint32_t *) irsp) + 7));
1378 case LPFC_ABORT_IOCB:
1381 * Idle exchange closed via ABTS from port. No iocb
1382 * resources need to be recovered.
1384 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
1385 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1386 "%d:0333 IOCB cmd 0x%x"
1387 " processed. Skipping"
1394 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
1396 if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
1397 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
1398 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1401 spin_unlock_irqrestore(&phba->hbalock,
1403 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1405 spin_lock_irqsave(&phba->hbalock,
1410 case LPFC_UNSOL_IOCB:
1411 spin_unlock_irqrestore(&phba->hbalock, iflag);
1412 lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
1413 spin_lock_irqsave(&phba->hbalock, iflag);
1416 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1417 char adaptermsg[LPFC_MAX_ADPTMSG];
1418 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
1419 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1421 dev_warn(&((phba->pcidev)->dev), "lpfc%d: %s",
1422 phba->brd_no, adaptermsg);
1424 /* Unknown IOCB command */
1425 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1426 "%d:0334 Unknown IOCB command "
1427 "Data: x%x, x%x x%x x%x x%x\n",
1438 * The response IOCB has been processed. Update the ring
1439 * pointer in SLIM. If the port response put pointer has not
1440 * been updated, sync the pgp->rspPutInx and fetch the new port
1441 * response put pointer.
1443 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
1445 if (pring->rspidx == portRspPut)
1446 portRspPut = le32_to_cpu(pgp->rspPutInx);
1449 if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
1450 pring->stats.iocb_rsp_full++;
1451 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
1452 writel(status, phba->CAregaddr);
1453 readl(phba->CAregaddr);
1455 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1456 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1457 pring->stats.iocb_cmd_empty++;
1459 /* Force update of the local copy of cmdGetInx */
1460 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1461 lpfc_sli_resume_iocb(phba, pring);
1463 if ((pring->lpfc_sli_cmd_available))
1464 (pring->lpfc_sli_cmd_available) (phba, pring);
1468 spin_unlock_irqrestore(&phba->hbalock, iflag);
1473 lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
1474 struct lpfc_sli_ring *pring, uint32_t mask)
1476 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
1477 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1478 &phba->slim2p->mbx.us.s2.port[pring->ringno];
1480 IOCB_t *irsp = NULL;
1481 struct lpfc_iocbq *rspiocbp = NULL;
1482 struct lpfc_iocbq *next_iocb;
1483 struct lpfc_iocbq *cmdiocbp;
1484 struct lpfc_iocbq *saveq;
1485 uint8_t iocb_cmd_type;
1486 lpfc_iocb_type type;
1487 uint32_t status, free_saveq;
1488 uint32_t portRspPut, portRspMax;
1490 unsigned long iflag;
1492 spin_lock_irqsave(&phba->hbalock, iflag);
1493 pring->stats.iocb_event++;
1496 * The next available response entry should never exceed the maximum
1497 * entries. If it does, treat it as an adapter hardware error.
1499 portRspMax = pring->numRiocb;
1500 portRspPut = le32_to_cpu(pgp->rspPutInx);
1501 if (portRspPut >= portRspMax) {
1503 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
1504 * rsp ring <portRspMax>
1506 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1507 "%d:0303 Ring %d handler: portRspPut %d "
1508 "is bigger then rsp ring %d\n",
1509 phba->brd_no, pring->ringno, portRspPut,
1512 phba->link_state = LPFC_HBA_ERROR;
1513 spin_unlock_irqrestore(&phba->hbalock, iflag);
1515 phba->work_hs = HS_FFER3;
1516 lpfc_handle_eratt(phba);
1522 while (pring->rspidx != portRspPut) {
1524 * Build a completion list and call the appropriate handler.
1525 * The process is to get the next available response iocb, get
1526 * a free iocb from the list, copy the response data into the
1527 * free iocb, insert to the continuation list, and update the
1528 * next response index to slim. This process makes response
1529 * iocb's in the ring available to DMA as fast as possible but
1530 * pays a penalty for a copy operation. Since the iocb is
1531 * only 32 bytes, this penalty is considered small relative to
1532 * the PCI reads for register values and a slim write. When
1533 * the ulpLe field is set, the entire Command has been
1536 entry = lpfc_resp_iocb(phba, pring);
1538 phba->last_completion_time = jiffies;
1539 rspiocbp = __lpfc_sli_get_iocbq(phba);
1540 if (rspiocbp == NULL) {
1541 printk(KERN_ERR "%s: out of buffers! Failing "
1542 "completion.\n", __FUNCTION__);
1546 lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
1547 phba->iocb_rsp_size);
1548 irsp = &rspiocbp->iocb;
1550 if (++pring->rspidx >= portRspMax)
1553 if (pring->ringno == LPFC_ELS_RING) {
1554 lpfc_debugfs_slow_ring_trc(phba,
1555 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
1556 *(((uint32_t *) irsp) + 4),
1557 *(((uint32_t *) irsp) + 6),
1558 *(((uint32_t *) irsp) + 7));
1561 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
1563 if (list_empty(&(pring->iocb_continueq))) {
1564 list_add(&rspiocbp->list, &(pring->iocb_continueq));
1566 list_add_tail(&rspiocbp->list,
1567 &(pring->iocb_continueq));
1570 pring->iocb_continueq_cnt++;
1573 * By default, the driver expects to free all resources
1574 * associated with this iocb completion.
1577 saveq = list_get_first(&pring->iocb_continueq,
1578 struct lpfc_iocbq, list);
1579 irsp = &(saveq->iocb);
1580 list_del_init(&pring->iocb_continueq);
1581 pring->iocb_continueq_cnt = 0;
1583 pring->stats.iocb_rsp++;
1586 * If resource errors reported from HBA, reduce
1587 * queuedepths of the SCSI device.
1589 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1590 (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
1591 spin_unlock_irqrestore(&phba->hbalock, iflag);
1592 lpfc_adjust_queue_depth(phba);
1593 spin_lock_irqsave(&phba->hbalock, iflag);
1596 if (irsp->ulpStatus) {
1597 /* Rsp ring <ringno> error: IOCB */
1598 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1599 "%d:0328 Rsp Ring %d error: "
1604 "x%x x%x x%x x%x\n",
1607 irsp->un.ulpWord[0],
1608 irsp->un.ulpWord[1],
1609 irsp->un.ulpWord[2],
1610 irsp->un.ulpWord[3],
1611 irsp->un.ulpWord[4],
1612 irsp->un.ulpWord[5],
1613 *(((uint32_t *) irsp) + 6),
1614 *(((uint32_t *) irsp) + 7),
1615 *(((uint32_t *) irsp) + 8),
1616 *(((uint32_t *) irsp) + 9),
1617 *(((uint32_t *) irsp) + 10),
1618 *(((uint32_t *) irsp) + 11),
1619 *(((uint32_t *) irsp) + 12),
1620 *(((uint32_t *) irsp) + 13),
1621 *(((uint32_t *) irsp) + 14),
1622 *(((uint32_t *) irsp) + 15));
1626 * Fetch the IOCB command type and call the correct
1627 * completion routine. Solicited and Unsolicited
1628 * IOCBs on the ELS ring get freed back to the
1629 * lpfc_iocb_list by the discovery kernel thread.
1631 iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
1632 type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
1633 if (type == LPFC_SOL_IOCB) {
1634 spin_unlock_irqrestore(&phba->hbalock,
1636 rc = lpfc_sli_process_sol_iocb(phba, pring,
1638 spin_lock_irqsave(&phba->hbalock, iflag);
1639 } else if (type == LPFC_UNSOL_IOCB) {
1640 spin_unlock_irqrestore(&phba->hbalock,
1642 rc = lpfc_sli_process_unsol_iocb(phba, pring,
1644 spin_lock_irqsave(&phba->hbalock, iflag);
1645 } else if (type == LPFC_ABORT_IOCB) {
1646 if ((irsp->ulpCommand != CMD_XRI_ABORTED_CX) &&
1648 lpfc_sli_iocbq_lookup(phba, pring,
1650 /* Call the specified completion
1652 if (cmdiocbp->iocb_cmpl) {
1653 spin_unlock_irqrestore(
1656 (cmdiocbp->iocb_cmpl) (phba,
1662 __lpfc_sli_release_iocbq(phba,
1665 } else if (type == LPFC_UNKNOWN_IOCB) {
1666 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1668 char adaptermsg[LPFC_MAX_ADPTMSG];
1670 memset(adaptermsg, 0,
1672 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1674 dev_warn(&((phba->pcidev)->dev),
1676 phba->brd_no, adaptermsg);
1678 /* Unknown IOCB command */
1679 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1680 "%d:0335 Unknown IOCB "
1681 "command Data: x%x "
1692 list_for_each_entry_safe(rspiocbp, next_iocb,
1693 &saveq->list, list) {
1694 list_del(&rspiocbp->list);
1695 __lpfc_sli_release_iocbq(phba,
1698 __lpfc_sli_release_iocbq(phba, saveq);
1704 * If the port response put pointer has not been updated, sync
1705 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
1706 * response put pointer.
1708 if (pring->rspidx == portRspPut) {
1709 portRspPut = le32_to_cpu(pgp->rspPutInx);
1711 } /* while (pring->rspidx != portRspPut) */
1713 if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
1714 /* At least one response entry has been freed */
1715 pring->stats.iocb_rsp_full++;
1716 /* SET RxRE_RSP in Chip Att register */
1717 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
1718 writel(status, phba->CAregaddr);
1719 readl(phba->CAregaddr); /* flush */
1721 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1722 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1723 pring->stats.iocb_cmd_empty++;
1725 /* Force update of the local copy of cmdGetInx */
1726 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1727 lpfc_sli_resume_iocb(phba, pring);
1729 if ((pring->lpfc_sli_cmd_available))
1730 (pring->lpfc_sli_cmd_available) (phba, pring);
1734 spin_unlock_irqrestore(&phba->hbalock, iflag);
1739 lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1741 LIST_HEAD(completions);
1742 struct lpfc_iocbq *iocb, *next_iocb;
1745 if (pring->ringno == LPFC_ELS_RING) {
1746 lpfc_fabric_abort_hba(phba);
1749 /* Error everything on txq and txcmplq
1752 spin_lock_irq(&phba->hbalock);
1753 list_splice_init(&pring->txq, &completions);
1756 /* Next issue ABTS for everything on the txcmplq */
1757 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
1758 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1760 spin_unlock_irq(&phba->hbalock);
1762 while (!list_empty(&completions)) {
1763 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
1765 list_del_init(&iocb->list);
1767 if (!iocb->iocb_cmpl)
1768 lpfc_sli_release_iocbq(phba, iocb);
1770 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
1771 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
1772 (iocb->iocb_cmpl) (phba, iocb, iocb);
1778 lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
1784 /* Read the HBA Host Status Register */
1785 status = readl(phba->HSregaddr);
1788 * Check status register every 100ms for 5 retries, then every
1789 * 500ms for 5, then every 2.5 sec for 5, then reset board and
1790 * every 2.5 sec for 4.
1791 * Break our of the loop if errors occurred during init.
1793 while (((status & mask) != mask) &&
1794 !(status & HS_FFERM) &&
1806 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
1807 lpfc_sli_brdrestart(phba);
1809 /* Read the HBA Host Status Register */
1810 status = readl(phba->HSregaddr);
1813 /* Check to see if any errors occurred during init */
1814 if ((status & HS_FFERM) || (i >= 20)) {
1815 phba->link_state = LPFC_HBA_ERROR;
1822 #define BARRIER_TEST_PATTERN (0xdeadbeef)
1824 void lpfc_reset_barrier(struct lpfc_hba *phba)
1826 uint32_t __iomem *resp_buf;
1827 uint32_t __iomem *mbox_buf;
1828 volatile uint32_t mbox;
1833 pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
1834 if (hdrtype != 0x80 ||
1835 (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
1836 FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
1840 * Tell the other part of the chip to suspend temporarily all
1843 resp_buf = phba->MBslimaddr;
1845 /* Disable the error attention */
1846 hc_copy = readl(phba->HCregaddr);
1847 writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
1848 readl(phba->HCregaddr); /* flush */
1849 phba->link_flag |= LS_IGNORE_ERATT;
1851 if (readl(phba->HAregaddr) & HA_ERATT) {
1852 /* Clear Chip error bit */
1853 writel(HA_ERATT, phba->HAregaddr);
1854 phba->pport->stopped = 1;
1858 ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
1859 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
1861 writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
1862 mbox_buf = phba->MBslimaddr;
1863 writel(mbox, mbox_buf);
1866 readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
1869 if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
1870 if (phba->sli.sli_flag & LPFC_SLI2_ACTIVE ||
1871 phba->pport->stopped)
1877 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
1878 for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
1883 while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
1886 if (readl(phba->HAregaddr) & HA_ERATT) {
1887 writel(HA_ERATT, phba->HAregaddr);
1888 phba->pport->stopped = 1;
1892 phba->link_flag &= ~LS_IGNORE_ERATT;
1893 writel(hc_copy, phba->HCregaddr);
1894 readl(phba->HCregaddr); /* flush */
1898 lpfc_sli_brdkill(struct lpfc_hba *phba)
1900 struct lpfc_sli *psli;
1910 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1911 "%d:0329 Kill HBA Data: x%x x%x\n",
1912 phba->brd_no, phba->pport->port_state, psli->sli_flag);
1914 if ((pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
1918 /* Disable the error attention */
1919 spin_lock_irq(&phba->hbalock);
1920 status = readl(phba->HCregaddr);
1921 status &= ~HC_ERINT_ENA;
1922 writel(status, phba->HCregaddr);
1923 readl(phba->HCregaddr); /* flush */
1924 phba->link_flag |= LS_IGNORE_ERATT;
1925 spin_unlock_irq(&phba->hbalock);
1927 lpfc_kill_board(phba, pmb);
1928 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1929 retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
1931 if (retval != MBX_SUCCESS) {
1932 if (retval != MBX_BUSY)
1933 mempool_free(pmb, phba->mbox_mem_pool);
1934 spin_lock_irq(&phba->hbalock);
1935 phba->link_flag &= ~LS_IGNORE_ERATT;
1936 spin_unlock_irq(&phba->hbalock);
1940 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
1942 mempool_free(pmb, phba->mbox_mem_pool);
1944 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
1945 * attention every 100ms for 3 seconds. If we don't get ERATT after
1946 * 3 seconds we still set HBA_ERROR state because the status of the
1947 * board is now undefined.
1949 ha_copy = readl(phba->HAregaddr);
1951 while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
1953 ha_copy = readl(phba->HAregaddr);
1956 del_timer_sync(&psli->mbox_tmo);
1957 if (ha_copy & HA_ERATT) {
1958 writel(HA_ERATT, phba->HAregaddr);
1959 phba->pport->stopped = 1;
1961 spin_lock_irq(&phba->hbalock);
1962 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
1963 phba->link_flag &= ~LS_IGNORE_ERATT;
1964 spin_unlock_irq(&phba->hbalock);
1966 psli->mbox_active = NULL;
1967 lpfc_hba_down_post(phba);
1968 phba->link_state = LPFC_HBA_ERROR;
1970 return ha_copy & HA_ERATT ? 0 : 1;
1974 lpfc_sli_brdreset(struct lpfc_hba *phba)
1976 struct lpfc_sli *psli;
1977 struct lpfc_sli_ring *pring;
1984 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1985 "%d:0325 Reset HBA Data: x%x x%x\n", phba->brd_no,
1986 phba->pport->port_state, psli->sli_flag);
1988 /* perform board reset */
1989 phba->fc_eventTag = 0;
1990 phba->pport->fc_myDID = 0;
1991 phba->pport->fc_prevDID = 0;
1993 /* Turn off parity checking and serr during the physical reset */
1994 pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
1995 pci_write_config_word(phba->pcidev, PCI_COMMAND,
1997 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
1999 psli->sli_flag &= ~(LPFC_SLI2_ACTIVE | LPFC_PROCESS_LA);
2000 /* Now toggle INITFF bit in the Host Control Register */
2001 writel(HC_INITFF, phba->HCregaddr);
2003 readl(phba->HCregaddr); /* flush */
2004 writel(0, phba->HCregaddr);
2005 readl(phba->HCregaddr); /* flush */
2007 /* Restore PCI cmd register */
2008 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
2010 /* Initialize relevant SLI info */
2011 for (i = 0; i < psli->num_rings; i++) {
2012 pring = &psli->ring[i];
2015 pring->next_cmdidx = 0;
2016 pring->local_getidx = 0;
2018 pring->missbufcnt = 0;
2021 phba->link_state = LPFC_WARM_START;
2026 lpfc_sli_brdrestart(struct lpfc_hba *phba)
2029 struct lpfc_sli *psli;
2031 volatile uint32_t word0;
2032 void __iomem *to_slim;
2034 spin_lock_irq(&phba->hbalock);
2039 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2040 "%d:0337 Restart HBA Data: x%x x%x\n", phba->brd_no,
2041 phba->pport->port_state, psli->sli_flag);
2044 mb = (MAILBOX_t *) &word0;
2045 mb->mbxCommand = MBX_RESTART;
2048 lpfc_reset_barrier(phba);
2050 to_slim = phba->MBslimaddr;
2051 writel(*(uint32_t *) mb, to_slim);
2052 readl(to_slim); /* flush */
2054 /* Only skip post after fc_ffinit is completed */
2055 if (phba->pport->port_state) {
2057 word0 = 1; /* This is really setting up word1 */
2060 word0 = 0; /* This is really setting up word1 */
2062 to_slim = phba->MBslimaddr + sizeof (uint32_t);
2063 writel(*(uint32_t *) mb, to_slim);
2064 readl(to_slim); /* flush */
2066 lpfc_sli_brdreset(phba);
2067 phba->pport->stopped = 0;
2068 phba->link_state = LPFC_INIT_START;
2070 spin_unlock_irq(&phba->hbalock);
2072 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
2073 psli->stats_start = get_seconds();
2080 lpfc_hba_down_post(phba);
2086 lpfc_sli_chipset_init(struct lpfc_hba *phba)
2088 uint32_t status, i = 0;
2090 /* Read the HBA Host Status Register */
2091 status = readl(phba->HSregaddr);
2093 /* Check status register to see what current state is */
2095 while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
2097 /* Check every 100ms for 5 retries, then every 500ms for 5, then
2098 * every 2.5 sec for 5, then reset board and every 2.5 sec for
2102 /* Adapter failed to init, timeout, status reg
2104 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2105 "%d:0436 Adapter failed to init, "
2106 "timeout, status reg x%x\n",
2107 phba->brd_no, status);
2108 phba->link_state = LPFC_HBA_ERROR;
2112 /* Check to see if any errors occurred during init */
2113 if (status & HS_FFERM) {
2114 /* ERROR: During chipset initialization */
2115 /* Adapter failed to init, chipset, status reg
2117 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2118 "%d:0437 Adapter failed to init, "
2119 "chipset, status reg x%x\n",
2122 phba->link_state = LPFC_HBA_ERROR;
2128 } else if (i <= 10) {
2136 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
2137 lpfc_sli_brdrestart(phba);
2139 /* Read the HBA Host Status Register */
2140 status = readl(phba->HSregaddr);
2143 /* Check to see if any errors occurred during init */
2144 if (status & HS_FFERM) {
2145 /* ERROR: During chipset initialization */
2146 /* Adapter failed to init, chipset, status reg <status> */
2147 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2148 "%d:0438 Adapter failed to init, chipset, "
2152 phba->link_state = LPFC_HBA_ERROR;
2156 /* Clear all interrupt enable conditions */
2157 writel(0, phba->HCregaddr);
2158 readl(phba->HCregaddr); /* flush */
2160 /* setup host attn register */
2161 writel(0xffffffff, phba->HAregaddr);
2162 readl(phba->HAregaddr); /* flush */
2167 lpfc_sli_hbq_count(void)
2169 return ARRAY_SIZE(lpfc_hbq_defs);
2173 lpfc_sli_hbq_entry_count(void)
2175 int hbq_count = lpfc_sli_hbq_count();
2179 for (i = 0; i < hbq_count; ++i)
2180 count += lpfc_hbq_defs[i]->entry_count;
2185 lpfc_sli_hbq_size(void)
2187 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
2191 lpfc_sli_hbq_setup(struct lpfc_hba *phba)
2193 int hbq_count = lpfc_sli_hbq_count();
2197 uint32_t hbq_entry_index;
2199 /* Get a Mailbox buffer to setup mailbox
2200 * commands for HBA initialization
2202 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2209 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
2210 phba->link_state = LPFC_INIT_MBX_CMDS;
2212 hbq_entry_index = 0;
2213 for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
2214 phba->hbqs[hbqno].next_hbqPutIdx = 0;
2215 phba->hbqs[hbqno].hbqPutIdx = 0;
2216 phba->hbqs[hbqno].local_hbqGetIdx = 0;
2217 phba->hbqs[hbqno].entry_count =
2218 lpfc_hbq_defs[hbqno]->entry_count;
2219 lpfc_config_hbq(phba, lpfc_hbq_defs[hbqno], hbq_entry_index,
2221 hbq_entry_index += phba->hbqs[hbqno].entry_count;
2223 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
2224 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
2225 mbxStatus <status>, ring <num> */
2227 lpfc_printf_log(phba, KERN_ERR,
2228 LOG_SLI | LOG_VPORT,
2229 "%d:1805 Adapter failed to init. "
2230 "Data: x%x x%x x%x\n",
2231 phba->brd_no, pmbox->mbxCommand,
2232 pmbox->mbxStatus, hbqno);
2234 phba->link_state = LPFC_HBA_ERROR;
2235 mempool_free(pmb, phba->mbox_mem_pool);
2239 phba->hbq_count = hbq_count;
2241 mempool_free(pmb, phba->mbox_mem_pool);
2243 /* Initially populate or replenish the HBQs */
2244 for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
2245 if (lpfc_sli_hbqbuf_init_hbqs(phba, hbqno))
2252 lpfc_do_config_port(struct lpfc_hba *phba, int sli_mode)
2255 uint32_t resetcount = 0, rc = 0, done = 0;
2257 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2259 phba->link_state = LPFC_HBA_ERROR;
2263 phba->sli_rev = sli_mode;
2264 while (resetcount < 2 && !done) {
2265 spin_lock_irq(&phba->hbalock);
2266 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
2267 spin_unlock_irq(&phba->hbalock);
2268 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
2269 lpfc_sli_brdrestart(phba);
2271 rc = lpfc_sli_chipset_init(phba);
2275 spin_lock_irq(&phba->hbalock);
2276 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2277 spin_unlock_irq(&phba->hbalock);
2280 /* Call pre CONFIG_PORT mailbox command initialization. A
2281 * value of 0 means the call was successful. Any other
2282 * nonzero value is a failure, but if ERESTART is returned,
2283 * the driver may reset the HBA and try again.
2285 rc = lpfc_config_port_prep(phba);
2286 if (rc == -ERESTART) {
2287 phba->link_state = LPFC_LINK_UNKNOWN;
2293 phba->link_state = LPFC_INIT_MBX_CMDS;
2294 lpfc_config_port(phba, pmb);
2295 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
2296 if (rc != MBX_SUCCESS) {
2297 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2298 "%d:0442 Adapter failed to init, mbxCmd x%x "
2299 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
2300 phba->brd_no, pmb->mb.mbxCommand,
2301 pmb->mb.mbxStatus, 0);
2302 spin_lock_irq(&phba->hbalock);
2303 phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE;
2304 spin_unlock_irq(&phba->hbalock);
2308 phba->max_vpi = (phba->max_vpi &&
2309 pmb->mb.un.varCfgPort.gmv) != 0
2310 ? pmb->mb.un.varCfgPort.max_vpi
2317 goto do_prep_failed;
2320 if ((pmb->mb.un.varCfgPort.sli_mode == 3) &&
2321 (!pmb->mb.un.varCfgPort.cMA)) {
2323 goto do_prep_failed;
2328 mempool_free(pmb, phba->mbox_mem_pool);
2333 lpfc_sli_hba_setup(struct lpfc_hba *phba)
2338 switch (lpfc_sli_mode) {
2340 if (phba->cfg_npiv_enable) {
2341 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
2342 "%d:1824 NPIV enabled: Override lpfc_sli_mode "
2343 "parameter (%d) to auto (0).\n",
2344 phba->brd_no, lpfc_sli_mode);
2353 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
2354 "%d:1819 Unrecognized lpfc_sli_mode "
2356 phba->brd_no, lpfc_sli_mode);
2361 rc = lpfc_do_config_port(phba, mode);
2362 if (rc && lpfc_sli_mode == 3)
2363 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
2364 "%d:1820 Unable to select SLI-3. "
2365 "Not supported by adapter.\n",
2367 if (rc && mode != 2)
2368 rc = lpfc_do_config_port(phba, 2);
2370 goto lpfc_sli_hba_setup_error;
2372 if (phba->sli_rev == 3) {
2373 phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
2374 phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
2375 phba->sli3_options |= LPFC_SLI3_ENABLED;
2376 phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
2379 phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
2380 phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
2381 phba->sli3_options = 0;
2384 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2385 "%d:0444 Firmware in SLI %x mode. Max_vpi %d\n",
2386 phba->brd_no, phba->sli_rev, phba->max_vpi);
2387 rc = lpfc_sli_ring_map(phba);
2390 goto lpfc_sli_hba_setup_error;
2394 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
2395 rc = lpfc_sli_hbq_setup(phba);
2397 goto lpfc_sli_hba_setup_error;
2400 phba->sli.sli_flag |= LPFC_PROCESS_LA;
2402 rc = lpfc_config_port_post(phba);
2404 goto lpfc_sli_hba_setup_error;
2408 lpfc_sli_hba_setup_error:
2409 phba->link_state = LPFC_HBA_ERROR;
2410 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2411 "%d:0445 Firmware initialization failed\n",
2416 /*! lpfc_mbox_timeout
2420 * \param hba Pointer to per struct lpfc_hba structure
2421 * \param l1 Pointer to the driver's mailbox queue.
2427 * This routine handles mailbox timeout events at timer interrupt context.
2430 lpfc_mbox_timeout(unsigned long ptr)
2432 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
2433 unsigned long iflag;
2434 uint32_t tmo_posted;
2436 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
2437 tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
2439 phba->pport->work_port_events |= WORKER_MBOX_TMO;
2440 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
2443 spin_lock_irqsave(&phba->hbalock, iflag);
2444 if (phba->work_wait)
2445 lpfc_worker_wake_up(phba);
2446 spin_unlock_irqrestore(&phba->hbalock, iflag);
2451 lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
2453 LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
2454 MAILBOX_t *mb = &pmbox->mb;
2455 struct lpfc_sli *psli = &phba->sli;
2456 struct lpfc_sli_ring *pring;
2458 if (!(phba->pport->work_port_events & WORKER_MBOX_TMO)) {
2462 /* Mbox cmd <mbxCommand> timeout */
2463 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
2464 "%d:0310 Mailbox command x%x timeout Data: x%x x%x "
2468 phba->pport->port_state,
2470 phba->sli.mbox_active);
2472 /* Setting state unknown so lpfc_sli_abort_iocb_ring
2473 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
2474 * it to fail all oustanding SCSI IO.
2476 spin_lock_irq(&phba->pport->work_port_lock);
2477 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
2478 spin_unlock_irq(&phba->pport->work_port_lock);
2479 spin_lock_irq(&phba->hbalock);
2480 phba->link_state = LPFC_LINK_UNKNOWN;
2481 phba->pport->fc_flag |= FC_ESTABLISH_LINK;
2482 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
2483 spin_unlock_irq(&phba->hbalock);
2485 pring = &psli->ring[psli->fcp_ring];
2486 lpfc_sli_abort_iocb_ring(phba, pring);
2488 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
2489 "%d:0316 Resetting board due to mailbox timeout\n",
2492 * lpfc_offline calls lpfc_sli_hba_down which will clean up
2493 * on oustanding mailbox commands.
2495 lpfc_offline_prep(phba);
2497 lpfc_sli_brdrestart(phba);
2498 if (lpfc_online(phba) == 0) /* Initialize the HBA */
2499 mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
2500 lpfc_unblock_mgmt_io(phba);
2505 lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
2508 struct lpfc_sli *psli = &phba->sli;
2509 uint32_t status, evtctr;
2512 unsigned long drvr_flag = 0;
2513 volatile uint32_t word0, ldata;
2514 void __iomem *to_slim;
2516 if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
2517 pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
2519 lpfc_printf_log(phba, KERN_ERR,
2520 LOG_MBOX | LOG_VPORT,
2521 "%d:1806 Mbox x%x failed. No vport\n",
2523 pmbox->mb.mbxCommand);
2525 return MBXERR_ERROR;
2530 /* If the PCI channel is in offline state, do not post mbox. */
2531 if (unlikely(pci_channel_offline(phba->pcidev)))
2532 return MBX_NOT_FINISHED;
2534 spin_lock_irqsave(&phba->hbalock, drvr_flag);
2539 status = MBX_SUCCESS;
2541 if (phba->link_state == LPFC_HBA_ERROR) {
2542 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2544 /* Mbox command <mbxCommand> cannot issue */
2545 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag)
2546 return MBX_NOT_FINISHED;
2549 if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
2550 !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
2551 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2552 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag)
2553 return MBX_NOT_FINISHED;
2556 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
2557 /* Polling for a mbox command when another one is already active
2558 * is not allowed in SLI. Also, the driver must have established
2559 * SLI2 mode to queue and process multiple mbox commands.
2562 if (flag & MBX_POLL) {
2563 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2565 /* Mbox command <mbxCommand> cannot issue */
2566 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
2567 return MBX_NOT_FINISHED;
2570 if (!(psli->sli_flag & LPFC_SLI2_ACTIVE)) {
2571 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2572 /* Mbox command <mbxCommand> cannot issue */
2573 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
2574 return MBX_NOT_FINISHED;
2577 /* Handle STOP IOCB processing flag. This is only meaningful
2578 * if we are not polling for mbox completion.
2580 if (flag & MBX_STOP_IOCB) {
2581 flag &= ~MBX_STOP_IOCB;
2582 /* Now flag each ring */
2583 for (i = 0; i < psli->num_rings; i++) {
2584 /* If the ring is active, flag it */
2585 if (psli->ring[i].cmdringaddr) {
2586 psli->ring[i].flag |=
2592 /* Another mailbox command is still being processed, queue this
2593 * command to be processed later.
2595 lpfc_mbox_put(phba, pmbox);
2597 /* Mbox cmd issue - BUSY */
2598 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
2599 "%d (%d):0308 Mbox cmd issue - BUSY Data: "
2600 "x%x x%x x%x x%x\n",
2602 pmbox->vport ? pmbox->vport->vpi : 0xffffff,
2603 mb->mbxCommand, phba->pport->port_state,
2604 psli->sli_flag, flag);
2606 psli->slistat.mbox_busy++;
2607 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2610 lpfc_debugfs_disc_trc(pmbox->vport,
2611 LPFC_DISC_TRC_MBOX_VPORT,
2612 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
2613 (uint32_t)mb->mbxCommand,
2614 mb->un.varWords[0], mb->un.varWords[1]);
2617 lpfc_debugfs_disc_trc(phba->pport,
2619 "MBOX Bsy: cmd:x%x mb:x%x x%x",
2620 (uint32_t)mb->mbxCommand,
2621 mb->un.varWords[0], mb->un.varWords[1]);
2627 /* Handle STOP IOCB processing flag. This is only meaningful
2628 * if we are not polling for mbox completion.
2630 if (flag & MBX_STOP_IOCB) {
2631 flag &= ~MBX_STOP_IOCB;
2632 if (flag == MBX_NOWAIT) {
2633 /* Now flag each ring */
2634 for (i = 0; i < psli->num_rings; i++) {
2635 /* If the ring is active, flag it */
2636 if (psli->ring[i].cmdringaddr) {
2637 psli->ring[i].flag |=
2644 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
2646 /* If we are not polling, we MUST be in SLI2 mode */
2647 if (flag != MBX_POLL) {
2648 if (!(psli->sli_flag & LPFC_SLI2_ACTIVE) &&
2649 (mb->mbxCommand != MBX_KILL_BOARD)) {
2650 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2651 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2652 /* Mbox command <mbxCommand> cannot issue */
2653 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
2654 return MBX_NOT_FINISHED;
2656 /* timeout active mbox command */
2657 mod_timer(&psli->mbox_tmo, (jiffies +
2658 (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
2661 /* Mailbox cmd <cmd> issue */
2662 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
2663 "%d (%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
2665 phba->brd_no, pmbox->vport ? pmbox->vport->vpi : 0,
2666 mb->mbxCommand, phba->pport->port_state,
2667 psli->sli_flag, flag);
2669 if (mb->mbxCommand != MBX_HEARTBEAT) {
2671 lpfc_debugfs_disc_trc(pmbox->vport,
2672 LPFC_DISC_TRC_MBOX_VPORT,
2673 "MBOX Send vport: cmd:x%x mb:x%x x%x",
2674 (uint32_t)mb->mbxCommand,
2675 mb->un.varWords[0], mb->un.varWords[1]);
2678 lpfc_debugfs_disc_trc(phba->pport,
2680 "MBOX Send: cmd:x%x mb:x%x x%x",
2681 (uint32_t)mb->mbxCommand,
2682 mb->un.varWords[0], mb->un.varWords[1]);
2686 psli->slistat.mbox_cmd++;
2687 evtctr = psli->slistat.mbox_event;
2689 /* next set own bit for the adapter and copy over command word */
2690 mb->mbxOwner = OWN_CHIP;
2692 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2693 /* First copy command data to host SLIM area */
2694 lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx, MAILBOX_CMD_SIZE);
2696 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2697 /* copy command data into host mbox for cmpl */
2698 lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx,
2702 /* First copy mbox command data to HBA SLIM, skip past first
2704 to_slim = phba->MBslimaddr + sizeof (uint32_t);
2705 lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
2706 MAILBOX_CMD_SIZE - sizeof (uint32_t));
2708 /* Next copy over first word, with mbxOwner set */
2709 ldata = *((volatile uint32_t *)mb);
2710 to_slim = phba->MBslimaddr;
2711 writel(ldata, to_slim);
2712 readl(to_slim); /* flush */
2714 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2715 /* switch over to host mailbox */
2716 psli->sli_flag |= LPFC_SLI2_ACTIVE;
2721 /* interrupt board to doit right away */
2722 writel(CA_MBATT, phba->CAregaddr);
2723 readl(phba->CAregaddr); /* flush */
2727 /* Don't wait for it to finish, just return */
2728 psli->mbox_active = pmbox;
2732 psli->mbox_active = NULL;
2733 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2734 /* First read mbox status word */
2735 word0 = *((volatile uint32_t *)&phba->slim2p->mbx);
2736 word0 = le32_to_cpu(word0);
2738 /* First read mbox status word */
2739 word0 = readl(phba->MBslimaddr);
2742 /* Read the HBA Host Attention Register */
2743 ha_copy = readl(phba->HAregaddr);
2745 i = lpfc_mbox_tmo_val(phba, mb->mbxCommand);
2746 i *= 1000; /* Convert to ms */
2748 /* Wait for command to complete */
2749 while (((word0 & OWN_CHIP) == OWN_CHIP) ||
2750 (!(ha_copy & HA_MBATT) &&
2751 (phba->link_state > LPFC_WARM_START))) {
2753 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2754 spin_unlock_irqrestore(&phba->hbalock,
2756 return MBX_NOT_FINISHED;
2759 /* Check if we took a mbox interrupt while we were
2761 if (((word0 & OWN_CHIP) != OWN_CHIP)
2762 && (evtctr != psli->slistat.mbox_event))
2765 spin_unlock_irqrestore(&phba->hbalock,
2770 spin_lock_irqsave(&phba->hbalock, drvr_flag);
2772 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2773 /* First copy command data */
2774 word0 = *((volatile uint32_t *)
2775 &phba->slim2p->mbx);
2776 word0 = le32_to_cpu(word0);
2777 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2779 volatile uint32_t slimword0;
2780 /* Check real SLIM for any errors */
2781 slimword0 = readl(phba->MBslimaddr);
2782 slimmb = (MAILBOX_t *) & slimword0;
2783 if (((slimword0 & OWN_CHIP) != OWN_CHIP)
2784 && slimmb->mbxStatus) {
2791 /* First copy command data */
2792 word0 = readl(phba->MBslimaddr);
2794 /* Read the HBA Host Attention Register */
2795 ha_copy = readl(phba->HAregaddr);
2798 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2799 /* copy results back to user */
2800 lpfc_sli_pcimem_bcopy(&phba->slim2p->mbx, mb,
2803 /* First copy command data */
2804 lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
2806 if ((mb->mbxCommand == MBX_DUMP_MEMORY) &&
2808 lpfc_memcpy_from_slim((void *)pmbox->context2,
2809 phba->MBslimaddr + DMP_RSP_OFFSET,
2810 mb->un.varDmp.word_cnt);
2814 writel(HA_MBATT, phba->HAregaddr);
2815 readl(phba->HAregaddr); /* flush */
2817 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2818 status = mb->mbxStatus;
2821 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2826 * Caller needs to hold lock.
2829 __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2830 struct lpfc_iocbq *piocb)
2832 /* Insert the caller's iocb in the txq tail for later processing. */
2833 list_add_tail(&piocb->list, &pring->txq);
2837 static struct lpfc_iocbq *
2838 lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2839 struct lpfc_iocbq **piocb)
2841 struct lpfc_iocbq * nextiocb;
2843 nextiocb = lpfc_sli_ringtx_get(phba, pring);
2853 * Lockless version of lpfc_sli_issue_iocb.
2856 __lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2857 struct lpfc_iocbq *piocb, uint32_t flag)
2859 struct lpfc_iocbq *nextiocb;
2862 if (piocb->iocb_cmpl && (!piocb->vport) &&
2863 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
2864 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
2865 lpfc_printf_log(phba, KERN_ERR,
2866 LOG_SLI | LOG_VPORT,
2867 "%d:1807 IOCB x%x failed. No vport\n",
2869 piocb->iocb.ulpCommand);
2875 /* If the PCI channel is in offline state, do not post iocbs. */
2876 if (unlikely(pci_channel_offline(phba->pcidev)))
2880 * We should never get an IOCB if we are in a < LINK_DOWN state
2882 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
2886 * Check to see if we are blocking IOCB processing because of a
2887 * outstanding mbox command.
2889 if (unlikely(pring->flag & LPFC_STOP_IOCB_MBX))
2892 if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
2894 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
2895 * can be issued if the link is not up.
2897 switch (piocb->iocb.ulpCommand) {
2898 case CMD_QUE_RING_BUF_CN:
2899 case CMD_QUE_RING_BUF64_CN:
2901 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
2902 * completion, iocb_cmpl MUST be 0.
2904 if (piocb->iocb_cmpl)
2905 piocb->iocb_cmpl = NULL;
2907 case CMD_CREATE_XRI_CR:
2908 case CMD_CLOSE_XRI_CN:
2909 case CMD_CLOSE_XRI_CX:
2916 * For FCP commands, we must be in a state where we can process link
2919 } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
2920 !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
2924 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
2925 (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
2926 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
2929 lpfc_sli_update_ring(phba, pring);
2931 lpfc_sli_update_full_ring(phba, pring);
2934 return IOCB_SUCCESS;
2939 pring->stats.iocb_cmd_delay++;
2943 if (!(flag & SLI_IOCB_RET_IOCB)) {
2944 __lpfc_sli_ringtx_put(phba, pring, piocb);
2945 return IOCB_SUCCESS;
2953 lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2954 struct lpfc_iocbq *piocb, uint32_t flag)
2956 unsigned long iflags;
2959 spin_lock_irqsave(&phba->hbalock, iflags);
2960 rc = __lpfc_sli_issue_iocb(phba, pring, piocb, flag);
2961 spin_unlock_irqrestore(&phba->hbalock, iflags);
2967 lpfc_extra_ring_setup( struct lpfc_hba *phba)
2969 struct lpfc_sli *psli;
2970 struct lpfc_sli_ring *pring;
2974 /* Adjust cmd/rsp ring iocb entries more evenly */
2976 /* Take some away from the FCP ring */
2977 pring = &psli->ring[psli->fcp_ring];
2978 pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
2979 pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
2980 pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
2981 pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
2983 /* and give them to the extra ring */
2984 pring = &psli->ring[psli->extra_ring];
2986 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
2987 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
2988 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
2989 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
2991 /* Setup default profile for this ring */
2992 pring->iotag_max = 4096;
2993 pring->num_mask = 1;
2994 pring->prt[0].profile = 0; /* Mask 0 */
2995 pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
2996 pring->prt[0].type = phba->cfg_multi_ring_type;
2997 pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
3002 lpfc_sli_setup(struct lpfc_hba *phba)
3004 int i, totiocbsize = 0;
3005 struct lpfc_sli *psli = &phba->sli;
3006 struct lpfc_sli_ring *pring;
3008 psli->num_rings = MAX_CONFIGURED_RINGS;
3010 psli->fcp_ring = LPFC_FCP_RING;
3011 psli->next_ring = LPFC_FCP_NEXT_RING;
3012 psli->extra_ring = LPFC_EXTRA_RING;
3014 psli->iocbq_lookup = NULL;
3015 psli->iocbq_lookup_len = 0;
3016 psli->last_iotag = 0;
3018 for (i = 0; i < psli->num_rings; i++) {
3019 pring = &psli->ring[i];
3021 case LPFC_FCP_RING: /* ring 0 - FCP */
3022 /* numCiocb and numRiocb are used in config_port */
3023 pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
3024 pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
3025 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
3026 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
3027 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
3028 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_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_ctr = 0;
3037 (phba->cfg_hba_queue_depth * 2);
3038 pring->fast_iotag = pring->iotag_max;
3039 pring->num_mask = 0;
3041 case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
3042 /* numCiocb and numRiocb are used in config_port */
3043 pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
3044 pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
3045 pring->sizeCiocb = (phba->sli_rev == 3) ?
3046 SLI3_IOCB_CMD_SIZE :
3048 pring->sizeRiocb = (phba->sli_rev == 3) ?
3049 SLI3_IOCB_RSP_SIZE :
3051 pring->iotag_max = phba->cfg_hba_queue_depth;
3052 pring->num_mask = 0;
3054 case LPFC_ELS_RING: /* ring 2 - ELS / CT */
3055 /* numCiocb and numRiocb are used in config_port */
3056 pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
3057 pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
3058 pring->sizeCiocb = (phba->sli_rev == 3) ?
3059 SLI3_IOCB_CMD_SIZE :
3061 pring->sizeRiocb = (phba->sli_rev == 3) ?
3062 SLI3_IOCB_RSP_SIZE :
3064 pring->fast_iotag = 0;
3065 pring->iotag_ctr = 0;
3066 pring->iotag_max = 4096;
3067 pring->num_mask = 4;
3068 pring->prt[0].profile = 0; /* Mask 0 */
3069 pring->prt[0].rctl = FC_ELS_REQ;
3070 pring->prt[0].type = FC_ELS_DATA;
3071 pring->prt[0].lpfc_sli_rcv_unsol_event =
3072 lpfc_els_unsol_event;
3073 pring->prt[1].profile = 0; /* Mask 1 */
3074 pring->prt[1].rctl = FC_ELS_RSP;
3075 pring->prt[1].type = FC_ELS_DATA;
3076 pring->prt[1].lpfc_sli_rcv_unsol_event =
3077 lpfc_els_unsol_event;
3078 pring->prt[2].profile = 0; /* Mask 2 */
3079 /* NameServer Inquiry */
3080 pring->prt[2].rctl = FC_UNSOL_CTL;
3082 pring->prt[2].type = FC_COMMON_TRANSPORT_ULP;
3083 pring->prt[2].lpfc_sli_rcv_unsol_event =
3084 lpfc_ct_unsol_event;
3085 pring->prt[3].profile = 0; /* Mask 3 */
3086 /* NameServer response */
3087 pring->prt[3].rctl = FC_SOL_CTL;
3089 pring->prt[3].type = FC_COMMON_TRANSPORT_ULP;
3090 pring->prt[3].lpfc_sli_rcv_unsol_event =
3091 lpfc_ct_unsol_event;
3094 totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
3095 (pring->numRiocb * pring->sizeRiocb);
3097 if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
3098 /* Too many cmd / rsp ring entries in SLI2 SLIM */
3099 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3100 "%d:0462 Too many cmd / rsp ring entries in "
3101 "SLI2 SLIM Data: x%x x%lx\n",
3102 phba->brd_no, totiocbsize,
3103 (unsigned long) MAX_SLIM_IOCB_SIZE);
3105 if (phba->cfg_multi_ring_support == 2)
3106 lpfc_extra_ring_setup(phba);
3112 lpfc_sli_queue_setup(struct lpfc_hba *phba)
3114 struct lpfc_sli *psli;
3115 struct lpfc_sli_ring *pring;
3119 spin_lock_irq(&phba->hbalock);
3120 INIT_LIST_HEAD(&psli->mboxq);
3121 INIT_LIST_HEAD(&psli->mboxq_cmpl);
3122 /* Initialize list headers for txq and txcmplq as double linked lists */
3123 for (i = 0; i < psli->num_rings; i++) {
3124 pring = &psli->ring[i];
3126 pring->next_cmdidx = 0;
3127 pring->local_getidx = 0;
3129 INIT_LIST_HEAD(&pring->txq);
3130 INIT_LIST_HEAD(&pring->txcmplq);
3131 INIT_LIST_HEAD(&pring->iocb_continueq);
3132 INIT_LIST_HEAD(&pring->postbufq);
3134 spin_unlock_irq(&phba->hbalock);
3139 lpfc_sli_host_down(struct lpfc_vport *vport)
3141 LIST_HEAD(completions);
3142 struct lpfc_hba *phba = vport->phba;
3143 struct lpfc_sli *psli = &phba->sli;
3144 struct lpfc_sli_ring *pring;
3145 struct lpfc_iocbq *iocb, *next_iocb;
3147 unsigned long flags = 0;
3148 uint16_t prev_pring_flag;
3150 lpfc_cleanup_discovery_resources(vport);
3152 spin_lock_irqsave(&phba->hbalock, flags);
3153 for (i = 0; i < psli->num_rings; i++) {
3154 pring = &psli->ring[i];
3155 prev_pring_flag = pring->flag;
3156 if (pring->ringno == LPFC_ELS_RING) /* Only slow rings */
3157 pring->flag |= LPFC_DEFERRED_RING_EVENT;
3159 * Error everything on the txq since these iocbs have not been
3160 * given to the FW yet.
3162 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
3163 if (iocb->vport != vport)
3165 list_move_tail(&iocb->list, &completions);
3169 /* Next issue ABTS for everything on the txcmplq */
3170 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
3172 if (iocb->vport != vport)
3174 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
3177 pring->flag = prev_pring_flag;
3180 spin_unlock_irqrestore(&phba->hbalock, flags);
3182 while (!list_empty(&completions)) {
3183 list_remove_head(&completions, iocb, struct lpfc_iocbq, list);
3185 if (!iocb->iocb_cmpl)
3186 lpfc_sli_release_iocbq(phba, iocb);
3188 iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
3189 iocb->iocb.un.ulpWord[4] = IOERR_SLI_DOWN;
3190 (iocb->iocb_cmpl) (phba, iocb, iocb);
3197 lpfc_sli_hba_down(struct lpfc_hba *phba)
3199 LIST_HEAD(completions);
3200 struct lpfc_sli *psli = &phba->sli;
3201 struct lpfc_sli_ring *pring;
3203 struct lpfc_iocbq *iocb;
3206 unsigned long flags = 0;
3208 lpfc_hba_down_prep(phba);
3210 lpfc_fabric_abort_hba(phba);
3212 spin_lock_irqsave(&phba->hbalock, flags);
3213 for (i = 0; i < psli->num_rings; i++) {
3214 pring = &psli->ring[i];
3215 if (pring->ringno == LPFC_ELS_RING) /* Only slow rings */
3216 pring->flag |= LPFC_DEFERRED_RING_EVENT;
3219 * Error everything on the txq since these iocbs have not been
3220 * given to the FW yet.
3222 list_splice_init(&pring->txq, &completions);
3226 spin_unlock_irqrestore(&phba->hbalock, flags);
3228 while (!list_empty(&completions)) {
3229 list_remove_head(&completions, iocb, struct lpfc_iocbq, list);
3232 if (!iocb->iocb_cmpl)
3233 lpfc_sli_release_iocbq(phba, iocb);
3235 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3236 cmd->un.ulpWord[4] = IOERR_SLI_DOWN;
3237 (iocb->iocb_cmpl) (phba, iocb, iocb);
3241 /* Return any active mbox cmds */
3242 del_timer_sync(&psli->mbox_tmo);
3243 spin_lock_irqsave(&phba->hbalock, flags);
3245 spin_lock(&phba->pport->work_port_lock);
3246 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
3247 spin_unlock(&phba->pport->work_port_lock);
3249 if (psli->mbox_active) {
3250 list_add_tail(&psli->mbox_active->list, &completions);
3251 psli->mbox_active = NULL;
3252 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
3255 /* Return any pending or completed mbox cmds */
3256 list_splice_init(&phba->sli.mboxq, &completions);
3257 list_splice_init(&phba->sli.mboxq_cmpl, &completions);
3258 INIT_LIST_HEAD(&psli->mboxq);
3259 INIT_LIST_HEAD(&psli->mboxq_cmpl);
3261 spin_unlock_irqrestore(&phba->hbalock, flags);
3263 while (!list_empty(&completions)) {
3264 list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
3265 pmb->mb.mbxStatus = MBX_NOT_FINISHED;
3266 if (pmb->mbox_cmpl) {
3267 pmb->mbox_cmpl(phba,pmb);
3274 lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
3276 uint32_t *src = srcp;
3277 uint32_t *dest = destp;
3281 for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
3283 ldata = le32_to_cpu(ldata);
3291 lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3292 struct lpfc_dmabuf *mp)
3294 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
3296 spin_lock_irq(&phba->hbalock);
3297 list_add_tail(&mp->list, &pring->postbufq);
3298 pring->postbufq_cnt++;
3299 spin_unlock_irq(&phba->hbalock);
3304 struct lpfc_dmabuf *
3305 lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3308 struct lpfc_dmabuf *mp, *next_mp;
3309 struct list_head *slp = &pring->postbufq;
3311 /* Search postbufq, from the begining, looking for a match on phys */
3312 spin_lock_irq(&phba->hbalock);
3313 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
3314 if (mp->phys == phys) {
3315 list_del_init(&mp->list);
3316 pring->postbufq_cnt--;
3317 spin_unlock_irq(&phba->hbalock);
3322 spin_unlock_irq(&phba->hbalock);
3323 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3324 "%d:0410 Cannot find virtual addr for mapped buf on "
3325 "ring %d Data x%llx x%p x%p x%x\n",
3326 phba->brd_no, pring->ringno, (unsigned long long)phys,
3327 slp->next, slp->prev, pring->postbufq_cnt);
3332 lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3333 struct lpfc_iocbq *rspiocb)
3335 IOCB_t *irsp = &rspiocb->iocb;
3336 uint16_t abort_iotag, abort_context;
3337 struct lpfc_iocbq *abort_iocb;
3338 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
3342 if (irsp->ulpStatus) {
3343 abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
3344 abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
3346 spin_lock_irq(&phba->hbalock);
3347 if (abort_iotag != 0 && abort_iotag <= phba->sli.last_iotag)
3348 abort_iocb = phba->sli.iocbq_lookup[abort_iotag];
3350 lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI,
3351 "%d:0327 Cannot abort els iocb %p "
3352 "with tag %x context %x, abort status %x, "
3354 phba->brd_no, abort_iocb, abort_iotag,
3355 abort_context, irsp->ulpStatus,
3356 irsp->un.ulpWord[4]);
3359 * make sure we have the right iocbq before taking it
3360 * off the txcmplq and try to call completion routine.
3363 abort_iocb->iocb.ulpContext != abort_context ||
3364 (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
3365 spin_unlock_irq(&phba->hbalock);
3367 list_del_init(&abort_iocb->list);
3368 pring->txcmplq_cnt--;
3369 spin_unlock_irq(&phba->hbalock);
3371 abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
3372 abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
3373 abort_iocb->iocb.un.ulpWord[4] = IOERR_SLI_ABORTED;
3374 (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
3378 lpfc_sli_release_iocbq(phba, cmdiocb);
3383 lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3384 struct lpfc_iocbq *rspiocb)
3386 IOCB_t *irsp = &rspiocb->iocb;
3388 /* ELS cmd tag <ulpIoTag> completes */
3389 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
3390 "%d (X):0133 Ignoring ELS cmd tag x%x completion Data: "
3392 phba->brd_no, irsp->ulpIoTag, irsp->ulpStatus,
3393 irsp->un.ulpWord[4], irsp->ulpTimeout);
3394 if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
3395 lpfc_ct_free_iocb(phba, cmdiocb);
3397 lpfc_els_free_iocb(phba, cmdiocb);
3402 lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3403 struct lpfc_iocbq *cmdiocb)
3405 struct lpfc_vport *vport = cmdiocb->vport;
3406 struct lpfc_iocbq *abtsiocbp;
3407 IOCB_t *icmd = NULL;
3408 IOCB_t *iabt = NULL;
3409 int retval = IOCB_ERROR;
3412 * There are certain command types we don't want to abort. And we
3413 * don't want to abort commands that are already in the process of
3416 icmd = &cmdiocb->iocb;
3417 if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
3418 icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
3419 (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
3422 /* If we're unloading, don't abort iocb on the ELS ring, but change the
3423 * callback so that nothing happens when it finishes.
3425 if ((vport->load_flag & FC_UNLOADING) &&
3426 (pring->ringno == LPFC_ELS_RING)) {
3427 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
3428 cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
3430 cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
3431 goto abort_iotag_exit;
3434 /* issue ABTS for this IOCB based on iotag */
3435 abtsiocbp = __lpfc_sli_get_iocbq(phba);
3436 if (abtsiocbp == NULL)
3439 /* This signals the response to set the correct status
3440 * before calling the completion handler.
3442 cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
3444 iabt = &abtsiocbp->iocb;
3445 iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
3446 iabt->un.acxri.abortContextTag = icmd->ulpContext;
3447 iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
3449 iabt->ulpClass = icmd->ulpClass;
3451 if (phba->link_state >= LPFC_LINK_UP)
3452 iabt->ulpCommand = CMD_ABORT_XRI_CN;
3454 iabt->ulpCommand = CMD_CLOSE_XRI_CN;
3456 abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
3458 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3459 "%d (%d):0339 Abort xri x%x, original iotag x%x, "
3460 "abort cmd iotag x%x\n",
3461 phba->brd_no, vport->vpi,
3462 iabt->un.acxri.abortContextTag,
3463 iabt->un.acxri.abortIoTag, abtsiocbp->iotag);
3464 retval = __lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0);
3468 * Caller to this routine should check for IOCB_ERROR
3469 * and handle it properly. This routine no longer removes
3470 * iocb off txcmplq and call compl in case of IOCB_ERROR.
3476 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, uint16_t tgt_id,
3477 uint64_t lun_id, uint32_t ctx,
3478 lpfc_ctx_cmd ctx_cmd)
3480 struct lpfc_scsi_buf *lpfc_cmd;
3481 struct scsi_cmnd *cmnd;
3484 if (!(iocbq->iocb_flag & LPFC_IO_FCP))
3487 lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
3488 cmnd = lpfc_cmd->pCmd;
3495 if ((cmnd->device->id == tgt_id) &&
3496 (cmnd->device->lun == lun_id))
3500 if (cmnd->device->id == tgt_id)
3504 if (iocbq->iocb.ulpContext == ctx)
3511 printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
3512 __FUNCTION__, ctx_cmd);
3520 lpfc_sli_sum_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3521 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd ctx_cmd)
3523 struct lpfc_iocbq *iocbq;
3526 for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
3527 iocbq = phba->sli.iocbq_lookup[i];
3529 if (lpfc_sli_validate_fcp_iocb (iocbq, tgt_id, lun_id,
3538 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3539 struct lpfc_iocbq *rspiocb)
3541 lpfc_sli_release_iocbq(phba, cmdiocb);
3546 lpfc_sli_abort_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3547 uint16_t tgt_id, uint64_t lun_id, uint32_t ctx,
3548 lpfc_ctx_cmd abort_cmd)
3550 struct lpfc_iocbq *iocbq;
3551 struct lpfc_iocbq *abtsiocb;
3553 int errcnt = 0, ret_val = 0;
3556 for (i = 1; i <= phba->sli.last_iotag; i++) {
3557 iocbq = phba->sli.iocbq_lookup[i];
3559 if (lpfc_sli_validate_fcp_iocb(iocbq, tgt_id, lun_id, 0,
3563 /* issue ABTS for this IOCB based on iotag */
3564 abtsiocb = lpfc_sli_get_iocbq(phba);
3565 if (abtsiocb == NULL) {
3571 abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
3572 abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
3573 abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
3574 abtsiocb->iocb.ulpLe = 1;
3575 abtsiocb->iocb.ulpClass = cmd->ulpClass;
3576 abtsiocb->vport = phba->pport;
3578 if (lpfc_is_link_up(phba))
3579 abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
3581 abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
3583 /* Setup callback routine and issue the command. */
3584 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
3585 ret_val = lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0);
3586 if (ret_val == IOCB_ERROR) {
3587 lpfc_sli_release_iocbq(phba, abtsiocb);
3597 lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
3598 struct lpfc_iocbq *cmdiocbq,
3599 struct lpfc_iocbq *rspiocbq)
3601 wait_queue_head_t *pdone_q;
3602 unsigned long iflags;
3604 spin_lock_irqsave(&phba->hbalock, iflags);
3605 cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
3606 if (cmdiocbq->context2 && rspiocbq)
3607 memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
3608 &rspiocbq->iocb, sizeof(IOCB_t));
3610 pdone_q = cmdiocbq->context_un.wait_queue;
3613 spin_unlock_irqrestore(&phba->hbalock, iflags);
3618 * Issue the caller's iocb and wait for its completion, but no longer than the
3619 * caller's timeout. Note that iocb_flags is cleared before the
3620 * lpfc_sli_issue_call since the wake routine sets a unique value and by
3621 * definition this is a wait function.
3625 lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
3626 struct lpfc_sli_ring *pring,
3627 struct lpfc_iocbq *piocb,
3628 struct lpfc_iocbq *prspiocbq,
3631 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
3632 long timeleft, timeout_req = 0;
3633 int retval = IOCB_SUCCESS;
3637 * If the caller has provided a response iocbq buffer, then context2
3638 * is NULL or its an error.
3641 if (piocb->context2)
3643 piocb->context2 = prspiocbq;
3646 piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
3647 piocb->context_un.wait_queue = &done_q;
3648 piocb->iocb_flag &= ~LPFC_IO_WAKE;
3650 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
3651 creg_val = readl(phba->HCregaddr);
3652 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
3653 writel(creg_val, phba->HCregaddr);
3654 readl(phba->HCregaddr); /* flush */
3657 retval = lpfc_sli_issue_iocb(phba, pring, piocb, 0);
3658 if (retval == IOCB_SUCCESS) {
3659 timeout_req = timeout * HZ;
3660 timeleft = wait_event_timeout(done_q,
3661 piocb->iocb_flag & LPFC_IO_WAKE,
3664 if (piocb->iocb_flag & LPFC_IO_WAKE) {
3665 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3666 "%d:0331 IOCB wake signaled\n",
3668 } else if (timeleft == 0) {
3669 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3670 "%d:0338 IOCB wait timeout error - no "
3671 "wake response Data x%x\n",
3672 phba->brd_no, timeout);
3673 retval = IOCB_TIMEDOUT;
3675 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3676 "%d:0330 IOCB wake NOT set, "
3677 "Data x%x x%lx\n", phba->brd_no,
3678 timeout, (timeleft / jiffies));
3679 retval = IOCB_TIMEDOUT;
3682 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3683 "%d:0332 IOCB wait issue failed, Data x%x\n",
3684 phba->brd_no, retval);
3685 retval = IOCB_ERROR;
3688 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
3689 creg_val = readl(phba->HCregaddr);
3690 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
3691 writel(creg_val, phba->HCregaddr);
3692 readl(phba->HCregaddr); /* flush */
3696 piocb->context2 = NULL;
3698 piocb->context_un.wait_queue = NULL;
3699 piocb->iocb_cmpl = NULL;
3704 lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
3707 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
3711 /* The caller must leave context1 empty. */
3712 if (pmboxq->context1 != 0)
3713 return MBX_NOT_FINISHED;
3715 /* setup wake call as IOCB callback */
3716 pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
3717 /* setup context field to pass wait_queue pointer to wake function */
3718 pmboxq->context1 = &done_q;
3720 /* now issue the command */
3721 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
3723 if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
3724 wait_event_interruptible_timeout(done_q,
3725 pmboxq->mbox_flag & LPFC_MBX_WAKE,
3728 spin_lock_irqsave(&phba->hbalock, flag);
3729 pmboxq->context1 = NULL;
3731 * if LPFC_MBX_WAKE flag is set the mailbox is completed
3732 * else do not free the resources.
3734 if (pmboxq->mbox_flag & LPFC_MBX_WAKE)
3735 retval = MBX_SUCCESS;
3737 retval = MBX_TIMEOUT;
3738 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3740 spin_unlock_irqrestore(&phba->hbalock, flag);
3747 lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba)
3749 struct lpfc_vport *vport = phba->pport;
3753 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE && !vport->stopped) {
3754 if (i++ > LPFC_MBOX_TMO * 1000)
3758 * Call lpfc_sli_handle_mb_event only if a mailbox cmd
3759 * did finish. This way we won't get the misleading
3760 * "Stray Mailbox Interrupt" message.
3762 spin_lock_irq(&phba->hbalock);
3763 ha_copy = phba->work_ha;
3764 phba->work_ha &= ~HA_MBATT;
3765 spin_unlock_irq(&phba->hbalock);
3767 if (ha_copy & HA_MBATT)
3768 if (lpfc_sli_handle_mb_event(phba) == 0)
3774 return (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) ? 1 : 0;
3778 lpfc_intr_handler(int irq, void *dev_id)
3780 struct lpfc_hba *phba;
3782 uint32_t work_ha_copy;
3783 unsigned long status;
3787 MAILBOX_t *mbox, *pmbox;
3788 struct lpfc_vport *vport;
3789 struct lpfc_nodelist *ndlp;
3790 struct lpfc_dmabuf *mp;
3795 * Get the driver's phba structure from the dev_id and
3796 * assume the HBA is not interrupting.
3798 phba = (struct lpfc_hba *) dev_id;
3800 if (unlikely(!phba))
3803 /* If the pci channel is offline, ignore all the interrupts. */
3804 if (unlikely(pci_channel_offline(phba->pcidev)))
3807 phba->sli.slistat.sli_intr++;
3810 * Call the HBA to see if it is interrupting. If not, don't claim
3814 /* Ignore all interrupts during initialization. */
3815 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
3819 * Read host attention register to determine interrupt source
3820 * Clear Attention Sources, except Error Attention (to
3821 * preserve status) and Link Attention
3823 spin_lock(&phba->hbalock);
3824 ha_copy = readl(phba->HAregaddr);
3825 /* If somebody is waiting to handle an eratt don't process it
3826 * here. The brdkill function will do this.
3828 if (phba->link_flag & LS_IGNORE_ERATT)
3829 ha_copy &= ~HA_ERATT;
3830 writel((ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
3831 readl(phba->HAregaddr); /* flush */
3832 spin_unlock(&phba->hbalock);
3834 if (unlikely(!ha_copy))
3837 work_ha_copy = ha_copy & phba->work_ha_mask;
3839 if (unlikely(work_ha_copy)) {
3840 if (work_ha_copy & HA_LATT) {
3841 if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
3843 * Turn off Link Attention interrupts
3844 * until CLEAR_LA done
3846 spin_lock(&phba->hbalock);
3847 phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
3848 control = readl(phba->HCregaddr);
3849 control &= ~HC_LAINT_ENA;
3850 writel(control, phba->HCregaddr);
3851 readl(phba->HCregaddr); /* flush */
3852 spin_unlock(&phba->hbalock);
3855 work_ha_copy &= ~HA_LATT;
3858 if (work_ha_copy & ~(HA_ERATT|HA_MBATT|HA_LATT)) {
3860 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
3861 * the only slow ring.
3863 status = (work_ha_copy &
3864 (HA_RXMASK << (4*LPFC_ELS_RING)));
3865 status >>= (4*LPFC_ELS_RING);
3866 if (status & HA_RXMASK) {
3867 spin_lock(&phba->hbalock);
3868 control = readl(phba->HCregaddr);
3870 lpfc_debugfs_slow_ring_trc(phba,
3871 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
3873 (uint32_t)phba->sli.slistat.sli_intr);
3875 if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
3876 lpfc_debugfs_slow_ring_trc(phba,
3878 "pwork:x%x hawork:x%x wait:x%x",
3879 phba->work_ha, work_ha_copy,
3880 (uint32_t)((unsigned long)
3884 ~(HC_R0INT_ENA << LPFC_ELS_RING);
3885 writel(control, phba->HCregaddr);
3886 readl(phba->HCregaddr); /* flush */
3889 lpfc_debugfs_slow_ring_trc(phba,
3890 "ISR slow ring: pwork:"
3891 "x%x hawork:x%x wait:x%x",
3892 phba->work_ha, work_ha_copy,
3893 (uint32_t)((unsigned long)
3896 spin_unlock(&phba->hbalock);
3900 if (work_ha_copy & HA_ERATT) {
3901 phba->link_state = LPFC_HBA_ERROR;
3903 * There was a link/board error. Read the
3904 * status register to retrieve the error event
3907 phba->sli.slistat.err_attn_event++;
3908 /* Save status info */
3909 phba->work_hs = readl(phba->HSregaddr);
3910 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
3911 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
3913 /* Clear Chip error bit */
3914 writel(HA_ERATT, phba->HAregaddr);
3915 readl(phba->HAregaddr); /* flush */
3916 phba->pport->stopped = 1;
3919 if ((work_ha_copy & HA_MBATT) &&
3920 (phba->sli.mbox_active)) {
3921 pmb = phba->sli.mbox_active;
3923 mbox = &phba->slim2p->mbx;
3926 /* First check out the status word */
3927 lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
3928 if (pmbox->mbxOwner != OWN_HOST) {
3930 * Stray Mailbox Interrupt, mbxCommand <cmd>
3931 * mbxStatus <status>
3933 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX |
3935 "%d (%d):0304 Stray Mailbox "
3936 "Interrupt mbxCommand x%x "
3944 phba->last_completion_time = jiffies;
3945 del_timer_sync(&phba->sli.mbox_tmo);
3947 phba->sli.mbox_active = NULL;
3948 if (pmb->mbox_cmpl) {
3949 lpfc_sli_pcimem_bcopy(mbox, pmbox,
3952 if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
3953 pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
3955 lpfc_debugfs_disc_trc(vport,
3956 LPFC_DISC_TRC_MBOX_VPORT,
3957 "MBOX dflt rpi: : status:x%x rpi:x%x",
3958 (uint32_t)pmbox->mbxStatus,
3959 pmbox->un.varWords[0], 0);
3961 if ( !pmbox->mbxStatus) {
3962 mp = (struct lpfc_dmabuf *)
3964 ndlp = (struct lpfc_nodelist *)
3967 /* Reg_LOGIN of dflt RPI was successful.
3968 * new lets get rid of the RPI using the
3971 lpfc_unreg_login(phba, vport->vpi,
3972 pmbox->un.varWords[0], pmb);
3973 pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3975 pmb->context2 = ndlp;
3977 spin_lock(&phba->hbalock);
3978 phba->sli.sli_flag &=
3979 ~LPFC_SLI_MBOX_ACTIVE;
3980 spin_unlock(&phba->hbalock);
3981 goto send_current_mbox;
3984 spin_lock(&phba->pport->work_port_lock);
3985 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
3986 spin_unlock(&phba->pport->work_port_lock);
3987 lpfc_mbox_cmpl_put(phba, pmb);
3989 if ((work_ha_copy & HA_MBATT) &&
3990 (phba->sli.mbox_active == NULL)) {
3992 spin_lock(&phba->hbalock);
3993 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
3994 pmb = lpfc_mbox_get(phba);
3995 spin_unlock(&phba->hbalock);
3997 /* Process next mailbox command if there is one */
3999 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4000 if (rc == MBX_NOT_FINISHED) {
4001 pmb->mb.mbxStatus = MBX_NOT_FINISHED;
4002 lpfc_mbox_cmpl_put(phba, pmb);
4003 goto send_next_mbox;
4006 /* Turn on IOCB processing */
4007 for (i = 0; i < phba->sli.num_rings; i++)
4008 lpfc_sli_turn_on_ring(phba, i);
4013 spin_lock(&phba->hbalock);
4014 phba->work_ha |= work_ha_copy;
4015 if (phba->work_wait)
4016 lpfc_worker_wake_up(phba);
4017 spin_unlock(&phba->hbalock);
4020 ha_copy &= ~(phba->work_ha_mask);
4023 * Process all events on FCP ring. Take the optimized path for
4024 * FCP IO. Any other IO is slow path and is handled by
4025 * the worker thread.
4027 status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
4028 status >>= (4*LPFC_FCP_RING);
4029 if (status & HA_RXMASK)
4030 lpfc_sli_handle_fast_ring_event(phba,
4031 &phba->sli.ring[LPFC_FCP_RING],
4034 if (phba->cfg_multi_ring_support == 2) {
4036 * Process all events on extra ring. Take the optimized path
4037 * for extra ring IO. Any other IO is slow path and is handled
4038 * by the worker thread.
4040 status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
4041 status >>= (4*LPFC_EXTRA_RING);
4042 if (status & HA_RXMASK) {
4043 lpfc_sli_handle_fast_ring_event(phba,
4044 &phba->sli.ring[LPFC_EXTRA_RING],
4050 } /* lpfc_intr_handler */