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):0311 Mailbox command x%x cannot " \
53 "issue Data: x%x x%x x%x\n", \
54 pmbox->vport ? pmbox->vport->vpi : 0, \
55 pmbox->mb.mbxCommand, \
56 phba->pport->port_state, \
61 /* There are only four IOCB completion types. */
62 typedef enum _lpfc_iocb_type {
69 /* SLI-2/SLI-3 provide different sized iocbs. Given a pointer
70 * to the start of the ring, and the slot number of the
71 * desired iocb entry, calc a pointer to that entry.
73 static inline IOCB_t *
74 lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
76 return (IOCB_t *) (((char *) pring->cmdringaddr) +
77 pring->cmdidx * phba->iocb_cmd_size);
80 static inline IOCB_t *
81 lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
83 return (IOCB_t *) (((char *) pring->rspringaddr) +
84 pring->rspidx * phba->iocb_rsp_size);
87 static struct lpfc_iocbq *
88 __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
90 struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
91 struct lpfc_iocbq * iocbq = NULL;
93 list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
98 lpfc_sli_get_iocbq(struct lpfc_hba *phba)
100 struct lpfc_iocbq * iocbq = NULL;
101 unsigned long iflags;
103 spin_lock_irqsave(&phba->hbalock, iflags);
104 iocbq = __lpfc_sli_get_iocbq(phba);
105 spin_unlock_irqrestore(&phba->hbalock, iflags);
110 __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
112 size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
115 * Clean all volatile data fields, preserve iotag and node struct.
117 memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
118 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
122 lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
124 unsigned long iflags;
127 * Clean all volatile data fields, preserve iotag and node struct.
129 spin_lock_irqsave(&phba->hbalock, iflags);
130 __lpfc_sli_release_iocbq(phba, iocbq);
131 spin_unlock_irqrestore(&phba->hbalock, iflags);
135 * Translate the iocb command to an iocb command type used to decide the final
136 * disposition of each completed IOCB.
138 static lpfc_iocb_type
139 lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
141 lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
143 if (iocb_cmnd > CMD_MAX_IOCB_CMD)
147 case CMD_XMIT_SEQUENCE_CR:
148 case CMD_XMIT_SEQUENCE_CX:
149 case CMD_XMIT_BCAST_CN:
150 case CMD_XMIT_BCAST_CX:
151 case CMD_ELS_REQUEST_CR:
152 case CMD_ELS_REQUEST_CX:
153 case CMD_CREATE_XRI_CR:
154 case CMD_CREATE_XRI_CX:
156 case CMD_XMIT_ELS_RSP_CX:
158 case CMD_FCP_IWRITE_CR:
159 case CMD_FCP_IWRITE_CX:
160 case CMD_FCP_IREAD_CR:
161 case CMD_FCP_IREAD_CX:
162 case CMD_FCP_ICMND_CR:
163 case CMD_FCP_ICMND_CX:
164 case CMD_FCP_TSEND_CX:
165 case CMD_FCP_TRSP_CX:
166 case CMD_FCP_TRECEIVE_CX:
167 case CMD_FCP_AUTO_TRSP_CX:
168 case CMD_ADAPTER_MSG:
169 case CMD_ADAPTER_DUMP:
170 case CMD_XMIT_SEQUENCE64_CR:
171 case CMD_XMIT_SEQUENCE64_CX:
172 case CMD_XMIT_BCAST64_CN:
173 case CMD_XMIT_BCAST64_CX:
174 case CMD_ELS_REQUEST64_CR:
175 case CMD_ELS_REQUEST64_CX:
176 case CMD_FCP_IWRITE64_CR:
177 case CMD_FCP_IWRITE64_CX:
178 case CMD_FCP_IREAD64_CR:
179 case CMD_FCP_IREAD64_CX:
180 case CMD_FCP_ICMND64_CR:
181 case CMD_FCP_ICMND64_CX:
182 case CMD_FCP_TSEND64_CX:
183 case CMD_FCP_TRSP64_CX:
184 case CMD_FCP_TRECEIVE64_CX:
185 case CMD_GEN_REQUEST64_CR:
186 case CMD_GEN_REQUEST64_CX:
187 case CMD_XMIT_ELS_RSP64_CX:
188 type = LPFC_SOL_IOCB;
190 case CMD_ABORT_XRI_CN:
191 case CMD_ABORT_XRI_CX:
192 case CMD_CLOSE_XRI_CN:
193 case CMD_CLOSE_XRI_CX:
194 case CMD_XRI_ABORTED_CX:
195 case CMD_ABORT_MXRI64_CN:
196 type = LPFC_ABORT_IOCB;
198 case CMD_RCV_SEQUENCE_CX:
199 case CMD_RCV_ELS_REQ_CX:
200 case CMD_RCV_SEQUENCE64_CX:
201 case CMD_RCV_ELS_REQ64_CX:
202 case CMD_ASYNC_STATUS:
203 case CMD_IOCB_RCV_SEQ64_CX:
204 case CMD_IOCB_RCV_ELS64_CX:
205 case CMD_IOCB_RCV_CONT64_CX:
206 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 "0446 Adapter failed to init (%d), "
235 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
237 rc, pmbox->mbxCommand,
238 pmbox->mbxStatus, i);
239 phba->link_state = LPFC_HBA_ERROR;
244 mempool_free(pmb, phba->mbox_mem_pool);
249 lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
250 struct lpfc_iocbq *piocb)
252 list_add_tail(&piocb->list, &pring->txcmplq);
253 pring->txcmplq_cnt++;
254 if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
255 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
256 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
260 mod_timer(&piocb->vport->els_tmofunc,
261 jiffies + HZ * (phba->fc_ratov << 1));
268 static struct lpfc_iocbq *
269 lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
271 struct lpfc_iocbq *cmd_iocb;
273 list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
274 if (cmd_iocb != NULL)
280 lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
282 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
283 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
284 &phba->slim2p->mbx.us.s2.port[pring->ringno];
285 uint32_t max_cmd_idx = pring->numCiocb;
287 if ((pring->next_cmdidx == pring->cmdidx) &&
288 (++pring->next_cmdidx >= max_cmd_idx))
289 pring->next_cmdidx = 0;
291 if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
293 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
295 if (unlikely(pring->local_getidx >= max_cmd_idx)) {
296 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
297 "0315 Ring %d issue: portCmdGet %d "
298 "is bigger then cmd ring %d\n",
300 pring->local_getidx, max_cmd_idx);
302 phba->link_state = LPFC_HBA_ERROR;
304 * All error attention handlers are posted to
307 phba->work_ha |= HA_ERATT;
308 phba->work_hs = HS_FFER3;
310 /* hbalock should already be held */
312 lpfc_worker_wake_up(phba);
317 if (pring->local_getidx == pring->next_cmdidx)
321 return lpfc_cmd_iocb(phba, pring);
325 lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
327 struct lpfc_iocbq **new_arr;
328 struct lpfc_iocbq **old_arr;
330 struct lpfc_sli *psli = &phba->sli;
333 spin_lock_irq(&phba->hbalock);
334 iotag = psli->last_iotag;
335 if(++iotag < psli->iocbq_lookup_len) {
336 psli->last_iotag = iotag;
337 psli->iocbq_lookup[iotag] = iocbq;
338 spin_unlock_irq(&phba->hbalock);
339 iocbq->iotag = iotag;
341 } else if (psli->iocbq_lookup_len < (0xffff
342 - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
343 new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
344 spin_unlock_irq(&phba->hbalock);
345 new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
348 spin_lock_irq(&phba->hbalock);
349 old_arr = psli->iocbq_lookup;
350 if (new_len <= psli->iocbq_lookup_len) {
351 /* highly unprobable case */
353 iotag = psli->last_iotag;
354 if(++iotag < psli->iocbq_lookup_len) {
355 psli->last_iotag = iotag;
356 psli->iocbq_lookup[iotag] = iocbq;
357 spin_unlock_irq(&phba->hbalock);
358 iocbq->iotag = iotag;
361 spin_unlock_irq(&phba->hbalock);
364 if (psli->iocbq_lookup)
365 memcpy(new_arr, old_arr,
366 ((psli->last_iotag + 1) *
367 sizeof (struct lpfc_iocbq *)));
368 psli->iocbq_lookup = new_arr;
369 psli->iocbq_lookup_len = new_len;
370 psli->last_iotag = iotag;
371 psli->iocbq_lookup[iotag] = iocbq;
372 spin_unlock_irq(&phba->hbalock);
373 iocbq->iotag = iotag;
378 spin_unlock_irq(&phba->hbalock);
380 lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
381 "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
388 lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
389 IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
394 nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
396 if (pring->ringno == LPFC_ELS_RING) {
397 lpfc_debugfs_slow_ring_trc(phba,
398 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
399 *(((uint32_t *) &nextiocb->iocb) + 4),
400 *(((uint32_t *) &nextiocb->iocb) + 6),
401 *(((uint32_t *) &nextiocb->iocb) + 7));
405 * Issue iocb command to adapter
407 lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
409 pring->stats.iocb_cmd++;
412 * If there is no completion routine to call, we can release the
413 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
414 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
416 if (nextiocb->iocb_cmpl)
417 lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
419 __lpfc_sli_release_iocbq(phba, nextiocb);
422 * Let the HBA know what IOCB slot will be the next one the
423 * driver will put a command into.
425 pring->cmdidx = pring->next_cmdidx;
426 writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
430 lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
432 int ringno = pring->ringno;
434 pring->flag |= LPFC_CALL_RING_AVAILABLE;
439 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
440 * The HBA will tell us when an IOCB entry is available.
442 writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
443 readl(phba->CAregaddr); /* flush */
445 pring->stats.iocb_cmd_full++;
449 lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
451 int ringno = pring->ringno;
454 * Tell the HBA that there is work to do in this ring.
457 writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
458 readl(phba->CAregaddr); /* flush */
462 lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
465 struct lpfc_iocbq *nextiocb;
469 * (a) there is anything on the txq to send
471 * (c) link attention events can be processed (fcp ring only)
472 * (d) IOCB processing is not blocked by the outstanding mbox command.
474 if (pring->txq_cnt &&
475 lpfc_is_link_up(phba) &&
476 (pring->ringno != phba->sli.fcp_ring ||
477 phba->sli.sli_flag & LPFC_PROCESS_LA) &&
478 !(pring->flag & LPFC_STOP_IOCB_MBX)) {
480 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
481 (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
482 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
485 lpfc_sli_update_ring(phba, pring);
487 lpfc_sli_update_full_ring(phba, pring);
493 /* lpfc_sli_turn_on_ring is only called by lpfc_sli_handle_mb_event below */
495 lpfc_sli_turn_on_ring(struct lpfc_hba *phba, int ringno)
497 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
498 &phba->slim2p->mbx.us.s3_pgp.port[ringno] :
499 &phba->slim2p->mbx.us.s2.port[ringno];
500 unsigned long iflags;
502 /* If the ring is active, flag it */
503 spin_lock_irqsave(&phba->hbalock, iflags);
504 if (phba->sli.ring[ringno].cmdringaddr) {
505 if (phba->sli.ring[ringno].flag & LPFC_STOP_IOCB_MBX) {
506 phba->sli.ring[ringno].flag &= ~LPFC_STOP_IOCB_MBX;
508 * Force update of the local copy of cmdGetInx
510 phba->sli.ring[ringno].local_getidx
511 = le32_to_cpu(pgp->cmdGetInx);
512 lpfc_sli_resume_iocb(phba, &phba->sli.ring[ringno]);
515 spin_unlock_irqrestore(&phba->hbalock, iflags);
518 struct lpfc_hbq_entry *
519 lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
521 struct hbq_s *hbqp = &phba->hbqs[hbqno];
523 if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
524 ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
525 hbqp->next_hbqPutIdx = 0;
527 if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
528 uint32_t raw_index = phba->hbq_get[hbqno];
529 uint32_t getidx = le32_to_cpu(raw_index);
531 hbqp->local_hbqGetIdx = getidx;
533 if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
534 lpfc_printf_log(phba, KERN_ERR,
536 "1802 HBQ %d: local_hbqGetIdx "
537 "%u is > than hbqp->entry_count %u\n",
538 hbqno, hbqp->local_hbqGetIdx,
541 phba->link_state = LPFC_HBA_ERROR;
545 if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
549 return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
554 lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
556 struct lpfc_dmabuf *dmabuf, *next_dmabuf;
557 struct hbq_dmabuf *hbq_buf;
560 hbq_count = lpfc_sli_hbq_count();
561 /* Return all memory used by all HBQs */
562 for (i = 0; i < hbq_count; ++i) {
563 list_for_each_entry_safe(dmabuf, next_dmabuf,
564 &phba->hbqs[i].hbq_buffer_list, list) {
565 hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
566 list_del(&hbq_buf->dbuf.list);
567 (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
572 static struct lpfc_hbq_entry *
573 lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
574 struct hbq_dmabuf *hbq_buf)
576 struct lpfc_hbq_entry *hbqe;
577 dma_addr_t physaddr = hbq_buf->dbuf.phys;
579 /* Get next HBQ entry slot to use */
580 hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
582 struct hbq_s *hbqp = &phba->hbqs[hbqno];
584 hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
585 hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
586 hbqe->bde.tus.f.bdeSize = hbq_buf->size;
587 hbqe->bde.tus.f.bdeFlags = 0;
588 hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
589 hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
591 hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
592 writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
594 readl(phba->hbq_put + hbqno);
595 list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
600 static struct lpfc_hbq_init lpfc_els_hbq = {
605 .ring_mask = (1 << LPFC_ELS_RING),
611 static struct lpfc_hbq_init lpfc_extra_hbq = {
616 .ring_mask = (1 << LPFC_EXTRA_RING),
622 struct lpfc_hbq_init *lpfc_hbq_defs[] = {
628 lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
630 uint32_t i, start, end;
631 struct hbq_dmabuf *hbq_buffer;
633 if (!phba->hbqs[hbqno].hbq_alloc_buffer) {
637 start = lpfc_hbq_defs[hbqno]->buffer_count;
638 end = count + lpfc_hbq_defs[hbqno]->buffer_count;
639 if (end > lpfc_hbq_defs[hbqno]->entry_count) {
640 end = lpfc_hbq_defs[hbqno]->entry_count;
643 /* Populate HBQ entries */
644 for (i = start; i < end; i++) {
645 hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
648 hbq_buffer->tag = (i | (hbqno << 16));
649 if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
650 lpfc_hbq_defs[hbqno]->buffer_count++;
652 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
658 lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
660 return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
661 lpfc_hbq_defs[qno]->add_count));
665 lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
667 return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
668 lpfc_hbq_defs[qno]->init_count));
672 lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
674 struct lpfc_dmabuf *d_buf;
675 struct hbq_dmabuf *hbq_buf;
679 if (hbqno >= LPFC_MAX_HBQS)
682 list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
683 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
684 if (hbq_buf->tag == tag) {
688 lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
689 "1803 Bad hbq tag. Data: x%x x%x\n",
690 tag, lpfc_hbq_defs[tag >> 16]->buffer_count);
695 lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
700 hbqno = hbq_buffer->tag >> 16;
701 if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
702 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
708 lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
712 switch (mbxCommand) {
716 case MBX_RUN_BIU_DIAG:
719 case MBX_CONFIG_LINK:
720 case MBX_CONFIG_RING:
722 case MBX_READ_CONFIG:
723 case MBX_READ_RCONFIG:
725 case MBX_READ_STATUS:
729 case MBX_READ_LNK_STAT:
731 case MBX_UNREG_LOGIN:
734 case MBX_DUMP_MEMORY:
735 case MBX_DUMP_CONTEXT:
740 case MBX_DEL_LD_ENTRY:
741 case MBX_RUN_PROGRAM:
746 case MBX_CONFIG_FARP:
749 case MBX_RUN_BIU_DIAG64:
750 case MBX_CONFIG_PORT:
751 case MBX_READ_SPARM64:
753 case MBX_REG_LOGIN64:
755 case MBX_FLASH_WR_ULA:
757 case MBX_LOAD_EXP_ROM:
758 case MBX_ASYNCEVT_ENABLE:
771 lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
773 wait_queue_head_t *pdone_q;
774 unsigned long drvr_flag;
777 * If pdone_q is empty, the driver thread gave up waiting and
780 pmboxq->mbox_flag |= LPFC_MBX_WAKE;
781 spin_lock_irqsave(&phba->hbalock, drvr_flag);
782 pdone_q = (wait_queue_head_t *) pmboxq->context1;
784 wake_up_interruptible(pdone_q);
785 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
790 lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
792 struct lpfc_dmabuf *mp;
796 mp = (struct lpfc_dmabuf *) (pmb->context1);
799 lpfc_mbuf_free(phba, mp->virt, mp->phys);
804 * If a REG_LOGIN succeeded after node is destroyed or node
805 * is in re-discovery driver need to cleanup the RPI.
807 if (!(phba->pport->load_flag & FC_UNLOADING) &&
808 pmb->mb.mbxCommand == MBX_REG_LOGIN64 &&
809 !pmb->mb.mbxStatus) {
811 rpi = pmb->mb.un.varWords[0];
812 lpfc_unreg_login(phba, pmb->mb.un.varRegLogin.vpi, rpi, pmb);
813 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
814 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
815 if (rc != MBX_NOT_FINISHED)
819 mempool_free(pmb, phba->mbox_mem_pool);
824 lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
831 phba->sli.slistat.mbox_event++;
833 /* Get all completed mailboxe buffers into the cmplq */
834 spin_lock_irq(&phba->hbalock);
835 list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
836 spin_unlock_irq(&phba->hbalock);
838 /* Get a Mailbox buffer to setup mailbox commands for callback */
840 list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
846 if (pmbox->mbxCommand != MBX_HEARTBEAT) {
848 lpfc_debugfs_disc_trc(pmb->vport,
849 LPFC_DISC_TRC_MBOX_VPORT,
850 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
851 (uint32_t)pmbox->mbxCommand,
852 pmbox->un.varWords[0],
853 pmbox->un.varWords[1]);
856 lpfc_debugfs_disc_trc(phba->pport,
858 "MBOX cmpl: cmd:x%x mb:x%x x%x",
859 (uint32_t)pmbox->mbxCommand,
860 pmbox->un.varWords[0],
861 pmbox->un.varWords[1]);
866 * It is a fatal error if unknown mbox command completion.
868 if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
870 /* Unknow mailbox command compl */
871 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
872 "(%d):0323 Unknown Mailbox command "
874 pmb->vport ? pmb->vport->vpi : 0,
876 phba->link_state = LPFC_HBA_ERROR;
877 phba->work_hs = HS_FFER3;
878 lpfc_handle_eratt(phba);
882 if (pmbox->mbxStatus) {
883 phba->sli.slistat.mbox_stat_err++;
884 if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
885 /* Mbox cmd cmpl error - RETRYing */
886 lpfc_printf_log(phba, KERN_INFO,
888 "(%d):0305 Mbox cmd cmpl "
889 "error - RETRYing Data: x%x "
891 pmb->vport ? pmb->vport->vpi :0,
894 pmbox->un.varWords[0],
895 pmb->vport->port_state);
896 pmbox->mbxStatus = 0;
897 pmbox->mbxOwner = OWN_HOST;
898 spin_lock_irq(&phba->hbalock);
899 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
900 spin_unlock_irq(&phba->hbalock);
901 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
902 if (rc == MBX_SUCCESS)
907 /* Mailbox cmd <cmd> Cmpl <cmpl> */
908 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
909 "(%d):0307 Mailbox cmd x%x Cmpl x%p "
910 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
911 pmb->vport ? pmb->vport->vpi : 0,
914 *((uint32_t *) pmbox),
915 pmbox->un.varWords[0],
916 pmbox->un.varWords[1],
917 pmbox->un.varWords[2],
918 pmbox->un.varWords[3],
919 pmbox->un.varWords[4],
920 pmbox->un.varWords[5],
921 pmbox->un.varWords[6],
922 pmbox->un.varWords[7]);
925 pmb->mbox_cmpl(phba,pmb);
930 static struct lpfc_dmabuf *
931 lpfc_sli_replace_hbqbuff(struct lpfc_hba *phba, uint32_t tag)
933 struct hbq_dmabuf *hbq_entry, *new_hbq_entry;
935 void *virt; /* virtual address ptr */
936 dma_addr_t phys; /* mapped address */
938 hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
939 if (hbq_entry == NULL)
941 list_del(&hbq_entry->dbuf.list);
944 new_hbq_entry = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
945 if (new_hbq_entry == NULL)
946 return &hbq_entry->dbuf;
947 new_hbq_entry->tag = -1;
948 phys = new_hbq_entry->dbuf.phys;
949 virt = new_hbq_entry->dbuf.virt;
950 new_hbq_entry->dbuf.phys = hbq_entry->dbuf.phys;
951 new_hbq_entry->dbuf.virt = hbq_entry->dbuf.virt;
952 hbq_entry->dbuf.phys = phys;
953 hbq_entry->dbuf.virt = virt;
954 lpfc_sli_free_hbq(phba, hbq_entry);
955 return &new_hbq_entry->dbuf;
960 lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
961 struct lpfc_iocbq *saveq)
969 irsp = &(saveq->iocb);
971 if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
972 if (pring->lpfc_sli_rcv_async_status)
973 pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
975 lpfc_printf_log(phba,
978 "0316 Ring %d handler: unexpected "
979 "ASYNC_STATUS iocb received evt_code "
982 irsp->un.asyncstat.evt_code);
986 if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX)
987 || (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX)
988 || (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)
989 || (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX)) {
994 (WORD5 *) & (saveq->iocb.un.
996 Rctl = w5p->hcsw.Rctl;
997 Type = w5p->hcsw.Type;
999 /* Firmware Workaround */
1000 if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
1001 (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
1002 irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
1005 w5p->hcsw.Rctl = Rctl;
1006 w5p->hcsw.Type = Type;
1010 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
1011 if (irsp->ulpBdeCount != 0)
1012 saveq->context2 = lpfc_sli_replace_hbqbuff(phba,
1013 irsp->un.ulpWord[3]);
1014 if (irsp->ulpBdeCount == 2)
1015 saveq->context3 = lpfc_sli_replace_hbqbuff(phba,
1016 irsp->unsli3.sli3Words[7]);
1019 /* unSolicited Responses */
1020 if (pring->prt[0].profile) {
1021 if (pring->prt[0].lpfc_sli_rcv_unsol_event)
1022 (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
1026 /* We must search, based on rctl / type
1027 for the right routine */
1028 for (i = 0; i < pring->num_mask;
1030 if ((pring->prt[i].rctl ==
1034 if (pring->prt[i].lpfc_sli_rcv_unsol_event)
1035 (pring->prt[i].lpfc_sli_rcv_unsol_event)
1036 (phba, pring, saveq);
1043 /* Unexpected Rctl / Type received */
1044 /* Ring <ringno> handler: unexpected
1045 Rctl <Rctl> Type <Type> received */
1046 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1047 "0313 Ring %d handler: unexpected Rctl x%x "
1048 "Type x%x received\n",
1049 pring->ringno, Rctl, Type);
1054 static struct lpfc_iocbq *
1055 lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
1056 struct lpfc_sli_ring *pring,
1057 struct lpfc_iocbq *prspiocb)
1059 struct lpfc_iocbq *cmd_iocb = NULL;
1062 iotag = prspiocb->iocb.ulpIoTag;
1064 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
1065 cmd_iocb = phba->sli.iocbq_lookup[iotag];
1066 list_del_init(&cmd_iocb->list);
1067 pring->txcmplq_cnt--;
1071 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1072 "0317 iotag x%x is out off "
1073 "range: max iotag x%x wd0 x%x\n",
1074 iotag, phba->sli.last_iotag,
1075 *(((uint32_t *) &prspiocb->iocb) + 7));
1080 lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1081 struct lpfc_iocbq *saveq)
1083 struct lpfc_iocbq *cmdiocbp;
1085 unsigned long iflag;
1087 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
1088 spin_lock_irqsave(&phba->hbalock, iflag);
1089 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
1090 spin_unlock_irqrestore(&phba->hbalock, iflag);
1093 if (cmdiocbp->iocb_cmpl) {
1095 * Post all ELS completions to the worker thread.
1096 * All other are passed to the completion callback.
1098 if (pring->ringno == LPFC_ELS_RING) {
1099 if (cmdiocbp->iocb_flag & LPFC_DRIVER_ABORTED) {
1100 cmdiocbp->iocb_flag &=
1101 ~LPFC_DRIVER_ABORTED;
1102 saveq->iocb.ulpStatus =
1103 IOSTAT_LOCAL_REJECT;
1104 saveq->iocb.un.ulpWord[4] =
1108 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
1110 lpfc_sli_release_iocbq(phba, cmdiocbp);
1113 * Unknown initiating command based on the response iotag.
1114 * This could be the case on the ELS ring because of
1117 if (pring->ringno != LPFC_ELS_RING) {
1119 * Ring <ringno> handler: unexpected completion IoTag
1122 lpfc_printf_vlog(cmdiocbp->vport, KERN_WARNING, LOG_SLI,
1123 "0322 Ring %d handler: "
1124 "unexpected completion IoTag x%x "
1125 "Data: x%x x%x x%x x%x\n",
1127 saveq->iocb.ulpIoTag,
1128 saveq->iocb.ulpStatus,
1129 saveq->iocb.un.ulpWord[4],
1130 saveq->iocb.ulpCommand,
1131 saveq->iocb.ulpContext);
1139 lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1141 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
1142 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1143 &phba->slim2p->mbx.us.s2.port[pring->ringno];
1145 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
1146 * rsp ring <portRspMax>
1148 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1149 "0312 Ring %d handler: portRspPut %d "
1150 "is bigger then rsp ring %d\n",
1151 pring->ringno, le32_to_cpu(pgp->rspPutInx),
1154 phba->link_state = LPFC_HBA_ERROR;
1157 * All error attention handlers are posted to
1160 phba->work_ha |= HA_ERATT;
1161 phba->work_hs = HS_FFER3;
1163 /* hbalock should already be held */
1164 if (phba->work_wait)
1165 lpfc_worker_wake_up(phba);
1170 void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba)
1172 struct lpfc_sli *psli = &phba->sli;
1173 struct lpfc_sli_ring *pring = &psli->ring[LPFC_FCP_RING];
1174 IOCB_t *irsp = NULL;
1175 IOCB_t *entry = NULL;
1176 struct lpfc_iocbq *cmdiocbq = NULL;
1177 struct lpfc_iocbq rspiocbq;
1178 struct lpfc_pgp *pgp;
1180 uint32_t portRspPut, portRspMax;
1182 uint32_t rsp_cmpl = 0;
1184 unsigned long iflags;
1186 pring->stats.iocb_event++;
1188 pgp = (phba->sli_rev == 3) ?
1189 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1190 &phba->slim2p->mbx.us.s2.port[pring->ringno];
1194 * The next available response entry should never exceed the maximum
1195 * entries. If it does, treat it as an adapter hardware error.
1197 portRspMax = pring->numRiocb;
1198 portRspPut = le32_to_cpu(pgp->rspPutInx);
1199 if (unlikely(portRspPut >= portRspMax)) {
1200 lpfc_sli_rsp_pointers_error(phba, pring);
1205 while (pring->rspidx != portRspPut) {
1206 entry = lpfc_resp_iocb(phba, pring);
1207 if (++pring->rspidx >= portRspMax)
1210 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
1211 (uint32_t *) &rspiocbq.iocb,
1212 phba->iocb_rsp_size);
1213 irsp = &rspiocbq.iocb;
1214 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
1215 pring->stats.iocb_rsp++;
1218 if (unlikely(irsp->ulpStatus)) {
1219 /* Rsp ring <ringno> error: IOCB */
1220 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1221 "0326 Rsp Ring %d error: IOCB Data: "
1222 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
1224 irsp->un.ulpWord[0],
1225 irsp->un.ulpWord[1],
1226 irsp->un.ulpWord[2],
1227 irsp->un.ulpWord[3],
1228 irsp->un.ulpWord[4],
1229 irsp->un.ulpWord[5],
1230 *(((uint32_t *) irsp) + 6),
1231 *(((uint32_t *) irsp) + 7));
1235 case LPFC_ABORT_IOCB:
1238 * Idle exchange closed via ABTS from port. No iocb
1239 * resources need to be recovered.
1241 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
1242 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1243 "0314 IOCB cmd 0x%x "
1244 "processed. Skipping "
1250 spin_lock_irqsave(&phba->hbalock, iflags);
1251 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
1253 spin_unlock_irqrestore(&phba->hbalock, iflags);
1254 if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
1255 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1260 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1261 char adaptermsg[LPFC_MAX_ADPTMSG];
1262 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
1263 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1265 dev_warn(&((phba->pcidev)->dev),
1267 phba->brd_no, adaptermsg);
1269 /* Unknown IOCB command */
1270 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1271 "0321 Unknown IOCB command "
1272 "Data: x%x, x%x x%x x%x x%x\n",
1273 type, irsp->ulpCommand,
1282 * The response IOCB has been processed. Update the ring
1283 * pointer in SLIM. If the port response put pointer has not
1284 * been updated, sync the pgp->rspPutInx and fetch the new port
1285 * response put pointer.
1287 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
1289 if (pring->rspidx == portRspPut)
1290 portRspPut = le32_to_cpu(pgp->rspPutInx);
1293 ha_copy = readl(phba->HAregaddr);
1294 ha_copy >>= (LPFC_FCP_RING * 4);
1296 if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) {
1297 spin_lock_irqsave(&phba->hbalock, iflags);
1298 pring->stats.iocb_rsp_full++;
1299 status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4));
1300 writel(status, phba->CAregaddr);
1301 readl(phba->CAregaddr);
1302 spin_unlock_irqrestore(&phba->hbalock, iflags);
1304 if ((ha_copy & HA_R0CE_RSP) &&
1305 (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1306 spin_lock_irqsave(&phba->hbalock, iflags);
1307 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1308 pring->stats.iocb_cmd_empty++;
1310 /* Force update of the local copy of cmdGetInx */
1311 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1312 lpfc_sli_resume_iocb(phba, pring);
1314 if ((pring->lpfc_sli_cmd_available))
1315 (pring->lpfc_sli_cmd_available) (phba, pring);
1317 spin_unlock_irqrestore(&phba->hbalock, iflags);
1324 * This routine presumes LPFC_FCP_RING handling and doesn't bother
1325 * to check it explicitly.
1328 lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
1329 struct lpfc_sli_ring *pring, uint32_t mask)
1331 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
1332 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1333 &phba->slim2p->mbx.us.s2.port[pring->ringno];
1334 IOCB_t *irsp = NULL;
1335 IOCB_t *entry = NULL;
1336 struct lpfc_iocbq *cmdiocbq = NULL;
1337 struct lpfc_iocbq rspiocbq;
1339 uint32_t portRspPut, portRspMax;
1341 lpfc_iocb_type type;
1342 unsigned long iflag;
1343 uint32_t rsp_cmpl = 0;
1345 spin_lock_irqsave(&phba->hbalock, iflag);
1346 pring->stats.iocb_event++;
1349 * The next available response entry should never exceed the maximum
1350 * entries. If it does, treat it as an adapter hardware error.
1352 portRspMax = pring->numRiocb;
1353 portRspPut = le32_to_cpu(pgp->rspPutInx);
1354 if (unlikely(portRspPut >= portRspMax)) {
1355 lpfc_sli_rsp_pointers_error(phba, pring);
1356 spin_unlock_irqrestore(&phba->hbalock, iflag);
1361 while (pring->rspidx != portRspPut) {
1363 * Fetch an entry off the ring and copy it into a local data
1364 * structure. The copy involves a byte-swap since the
1365 * network byte order and pci byte orders are different.
1367 entry = lpfc_resp_iocb(phba, pring);
1368 phba->last_completion_time = jiffies;
1370 if (++pring->rspidx >= portRspMax)
1373 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
1374 (uint32_t *) &rspiocbq.iocb,
1375 phba->iocb_rsp_size);
1376 INIT_LIST_HEAD(&(rspiocbq.list));
1377 irsp = &rspiocbq.iocb;
1379 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
1380 pring->stats.iocb_rsp++;
1383 if (unlikely(irsp->ulpStatus)) {
1385 * If resource errors reported from HBA, reduce
1386 * queuedepths of the SCSI device.
1388 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1389 (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
1390 spin_unlock_irqrestore(&phba->hbalock, iflag);
1391 lpfc_adjust_queue_depth(phba);
1392 spin_lock_irqsave(&phba->hbalock, iflag);
1395 /* Rsp ring <ringno> error: IOCB */
1396 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1397 "0336 Rsp Ring %d error: IOCB Data: "
1398 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
1400 irsp->un.ulpWord[0],
1401 irsp->un.ulpWord[1],
1402 irsp->un.ulpWord[2],
1403 irsp->un.ulpWord[3],
1404 irsp->un.ulpWord[4],
1405 irsp->un.ulpWord[5],
1406 *(((uint32_t *) irsp) + 6),
1407 *(((uint32_t *) irsp) + 7));
1411 case LPFC_ABORT_IOCB:
1414 * Idle exchange closed via ABTS from port. No iocb
1415 * resources need to be recovered.
1417 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
1418 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1419 "0333 IOCB cmd 0x%x"
1420 " processed. Skipping"
1426 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
1428 if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
1429 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
1430 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1433 spin_unlock_irqrestore(&phba->hbalock,
1435 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1437 spin_lock_irqsave(&phba->hbalock,
1442 case LPFC_UNSOL_IOCB:
1443 spin_unlock_irqrestore(&phba->hbalock, iflag);
1444 lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
1445 spin_lock_irqsave(&phba->hbalock, iflag);
1448 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1449 char adaptermsg[LPFC_MAX_ADPTMSG];
1450 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
1451 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1453 dev_warn(&((phba->pcidev)->dev),
1455 phba->brd_no, adaptermsg);
1457 /* Unknown IOCB command */
1458 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1459 "0334 Unknown IOCB command "
1460 "Data: x%x, x%x x%x x%x x%x\n",
1461 type, irsp->ulpCommand,
1470 * The response IOCB has been processed. Update the ring
1471 * pointer in SLIM. If the port response put pointer has not
1472 * been updated, sync the pgp->rspPutInx and fetch the new port
1473 * response put pointer.
1475 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
1477 if (pring->rspidx == portRspPut)
1478 portRspPut = le32_to_cpu(pgp->rspPutInx);
1481 if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
1482 pring->stats.iocb_rsp_full++;
1483 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
1484 writel(status, phba->CAregaddr);
1485 readl(phba->CAregaddr);
1487 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1488 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1489 pring->stats.iocb_cmd_empty++;
1491 /* Force update of the local copy of cmdGetInx */
1492 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1493 lpfc_sli_resume_iocb(phba, pring);
1495 if ((pring->lpfc_sli_cmd_available))
1496 (pring->lpfc_sli_cmd_available) (phba, pring);
1500 spin_unlock_irqrestore(&phba->hbalock, iflag);
1505 lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
1506 struct lpfc_sli_ring *pring, uint32_t mask)
1508 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
1509 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1510 &phba->slim2p->mbx.us.s2.port[pring->ringno];
1512 IOCB_t *irsp = NULL;
1513 struct lpfc_iocbq *rspiocbp = NULL;
1514 struct lpfc_iocbq *next_iocb;
1515 struct lpfc_iocbq *cmdiocbp;
1516 struct lpfc_iocbq *saveq;
1517 uint8_t iocb_cmd_type;
1518 lpfc_iocb_type type;
1519 uint32_t status, free_saveq;
1520 uint32_t portRspPut, portRspMax;
1522 unsigned long iflag;
1524 spin_lock_irqsave(&phba->hbalock, iflag);
1525 pring->stats.iocb_event++;
1528 * The next available response entry should never exceed the maximum
1529 * entries. If it does, treat it as an adapter hardware error.
1531 portRspMax = pring->numRiocb;
1532 portRspPut = le32_to_cpu(pgp->rspPutInx);
1533 if (portRspPut >= portRspMax) {
1535 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
1536 * rsp ring <portRspMax>
1538 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1539 "0303 Ring %d handler: portRspPut %d "
1540 "is bigger then rsp ring %d\n",
1541 pring->ringno, portRspPut, portRspMax);
1543 phba->link_state = LPFC_HBA_ERROR;
1544 spin_unlock_irqrestore(&phba->hbalock, iflag);
1546 phba->work_hs = HS_FFER3;
1547 lpfc_handle_eratt(phba);
1553 while (pring->rspidx != portRspPut) {
1555 * Build a completion list and call the appropriate handler.
1556 * The process is to get the next available response iocb, get
1557 * a free iocb from the list, copy the response data into the
1558 * free iocb, insert to the continuation list, and update the
1559 * next response index to slim. This process makes response
1560 * iocb's in the ring available to DMA as fast as possible but
1561 * pays a penalty for a copy operation. Since the iocb is
1562 * only 32 bytes, this penalty is considered small relative to
1563 * the PCI reads for register values and a slim write. When
1564 * the ulpLe field is set, the entire Command has been
1567 entry = lpfc_resp_iocb(phba, pring);
1569 phba->last_completion_time = jiffies;
1570 rspiocbp = __lpfc_sli_get_iocbq(phba);
1571 if (rspiocbp == NULL) {
1572 printk(KERN_ERR "%s: out of buffers! Failing "
1573 "completion.\n", __FUNCTION__);
1577 lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
1578 phba->iocb_rsp_size);
1579 irsp = &rspiocbp->iocb;
1581 if (++pring->rspidx >= portRspMax)
1584 if (pring->ringno == LPFC_ELS_RING) {
1585 lpfc_debugfs_slow_ring_trc(phba,
1586 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
1587 *(((uint32_t *) irsp) + 4),
1588 *(((uint32_t *) irsp) + 6),
1589 *(((uint32_t *) irsp) + 7));
1592 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
1594 if (list_empty(&(pring->iocb_continueq))) {
1595 list_add(&rspiocbp->list, &(pring->iocb_continueq));
1597 list_add_tail(&rspiocbp->list,
1598 &(pring->iocb_continueq));
1601 pring->iocb_continueq_cnt++;
1604 * By default, the driver expects to free all resources
1605 * associated with this iocb completion.
1608 saveq = list_get_first(&pring->iocb_continueq,
1609 struct lpfc_iocbq, list);
1610 irsp = &(saveq->iocb);
1611 list_del_init(&pring->iocb_continueq);
1612 pring->iocb_continueq_cnt = 0;
1614 pring->stats.iocb_rsp++;
1617 * If resource errors reported from HBA, reduce
1618 * queuedepths of the SCSI device.
1620 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1621 (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
1622 spin_unlock_irqrestore(&phba->hbalock, iflag);
1623 lpfc_adjust_queue_depth(phba);
1624 spin_lock_irqsave(&phba->hbalock, iflag);
1627 if (irsp->ulpStatus) {
1628 /* Rsp ring <ringno> error: IOCB */
1629 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1630 "0328 Rsp Ring %d error: "
1635 "x%x x%x x%x x%x\n",
1637 irsp->un.ulpWord[0],
1638 irsp->un.ulpWord[1],
1639 irsp->un.ulpWord[2],
1640 irsp->un.ulpWord[3],
1641 irsp->un.ulpWord[4],
1642 irsp->un.ulpWord[5],
1643 *(((uint32_t *) irsp) + 6),
1644 *(((uint32_t *) irsp) + 7),
1645 *(((uint32_t *) irsp) + 8),
1646 *(((uint32_t *) irsp) + 9),
1647 *(((uint32_t *) irsp) + 10),
1648 *(((uint32_t *) irsp) + 11),
1649 *(((uint32_t *) irsp) + 12),
1650 *(((uint32_t *) irsp) + 13),
1651 *(((uint32_t *) irsp) + 14),
1652 *(((uint32_t *) irsp) + 15));
1656 * Fetch the IOCB command type and call the correct
1657 * completion routine. Solicited and Unsolicited
1658 * IOCBs on the ELS ring get freed back to the
1659 * lpfc_iocb_list by the discovery kernel thread.
1661 iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
1662 type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
1663 if (type == LPFC_SOL_IOCB) {
1664 spin_unlock_irqrestore(&phba->hbalock,
1666 rc = lpfc_sli_process_sol_iocb(phba, pring,
1668 spin_lock_irqsave(&phba->hbalock, iflag);
1669 } else if (type == LPFC_UNSOL_IOCB) {
1670 spin_unlock_irqrestore(&phba->hbalock,
1672 rc = lpfc_sli_process_unsol_iocb(phba, pring,
1674 spin_lock_irqsave(&phba->hbalock, iflag);
1675 } else if (type == LPFC_ABORT_IOCB) {
1676 if ((irsp->ulpCommand != CMD_XRI_ABORTED_CX) &&
1678 lpfc_sli_iocbq_lookup(phba, pring,
1680 /* Call the specified completion
1682 if (cmdiocbp->iocb_cmpl) {
1683 spin_unlock_irqrestore(
1686 (cmdiocbp->iocb_cmpl) (phba,
1692 __lpfc_sli_release_iocbq(phba,
1695 } else if (type == LPFC_UNKNOWN_IOCB) {
1696 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1698 char adaptermsg[LPFC_MAX_ADPTMSG];
1700 memset(adaptermsg, 0,
1702 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1704 dev_warn(&((phba->pcidev)->dev),
1706 phba->brd_no, adaptermsg);
1708 /* Unknown IOCB command */
1709 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1710 "0335 Unknown IOCB "
1711 "command Data: x%x "
1721 list_for_each_entry_safe(rspiocbp, next_iocb,
1722 &saveq->list, list) {
1723 list_del(&rspiocbp->list);
1724 __lpfc_sli_release_iocbq(phba,
1727 __lpfc_sli_release_iocbq(phba, saveq);
1733 * If the port response put pointer has not been updated, sync
1734 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
1735 * response put pointer.
1737 if (pring->rspidx == portRspPut) {
1738 portRspPut = le32_to_cpu(pgp->rspPutInx);
1740 } /* while (pring->rspidx != portRspPut) */
1742 if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
1743 /* At least one response entry has been freed */
1744 pring->stats.iocb_rsp_full++;
1745 /* SET RxRE_RSP in Chip Att register */
1746 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
1747 writel(status, phba->CAregaddr);
1748 readl(phba->CAregaddr); /* flush */
1750 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1751 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1752 pring->stats.iocb_cmd_empty++;
1754 /* Force update of the local copy of cmdGetInx */
1755 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1756 lpfc_sli_resume_iocb(phba, pring);
1758 if ((pring->lpfc_sli_cmd_available))
1759 (pring->lpfc_sli_cmd_available) (phba, pring);
1763 spin_unlock_irqrestore(&phba->hbalock, iflag);
1768 lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1770 LIST_HEAD(completions);
1771 struct lpfc_iocbq *iocb, *next_iocb;
1774 if (pring->ringno == LPFC_ELS_RING) {
1775 lpfc_fabric_abort_hba(phba);
1778 /* Error everything on txq and txcmplq
1781 spin_lock_irq(&phba->hbalock);
1782 list_splice_init(&pring->txq, &completions);
1785 /* Next issue ABTS for everything on the txcmplq */
1786 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
1787 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1789 spin_unlock_irq(&phba->hbalock);
1791 while (!list_empty(&completions)) {
1792 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
1794 list_del_init(&iocb->list);
1796 if (!iocb->iocb_cmpl)
1797 lpfc_sli_release_iocbq(phba, iocb);
1799 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
1800 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
1801 (iocb->iocb_cmpl) (phba, iocb, iocb);
1807 lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
1813 /* Read the HBA Host Status Register */
1814 status = readl(phba->HSregaddr);
1817 * Check status register every 100ms for 5 retries, then every
1818 * 500ms for 5, then every 2.5 sec for 5, then reset board and
1819 * every 2.5 sec for 4.
1820 * Break our of the loop if errors occurred during init.
1822 while (((status & mask) != mask) &&
1823 !(status & HS_FFERM) &&
1835 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
1836 lpfc_sli_brdrestart(phba);
1838 /* Read the HBA Host Status Register */
1839 status = readl(phba->HSregaddr);
1842 /* Check to see if any errors occurred during init */
1843 if ((status & HS_FFERM) || (i >= 20)) {
1844 phba->link_state = LPFC_HBA_ERROR;
1851 #define BARRIER_TEST_PATTERN (0xdeadbeef)
1853 void lpfc_reset_barrier(struct lpfc_hba *phba)
1855 uint32_t __iomem *resp_buf;
1856 uint32_t __iomem *mbox_buf;
1857 volatile uint32_t mbox;
1862 pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
1863 if (hdrtype != 0x80 ||
1864 (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
1865 FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
1869 * Tell the other part of the chip to suspend temporarily all
1872 resp_buf = phba->MBslimaddr;
1874 /* Disable the error attention */
1875 hc_copy = readl(phba->HCregaddr);
1876 writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
1877 readl(phba->HCregaddr); /* flush */
1878 phba->link_flag |= LS_IGNORE_ERATT;
1880 if (readl(phba->HAregaddr) & HA_ERATT) {
1881 /* Clear Chip error bit */
1882 writel(HA_ERATT, phba->HAregaddr);
1883 phba->pport->stopped = 1;
1887 ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
1888 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
1890 writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
1891 mbox_buf = phba->MBslimaddr;
1892 writel(mbox, mbox_buf);
1895 readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
1898 if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
1899 if (phba->sli.sli_flag & LPFC_SLI2_ACTIVE ||
1900 phba->pport->stopped)
1906 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
1907 for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
1912 while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
1915 if (readl(phba->HAregaddr) & HA_ERATT) {
1916 writel(HA_ERATT, phba->HAregaddr);
1917 phba->pport->stopped = 1;
1921 phba->link_flag &= ~LS_IGNORE_ERATT;
1922 writel(hc_copy, phba->HCregaddr);
1923 readl(phba->HCregaddr); /* flush */
1927 lpfc_sli_brdkill(struct lpfc_hba *phba)
1929 struct lpfc_sli *psli;
1939 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1940 "0329 Kill HBA Data: x%x x%x\n",
1941 phba->pport->port_state, psli->sli_flag);
1943 if ((pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
1947 /* Disable the error attention */
1948 spin_lock_irq(&phba->hbalock);
1949 status = readl(phba->HCregaddr);
1950 status &= ~HC_ERINT_ENA;
1951 writel(status, phba->HCregaddr);
1952 readl(phba->HCregaddr); /* flush */
1953 phba->link_flag |= LS_IGNORE_ERATT;
1954 spin_unlock_irq(&phba->hbalock);
1956 lpfc_kill_board(phba, pmb);
1957 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1958 retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
1960 if (retval != MBX_SUCCESS) {
1961 if (retval != MBX_BUSY)
1962 mempool_free(pmb, phba->mbox_mem_pool);
1963 spin_lock_irq(&phba->hbalock);
1964 phba->link_flag &= ~LS_IGNORE_ERATT;
1965 spin_unlock_irq(&phba->hbalock);
1969 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
1971 mempool_free(pmb, phba->mbox_mem_pool);
1973 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
1974 * attention every 100ms for 3 seconds. If we don't get ERATT after
1975 * 3 seconds we still set HBA_ERROR state because the status of the
1976 * board is now undefined.
1978 ha_copy = readl(phba->HAregaddr);
1980 while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
1982 ha_copy = readl(phba->HAregaddr);
1985 del_timer_sync(&psli->mbox_tmo);
1986 if (ha_copy & HA_ERATT) {
1987 writel(HA_ERATT, phba->HAregaddr);
1988 phba->pport->stopped = 1;
1990 spin_lock_irq(&phba->hbalock);
1991 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
1992 phba->link_flag &= ~LS_IGNORE_ERATT;
1993 spin_unlock_irq(&phba->hbalock);
1995 psli->mbox_active = NULL;
1996 lpfc_hba_down_post(phba);
1997 phba->link_state = LPFC_HBA_ERROR;
1999 return ha_copy & HA_ERATT ? 0 : 1;
2003 lpfc_sli_brdreset(struct lpfc_hba *phba)
2005 struct lpfc_sli *psli;
2006 struct lpfc_sli_ring *pring;
2013 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2014 "0325 Reset HBA Data: x%x x%x\n",
2015 phba->pport->port_state, psli->sli_flag);
2017 /* perform board reset */
2018 phba->fc_eventTag = 0;
2019 phba->pport->fc_myDID = 0;
2020 phba->pport->fc_prevDID = 0;
2022 /* Turn off parity checking and serr during the physical reset */
2023 pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
2024 pci_write_config_word(phba->pcidev, PCI_COMMAND,
2026 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
2028 psli->sli_flag &= ~(LPFC_SLI2_ACTIVE | LPFC_PROCESS_LA);
2029 /* Now toggle INITFF bit in the Host Control Register */
2030 writel(HC_INITFF, phba->HCregaddr);
2032 readl(phba->HCregaddr); /* flush */
2033 writel(0, phba->HCregaddr);
2034 readl(phba->HCregaddr); /* flush */
2036 /* Restore PCI cmd register */
2037 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
2039 /* Initialize relevant SLI info */
2040 for (i = 0; i < psli->num_rings; i++) {
2041 pring = &psli->ring[i];
2044 pring->next_cmdidx = 0;
2045 pring->local_getidx = 0;
2047 pring->missbufcnt = 0;
2050 phba->link_state = LPFC_WARM_START;
2055 lpfc_sli_brdrestart(struct lpfc_hba *phba)
2058 struct lpfc_sli *psli;
2060 volatile uint32_t word0;
2061 void __iomem *to_slim;
2063 spin_lock_irq(&phba->hbalock);
2068 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2069 "0337 Restart HBA Data: x%x x%x\n",
2070 phba->pport->port_state, psli->sli_flag);
2073 mb = (MAILBOX_t *) &word0;
2074 mb->mbxCommand = MBX_RESTART;
2077 lpfc_reset_barrier(phba);
2079 to_slim = phba->MBslimaddr;
2080 writel(*(uint32_t *) mb, to_slim);
2081 readl(to_slim); /* flush */
2083 /* Only skip post after fc_ffinit is completed */
2084 if (phba->pport->port_state) {
2086 word0 = 1; /* This is really setting up word1 */
2089 word0 = 0; /* This is really setting up word1 */
2091 to_slim = phba->MBslimaddr + sizeof (uint32_t);
2092 writel(*(uint32_t *) mb, to_slim);
2093 readl(to_slim); /* flush */
2095 lpfc_sli_brdreset(phba);
2096 phba->pport->stopped = 0;
2097 phba->link_state = LPFC_INIT_START;
2099 spin_unlock_irq(&phba->hbalock);
2101 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
2102 psli->stats_start = get_seconds();
2109 lpfc_hba_down_post(phba);
2115 lpfc_sli_chipset_init(struct lpfc_hba *phba)
2117 uint32_t status, i = 0;
2119 /* Read the HBA Host Status Register */
2120 status = readl(phba->HSregaddr);
2122 /* Check status register to see what current state is */
2124 while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
2126 /* Check every 100ms for 5 retries, then every 500ms for 5, then
2127 * every 2.5 sec for 5, then reset board and every 2.5 sec for
2131 /* Adapter failed to init, timeout, status reg
2133 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2134 "0436 Adapter failed to init, "
2135 "timeout, status reg x%x\n", status);
2136 phba->link_state = LPFC_HBA_ERROR;
2140 /* Check to see if any errors occurred during init */
2141 if (status & HS_FFERM) {
2142 /* ERROR: During chipset initialization */
2143 /* Adapter failed to init, chipset, status reg
2145 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2146 "0437 Adapter failed to init, "
2147 "chipset, status reg x%x\n", status);
2148 phba->link_state = LPFC_HBA_ERROR;
2154 } else if (i <= 10) {
2162 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
2163 lpfc_sli_brdrestart(phba);
2165 /* Read the HBA Host Status Register */
2166 status = readl(phba->HSregaddr);
2169 /* Check to see if any errors occurred during init */
2170 if (status & HS_FFERM) {
2171 /* ERROR: During chipset initialization */
2172 /* Adapter failed to init, chipset, status reg <status> */
2173 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2174 "0438 Adapter failed to init, chipset, "
2175 "status reg x%x\n", status);
2176 phba->link_state = LPFC_HBA_ERROR;
2180 /* Clear all interrupt enable conditions */
2181 writel(0, phba->HCregaddr);
2182 readl(phba->HCregaddr); /* flush */
2184 /* setup host attn register */
2185 writel(0xffffffff, phba->HAregaddr);
2186 readl(phba->HAregaddr); /* flush */
2191 lpfc_sli_hbq_count(void)
2193 return ARRAY_SIZE(lpfc_hbq_defs);
2197 lpfc_sli_hbq_entry_count(void)
2199 int hbq_count = lpfc_sli_hbq_count();
2203 for (i = 0; i < hbq_count; ++i)
2204 count += lpfc_hbq_defs[i]->entry_count;
2209 lpfc_sli_hbq_size(void)
2211 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
2215 lpfc_sli_hbq_setup(struct lpfc_hba *phba)
2217 int hbq_count = lpfc_sli_hbq_count();
2221 uint32_t hbq_entry_index;
2223 /* Get a Mailbox buffer to setup mailbox
2224 * commands for HBA initialization
2226 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2233 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
2234 phba->link_state = LPFC_INIT_MBX_CMDS;
2236 hbq_entry_index = 0;
2237 for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
2238 phba->hbqs[hbqno].next_hbqPutIdx = 0;
2239 phba->hbqs[hbqno].hbqPutIdx = 0;
2240 phba->hbqs[hbqno].local_hbqGetIdx = 0;
2241 phba->hbqs[hbqno].entry_count =
2242 lpfc_hbq_defs[hbqno]->entry_count;
2243 lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
2244 hbq_entry_index, pmb);
2245 hbq_entry_index += phba->hbqs[hbqno].entry_count;
2247 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
2248 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
2249 mbxStatus <status>, ring <num> */
2251 lpfc_printf_log(phba, KERN_ERR,
2252 LOG_SLI | LOG_VPORT,
2253 "1805 Adapter failed to init. "
2254 "Data: x%x x%x x%x\n",
2256 pmbox->mbxStatus, hbqno);
2258 phba->link_state = LPFC_HBA_ERROR;
2259 mempool_free(pmb, phba->mbox_mem_pool);
2263 phba->hbq_count = hbq_count;
2265 mempool_free(pmb, phba->mbox_mem_pool);
2267 /* Initially populate or replenish the HBQs */
2268 for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
2269 if (lpfc_sli_hbqbuf_init_hbqs(phba, hbqno))
2276 lpfc_do_config_port(struct lpfc_hba *phba, int sli_mode)
2279 uint32_t resetcount = 0, rc = 0, done = 0;
2281 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2283 phba->link_state = LPFC_HBA_ERROR;
2287 phba->sli_rev = sli_mode;
2288 while (resetcount < 2 && !done) {
2289 spin_lock_irq(&phba->hbalock);
2290 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
2291 spin_unlock_irq(&phba->hbalock);
2292 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
2293 lpfc_sli_brdrestart(phba);
2295 rc = lpfc_sli_chipset_init(phba);
2299 spin_lock_irq(&phba->hbalock);
2300 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2301 spin_unlock_irq(&phba->hbalock);
2304 /* Call pre CONFIG_PORT mailbox command initialization. A
2305 * value of 0 means the call was successful. Any other
2306 * nonzero value is a failure, but if ERESTART is returned,
2307 * the driver may reset the HBA and try again.
2309 rc = lpfc_config_port_prep(phba);
2310 if (rc == -ERESTART) {
2311 phba->link_state = LPFC_LINK_UNKNOWN;
2317 phba->link_state = LPFC_INIT_MBX_CMDS;
2318 lpfc_config_port(phba, pmb);
2319 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
2320 if (rc != MBX_SUCCESS) {
2321 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2322 "0442 Adapter failed to init, mbxCmd x%x "
2323 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
2324 pmb->mb.mbxCommand, pmb->mb.mbxStatus, 0);
2325 spin_lock_irq(&phba->hbalock);
2326 phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE;
2327 spin_unlock_irq(&phba->hbalock);
2331 phba->max_vpi = (phba->max_vpi &&
2332 pmb->mb.un.varCfgPort.gmv) != 0
2333 ? pmb->mb.un.varCfgPort.max_vpi
2340 goto do_prep_failed;
2343 if ((pmb->mb.un.varCfgPort.sli_mode == 3) &&
2344 (!pmb->mb.un.varCfgPort.cMA)) {
2346 goto do_prep_failed;
2351 mempool_free(pmb, phba->mbox_mem_pool);
2356 lpfc_sli_hba_setup(struct lpfc_hba *phba)
2361 switch (lpfc_sli_mode) {
2363 if (phba->cfg_enable_npiv) {
2364 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
2365 "1824 NPIV enabled: Override lpfc_sli_mode "
2366 "parameter (%d) to auto (0).\n",
2376 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
2377 "1819 Unrecognized lpfc_sli_mode "
2378 "parameter: %d.\n", lpfc_sli_mode);
2383 rc = lpfc_do_config_port(phba, mode);
2384 if (rc && lpfc_sli_mode == 3)
2385 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
2386 "1820 Unable to select SLI-3. "
2387 "Not supported by adapter.\n");
2388 if (rc && mode != 2)
2389 rc = lpfc_do_config_port(phba, 2);
2391 goto lpfc_sli_hba_setup_error;
2393 if (phba->sli_rev == 3) {
2394 phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
2395 phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
2396 phba->sli3_options |= LPFC_SLI3_ENABLED;
2397 phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
2400 phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
2401 phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
2402 phba->sli3_options = 0;
2405 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2406 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
2407 phba->sli_rev, phba->max_vpi);
2408 rc = lpfc_sli_ring_map(phba);
2411 goto lpfc_sli_hba_setup_error;
2415 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
2416 rc = lpfc_sli_hbq_setup(phba);
2418 goto lpfc_sli_hba_setup_error;
2421 phba->sli.sli_flag |= LPFC_PROCESS_LA;
2423 rc = lpfc_config_port_post(phba);
2425 goto lpfc_sli_hba_setup_error;
2429 lpfc_sli_hba_setup_error:
2430 phba->link_state = LPFC_HBA_ERROR;
2431 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2432 "0445 Firmware initialization failed\n");
2436 /*! lpfc_mbox_timeout
2440 * \param hba Pointer to per struct lpfc_hba structure
2441 * \param l1 Pointer to the driver's mailbox queue.
2447 * This routine handles mailbox timeout events at timer interrupt context.
2450 lpfc_mbox_timeout(unsigned long ptr)
2452 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
2453 unsigned long iflag;
2454 uint32_t tmo_posted;
2456 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
2457 tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
2459 phba->pport->work_port_events |= WORKER_MBOX_TMO;
2460 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
2463 spin_lock_irqsave(&phba->hbalock, iflag);
2464 if (phba->work_wait)
2465 lpfc_worker_wake_up(phba);
2466 spin_unlock_irqrestore(&phba->hbalock, iflag);
2471 lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
2473 LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
2474 MAILBOX_t *mb = &pmbox->mb;
2475 struct lpfc_sli *psli = &phba->sli;
2476 struct lpfc_sli_ring *pring;
2478 if (!(phba->pport->work_port_events & WORKER_MBOX_TMO)) {
2482 /* Mbox cmd <mbxCommand> timeout */
2483 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
2484 "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
2486 phba->pport->port_state,
2488 phba->sli.mbox_active);
2490 /* Setting state unknown so lpfc_sli_abort_iocb_ring
2491 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
2492 * it to fail all oustanding SCSI IO.
2494 spin_lock_irq(&phba->pport->work_port_lock);
2495 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
2496 spin_unlock_irq(&phba->pport->work_port_lock);
2497 spin_lock_irq(&phba->hbalock);
2498 phba->link_state = LPFC_LINK_UNKNOWN;
2499 phba->pport->fc_flag |= FC_ESTABLISH_LINK;
2500 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
2501 spin_unlock_irq(&phba->hbalock);
2503 pring = &psli->ring[psli->fcp_ring];
2504 lpfc_sli_abort_iocb_ring(phba, pring);
2506 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
2507 "0316 Resetting board due to mailbox timeout\n");
2509 * lpfc_offline calls lpfc_sli_hba_down which will clean up
2510 * on oustanding mailbox commands.
2512 lpfc_offline_prep(phba);
2514 lpfc_sli_brdrestart(phba);
2515 if (lpfc_online(phba) == 0) /* Initialize the HBA */
2516 mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
2517 lpfc_unblock_mgmt_io(phba);
2522 lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
2525 struct lpfc_sli *psli = &phba->sli;
2526 uint32_t status, evtctr;
2529 unsigned long drvr_flag = 0;
2530 volatile uint32_t word0, ldata;
2531 void __iomem *to_slim;
2533 if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
2534 pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
2536 lpfc_printf_log(phba, KERN_ERR,
2537 LOG_MBOX | LOG_VPORT,
2538 "1806 Mbox x%x failed. No vport\n",
2539 pmbox->mb.mbxCommand);
2541 return MBXERR_ERROR;
2546 /* If the PCI channel is in offline state, do not post mbox. */
2547 if (unlikely(pci_channel_offline(phba->pcidev)))
2548 return MBX_NOT_FINISHED;
2550 spin_lock_irqsave(&phba->hbalock, drvr_flag);
2555 status = MBX_SUCCESS;
2557 if (phba->link_state == LPFC_HBA_ERROR) {
2558 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2560 /* Mbox command <mbxCommand> cannot issue */
2561 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag)
2562 return MBX_NOT_FINISHED;
2565 if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
2566 !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
2567 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2568 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag)
2569 return MBX_NOT_FINISHED;
2572 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
2573 /* Polling for a mbox command when another one is already active
2574 * is not allowed in SLI. Also, the driver must have established
2575 * SLI2 mode to queue and process multiple mbox commands.
2578 if (flag & MBX_POLL) {
2579 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2581 /* Mbox command <mbxCommand> cannot issue */
2582 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
2583 return MBX_NOT_FINISHED;
2586 if (!(psli->sli_flag & LPFC_SLI2_ACTIVE)) {
2587 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2588 /* Mbox command <mbxCommand> cannot issue */
2589 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
2590 return MBX_NOT_FINISHED;
2593 /* Handle STOP IOCB processing flag. This is only meaningful
2594 * if we are not polling for mbox completion.
2596 if (flag & MBX_STOP_IOCB) {
2597 flag &= ~MBX_STOP_IOCB;
2598 /* Now flag each ring */
2599 for (i = 0; i < psli->num_rings; i++) {
2600 /* If the ring is active, flag it */
2601 if (psli->ring[i].cmdringaddr) {
2602 psli->ring[i].flag |=
2608 /* Another mailbox command is still being processed, queue this
2609 * command to be processed later.
2611 lpfc_mbox_put(phba, pmbox);
2613 /* Mbox cmd issue - BUSY */
2614 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
2615 "(%d):0308 Mbox cmd issue - BUSY Data: "
2616 "x%x x%x x%x x%x\n",
2617 pmbox->vport ? pmbox->vport->vpi : 0xffffff,
2618 mb->mbxCommand, phba->pport->port_state,
2619 psli->sli_flag, flag);
2621 psli->slistat.mbox_busy++;
2622 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2625 lpfc_debugfs_disc_trc(pmbox->vport,
2626 LPFC_DISC_TRC_MBOX_VPORT,
2627 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
2628 (uint32_t)mb->mbxCommand,
2629 mb->un.varWords[0], mb->un.varWords[1]);
2632 lpfc_debugfs_disc_trc(phba->pport,
2634 "MBOX Bsy: cmd:x%x mb:x%x x%x",
2635 (uint32_t)mb->mbxCommand,
2636 mb->un.varWords[0], mb->un.varWords[1]);
2642 /* Handle STOP IOCB processing flag. This is only meaningful
2643 * if we are not polling for mbox completion.
2645 if (flag & MBX_STOP_IOCB) {
2646 flag &= ~MBX_STOP_IOCB;
2647 if (flag == MBX_NOWAIT) {
2648 /* Now flag each ring */
2649 for (i = 0; i < psli->num_rings; i++) {
2650 /* If the ring is active, flag it */
2651 if (psli->ring[i].cmdringaddr) {
2652 psli->ring[i].flag |=
2659 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
2661 /* If we are not polling, we MUST be in SLI2 mode */
2662 if (flag != MBX_POLL) {
2663 if (!(psli->sli_flag & LPFC_SLI2_ACTIVE) &&
2664 (mb->mbxCommand != MBX_KILL_BOARD)) {
2665 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2666 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2667 /* Mbox command <mbxCommand> cannot issue */
2668 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
2669 return MBX_NOT_FINISHED;
2671 /* timeout active mbox command */
2672 mod_timer(&psli->mbox_tmo, (jiffies +
2673 (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
2676 /* Mailbox cmd <cmd> issue */
2677 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
2678 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
2680 pmbox->vport ? pmbox->vport->vpi : 0,
2681 mb->mbxCommand, phba->pport->port_state,
2682 psli->sli_flag, flag);
2684 if (mb->mbxCommand != MBX_HEARTBEAT) {
2686 lpfc_debugfs_disc_trc(pmbox->vport,
2687 LPFC_DISC_TRC_MBOX_VPORT,
2688 "MBOX Send vport: cmd:x%x mb:x%x x%x",
2689 (uint32_t)mb->mbxCommand,
2690 mb->un.varWords[0], mb->un.varWords[1]);
2693 lpfc_debugfs_disc_trc(phba->pport,
2695 "MBOX Send: cmd:x%x mb:x%x x%x",
2696 (uint32_t)mb->mbxCommand,
2697 mb->un.varWords[0], mb->un.varWords[1]);
2701 psli->slistat.mbox_cmd++;
2702 evtctr = psli->slistat.mbox_event;
2704 /* next set own bit for the adapter and copy over command word */
2705 mb->mbxOwner = OWN_CHIP;
2707 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2708 /* First copy command data to host SLIM area */
2709 lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx, MAILBOX_CMD_SIZE);
2711 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2712 /* copy command data into host mbox for cmpl */
2713 lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx,
2717 /* First copy mbox command data to HBA SLIM, skip past first
2719 to_slim = phba->MBslimaddr + sizeof (uint32_t);
2720 lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
2721 MAILBOX_CMD_SIZE - sizeof (uint32_t));
2723 /* Next copy over first word, with mbxOwner set */
2724 ldata = *((volatile uint32_t *)mb);
2725 to_slim = phba->MBslimaddr;
2726 writel(ldata, to_slim);
2727 readl(to_slim); /* flush */
2729 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2730 /* switch over to host mailbox */
2731 psli->sli_flag |= LPFC_SLI2_ACTIVE;
2736 /* interrupt board to doit right away */
2737 writel(CA_MBATT, phba->CAregaddr);
2738 readl(phba->CAregaddr); /* flush */
2742 /* Don't wait for it to finish, just return */
2743 psli->mbox_active = pmbox;
2747 psli->mbox_active = NULL;
2748 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2749 /* First read mbox status word */
2750 word0 = *((volatile uint32_t *)&phba->slim2p->mbx);
2751 word0 = le32_to_cpu(word0);
2753 /* First read mbox status word */
2754 word0 = readl(phba->MBslimaddr);
2757 /* Read the HBA Host Attention Register */
2758 ha_copy = readl(phba->HAregaddr);
2760 i = lpfc_mbox_tmo_val(phba, mb->mbxCommand);
2761 i *= 1000; /* Convert to ms */
2763 /* Wait for command to complete */
2764 while (((word0 & OWN_CHIP) == OWN_CHIP) ||
2765 (!(ha_copy & HA_MBATT) &&
2766 (phba->link_state > LPFC_WARM_START))) {
2768 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2769 spin_unlock_irqrestore(&phba->hbalock,
2771 return MBX_NOT_FINISHED;
2774 /* Check if we took a mbox interrupt while we were
2776 if (((word0 & OWN_CHIP) != OWN_CHIP)
2777 && (evtctr != psli->slistat.mbox_event))
2780 spin_unlock_irqrestore(&phba->hbalock,
2785 spin_lock_irqsave(&phba->hbalock, drvr_flag);
2787 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2788 /* First copy command data */
2789 word0 = *((volatile uint32_t *)
2790 &phba->slim2p->mbx);
2791 word0 = le32_to_cpu(word0);
2792 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2794 volatile uint32_t slimword0;
2795 /* Check real SLIM for any errors */
2796 slimword0 = readl(phba->MBslimaddr);
2797 slimmb = (MAILBOX_t *) & slimword0;
2798 if (((slimword0 & OWN_CHIP) != OWN_CHIP)
2799 && slimmb->mbxStatus) {
2806 /* First copy command data */
2807 word0 = readl(phba->MBslimaddr);
2809 /* Read the HBA Host Attention Register */
2810 ha_copy = readl(phba->HAregaddr);
2813 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2814 /* copy results back to user */
2815 lpfc_sli_pcimem_bcopy(&phba->slim2p->mbx, mb,
2818 /* First copy command data */
2819 lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
2821 if ((mb->mbxCommand == MBX_DUMP_MEMORY) &&
2823 lpfc_memcpy_from_slim((void *)pmbox->context2,
2824 phba->MBslimaddr + DMP_RSP_OFFSET,
2825 mb->un.varDmp.word_cnt);
2829 writel(HA_MBATT, phba->HAregaddr);
2830 readl(phba->HAregaddr); /* flush */
2832 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2833 status = mb->mbxStatus;
2836 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2841 * Caller needs to hold lock.
2844 __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2845 struct lpfc_iocbq *piocb)
2847 /* Insert the caller's iocb in the txq tail for later processing. */
2848 list_add_tail(&piocb->list, &pring->txq);
2852 static struct lpfc_iocbq *
2853 lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2854 struct lpfc_iocbq **piocb)
2856 struct lpfc_iocbq * nextiocb;
2858 nextiocb = lpfc_sli_ringtx_get(phba, pring);
2868 * Lockless version of lpfc_sli_issue_iocb.
2871 __lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2872 struct lpfc_iocbq *piocb, uint32_t flag)
2874 struct lpfc_iocbq *nextiocb;
2877 if (piocb->iocb_cmpl && (!piocb->vport) &&
2878 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
2879 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
2880 lpfc_printf_log(phba, KERN_ERR,
2881 LOG_SLI | LOG_VPORT,
2882 "1807 IOCB x%x failed. No vport\n",
2883 piocb->iocb.ulpCommand);
2889 /* If the PCI channel is in offline state, do not post iocbs. */
2890 if (unlikely(pci_channel_offline(phba->pcidev)))
2894 * We should never get an IOCB if we are in a < LINK_DOWN state
2896 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
2900 * Check to see if we are blocking IOCB processing because of a
2901 * outstanding mbox command.
2903 if (unlikely(pring->flag & LPFC_STOP_IOCB_MBX))
2906 if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
2908 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
2909 * can be issued if the link is not up.
2911 switch (piocb->iocb.ulpCommand) {
2912 case CMD_QUE_RING_BUF_CN:
2913 case CMD_QUE_RING_BUF64_CN:
2915 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
2916 * completion, iocb_cmpl MUST be 0.
2918 if (piocb->iocb_cmpl)
2919 piocb->iocb_cmpl = NULL;
2921 case CMD_CREATE_XRI_CR:
2922 case CMD_CLOSE_XRI_CN:
2923 case CMD_CLOSE_XRI_CX:
2930 * For FCP commands, we must be in a state where we can process link
2933 } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
2934 !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
2938 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
2939 (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
2940 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
2943 lpfc_sli_update_ring(phba, pring);
2945 lpfc_sli_update_full_ring(phba, pring);
2948 return IOCB_SUCCESS;
2953 pring->stats.iocb_cmd_delay++;
2957 if (!(flag & SLI_IOCB_RET_IOCB)) {
2958 __lpfc_sli_ringtx_put(phba, pring, piocb);
2959 return IOCB_SUCCESS;
2967 lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2968 struct lpfc_iocbq *piocb, uint32_t flag)
2970 unsigned long iflags;
2973 spin_lock_irqsave(&phba->hbalock, iflags);
2974 rc = __lpfc_sli_issue_iocb(phba, pring, piocb, flag);
2975 spin_unlock_irqrestore(&phba->hbalock, iflags);
2981 lpfc_extra_ring_setup( struct lpfc_hba *phba)
2983 struct lpfc_sli *psli;
2984 struct lpfc_sli_ring *pring;
2988 /* Adjust cmd/rsp ring iocb entries more evenly */
2990 /* Take some away from the FCP ring */
2991 pring = &psli->ring[psli->fcp_ring];
2992 pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
2993 pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
2994 pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
2995 pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
2997 /* and give them to the extra ring */
2998 pring = &psli->ring[psli->extra_ring];
3000 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
3001 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
3002 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
3003 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
3005 /* Setup default profile for this ring */
3006 pring->iotag_max = 4096;
3007 pring->num_mask = 1;
3008 pring->prt[0].profile = 0; /* Mask 0 */
3009 pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
3010 pring->prt[0].type = phba->cfg_multi_ring_type;
3011 pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
3016 lpfc_sli_async_event_handler(struct lpfc_hba * phba,
3017 struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
3022 struct temp_event temp_event_data;
3023 struct Scsi_Host *shost;
3025 icmd = &iocbq->iocb;
3026 evt_code = icmd->un.asyncstat.evt_code;
3027 temp = icmd->ulpContext;
3029 if ((evt_code != ASYNC_TEMP_WARN) &&
3030 (evt_code != ASYNC_TEMP_SAFE)) {
3031 lpfc_printf_log(phba,
3034 "0327 Ring %d handler: unexpected ASYNC_STATUS"
3037 icmd->un.asyncstat.evt_code);
3040 temp_event_data.data = (uint32_t)temp;
3041 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
3042 if (evt_code == ASYNC_TEMP_WARN) {
3043 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
3044 lpfc_printf_log(phba,
3047 "0339 Adapter is very hot, please take "
3048 "corrective action. temperature : %d Celsius\n",
3051 if (evt_code == ASYNC_TEMP_SAFE) {
3052 temp_event_data.event_code = LPFC_NORMAL_TEMP;
3053 lpfc_printf_log(phba,
3056 "0340 Adapter temperature is OK now. "
3057 "temperature : %d Celsius\n",
3061 /* Send temperature change event to applications */
3062 shost = lpfc_shost_from_vport(phba->pport);
3063 fc_host_post_vendor_event(shost, fc_get_event_number(),
3064 sizeof(temp_event_data), (char *) &temp_event_data,
3065 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
3071 lpfc_sli_setup(struct lpfc_hba *phba)
3073 int i, totiocbsize = 0;
3074 struct lpfc_sli *psli = &phba->sli;
3075 struct lpfc_sli_ring *pring;
3077 psli->num_rings = MAX_CONFIGURED_RINGS;
3079 psli->fcp_ring = LPFC_FCP_RING;
3080 psli->next_ring = LPFC_FCP_NEXT_RING;
3081 psli->extra_ring = LPFC_EXTRA_RING;
3083 psli->iocbq_lookup = NULL;
3084 psli->iocbq_lookup_len = 0;
3085 psli->last_iotag = 0;
3087 for (i = 0; i < psli->num_rings; i++) {
3088 pring = &psli->ring[i];
3090 case LPFC_FCP_RING: /* ring 0 - FCP */
3091 /* numCiocb and numRiocb are used in config_port */
3092 pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
3093 pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
3094 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
3095 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
3096 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
3097 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
3098 pring->sizeCiocb = (phba->sli_rev == 3) ?
3099 SLI3_IOCB_CMD_SIZE :
3101 pring->sizeRiocb = (phba->sli_rev == 3) ?
3102 SLI3_IOCB_RSP_SIZE :
3104 pring->iotag_ctr = 0;
3106 (phba->cfg_hba_queue_depth * 2);
3107 pring->fast_iotag = pring->iotag_max;
3108 pring->num_mask = 0;
3110 case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
3111 /* numCiocb and numRiocb are used in config_port */
3112 pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
3113 pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
3114 pring->sizeCiocb = (phba->sli_rev == 3) ?
3115 SLI3_IOCB_CMD_SIZE :
3117 pring->sizeRiocb = (phba->sli_rev == 3) ?
3118 SLI3_IOCB_RSP_SIZE :
3120 pring->iotag_max = phba->cfg_hba_queue_depth;
3121 pring->num_mask = 0;
3123 case LPFC_ELS_RING: /* ring 2 - ELS / CT */
3124 /* numCiocb and numRiocb are used in config_port */
3125 pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
3126 pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
3127 pring->sizeCiocb = (phba->sli_rev == 3) ?
3128 SLI3_IOCB_CMD_SIZE :
3130 pring->sizeRiocb = (phba->sli_rev == 3) ?
3131 SLI3_IOCB_RSP_SIZE :
3133 pring->fast_iotag = 0;
3134 pring->iotag_ctr = 0;
3135 pring->iotag_max = 4096;
3136 pring->lpfc_sli_rcv_async_status =
3137 lpfc_sli_async_event_handler;
3138 pring->num_mask = 4;
3139 pring->prt[0].profile = 0; /* Mask 0 */
3140 pring->prt[0].rctl = FC_ELS_REQ;
3141 pring->prt[0].type = FC_ELS_DATA;
3142 pring->prt[0].lpfc_sli_rcv_unsol_event =
3143 lpfc_els_unsol_event;
3144 pring->prt[1].profile = 0; /* Mask 1 */
3145 pring->prt[1].rctl = FC_ELS_RSP;
3146 pring->prt[1].type = FC_ELS_DATA;
3147 pring->prt[1].lpfc_sli_rcv_unsol_event =
3148 lpfc_els_unsol_event;
3149 pring->prt[2].profile = 0; /* Mask 2 */
3150 /* NameServer Inquiry */
3151 pring->prt[2].rctl = FC_UNSOL_CTL;
3153 pring->prt[2].type = FC_COMMON_TRANSPORT_ULP;
3154 pring->prt[2].lpfc_sli_rcv_unsol_event =
3155 lpfc_ct_unsol_event;
3156 pring->prt[3].profile = 0; /* Mask 3 */
3157 /* NameServer response */
3158 pring->prt[3].rctl = FC_SOL_CTL;
3160 pring->prt[3].type = FC_COMMON_TRANSPORT_ULP;
3161 pring->prt[3].lpfc_sli_rcv_unsol_event =
3162 lpfc_ct_unsol_event;
3165 totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
3166 (pring->numRiocb * pring->sizeRiocb);
3168 if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
3169 /* Too many cmd / rsp ring entries in SLI2 SLIM */
3170 printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
3171 "SLI2 SLIM Data: x%x x%lx\n",
3172 phba->brd_no, totiocbsize,
3173 (unsigned long) MAX_SLIM_IOCB_SIZE);
3175 if (phba->cfg_multi_ring_support == 2)
3176 lpfc_extra_ring_setup(phba);
3182 lpfc_sli_queue_setup(struct lpfc_hba *phba)
3184 struct lpfc_sli *psli;
3185 struct lpfc_sli_ring *pring;
3189 spin_lock_irq(&phba->hbalock);
3190 INIT_LIST_HEAD(&psli->mboxq);
3191 INIT_LIST_HEAD(&psli->mboxq_cmpl);
3192 /* Initialize list headers for txq and txcmplq as double linked lists */
3193 for (i = 0; i < psli->num_rings; i++) {
3194 pring = &psli->ring[i];
3196 pring->next_cmdidx = 0;
3197 pring->local_getidx = 0;
3199 INIT_LIST_HEAD(&pring->txq);
3200 INIT_LIST_HEAD(&pring->txcmplq);
3201 INIT_LIST_HEAD(&pring->iocb_continueq);
3202 INIT_LIST_HEAD(&pring->postbufq);
3204 spin_unlock_irq(&phba->hbalock);
3209 lpfc_sli_host_down(struct lpfc_vport *vport)
3211 LIST_HEAD(completions);
3212 struct lpfc_hba *phba = vport->phba;
3213 struct lpfc_sli *psli = &phba->sli;
3214 struct lpfc_sli_ring *pring;
3215 struct lpfc_iocbq *iocb, *next_iocb;
3217 unsigned long flags = 0;
3218 uint16_t prev_pring_flag;
3220 lpfc_cleanup_discovery_resources(vport);
3222 spin_lock_irqsave(&phba->hbalock, flags);
3223 for (i = 0; i < psli->num_rings; i++) {
3224 pring = &psli->ring[i];
3225 prev_pring_flag = pring->flag;
3226 if (pring->ringno == LPFC_ELS_RING) /* Only slow rings */
3227 pring->flag |= LPFC_DEFERRED_RING_EVENT;
3229 * Error everything on the txq since these iocbs have not been
3230 * given to the FW yet.
3232 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
3233 if (iocb->vport != vport)
3235 list_move_tail(&iocb->list, &completions);
3239 /* Next issue ABTS for everything on the txcmplq */
3240 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
3242 if (iocb->vport != vport)
3244 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
3247 pring->flag = prev_pring_flag;
3250 spin_unlock_irqrestore(&phba->hbalock, flags);
3252 while (!list_empty(&completions)) {
3253 list_remove_head(&completions, iocb, struct lpfc_iocbq, list);
3255 if (!iocb->iocb_cmpl)
3256 lpfc_sli_release_iocbq(phba, iocb);
3258 iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
3259 iocb->iocb.un.ulpWord[4] = IOERR_SLI_DOWN;
3260 (iocb->iocb_cmpl) (phba, iocb, iocb);
3267 lpfc_sli_hba_down(struct lpfc_hba *phba)
3269 LIST_HEAD(completions);
3270 struct lpfc_sli *psli = &phba->sli;
3271 struct lpfc_sli_ring *pring;
3273 struct lpfc_iocbq *iocb;
3276 unsigned long flags = 0;
3278 lpfc_hba_down_prep(phba);
3280 lpfc_fabric_abort_hba(phba);
3282 spin_lock_irqsave(&phba->hbalock, flags);
3283 for (i = 0; i < psli->num_rings; i++) {
3284 pring = &psli->ring[i];
3285 if (pring->ringno == LPFC_ELS_RING) /* Only slow rings */
3286 pring->flag |= LPFC_DEFERRED_RING_EVENT;
3289 * Error everything on the txq since these iocbs have not been
3290 * given to the FW yet.
3292 list_splice_init(&pring->txq, &completions);
3296 spin_unlock_irqrestore(&phba->hbalock, flags);
3298 while (!list_empty(&completions)) {
3299 list_remove_head(&completions, iocb, struct lpfc_iocbq, list);
3302 if (!iocb->iocb_cmpl)
3303 lpfc_sli_release_iocbq(phba, iocb);
3305 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3306 cmd->un.ulpWord[4] = IOERR_SLI_DOWN;
3307 (iocb->iocb_cmpl) (phba, iocb, iocb);
3311 /* Return any active mbox cmds */
3312 del_timer_sync(&psli->mbox_tmo);
3313 spin_lock_irqsave(&phba->hbalock, flags);
3315 spin_lock(&phba->pport->work_port_lock);
3316 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
3317 spin_unlock(&phba->pport->work_port_lock);
3319 if (psli->mbox_active) {
3320 list_add_tail(&psli->mbox_active->list, &completions);
3321 psli->mbox_active = NULL;
3322 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
3325 /* Return any pending or completed mbox cmds */
3326 list_splice_init(&phba->sli.mboxq, &completions);
3327 list_splice_init(&phba->sli.mboxq_cmpl, &completions);
3328 INIT_LIST_HEAD(&psli->mboxq);
3329 INIT_LIST_HEAD(&psli->mboxq_cmpl);
3331 spin_unlock_irqrestore(&phba->hbalock, flags);
3333 while (!list_empty(&completions)) {
3334 list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
3335 pmb->mb.mbxStatus = MBX_NOT_FINISHED;
3336 if (pmb->mbox_cmpl) {
3337 pmb->mbox_cmpl(phba,pmb);
3344 lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
3346 uint32_t *src = srcp;
3347 uint32_t *dest = destp;
3351 for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
3353 ldata = le32_to_cpu(ldata);
3361 lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3362 struct lpfc_dmabuf *mp)
3364 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
3366 spin_lock_irq(&phba->hbalock);
3367 list_add_tail(&mp->list, &pring->postbufq);
3368 pring->postbufq_cnt++;
3369 spin_unlock_irq(&phba->hbalock);
3374 struct lpfc_dmabuf *
3375 lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3378 struct lpfc_dmabuf *mp, *next_mp;
3379 struct list_head *slp = &pring->postbufq;
3381 /* Search postbufq, from the begining, looking for a match on phys */
3382 spin_lock_irq(&phba->hbalock);
3383 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
3384 if (mp->phys == phys) {
3385 list_del_init(&mp->list);
3386 pring->postbufq_cnt--;
3387 spin_unlock_irq(&phba->hbalock);
3392 spin_unlock_irq(&phba->hbalock);
3393 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3394 "0410 Cannot find virtual addr for mapped buf on "
3395 "ring %d Data x%llx x%p x%p x%x\n",
3396 pring->ringno, (unsigned long long)phys,
3397 slp->next, slp->prev, pring->postbufq_cnt);
3402 lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3403 struct lpfc_iocbq *rspiocb)
3405 IOCB_t *irsp = &rspiocb->iocb;
3406 uint16_t abort_iotag, abort_context;
3407 struct lpfc_iocbq *abort_iocb;
3408 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
3412 if (irsp->ulpStatus) {
3413 abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
3414 abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
3416 spin_lock_irq(&phba->hbalock);
3417 if (abort_iotag != 0 && abort_iotag <= phba->sli.last_iotag)
3418 abort_iocb = phba->sli.iocbq_lookup[abort_iotag];
3420 lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI,
3421 "0327 Cannot abort els iocb %p "
3422 "with tag %x context %x, abort status %x, "
3424 abort_iocb, abort_iotag, abort_context,
3425 irsp->ulpStatus, irsp->un.ulpWord[4]);
3428 * make sure we have the right iocbq before taking it
3429 * off the txcmplq and try to call completion routine.
3432 abort_iocb->iocb.ulpContext != abort_context ||
3433 (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
3434 spin_unlock_irq(&phba->hbalock);
3436 list_del_init(&abort_iocb->list);
3437 pring->txcmplq_cnt--;
3438 spin_unlock_irq(&phba->hbalock);
3440 abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
3441 abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
3442 abort_iocb->iocb.un.ulpWord[4] = IOERR_SLI_ABORTED;
3443 (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
3447 lpfc_sli_release_iocbq(phba, cmdiocb);
3452 lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3453 struct lpfc_iocbq *rspiocb)
3455 IOCB_t *irsp = &rspiocb->iocb;
3457 /* ELS cmd tag <ulpIoTag> completes */
3458 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
3459 "0133 Ignoring ELS cmd tag x%x completion Data: "
3461 irsp->ulpIoTag, irsp->ulpStatus,
3462 irsp->un.ulpWord[4], irsp->ulpTimeout);
3463 if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
3464 lpfc_ct_free_iocb(phba, cmdiocb);
3466 lpfc_els_free_iocb(phba, cmdiocb);
3471 lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3472 struct lpfc_iocbq *cmdiocb)
3474 struct lpfc_vport *vport = cmdiocb->vport;
3475 struct lpfc_iocbq *abtsiocbp;
3476 IOCB_t *icmd = NULL;
3477 IOCB_t *iabt = NULL;
3478 int retval = IOCB_ERROR;
3481 * There are certain command types we don't want to abort. And we
3482 * don't want to abort commands that are already in the process of
3485 icmd = &cmdiocb->iocb;
3486 if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
3487 icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
3488 (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
3491 /* If we're unloading, don't abort iocb on the ELS ring, but change the
3492 * callback so that nothing happens when it finishes.
3494 if ((vport->load_flag & FC_UNLOADING) &&
3495 (pring->ringno == LPFC_ELS_RING)) {
3496 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
3497 cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
3499 cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
3500 goto abort_iotag_exit;
3503 /* issue ABTS for this IOCB based on iotag */
3504 abtsiocbp = __lpfc_sli_get_iocbq(phba);
3505 if (abtsiocbp == NULL)
3508 /* This signals the response to set the correct status
3509 * before calling the completion handler.
3511 cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
3513 iabt = &abtsiocbp->iocb;
3514 iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
3515 iabt->un.acxri.abortContextTag = icmd->ulpContext;
3516 iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
3518 iabt->ulpClass = icmd->ulpClass;
3520 if (phba->link_state >= LPFC_LINK_UP)
3521 iabt->ulpCommand = CMD_ABORT_XRI_CN;
3523 iabt->ulpCommand = CMD_CLOSE_XRI_CN;
3525 abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
3527 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
3528 "0339 Abort xri x%x, original iotag x%x, "
3529 "abort cmd iotag x%x\n",
3530 iabt->un.acxri.abortContextTag,
3531 iabt->un.acxri.abortIoTag, abtsiocbp->iotag);
3532 retval = __lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0);
3536 * Caller to this routine should check for IOCB_ERROR
3537 * and handle it properly. This routine no longer removes
3538 * iocb off txcmplq and call compl in case of IOCB_ERROR.
3544 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
3545 uint16_t tgt_id, uint64_t lun_id,
3546 lpfc_ctx_cmd ctx_cmd)
3548 struct lpfc_scsi_buf *lpfc_cmd;
3549 struct scsi_cmnd *cmnd;
3552 if (!(iocbq->iocb_flag & LPFC_IO_FCP))
3555 if (iocbq->vport != vport)
3558 lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
3559 cmnd = lpfc_cmd->pCmd;
3566 if ((cmnd->device->id == tgt_id) &&
3567 (cmnd->device->lun == lun_id))
3571 if (cmnd->device->id == tgt_id)
3578 printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
3579 __FUNCTION__, ctx_cmd);
3587 lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
3588 lpfc_ctx_cmd ctx_cmd)
3590 struct lpfc_hba *phba = vport->phba;
3591 struct lpfc_iocbq *iocbq;
3594 for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
3595 iocbq = phba->sli.iocbq_lookup[i];
3597 if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
3606 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3607 struct lpfc_iocbq *rspiocb)
3609 lpfc_sli_release_iocbq(phba, cmdiocb);
3614 lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
3615 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
3617 struct lpfc_hba *phba = vport->phba;
3618 struct lpfc_iocbq *iocbq;
3619 struct lpfc_iocbq *abtsiocb;
3621 int errcnt = 0, ret_val = 0;
3624 for (i = 1; i <= phba->sli.last_iotag; i++) {
3625 iocbq = phba->sli.iocbq_lookup[i];
3627 if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
3631 /* issue ABTS for this IOCB based on iotag */
3632 abtsiocb = lpfc_sli_get_iocbq(phba);
3633 if (abtsiocb == NULL) {
3639 abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
3640 abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
3641 abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
3642 abtsiocb->iocb.ulpLe = 1;
3643 abtsiocb->iocb.ulpClass = cmd->ulpClass;
3644 abtsiocb->vport = phba->pport;
3646 if (lpfc_is_link_up(phba))
3647 abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
3649 abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
3651 /* Setup callback routine and issue the command. */
3652 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
3653 ret_val = lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0);
3654 if (ret_val == IOCB_ERROR) {
3655 lpfc_sli_release_iocbq(phba, abtsiocb);
3665 lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
3666 struct lpfc_iocbq *cmdiocbq,
3667 struct lpfc_iocbq *rspiocbq)
3669 wait_queue_head_t *pdone_q;
3670 unsigned long iflags;
3672 spin_lock_irqsave(&phba->hbalock, iflags);
3673 cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
3674 if (cmdiocbq->context2 && rspiocbq)
3675 memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
3676 &rspiocbq->iocb, sizeof(IOCB_t));
3678 pdone_q = cmdiocbq->context_un.wait_queue;
3681 spin_unlock_irqrestore(&phba->hbalock, iflags);
3686 * Issue the caller's iocb and wait for its completion, but no longer than the
3687 * caller's timeout. Note that iocb_flags is cleared before the
3688 * lpfc_sli_issue_call since the wake routine sets a unique value and by
3689 * definition this is a wait function.
3693 lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
3694 struct lpfc_sli_ring *pring,
3695 struct lpfc_iocbq *piocb,
3696 struct lpfc_iocbq *prspiocbq,
3699 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
3700 long timeleft, timeout_req = 0;
3701 int retval = IOCB_SUCCESS;
3705 * If the caller has provided a response iocbq buffer, then context2
3706 * is NULL or its an error.
3709 if (piocb->context2)
3711 piocb->context2 = prspiocbq;
3714 piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
3715 piocb->context_un.wait_queue = &done_q;
3716 piocb->iocb_flag &= ~LPFC_IO_WAKE;
3718 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
3719 creg_val = readl(phba->HCregaddr);
3720 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
3721 writel(creg_val, phba->HCregaddr);
3722 readl(phba->HCregaddr); /* flush */
3725 retval = lpfc_sli_issue_iocb(phba, pring, piocb, 0);
3726 if (retval == IOCB_SUCCESS) {
3727 timeout_req = timeout * HZ;
3728 timeleft = wait_event_timeout(done_q,
3729 piocb->iocb_flag & LPFC_IO_WAKE,
3732 if (piocb->iocb_flag & LPFC_IO_WAKE) {
3733 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3734 "0331 IOCB wake signaled\n");
3735 } else if (timeleft == 0) {
3736 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3737 "0338 IOCB wait timeout error - no "
3738 "wake response Data x%x\n", timeout);
3739 retval = IOCB_TIMEDOUT;
3741 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3742 "0330 IOCB wake NOT set, "
3744 timeout, (timeleft / jiffies));
3745 retval = IOCB_TIMEDOUT;
3748 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3749 ":0332 IOCB wait issue failed, Data x%x\n",
3751 retval = IOCB_ERROR;
3754 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
3755 creg_val = readl(phba->HCregaddr);
3756 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
3757 writel(creg_val, phba->HCregaddr);
3758 readl(phba->HCregaddr); /* flush */
3762 piocb->context2 = NULL;
3764 piocb->context_un.wait_queue = NULL;
3765 piocb->iocb_cmpl = NULL;
3770 lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
3773 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
3777 /* The caller must leave context1 empty. */
3778 if (pmboxq->context1 != 0)
3779 return MBX_NOT_FINISHED;
3781 /* setup wake call as IOCB callback */
3782 pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
3783 /* setup context field to pass wait_queue pointer to wake function */
3784 pmboxq->context1 = &done_q;
3786 /* now issue the command */
3787 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
3789 if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
3790 wait_event_interruptible_timeout(done_q,
3791 pmboxq->mbox_flag & LPFC_MBX_WAKE,
3794 spin_lock_irqsave(&phba->hbalock, flag);
3795 pmboxq->context1 = NULL;
3797 * if LPFC_MBX_WAKE flag is set the mailbox is completed
3798 * else do not free the resources.
3800 if (pmboxq->mbox_flag & LPFC_MBX_WAKE)
3801 retval = MBX_SUCCESS;
3803 retval = MBX_TIMEOUT;
3804 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3806 spin_unlock_irqrestore(&phba->hbalock, flag);
3813 lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba)
3815 struct lpfc_vport *vport = phba->pport;
3819 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE && !vport->stopped) {
3820 if (i++ > LPFC_MBOX_TMO * 1000)
3824 * Call lpfc_sli_handle_mb_event only if a mailbox cmd
3825 * did finish. This way we won't get the misleading
3826 * "Stray Mailbox Interrupt" message.
3828 spin_lock_irq(&phba->hbalock);
3829 ha_copy = phba->work_ha;
3830 phba->work_ha &= ~HA_MBATT;
3831 spin_unlock_irq(&phba->hbalock);
3833 if (ha_copy & HA_MBATT)
3834 if (lpfc_sli_handle_mb_event(phba) == 0)
3840 return (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) ? 1 : 0;
3844 lpfc_intr_handler(int irq, void *dev_id)
3846 struct lpfc_hba *phba;
3848 uint32_t work_ha_copy;
3849 unsigned long status;
3853 MAILBOX_t *mbox, *pmbox;
3854 struct lpfc_vport *vport;
3855 struct lpfc_nodelist *ndlp;
3856 struct lpfc_dmabuf *mp;
3861 * Get the driver's phba structure from the dev_id and
3862 * assume the HBA is not interrupting.
3864 phba = (struct lpfc_hba *) dev_id;
3866 if (unlikely(!phba))
3869 /* If the pci channel is offline, ignore all the interrupts. */
3870 if (unlikely(pci_channel_offline(phba->pcidev)))
3873 phba->sli.slistat.sli_intr++;
3876 * Call the HBA to see if it is interrupting. If not, don't claim
3880 /* Ignore all interrupts during initialization. */
3881 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
3885 * Read host attention register to determine interrupt source
3886 * Clear Attention Sources, except Error Attention (to
3887 * preserve status) and Link Attention
3889 spin_lock(&phba->hbalock);
3890 ha_copy = readl(phba->HAregaddr);
3891 /* If somebody is waiting to handle an eratt don't process it
3892 * here. The brdkill function will do this.
3894 if (phba->link_flag & LS_IGNORE_ERATT)
3895 ha_copy &= ~HA_ERATT;
3896 writel((ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
3897 readl(phba->HAregaddr); /* flush */
3898 spin_unlock(&phba->hbalock);
3900 if (unlikely(!ha_copy))
3903 work_ha_copy = ha_copy & phba->work_ha_mask;
3905 if (unlikely(work_ha_copy)) {
3906 if (work_ha_copy & HA_LATT) {
3907 if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
3909 * Turn off Link Attention interrupts
3910 * until CLEAR_LA done
3912 spin_lock(&phba->hbalock);
3913 phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
3914 control = readl(phba->HCregaddr);
3915 control &= ~HC_LAINT_ENA;
3916 writel(control, phba->HCregaddr);
3917 readl(phba->HCregaddr); /* flush */
3918 spin_unlock(&phba->hbalock);
3921 work_ha_copy &= ~HA_LATT;
3924 if (work_ha_copy & ~(HA_ERATT|HA_MBATT|HA_LATT)) {
3926 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
3927 * the only slow ring.
3929 status = (work_ha_copy &
3930 (HA_RXMASK << (4*LPFC_ELS_RING)));
3931 status >>= (4*LPFC_ELS_RING);
3932 if (status & HA_RXMASK) {
3933 spin_lock(&phba->hbalock);
3934 control = readl(phba->HCregaddr);
3936 lpfc_debugfs_slow_ring_trc(phba,
3937 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
3939 (uint32_t)phba->sli.slistat.sli_intr);
3941 if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
3942 lpfc_debugfs_slow_ring_trc(phba,
3944 "pwork:x%x hawork:x%x wait:x%x",
3945 phba->work_ha, work_ha_copy,
3946 (uint32_t)((unsigned long)
3950 ~(HC_R0INT_ENA << LPFC_ELS_RING);
3951 writel(control, phba->HCregaddr);
3952 readl(phba->HCregaddr); /* flush */
3955 lpfc_debugfs_slow_ring_trc(phba,
3956 "ISR slow ring: pwork:"
3957 "x%x hawork:x%x wait:x%x",
3958 phba->work_ha, work_ha_copy,
3959 (uint32_t)((unsigned long)
3962 spin_unlock(&phba->hbalock);
3966 if (work_ha_copy & HA_ERATT) {
3967 phba->link_state = LPFC_HBA_ERROR;
3969 * There was a link/board error. Read the
3970 * status register to retrieve the error event
3973 phba->sli.slistat.err_attn_event++;
3974 /* Save status info */
3975 phba->work_hs = readl(phba->HSregaddr);
3976 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
3977 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
3979 /* Clear Chip error bit */
3980 writel(HA_ERATT, phba->HAregaddr);
3981 readl(phba->HAregaddr); /* flush */
3982 phba->pport->stopped = 1;
3985 if ((work_ha_copy & HA_MBATT) &&
3986 (phba->sli.mbox_active)) {
3987 pmb = phba->sli.mbox_active;
3989 mbox = &phba->slim2p->mbx;
3992 /* First check out the status word */
3993 lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
3994 if (pmbox->mbxOwner != OWN_HOST) {
3996 * Stray Mailbox Interrupt, mbxCommand <cmd>
3997 * mbxStatus <status>
3999 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX |
4001 "(%d):0304 Stray Mailbox "
4002 "Interrupt mbxCommand x%x "
4004 (vport ? vport->vpi : 0),
4008 phba->last_completion_time = jiffies;
4009 del_timer_sync(&phba->sli.mbox_tmo);
4011 phba->sli.mbox_active = NULL;
4012 if (pmb->mbox_cmpl) {
4013 lpfc_sli_pcimem_bcopy(mbox, pmbox,
4016 if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
4017 pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
4019 lpfc_debugfs_disc_trc(vport,
4020 LPFC_DISC_TRC_MBOX_VPORT,
4021 "MBOX dflt rpi: : status:x%x rpi:x%x",
4022 (uint32_t)pmbox->mbxStatus,
4023 pmbox->un.varWords[0], 0);
4025 if ( !pmbox->mbxStatus) {
4026 mp = (struct lpfc_dmabuf *)
4028 ndlp = (struct lpfc_nodelist *)
4031 /* Reg_LOGIN of dflt RPI was successful.
4032 * new lets get rid of the RPI using the
4035 lpfc_unreg_login(phba, vport->vpi,
4036 pmbox->un.varWords[0], pmb);
4037 pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
4039 pmb->context2 = ndlp;
4041 spin_lock(&phba->hbalock);
4042 phba->sli.sli_flag &=
4043 ~LPFC_SLI_MBOX_ACTIVE;
4044 spin_unlock(&phba->hbalock);
4045 goto send_current_mbox;
4048 spin_lock(&phba->pport->work_port_lock);
4049 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
4050 spin_unlock(&phba->pport->work_port_lock);
4051 lpfc_mbox_cmpl_put(phba, pmb);
4053 if ((work_ha_copy & HA_MBATT) &&
4054 (phba->sli.mbox_active == NULL)) {
4056 spin_lock(&phba->hbalock);
4057 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
4058 pmb = lpfc_mbox_get(phba);
4059 spin_unlock(&phba->hbalock);
4061 /* Process next mailbox command if there is one */
4063 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4064 if (rc == MBX_NOT_FINISHED) {
4065 pmb->mb.mbxStatus = MBX_NOT_FINISHED;
4066 lpfc_mbox_cmpl_put(phba, pmb);
4067 goto send_next_mbox;
4070 /* Turn on IOCB processing */
4071 for (i = 0; i < phba->sli.num_rings; i++)
4072 lpfc_sli_turn_on_ring(phba, i);
4077 spin_lock(&phba->hbalock);
4078 phba->work_ha |= work_ha_copy;
4079 if (phba->work_wait)
4080 lpfc_worker_wake_up(phba);
4081 spin_unlock(&phba->hbalock);
4084 ha_copy &= ~(phba->work_ha_mask);
4087 * Process all events on FCP ring. Take the optimized path for
4088 * FCP IO. Any other IO is slow path and is handled by
4089 * the worker thread.
4091 status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
4092 status >>= (4*LPFC_FCP_RING);
4093 if (status & HA_RXMASK)
4094 lpfc_sli_handle_fast_ring_event(phba,
4095 &phba->sli.ring[LPFC_FCP_RING],
4098 if (phba->cfg_multi_ring_support == 2) {
4100 * Process all events on extra ring. Take the optimized path
4101 * for extra ring IO. Any other IO is slow path and is handled
4102 * by the worker thread.
4104 status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
4105 status >>= (4*LPFC_EXTRA_RING);
4106 if (status & HA_RXMASK) {
4107 lpfc_sli_handle_fast_ring_event(phba,
4108 &phba->sli.ring[LPFC_EXTRA_RING],
4114 } /* lpfc_intr_handler */