1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2006 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/interrupt.h>
25 #include <linux/delay.h>
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_cmnd.h>
29 #include <scsi/scsi_device.h>
30 #include <scsi/scsi_host.h>
31 #include <scsi/scsi_transport_fc.h>
35 #include "lpfc_disc.h"
36 #include "lpfc_scsi.h"
38 #include "lpfc_crtn.h"
39 #include "lpfc_logmsg.h"
40 #include "lpfc_compat.h"
43 * Define macro to log: Mailbox command x%x cannot issue Data
44 * This allows multiple uses of lpfc_msgBlk0311
45 * w/o perturbing log msg utility.
47 #define LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag) \
48 lpfc_printf_log(phba, \
51 "%d:0311 Mailbox command x%x cannot issue " \
52 "Data: x%x x%x x%x\n", \
60 /* There are only four IOCB completion types. */
61 typedef enum _lpfc_iocb_type
{
69 lpfc_sli_get_iocbq(struct lpfc_hba
* phba
)
71 struct list_head
*lpfc_iocb_list
= &phba
->lpfc_iocb_list
;
72 struct lpfc_iocbq
* iocbq
= NULL
;
74 list_remove_head(lpfc_iocb_list
, iocbq
, struct lpfc_iocbq
, list
);
79 lpfc_sli_release_iocbq(struct lpfc_hba
* phba
, struct lpfc_iocbq
* iocbq
)
81 size_t start_clean
= (size_t)(&((struct lpfc_iocbq
*)NULL
)->iocb
);
84 * Clean all volatile data fields, preserve iotag and node struct.
86 memset((char*)iocbq
+ start_clean
, 0, sizeof(*iocbq
) - start_clean
);
87 list_add_tail(&iocbq
->list
, &phba
->lpfc_iocb_list
);
91 * Translate the iocb command to an iocb command type used to decide the final
92 * disposition of each completed IOCB.
95 lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd
)
97 lpfc_iocb_type type
= LPFC_UNKNOWN_IOCB
;
99 if (iocb_cmnd
> CMD_MAX_IOCB_CMD
)
103 case CMD_XMIT_SEQUENCE_CR
:
104 case CMD_XMIT_SEQUENCE_CX
:
105 case CMD_XMIT_BCAST_CN
:
106 case CMD_XMIT_BCAST_CX
:
107 case CMD_ELS_REQUEST_CR
:
108 case CMD_ELS_REQUEST_CX
:
109 case CMD_CREATE_XRI_CR
:
110 case CMD_CREATE_XRI_CX
:
112 case CMD_XMIT_ELS_RSP_CX
:
114 case CMD_FCP_IWRITE_CR
:
115 case CMD_FCP_IWRITE_CX
:
116 case CMD_FCP_IREAD_CR
:
117 case CMD_FCP_IREAD_CX
:
118 case CMD_FCP_ICMND_CR
:
119 case CMD_FCP_ICMND_CX
:
120 case CMD_FCP_TSEND_CX
:
121 case CMD_FCP_TRSP_CX
:
122 case CMD_FCP_TRECEIVE_CX
:
123 case CMD_FCP_AUTO_TRSP_CX
:
124 case CMD_ADAPTER_MSG
:
125 case CMD_ADAPTER_DUMP
:
126 case CMD_XMIT_SEQUENCE64_CR
:
127 case CMD_XMIT_SEQUENCE64_CX
:
128 case CMD_XMIT_BCAST64_CN
:
129 case CMD_XMIT_BCAST64_CX
:
130 case CMD_ELS_REQUEST64_CR
:
131 case CMD_ELS_REQUEST64_CX
:
132 case CMD_FCP_IWRITE64_CR
:
133 case CMD_FCP_IWRITE64_CX
:
134 case CMD_FCP_IREAD64_CR
:
135 case CMD_FCP_IREAD64_CX
:
136 case CMD_FCP_ICMND64_CR
:
137 case CMD_FCP_ICMND64_CX
:
138 case CMD_FCP_TSEND64_CX
:
139 case CMD_FCP_TRSP64_CX
:
140 case CMD_FCP_TRECEIVE64_CX
:
141 case CMD_GEN_REQUEST64_CR
:
142 case CMD_GEN_REQUEST64_CX
:
143 case CMD_XMIT_ELS_RSP64_CX
:
144 type
= LPFC_SOL_IOCB
;
146 case CMD_ABORT_XRI_CN
:
147 case CMD_ABORT_XRI_CX
:
148 case CMD_CLOSE_XRI_CN
:
149 case CMD_CLOSE_XRI_CX
:
150 case CMD_XRI_ABORTED_CX
:
151 case CMD_ABORT_MXRI64_CN
:
152 type
= LPFC_ABORT_IOCB
;
154 case CMD_RCV_SEQUENCE_CX
:
155 case CMD_RCV_ELS_REQ_CX
:
156 case CMD_RCV_SEQUENCE64_CX
:
157 case CMD_RCV_ELS_REQ64_CX
:
158 type
= LPFC_UNSOL_IOCB
;
161 type
= LPFC_UNKNOWN_IOCB
;
169 lpfc_sli_ring_map(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
*pmb
)
171 struct lpfc_sli
*psli
= &phba
->sli
;
172 MAILBOX_t
*pmbox
= &pmb
->mb
;
175 for (i
= 0; i
< psli
->num_rings
; i
++) {
176 phba
->hba_state
= LPFC_INIT_MBX_CMDS
;
177 lpfc_config_ring(phba
, i
, pmb
);
178 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
179 if (rc
!= MBX_SUCCESS
) {
180 lpfc_printf_log(phba
,
183 "%d:0446 Adapter failed to init, "
184 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
190 phba
->hba_state
= LPFC_HBA_ERROR
;
198 lpfc_sli_ringtxcmpl_put(struct lpfc_hba
* phba
,
199 struct lpfc_sli_ring
* pring
, struct lpfc_iocbq
* piocb
)
201 list_add_tail(&piocb
->list
, &pring
->txcmplq
);
202 pring
->txcmplq_cnt
++;
203 if (unlikely(pring
->ringno
== LPFC_ELS_RING
))
204 mod_timer(&phba
->els_tmofunc
,
205 jiffies
+ HZ
* (phba
->fc_ratov
<< 1));
210 static struct lpfc_iocbq
*
211 lpfc_sli_ringtx_get(struct lpfc_hba
* phba
, struct lpfc_sli_ring
* pring
)
213 struct list_head
*dlp
;
214 struct lpfc_iocbq
*cmd_iocb
;
218 list_remove_head((&pring
->txq
), cmd_iocb
,
222 /* If the first ptr is not equal to the list header,
223 * deque the IOCBQ_t and return it.
231 lpfc_sli_next_iocb_slot (struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
233 struct lpfc_pgp
*pgp
= &phba
->slim2p
->mbx
.us
.s2
.port
[pring
->ringno
];
234 uint32_t max_cmd_idx
= pring
->numCiocb
;
237 if ((pring
->next_cmdidx
== pring
->cmdidx
) &&
238 (++pring
->next_cmdidx
>= max_cmd_idx
))
239 pring
->next_cmdidx
= 0;
241 if (unlikely(pring
->local_getidx
== pring
->next_cmdidx
)) {
243 pring
->local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
245 if (unlikely(pring
->local_getidx
>= max_cmd_idx
)) {
246 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
247 "%d:0315 Ring %d issue: portCmdGet %d "
248 "is bigger then cmd ring %d\n",
249 phba
->brd_no
, pring
->ringno
,
250 pring
->local_getidx
, max_cmd_idx
);
252 phba
->hba_state
= LPFC_HBA_ERROR
;
254 * All error attention handlers are posted to
257 phba
->work_ha
|= HA_ERATT
;
258 phba
->work_hs
= HS_FFER3
;
260 wake_up(phba
->work_wait
);
265 if (pring
->local_getidx
== pring
->next_cmdidx
)
269 iocb
= IOCB_ENTRY(pring
->cmdringaddr
, pring
->cmdidx
);
275 lpfc_sli_next_iotag(struct lpfc_hba
* phba
, struct lpfc_iocbq
* iocbq
)
277 struct lpfc_iocbq
** new_arr
;
278 struct lpfc_iocbq
** old_arr
;
280 struct lpfc_sli
*psli
= &phba
->sli
;
283 spin_lock_irq(phba
->host
->host_lock
);
284 iotag
= psli
->last_iotag
;
285 if(++iotag
< psli
->iocbq_lookup_len
) {
286 psli
->last_iotag
= iotag
;
287 psli
->iocbq_lookup
[iotag
] = iocbq
;
288 spin_unlock_irq(phba
->host
->host_lock
);
289 iocbq
->iotag
= iotag
;
292 else if (psli
->iocbq_lookup_len
< (0xffff
293 - LPFC_IOCBQ_LOOKUP_INCREMENT
)) {
294 new_len
= psli
->iocbq_lookup_len
+ LPFC_IOCBQ_LOOKUP_INCREMENT
;
295 spin_unlock_irq(phba
->host
->host_lock
);
296 new_arr
= kmalloc(new_len
* sizeof (struct lpfc_iocbq
*),
299 memset((char *)new_arr
, 0,
300 new_len
* sizeof (struct lpfc_iocbq
*));
301 spin_lock_irq(phba
->host
->host_lock
);
302 old_arr
= psli
->iocbq_lookup
;
303 if (new_len
<= psli
->iocbq_lookup_len
) {
304 /* highly unprobable case */
306 iotag
= psli
->last_iotag
;
307 if(++iotag
< psli
->iocbq_lookup_len
) {
308 psli
->last_iotag
= iotag
;
309 psli
->iocbq_lookup
[iotag
] = iocbq
;
310 spin_unlock_irq(phba
->host
->host_lock
);
311 iocbq
->iotag
= iotag
;
314 spin_unlock_irq(phba
->host
->host_lock
);
317 if (psli
->iocbq_lookup
)
318 memcpy(new_arr
, old_arr
,
319 ((psli
->last_iotag
+ 1) *
320 sizeof (struct lpfc_iocbq
*)));
321 psli
->iocbq_lookup
= new_arr
;
322 psli
->iocbq_lookup_len
= new_len
;
323 psli
->last_iotag
= iotag
;
324 psli
->iocbq_lookup
[iotag
] = iocbq
;
325 spin_unlock_irq(phba
->host
->host_lock
);
326 iocbq
->iotag
= iotag
;
331 spin_unlock_irq(phba
->host
->host_lock
);
333 lpfc_printf_log(phba
, KERN_ERR
,LOG_SLI
,
334 "%d:0318 Failed to allocate IOTAG.last IOTAG is %d\n",
335 phba
->brd_no
, psli
->last_iotag
);
341 lpfc_sli_submit_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
342 IOCB_t
*iocb
, struct lpfc_iocbq
*nextiocb
)
347 nextiocb
->iocb
.ulpIoTag
= (nextiocb
->iocb_cmpl
) ? nextiocb
->iotag
: 0;
350 * Issue iocb command to adapter
352 lpfc_sli_pcimem_bcopy(&nextiocb
->iocb
, iocb
, sizeof (IOCB_t
));
354 pring
->stats
.iocb_cmd
++;
357 * If there is no completion routine to call, we can release the
358 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
359 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
361 if (nextiocb
->iocb_cmpl
)
362 lpfc_sli_ringtxcmpl_put(phba
, pring
, nextiocb
);
364 lpfc_sli_release_iocbq(phba
, nextiocb
);
367 * Let the HBA know what IOCB slot will be the next one the
368 * driver will put a command into.
370 pring
->cmdidx
= pring
->next_cmdidx
;
371 writel(pring
->cmdidx
, phba
->MBslimaddr
372 + (SLIMOFF
+ (pring
->ringno
* 2)) * 4);
376 lpfc_sli_update_full_ring(struct lpfc_hba
* phba
,
377 struct lpfc_sli_ring
*pring
)
379 int ringno
= pring
->ringno
;
381 pring
->flag
|= LPFC_CALL_RING_AVAILABLE
;
386 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
387 * The HBA will tell us when an IOCB entry is available.
389 writel((CA_R0ATT
|CA_R0CE_REQ
) << (ringno
*4), phba
->CAregaddr
);
390 readl(phba
->CAregaddr
); /* flush */
392 pring
->stats
.iocb_cmd_full
++;
396 lpfc_sli_update_ring(struct lpfc_hba
* phba
,
397 struct lpfc_sli_ring
*pring
)
399 int ringno
= pring
->ringno
;
402 * Tell the HBA that there is work to do in this ring.
405 writel(CA_R0ATT
<< (ringno
* 4), phba
->CAregaddr
);
406 readl(phba
->CAregaddr
); /* flush */
410 lpfc_sli_resume_iocb(struct lpfc_hba
* phba
, struct lpfc_sli_ring
* pring
)
413 struct lpfc_iocbq
*nextiocb
;
417 * (a) there is anything on the txq to send
419 * (c) link attention events can be processed (fcp ring only)
420 * (d) IOCB processing is not blocked by the outstanding mbox command.
422 if (pring
->txq_cnt
&&
423 (phba
->hba_state
> LPFC_LINK_DOWN
) &&
424 (pring
->ringno
!= phba
->sli
.fcp_ring
||
425 phba
->sli
.sli_flag
& LPFC_PROCESS_LA
) &&
426 !(pring
->flag
& LPFC_STOP_IOCB_MBX
)) {
428 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
429 (nextiocb
= lpfc_sli_ringtx_get(phba
, pring
)))
430 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
433 lpfc_sli_update_ring(phba
, pring
);
435 lpfc_sli_update_full_ring(phba
, pring
);
441 /* lpfc_sli_turn_on_ring is only called by lpfc_sli_handle_mb_event below */
443 lpfc_sli_turn_on_ring(struct lpfc_hba
* phba
, int ringno
)
445 struct lpfc_pgp
*pgp
= &phba
->slim2p
->mbx
.us
.s2
.port
[ringno
];
447 /* If the ring is active, flag it */
448 if (phba
->sli
.ring
[ringno
].cmdringaddr
) {
449 if (phba
->sli
.ring
[ringno
].flag
& LPFC_STOP_IOCB_MBX
) {
450 phba
->sli
.ring
[ringno
].flag
&= ~LPFC_STOP_IOCB_MBX
;
452 * Force update of the local copy of cmdGetInx
454 phba
->sli
.ring
[ringno
].local_getidx
455 = le32_to_cpu(pgp
->cmdGetInx
);
456 spin_lock_irq(phba
->host
->host_lock
);
457 lpfc_sli_resume_iocb(phba
, &phba
->sli
.ring
[ringno
]);
458 spin_unlock_irq(phba
->host
->host_lock
);
464 lpfc_sli_chk_mbx_command(uint8_t mbxCommand
)
468 switch (mbxCommand
) {
472 case MBX_RUN_BIU_DIAG
:
475 case MBX_CONFIG_LINK
:
476 case MBX_CONFIG_RING
:
478 case MBX_READ_CONFIG
:
479 case MBX_READ_RCONFIG
:
481 case MBX_READ_STATUS
:
485 case MBX_READ_LNK_STAT
:
487 case MBX_UNREG_LOGIN
:
490 case MBX_DUMP_MEMORY
:
491 case MBX_DUMP_CONTEXT
:
496 case MBX_DEL_LD_ENTRY
:
497 case MBX_RUN_PROGRAM
:
502 case MBX_CONFIG_FARP
:
505 case MBX_RUN_BIU_DIAG64
:
506 case MBX_CONFIG_PORT
:
507 case MBX_READ_SPARM64
:
509 case MBX_REG_LOGIN64
:
511 case MBX_FLASH_WR_ULA
:
513 case MBX_LOAD_EXP_ROM
:
523 lpfc_sli_wake_mbox_wait(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmboxq
)
525 wait_queue_head_t
*pdone_q
;
528 * If pdone_q is empty, the driver thread gave up waiting and
531 pdone_q
= (wait_queue_head_t
*) pmboxq
->context1
;
533 wake_up_interruptible(pdone_q
);
538 lpfc_sli_def_mbox_cmpl(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
540 struct lpfc_dmabuf
*mp
;
541 mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
543 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
546 mempool_free( pmb
, phba
->mbox_mem_pool
);
551 lpfc_sli_handle_mb_event(struct lpfc_hba
* phba
)
556 struct lpfc_sli
*psli
;
558 uint32_t process_next
;
561 /* We should only get here if we are in SLI2 mode */
562 if (!(phba
->sli
.sli_flag
& LPFC_SLI2_ACTIVE
)) {
566 phba
->sli
.slistat
.mbox_event
++;
568 /* Get a Mailbox buffer to setup mailbox commands for callback */
569 if ((pmb
= phba
->sli
.mbox_active
)) {
571 mbox
= &phba
->slim2p
->mbx
;
573 /* First check out the status word */
574 lpfc_sli_pcimem_bcopy(mbox
, pmbox
, sizeof (uint32_t));
576 /* Sanity check to ensure the host owns the mailbox */
577 if (pmbox
->mbxOwner
!= OWN_HOST
) {
578 /* Lets try for a while */
579 for (i
= 0; i
< 10240; i
++) {
580 /* First copy command data */
581 lpfc_sli_pcimem_bcopy(mbox
, pmbox
,
583 if (pmbox
->mbxOwner
== OWN_HOST
)
586 /* Stray Mailbox Interrupt, mbxCommand <cmd> mbxStatus
588 lpfc_printf_log(phba
,
591 "%d:0304 Stray Mailbox Interrupt "
592 "mbxCommand x%x mbxStatus x%x\n",
597 spin_lock_irq(phba
->host
->host_lock
);
598 phba
->sli
.sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
599 spin_unlock_irq(phba
->host
->host_lock
);
604 del_timer_sync(&phba
->sli
.mbox_tmo
);
605 phba
->work_hba_events
&= ~WORKER_MBOX_TMO
;
608 * It is a fatal error if unknown mbox command completion.
610 if (lpfc_sli_chk_mbx_command(pmbox
->mbxCommand
) ==
613 /* Unknow mailbox command compl */
614 lpfc_printf_log(phba
,
617 "%d:0323 Unknown Mailbox command %x Cmpl\n",
620 phba
->hba_state
= LPFC_HBA_ERROR
;
621 phba
->work_hs
= HS_FFER3
;
622 lpfc_handle_eratt(phba
);
626 phba
->sli
.mbox_active
= NULL
;
627 if (pmbox
->mbxStatus
) {
628 phba
->sli
.slistat
.mbox_stat_err
++;
629 if (pmbox
->mbxStatus
== MBXERR_NO_RESOURCES
) {
630 /* Mbox cmd cmpl error - RETRYing */
631 lpfc_printf_log(phba
,
634 "%d:0305 Mbox cmd cmpl error - "
635 "RETRYing Data: x%x x%x x%x x%x\n",
639 pmbox
->un
.varWords
[0],
641 pmbox
->mbxStatus
= 0;
642 pmbox
->mbxOwner
= OWN_HOST
;
643 spin_lock_irq(phba
->host
->host_lock
);
644 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
645 spin_unlock_irq(phba
->host
->host_lock
);
646 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
647 if (rc
== MBX_SUCCESS
)
652 /* Mailbox cmd <cmd> Cmpl <cmpl> */
653 lpfc_printf_log(phba
,
656 "%d:0307 Mailbox cmd x%x Cmpl x%p "
657 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
661 *((uint32_t *) pmbox
),
662 pmbox
->un
.varWords
[0],
663 pmbox
->un
.varWords
[1],
664 pmbox
->un
.varWords
[2],
665 pmbox
->un
.varWords
[3],
666 pmbox
->un
.varWords
[4],
667 pmbox
->un
.varWords
[5],
668 pmbox
->un
.varWords
[6],
669 pmbox
->un
.varWords
[7]);
671 if (pmb
->mbox_cmpl
) {
672 lpfc_sli_pcimem_bcopy(mbox
, pmbox
, MAILBOX_CMD_SIZE
);
673 pmb
->mbox_cmpl(phba
,pmb
);
679 process_next
= 0; /* by default don't loop */
680 spin_lock_irq(phba
->host
->host_lock
);
681 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
683 /* Process next mailbox command if there is one */
684 if ((pmb
= lpfc_mbox_get(phba
))) {
685 spin_unlock_irq(phba
->host
->host_lock
);
686 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
687 if (rc
== MBX_NOT_FINISHED
) {
688 pmb
->mb
.mbxStatus
= MBX_NOT_FINISHED
;
689 pmb
->mbox_cmpl(phba
,pmb
);
691 continue; /* loop back */
694 spin_unlock_irq(phba
->host
->host_lock
);
695 /* Turn on IOCB processing */
696 for (i
= 0; i
< phba
->sli
.num_rings
; i
++) {
697 lpfc_sli_turn_on_ring(phba
, i
);
700 /* Free any lpfc_dmabuf's waiting for mbox cmd cmpls */
701 while (!list_empty(&phba
->freebufList
)) {
702 struct lpfc_dmabuf
*mp
;
705 list_remove_head((&phba
->freebufList
),
710 lpfc_mbuf_free(phba
, mp
->virt
,
717 } while (process_next
);
722 lpfc_sli_process_unsol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
723 struct lpfc_iocbq
*saveq
)
731 irsp
= &(saveq
->iocb
);
732 if ((irsp
->ulpCommand
== CMD_RCV_ELS_REQ64_CX
)
733 || (irsp
->ulpCommand
== CMD_RCV_ELS_REQ_CX
)) {
738 (WORD5
*) & (saveq
->iocb
.un
.
740 Rctl
= w5p
->hcsw
.Rctl
;
741 Type
= w5p
->hcsw
.Type
;
743 /* Firmware Workaround */
744 if ((Rctl
== 0) && (pring
->ringno
== LPFC_ELS_RING
) &&
745 (irsp
->ulpCommand
== CMD_RCV_SEQUENCE64_CX
)) {
748 w5p
->hcsw
.Rctl
= Rctl
;
749 w5p
->hcsw
.Type
= Type
;
752 /* unSolicited Responses */
753 if (pring
->prt
[0].profile
) {
754 if (pring
->prt
[0].lpfc_sli_rcv_unsol_event
)
755 (pring
->prt
[0].lpfc_sli_rcv_unsol_event
) (phba
, pring
,
759 /* We must search, based on rctl / type
760 for the right routine */
761 for (i
= 0; i
< pring
->num_mask
;
763 if ((pring
->prt
[i
].rctl
==
767 if (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
768 (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
769 (phba
, pring
, saveq
);
776 /* Unexpected Rctl / Type received */
777 /* Ring <ringno> handler: unexpected
778 Rctl <Rctl> Type <Type> received */
779 lpfc_printf_log(phba
,
782 "%d:0313 Ring %d handler: unexpected Rctl x%x "
783 "Type x%x received \n",
792 static struct lpfc_iocbq
*
793 lpfc_sli_iocbq_lookup(struct lpfc_hba
* phba
,
794 struct lpfc_sli_ring
* pring
,
795 struct lpfc_iocbq
* prspiocb
)
797 struct lpfc_iocbq
*cmd_iocb
= NULL
;
800 iotag
= prspiocb
->iocb
.ulpIoTag
;
802 if (iotag
!= 0 && iotag
<= phba
->sli
.last_iotag
) {
803 cmd_iocb
= phba
->sli
.iocbq_lookup
[iotag
];
804 list_del(&cmd_iocb
->list
);
805 pring
->txcmplq_cnt
--;
809 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
810 "%d:0317 iotag x%x is out off "
811 "range: max iotag x%x wd0 x%x\n",
813 phba
->sli
.last_iotag
,
814 *(((uint32_t *) &prspiocb
->iocb
) + 7));
819 lpfc_sli_process_sol_iocb(struct lpfc_hba
* phba
, struct lpfc_sli_ring
* pring
,
820 struct lpfc_iocbq
*saveq
)
822 struct lpfc_iocbq
* cmdiocbp
;
826 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
827 spin_lock_irqsave(phba
->host
->host_lock
, iflag
);
828 cmdiocbp
= lpfc_sli_iocbq_lookup(phba
, pring
, saveq
);
830 if (cmdiocbp
->iocb_cmpl
) {
832 * Post all ELS completions to the worker thread.
833 * All other are passed to the completion callback.
835 if (pring
->ringno
== LPFC_ELS_RING
) {
836 spin_unlock_irqrestore(phba
->host
->host_lock
,
838 (cmdiocbp
->iocb_cmpl
) (phba
, cmdiocbp
, saveq
);
839 spin_lock_irqsave(phba
->host
->host_lock
, iflag
);
842 spin_unlock_irqrestore(phba
->host
->host_lock
,
844 (cmdiocbp
->iocb_cmpl
) (phba
, cmdiocbp
, saveq
);
845 spin_lock_irqsave(phba
->host
->host_lock
, iflag
);
848 lpfc_sli_release_iocbq(phba
, cmdiocbp
);
851 * Unknown initiating command based on the response iotag.
852 * This could be the case on the ELS ring because of
855 if (pring
->ringno
!= LPFC_ELS_RING
) {
857 * Ring <ringno> handler: unexpected completion IoTag
860 lpfc_printf_log(phba
,
863 "%d:0322 Ring %d handler: unexpected "
864 "completion IoTag x%x Data: x%x x%x x%x x%x\n",
867 saveq
->iocb
.ulpIoTag
,
868 saveq
->iocb
.ulpStatus
,
869 saveq
->iocb
.un
.ulpWord
[4],
870 saveq
->iocb
.ulpCommand
,
871 saveq
->iocb
.ulpContext
);
875 spin_unlock_irqrestore(phba
->host
->host_lock
, iflag
);
879 static void lpfc_sli_rsp_pointers_error(struct lpfc_hba
* phba
,
880 struct lpfc_sli_ring
* pring
)
882 struct lpfc_pgp
*pgp
= &phba
->slim2p
->mbx
.us
.s2
.port
[pring
->ringno
];
884 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
885 * rsp ring <portRspMax>
887 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
888 "%d:0312 Ring %d handler: portRspPut %d "
889 "is bigger then rsp ring %d\n",
890 phba
->brd_no
, pring
->ringno
,
891 le32_to_cpu(pgp
->rspPutInx
),
894 phba
->hba_state
= LPFC_HBA_ERROR
;
897 * All error attention handlers are posted to
900 phba
->work_ha
|= HA_ERATT
;
901 phba
->work_hs
= HS_FFER3
;
903 wake_up(phba
->work_wait
);
908 void lpfc_sli_poll_fcp_ring(struct lpfc_hba
* phba
)
910 struct lpfc_sli
* psli
= &phba
->sli
;
911 struct lpfc_sli_ring
* pring
= &psli
->ring
[LPFC_FCP_RING
];
913 IOCB_t
*entry
= NULL
;
914 struct lpfc_iocbq
*cmdiocbq
= NULL
;
915 struct lpfc_iocbq rspiocbq
;
916 struct lpfc_pgp
*pgp
;
918 uint32_t portRspPut
, portRspMax
;
920 uint32_t rsp_cmpl
= 0;
921 void __iomem
*to_slim
;
924 pring
->stats
.iocb_event
++;
926 /* The driver assumes SLI-2 mode */
927 pgp
= &phba
->slim2p
->mbx
.us
.s2
.port
[pring
->ringno
];
930 * The next available response entry should never exceed the maximum
931 * entries. If it does, treat it as an adapter hardware error.
933 portRspMax
= pring
->numRiocb
;
934 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
935 if (unlikely(portRspPut
>= portRspMax
)) {
936 lpfc_sli_rsp_pointers_error(phba
, pring
);
941 while (pring
->rspidx
!= portRspPut
) {
943 entry
= IOCB_ENTRY(pring
->rspringaddr
, pring
->rspidx
);
945 if (++pring
->rspidx
>= portRspMax
)
948 lpfc_sli_pcimem_bcopy((uint32_t *) entry
,
949 (uint32_t *) &rspiocbq
.iocb
,
951 irsp
= &rspiocbq
.iocb
;
952 type
= lpfc_sli_iocb_cmd_type(irsp
->ulpCommand
& CMD_IOCB_MASK
);
953 pring
->stats
.iocb_rsp
++;
956 if (unlikely(irsp
->ulpStatus
)) {
957 /* Rsp ring <ringno> error: IOCB */
958 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
959 "%d:0326 Rsp Ring %d error: IOCB Data: "
960 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
961 phba
->brd_no
, pring
->ringno
,
968 *(((uint32_t *) irsp
) + 6),
969 *(((uint32_t *) irsp
) + 7));
973 case LPFC_ABORT_IOCB
:
976 * Idle exchange closed via ABTS from port. No iocb
977 * resources need to be recovered.
979 if (unlikely(irsp
->ulpCommand
== CMD_XRI_ABORTED_CX
)) {
980 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
981 "%d:0314 IOCB cmd 0x%x"
982 " processed. Skipping"
983 " completion", phba
->brd_no
,
988 cmdiocbq
= lpfc_sli_iocbq_lookup(phba
, pring
,
990 if ((cmdiocbq
) && (cmdiocbq
->iocb_cmpl
)) {
991 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
,
996 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
997 char adaptermsg
[LPFC_MAX_ADPTMSG
];
998 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
999 memcpy(&adaptermsg
[0], (uint8_t *) irsp
,
1001 dev_warn(&((phba
->pcidev
)->dev
), "lpfc%d: %s",
1002 phba
->brd_no
, adaptermsg
);
1004 /* Unknown IOCB command */
1005 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
1006 "%d:0321 Unknown IOCB command "
1007 "Data: x%x, x%x x%x x%x x%x\n",
1018 * The response IOCB has been processed. Update the ring
1019 * pointer in SLIM. If the port response put pointer has not
1020 * been updated, sync the pgp->rspPutInx and fetch the new port
1021 * response put pointer.
1023 to_slim
= phba
->MBslimaddr
+
1024 (SLIMOFF
+ (pring
->ringno
* 2) + 1) * 4;
1025 writeb(pring
->rspidx
, to_slim
);
1027 if (pring
->rspidx
== portRspPut
)
1028 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
1031 ha_copy
= readl(phba
->HAregaddr
);
1032 ha_copy
>>= (LPFC_FCP_RING
* 4);
1034 if ((rsp_cmpl
> 0) && (ha_copy
& HA_R0RE_REQ
)) {
1035 pring
->stats
.iocb_rsp_full
++;
1036 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (LPFC_FCP_RING
* 4));
1037 writel(status
, phba
->CAregaddr
);
1038 readl(phba
->CAregaddr
);
1040 if ((ha_copy
& HA_R0CE_RSP
) &&
1041 (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
1042 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
1043 pring
->stats
.iocb_cmd_empty
++;
1045 /* Force update of the local copy of cmdGetInx */
1046 pring
->local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
1047 lpfc_sli_resume_iocb(phba
, pring
);
1049 if ((pring
->lpfc_sli_cmd_available
))
1050 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
1058 * This routine presumes LPFC_FCP_RING handling and doesn't bother
1059 * to check it explicitly.
1062 lpfc_sli_handle_fast_ring_event(struct lpfc_hba
* phba
,
1063 struct lpfc_sli_ring
* pring
, uint32_t mask
)
1065 struct lpfc_pgp
*pgp
= &phba
->slim2p
->mbx
.us
.s2
.port
[pring
->ringno
];
1066 IOCB_t
*irsp
= NULL
;
1067 IOCB_t
*entry
= NULL
;
1068 struct lpfc_iocbq
*cmdiocbq
= NULL
;
1069 struct lpfc_iocbq rspiocbq
;
1071 uint32_t portRspPut
, portRspMax
;
1073 lpfc_iocb_type type
;
1074 unsigned long iflag
;
1075 uint32_t rsp_cmpl
= 0;
1076 void __iomem
*to_slim
;
1078 spin_lock_irqsave(phba
->host
->host_lock
, iflag
);
1079 pring
->stats
.iocb_event
++;
1082 * The next available response entry should never exceed the maximum
1083 * entries. If it does, treat it as an adapter hardware error.
1085 portRspMax
= pring
->numRiocb
;
1086 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
1087 if (unlikely(portRspPut
>= portRspMax
)) {
1088 lpfc_sli_rsp_pointers_error(phba
, pring
);
1089 spin_unlock_irqrestore(phba
->host
->host_lock
, iflag
);
1094 while (pring
->rspidx
!= portRspPut
) {
1096 * Fetch an entry off the ring and copy it into a local data
1097 * structure. The copy involves a byte-swap since the
1098 * network byte order and pci byte orders are different.
1100 entry
= IOCB_ENTRY(pring
->rspringaddr
, pring
->rspidx
);
1102 if (++pring
->rspidx
>= portRspMax
)
1105 lpfc_sli_pcimem_bcopy((uint32_t *) entry
,
1106 (uint32_t *) &rspiocbq
.iocb
,
1108 INIT_LIST_HEAD(&(rspiocbq
.list
));
1109 irsp
= &rspiocbq
.iocb
;
1111 type
= lpfc_sli_iocb_cmd_type(irsp
->ulpCommand
& CMD_IOCB_MASK
);
1112 pring
->stats
.iocb_rsp
++;
1115 if (unlikely(irsp
->ulpStatus
)) {
1116 /* Rsp ring <ringno> error: IOCB */
1117 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
1118 "%d:0336 Rsp Ring %d error: IOCB Data: "
1119 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
1120 phba
->brd_no
, pring
->ringno
,
1121 irsp
->un
.ulpWord
[0], irsp
->un
.ulpWord
[1],
1122 irsp
->un
.ulpWord
[2], irsp
->un
.ulpWord
[3],
1123 irsp
->un
.ulpWord
[4], irsp
->un
.ulpWord
[5],
1124 *(((uint32_t *) irsp
) + 6),
1125 *(((uint32_t *) irsp
) + 7));
1129 case LPFC_ABORT_IOCB
:
1132 * Idle exchange closed via ABTS from port. No iocb
1133 * resources need to be recovered.
1135 if (unlikely(irsp
->ulpCommand
== CMD_XRI_ABORTED_CX
)) {
1136 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
1137 "%d:0333 IOCB cmd 0x%x"
1138 " processed. Skipping"
1139 " completion\n", phba
->brd_no
,
1144 cmdiocbq
= lpfc_sli_iocbq_lookup(phba
, pring
,
1146 if ((cmdiocbq
) && (cmdiocbq
->iocb_cmpl
)) {
1147 if (phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) {
1148 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
,
1151 spin_unlock_irqrestore(
1152 phba
->host
->host_lock
, iflag
);
1153 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
,
1155 spin_lock_irqsave(phba
->host
->host_lock
,
1160 case LPFC_UNSOL_IOCB
:
1161 spin_unlock_irqrestore(phba
->host
->host_lock
, iflag
);
1162 lpfc_sli_process_unsol_iocb(phba
, pring
, &rspiocbq
);
1163 spin_lock_irqsave(phba
->host
->host_lock
, iflag
);
1166 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
1167 char adaptermsg
[LPFC_MAX_ADPTMSG
];
1168 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
1169 memcpy(&adaptermsg
[0], (uint8_t *) irsp
,
1171 dev_warn(&((phba
->pcidev
)->dev
), "lpfc%d: %s",
1172 phba
->brd_no
, adaptermsg
);
1174 /* Unknown IOCB command */
1175 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
1176 "%d:0334 Unknown IOCB command "
1177 "Data: x%x, x%x x%x x%x x%x\n",
1178 phba
->brd_no
, type
, irsp
->ulpCommand
,
1179 irsp
->ulpStatus
, irsp
->ulpIoTag
,
1186 * The response IOCB has been processed. Update the ring
1187 * pointer in SLIM. If the port response put pointer has not
1188 * been updated, sync the pgp->rspPutInx and fetch the new port
1189 * response put pointer.
1191 to_slim
= phba
->MBslimaddr
+
1192 (SLIMOFF
+ (pring
->ringno
* 2) + 1) * 4;
1193 writel(pring
->rspidx
, to_slim
);
1195 if (pring
->rspidx
== portRspPut
)
1196 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
1199 if ((rsp_cmpl
> 0) && (mask
& HA_R0RE_REQ
)) {
1200 pring
->stats
.iocb_rsp_full
++;
1201 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
1202 writel(status
, phba
->CAregaddr
);
1203 readl(phba
->CAregaddr
);
1205 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
1206 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
1207 pring
->stats
.iocb_cmd_empty
++;
1209 /* Force update of the local copy of cmdGetInx */
1210 pring
->local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
1211 lpfc_sli_resume_iocb(phba
, pring
);
1213 if ((pring
->lpfc_sli_cmd_available
))
1214 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
1218 spin_unlock_irqrestore(phba
->host
->host_lock
, iflag
);
1224 lpfc_sli_handle_slow_ring_event(struct lpfc_hba
* phba
,
1225 struct lpfc_sli_ring
* pring
, uint32_t mask
)
1228 IOCB_t
*irsp
= NULL
;
1229 struct lpfc_iocbq
*rspiocbp
= NULL
;
1230 struct lpfc_iocbq
*next_iocb
;
1231 struct lpfc_iocbq
*cmdiocbp
;
1232 struct lpfc_iocbq
*saveq
;
1233 struct lpfc_pgp
*pgp
= &phba
->slim2p
->mbx
.us
.s2
.port
[pring
->ringno
];
1234 uint8_t iocb_cmd_type
;
1235 lpfc_iocb_type type
;
1236 uint32_t status
, free_saveq
;
1237 uint32_t portRspPut
, portRspMax
;
1239 unsigned long iflag
;
1240 void __iomem
*to_slim
;
1242 spin_lock_irqsave(phba
->host
->host_lock
, iflag
);
1243 pring
->stats
.iocb_event
++;
1246 * The next available response entry should never exceed the maximum
1247 * entries. If it does, treat it as an adapter hardware error.
1249 portRspMax
= pring
->numRiocb
;
1250 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
1251 if (portRspPut
>= portRspMax
) {
1253 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
1254 * rsp ring <portRspMax>
1256 lpfc_printf_log(phba
,
1259 "%d:0303 Ring %d handler: portRspPut %d "
1260 "is bigger then rsp ring %d\n",
1262 pring
->ringno
, portRspPut
, portRspMax
);
1264 phba
->hba_state
= LPFC_HBA_ERROR
;
1265 spin_unlock_irqrestore(phba
->host
->host_lock
, iflag
);
1267 phba
->work_hs
= HS_FFER3
;
1268 lpfc_handle_eratt(phba
);
1274 while (pring
->rspidx
!= portRspPut
) {
1276 * Build a completion list and call the appropriate handler.
1277 * The process is to get the next available response iocb, get
1278 * a free iocb from the list, copy the response data into the
1279 * free iocb, insert to the continuation list, and update the
1280 * next response index to slim. This process makes response
1281 * iocb's in the ring available to DMA as fast as possible but
1282 * pays a penalty for a copy operation. Since the iocb is
1283 * only 32 bytes, this penalty is considered small relative to
1284 * the PCI reads for register values and a slim write. When
1285 * the ulpLe field is set, the entire Command has been
1288 entry
= IOCB_ENTRY(pring
->rspringaddr
, pring
->rspidx
);
1289 rspiocbp
= lpfc_sli_get_iocbq(phba
);
1290 if (rspiocbp
== NULL
) {
1291 printk(KERN_ERR
"%s: out of buffers! Failing "
1292 "completion.\n", __FUNCTION__
);
1296 lpfc_sli_pcimem_bcopy(entry
, &rspiocbp
->iocb
, sizeof (IOCB_t
));
1297 irsp
= &rspiocbp
->iocb
;
1299 if (++pring
->rspidx
>= portRspMax
)
1302 to_slim
= phba
->MBslimaddr
+ (SLIMOFF
+ (pring
->ringno
* 2)
1304 writel(pring
->rspidx
, to_slim
);
1306 if (list_empty(&(pring
->iocb_continueq
))) {
1307 list_add(&rspiocbp
->list
, &(pring
->iocb_continueq
));
1309 list_add_tail(&rspiocbp
->list
,
1310 &(pring
->iocb_continueq
));
1313 pring
->iocb_continueq_cnt
++;
1316 * By default, the driver expects to free all resources
1317 * associated with this iocb completion.
1320 saveq
= list_get_first(&pring
->iocb_continueq
,
1321 struct lpfc_iocbq
, list
);
1322 irsp
= &(saveq
->iocb
);
1323 list_del_init(&pring
->iocb_continueq
);
1324 pring
->iocb_continueq_cnt
= 0;
1326 pring
->stats
.iocb_rsp
++;
1328 if (irsp
->ulpStatus
) {
1329 /* Rsp ring <ringno> error: IOCB */
1330 lpfc_printf_log(phba
,
1333 "%d:0328 Rsp Ring %d error: IOCB Data: "
1334 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
1337 irsp
->un
.ulpWord
[0],
1338 irsp
->un
.ulpWord
[1],
1339 irsp
->un
.ulpWord
[2],
1340 irsp
->un
.ulpWord
[3],
1341 irsp
->un
.ulpWord
[4],
1342 irsp
->un
.ulpWord
[5],
1343 *(((uint32_t *) irsp
) + 6),
1344 *(((uint32_t *) irsp
) + 7));
1348 * Fetch the IOCB command type and call the correct
1349 * completion routine. Solicited and Unsolicited
1350 * IOCBs on the ELS ring get freed back to the
1351 * lpfc_iocb_list by the discovery kernel thread.
1353 iocb_cmd_type
= irsp
->ulpCommand
& CMD_IOCB_MASK
;
1354 type
= lpfc_sli_iocb_cmd_type(iocb_cmd_type
);
1355 if (type
== LPFC_SOL_IOCB
) {
1356 spin_unlock_irqrestore(phba
->host
->host_lock
,
1358 rc
= lpfc_sli_process_sol_iocb(phba
, pring
,
1360 spin_lock_irqsave(phba
->host
->host_lock
, iflag
);
1361 } else if (type
== LPFC_UNSOL_IOCB
) {
1362 spin_unlock_irqrestore(phba
->host
->host_lock
,
1364 rc
= lpfc_sli_process_unsol_iocb(phba
, pring
,
1366 spin_lock_irqsave(phba
->host
->host_lock
, iflag
);
1367 } else if (type
== LPFC_ABORT_IOCB
) {
1368 if ((irsp
->ulpCommand
!= CMD_XRI_ABORTED_CX
) &&
1370 lpfc_sli_iocbq_lookup(phba
, pring
,
1372 /* Call the specified completion
1374 if (cmdiocbp
->iocb_cmpl
) {
1375 spin_unlock_irqrestore(
1376 phba
->host
->host_lock
,
1378 (cmdiocbp
->iocb_cmpl
) (phba
,
1381 phba
->host
->host_lock
,
1384 lpfc_sli_release_iocbq(phba
,
1387 } else if (type
== LPFC_UNKNOWN_IOCB
) {
1388 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
1390 char adaptermsg
[LPFC_MAX_ADPTMSG
];
1392 memset(adaptermsg
, 0,
1394 memcpy(&adaptermsg
[0], (uint8_t *) irsp
,
1396 dev_warn(&((phba
->pcidev
)->dev
),
1398 phba
->brd_no
, adaptermsg
);
1400 /* Unknown IOCB command */
1401 lpfc_printf_log(phba
,
1404 "%d:0335 Unknown IOCB command "
1405 "Data: x%x x%x x%x x%x\n",
1415 if (!list_empty(&saveq
->list
)) {
1416 list_for_each_entry_safe(rspiocbp
,
1420 list_del(&rspiocbp
->list
);
1421 lpfc_sli_release_iocbq(phba
,
1425 lpfc_sli_release_iocbq(phba
, saveq
);
1430 * If the port response put pointer has not been updated, sync
1431 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
1432 * response put pointer.
1434 if (pring
->rspidx
== portRspPut
) {
1435 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
1437 } /* while (pring->rspidx != portRspPut) */
1439 if ((rspiocbp
!= 0) && (mask
& HA_R0RE_REQ
)) {
1440 /* At least one response entry has been freed */
1441 pring
->stats
.iocb_rsp_full
++;
1442 /* SET RxRE_RSP in Chip Att register */
1443 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
1444 writel(status
, phba
->CAregaddr
);
1445 readl(phba
->CAregaddr
); /* flush */
1447 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
1448 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
1449 pring
->stats
.iocb_cmd_empty
++;
1451 /* Force update of the local copy of cmdGetInx */
1452 pring
->local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
1453 lpfc_sli_resume_iocb(phba
, pring
);
1455 if ((pring
->lpfc_sli_cmd_available
))
1456 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
1460 spin_unlock_irqrestore(phba
->host
->host_lock
, iflag
);
1465 lpfc_sli_abort_iocb_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1467 struct lpfc_iocbq
*iocb
, *next_iocb
;
1468 IOCB_t
*icmd
= NULL
, *cmd
= NULL
;
1473 /* Error everything on txq and txcmplq
1476 spin_lock_irq(phba
->host
->host_lock
);
1477 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
1478 list_del_init(&iocb
->list
);
1479 if (iocb
->iocb_cmpl
) {
1481 icmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
1482 icmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
1483 spin_unlock_irq(phba
->host
->host_lock
);
1484 (iocb
->iocb_cmpl
) (phba
, iocb
, iocb
);
1485 spin_lock_irq(phba
->host
->host_lock
);
1487 lpfc_sli_release_iocbq(phba
, iocb
);
1490 INIT_LIST_HEAD(&(pring
->txq
));
1492 /* Next issue ABTS for everything on the txcmplq */
1493 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
) {
1497 * Imediate abort of IOCB, deque and call compl
1500 list_del_init(&iocb
->list
);
1501 pring
->txcmplq_cnt
--;
1503 if (iocb
->iocb_cmpl
) {
1504 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
1505 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
1506 spin_unlock_irq(phba
->host
->host_lock
);
1507 (iocb
->iocb_cmpl
) (phba
, iocb
, iocb
);
1508 spin_lock_irq(phba
->host
->host_lock
);
1510 lpfc_sli_release_iocbq(phba
, iocb
);
1513 INIT_LIST_HEAD(&pring
->txcmplq
);
1514 pring
->txcmplq_cnt
= 0;
1515 spin_unlock_irq(phba
->host
->host_lock
);
1521 lpfc_sli_brdready(struct lpfc_hba
* phba
, uint32_t mask
)
1527 /* Read the HBA Host Status Register */
1528 status
= readl(phba
->HSregaddr
);
1531 * Check status register every 100ms for 5 retries, then every
1532 * 500ms for 5, then every 2.5 sec for 5, then reset board and
1533 * every 2.5 sec for 4.
1534 * Break our of the loop if errors occurred during init.
1536 while (((status
& mask
) != mask
) &&
1537 !(status
& HS_FFERM
) &&
1548 phba
->hba_state
= LPFC_STATE_UNKNOWN
; /* Do post */
1549 lpfc_sli_brdrestart(phba
);
1551 /* Read the HBA Host Status Register */
1552 status
= readl(phba
->HSregaddr
);
1555 /* Check to see if any errors occurred during init */
1556 if ((status
& HS_FFERM
) || (i
>= 20)) {
1557 phba
->hba_state
= LPFC_HBA_ERROR
;
1564 #define BARRIER_TEST_PATTERN (0xdeadbeef)
1566 void lpfc_reset_barrier(struct lpfc_hba
* phba
)
1568 uint32_t __iomem
*resp_buf
;
1569 uint32_t __iomem
*mbox_buf
;
1570 volatile uint32_t mbox
;
1575 pci_read_config_byte(phba
->pcidev
, PCI_HEADER_TYPE
, &hdrtype
);
1576 if (hdrtype
!= 0x80 ||
1577 (FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != HELIOS_JEDEC_ID
&&
1578 FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != THOR_JEDEC_ID
))
1582 * Tell the other part of the chip to suspend temporarily all
1585 resp_buf
= phba
->MBslimaddr
;
1587 /* Disable the error attention */
1588 hc_copy
= readl(phba
->HCregaddr
);
1589 writel((hc_copy
& ~HC_ERINT_ENA
), phba
->HCregaddr
);
1590 readl(phba
->HCregaddr
); /* flush */
1592 if (readl(phba
->HAregaddr
) & HA_ERATT
) {
1593 /* Clear Chip error bit */
1594 writel(HA_ERATT
, phba
->HAregaddr
);
1599 ((MAILBOX_t
*)&mbox
)->mbxCommand
= MBX_KILL_BOARD
;
1600 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_CHIP
;
1602 writel(BARRIER_TEST_PATTERN
, (resp_buf
+ 1));
1603 mbox_buf
= phba
->MBslimaddr
;
1604 writel(mbox
, mbox_buf
);
1607 readl(resp_buf
+ 1) != ~(BARRIER_TEST_PATTERN
) && i
< 50; i
++)
1610 if (readl(resp_buf
+ 1) != ~(BARRIER_TEST_PATTERN
)) {
1611 if (phba
->sli
.sli_flag
& LPFC_SLI2_ACTIVE
||
1618 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_HOST
;
1619 for (i
= 0; readl(resp_buf
) != mbox
&& i
< 500; i
++)
1624 while (!(readl(phba
->HAregaddr
) & HA_ERATT
) && ++i
< 500)
1627 if (readl(phba
->HAregaddr
) & HA_ERATT
) {
1628 writel(HA_ERATT
, phba
->HAregaddr
);
1633 writel(hc_copy
, phba
->HCregaddr
);
1634 readl(phba
->HCregaddr
); /* flush */
1638 lpfc_sli_brdkill(struct lpfc_hba
* phba
)
1640 struct lpfc_sli
*psli
;
1650 lpfc_printf_log(phba
,
1653 "%d:0329 Kill HBA Data: x%x x%x\n",
1658 if ((pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
,
1662 /* Disable the error attention */
1663 spin_lock_irq(phba
->host
->host_lock
);
1664 status
= readl(phba
->HCregaddr
);
1665 status
&= ~HC_ERINT_ENA
;
1666 writel(status
, phba
->HCregaddr
);
1667 readl(phba
->HCregaddr
); /* flush */
1668 spin_unlock_irq(phba
->host
->host_lock
);
1670 lpfc_kill_board(phba
, pmb
);
1671 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
1672 retval
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
1674 if (retval
!= MBX_SUCCESS
) {
1675 if (retval
!= MBX_BUSY
)
1676 mempool_free(pmb
, phba
->mbox_mem_pool
);
1680 psli
->sli_flag
&= ~LPFC_SLI2_ACTIVE
;
1682 mempool_free(pmb
, phba
->mbox_mem_pool
);
1684 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
1685 * attention every 100ms for 3 seconds. If we don't get ERATT after
1686 * 3 seconds we still set HBA_ERROR state because the status of the
1687 * board is now undefined.
1689 ha_copy
= readl(phba
->HAregaddr
);
1691 while ((i
++ < 30) && !(ha_copy
& HA_ERATT
)) {
1693 ha_copy
= readl(phba
->HAregaddr
);
1696 del_timer_sync(&psli
->mbox_tmo
);
1697 if (ha_copy
& HA_ERATT
) {
1698 writel(HA_ERATT
, phba
->HAregaddr
);
1701 spin_lock_irq(phba
->host
->host_lock
);
1702 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
1703 spin_unlock_irq(phba
->host
->host_lock
);
1705 psli
->mbox_active
= NULL
;
1706 lpfc_hba_down_post(phba
);
1707 phba
->hba_state
= LPFC_HBA_ERROR
;
1709 return (ha_copy
& HA_ERATT
? 0 : 1);
1713 lpfc_sli_brdreset(struct lpfc_hba
* phba
)
1715 struct lpfc_sli
*psli
;
1716 struct lpfc_sli_ring
*pring
;
1723 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
1724 "%d:0325 Reset HBA Data: x%x x%x\n", phba
->brd_no
,
1725 phba
->hba_state
, psli
->sli_flag
);
1727 /* perform board reset */
1728 phba
->fc_eventTag
= 0;
1730 phba
->fc_prevDID
= 0;
1732 /* Turn off parity checking and serr during the physical reset */
1733 pci_read_config_word(phba
->pcidev
, PCI_COMMAND
, &cfg_value
);
1734 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
,
1736 ~(PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
)));
1738 psli
->sli_flag
&= ~(LPFC_SLI2_ACTIVE
| LPFC_PROCESS_LA
);
1739 /* Now toggle INITFF bit in the Host Control Register */
1740 writel(HC_INITFF
, phba
->HCregaddr
);
1742 readl(phba
->HCregaddr
); /* flush */
1743 writel(0, phba
->HCregaddr
);
1744 readl(phba
->HCregaddr
); /* flush */
1746 /* Restore PCI cmd register */
1747 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, cfg_value
);
1749 /* Initialize relevant SLI info */
1750 for (i
= 0; i
< psli
->num_rings
; i
++) {
1751 pring
= &psli
->ring
[i
];
1754 pring
->next_cmdidx
= 0;
1755 pring
->local_getidx
= 0;
1757 pring
->missbufcnt
= 0;
1760 phba
->hba_state
= LPFC_WARM_START
;
1765 lpfc_sli_brdrestart(struct lpfc_hba
* phba
)
1768 struct lpfc_sli
*psli
;
1770 volatile uint32_t word0
;
1771 void __iomem
*to_slim
;
1773 spin_lock_irq(phba
->host
->host_lock
);
1778 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
1779 "%d:0337 Restart HBA Data: x%x x%x\n", phba
->brd_no
,
1780 phba
->hba_state
, psli
->sli_flag
);
1783 mb
= (MAILBOX_t
*) &word0
;
1784 mb
->mbxCommand
= MBX_RESTART
;
1787 lpfc_reset_barrier(phba
);
1789 to_slim
= phba
->MBslimaddr
;
1790 writel(*(uint32_t *) mb
, to_slim
);
1791 readl(to_slim
); /* flush */
1793 /* Only skip post after fc_ffinit is completed */
1794 if (phba
->hba_state
) {
1796 word0
= 1; /* This is really setting up word1 */
1799 word0
= 0; /* This is really setting up word1 */
1801 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
1802 writel(*(uint32_t *) mb
, to_slim
);
1803 readl(to_slim
); /* flush */
1805 lpfc_sli_brdreset(phba
);
1807 phba
->hba_state
= LPFC_INIT_START
;
1809 spin_unlock_irq(phba
->host
->host_lock
);
1811 memset(&psli
->lnk_stat_offsets
, 0, sizeof(psli
->lnk_stat_offsets
));
1812 psli
->stats_start
= get_seconds();
1819 lpfc_hba_down_post(phba
);
1825 lpfc_sli_chipset_init(struct lpfc_hba
*phba
)
1827 uint32_t status
, i
= 0;
1829 /* Read the HBA Host Status Register */
1830 status
= readl(phba
->HSregaddr
);
1832 /* Check status register to see what current state is */
1834 while ((status
& (HS_FFRDY
| HS_MBRDY
)) != (HS_FFRDY
| HS_MBRDY
)) {
1836 /* Check every 100ms for 5 retries, then every 500ms for 5, then
1837 * every 2.5 sec for 5, then reset board and every 2.5 sec for
1841 /* Adapter failed to init, timeout, status reg
1843 lpfc_printf_log(phba
,
1846 "%d:0436 Adapter failed to init, "
1847 "timeout, status reg x%x\n",
1850 phba
->hba_state
= LPFC_HBA_ERROR
;
1854 /* Check to see if any errors occurred during init */
1855 if (status
& HS_FFERM
) {
1856 /* ERROR: During chipset initialization */
1857 /* Adapter failed to init, chipset, status reg
1859 lpfc_printf_log(phba
,
1862 "%d:0437 Adapter failed to init, "
1863 "chipset, status reg x%x\n",
1866 phba
->hba_state
= LPFC_HBA_ERROR
;
1872 } else if (i
<= 10) {
1879 phba
->hba_state
= LPFC_STATE_UNKNOWN
; /* Do post */
1880 lpfc_sli_brdrestart(phba
);
1882 /* Read the HBA Host Status Register */
1883 status
= readl(phba
->HSregaddr
);
1886 /* Check to see if any errors occurred during init */
1887 if (status
& HS_FFERM
) {
1888 /* ERROR: During chipset initialization */
1889 /* Adapter failed to init, chipset, status reg <status> */
1890 lpfc_printf_log(phba
,
1893 "%d:0438 Adapter failed to init, chipset, "
1897 phba
->hba_state
= LPFC_HBA_ERROR
;
1901 /* Clear all interrupt enable conditions */
1902 writel(0, phba
->HCregaddr
);
1903 readl(phba
->HCregaddr
); /* flush */
1905 /* setup host attn register */
1906 writel(0xffffffff, phba
->HAregaddr
);
1907 readl(phba
->HAregaddr
); /* flush */
1912 lpfc_sli_hba_setup(struct lpfc_hba
* phba
)
1915 uint32_t resetcount
= 0, rc
= 0, done
= 0;
1917 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1919 phba
->hba_state
= LPFC_HBA_ERROR
;
1923 while (resetcount
< 2 && !done
) {
1924 spin_lock_irq(phba
->host
->host_lock
);
1925 phba
->sli
.sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
1926 spin_unlock_irq(phba
->host
->host_lock
);
1927 phba
->hba_state
= LPFC_STATE_UNKNOWN
;
1928 lpfc_sli_brdrestart(phba
);
1930 rc
= lpfc_sli_chipset_init(phba
);
1934 spin_lock_irq(phba
->host
->host_lock
);
1935 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
1936 spin_unlock_irq(phba
->host
->host_lock
);
1939 /* Call pre CONFIG_PORT mailbox command initialization. A value of 0
1940 * means the call was successful. Any other nonzero value is a failure,
1941 * but if ERESTART is returned, the driver may reset the HBA and try
1944 rc
= lpfc_config_port_prep(phba
);
1945 if (rc
== -ERESTART
) {
1946 phba
->hba_state
= 0;
1952 phba
->hba_state
= LPFC_INIT_MBX_CMDS
;
1953 lpfc_config_port(phba
, pmb
);
1954 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
1955 if (rc
== MBX_SUCCESS
)
1958 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1959 "%d:0442 Adapter failed to init, mbxCmd x%x "
1960 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
1961 phba
->brd_no
, pmb
->mb
.mbxCommand
,
1962 pmb
->mb
.mbxStatus
, 0);
1963 phba
->sli
.sli_flag
&= ~LPFC_SLI2_ACTIVE
;
1967 goto lpfc_sli_hba_setup_error
;
1969 rc
= lpfc_sli_ring_map(phba
, pmb
);
1972 goto lpfc_sli_hba_setup_error
;
1974 phba
->sli
.sli_flag
|= LPFC_PROCESS_LA
;
1976 rc
= lpfc_config_port_post(phba
);
1978 goto lpfc_sli_hba_setup_error
;
1980 goto lpfc_sli_hba_setup_exit
;
1981 lpfc_sli_hba_setup_error
:
1982 phba
->hba_state
= LPFC_HBA_ERROR
;
1983 lpfc_sli_hba_setup_exit
:
1984 mempool_free(pmb
, phba
->mbox_mem_pool
);
1989 lpfc_mbox_abort(struct lpfc_hba
* phba
)
1991 LPFC_MBOXQ_t
*pmbox
;
1994 if (phba
->sli
.mbox_active
) {
1995 del_timer_sync(&phba
->sli
.mbox_tmo
);
1996 phba
->work_hba_events
&= ~WORKER_MBOX_TMO
;
1997 pmbox
= phba
->sli
.mbox_active
;
1999 phba
->sli
.mbox_active
= NULL
;
2000 if (pmbox
->mbox_cmpl
) {
2001 mb
->mbxStatus
= MBX_NOT_FINISHED
;
2002 (pmbox
->mbox_cmpl
) (phba
, pmbox
);
2004 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
2007 /* Abort all the non active mailbox commands. */
2008 spin_lock_irq(phba
->host
->host_lock
);
2009 pmbox
= lpfc_mbox_get(phba
);
2012 if (pmbox
->mbox_cmpl
) {
2013 mb
->mbxStatus
= MBX_NOT_FINISHED
;
2014 spin_unlock_irq(phba
->host
->host_lock
);
2015 (pmbox
->mbox_cmpl
) (phba
, pmbox
);
2016 spin_lock_irq(phba
->host
->host_lock
);
2018 pmbox
= lpfc_mbox_get(phba
);
2020 spin_unlock_irq(phba
->host
->host_lock
);
2024 /*! lpfc_mbox_timeout
2028 * \param hba Pointer to per struct lpfc_hba structure
2029 * \param l1 Pointer to the driver's mailbox queue.
2035 * This routine handles mailbox timeout events at timer interrupt context.
2038 lpfc_mbox_timeout(unsigned long ptr
)
2040 struct lpfc_hba
*phba
;
2041 unsigned long iflag
;
2043 phba
= (struct lpfc_hba
*)ptr
;
2044 spin_lock_irqsave(phba
->host
->host_lock
, iflag
);
2045 if (!(phba
->work_hba_events
& WORKER_MBOX_TMO
)) {
2046 phba
->work_hba_events
|= WORKER_MBOX_TMO
;
2047 if (phba
->work_wait
)
2048 wake_up(phba
->work_wait
);
2050 spin_unlock_irqrestore(phba
->host
->host_lock
, iflag
);
2054 lpfc_mbox_timeout_handler(struct lpfc_hba
*phba
)
2056 LPFC_MBOXQ_t
*pmbox
;
2059 spin_lock_irq(phba
->host
->host_lock
);
2060 if (!(phba
->work_hba_events
& WORKER_MBOX_TMO
)) {
2061 spin_unlock_irq(phba
->host
->host_lock
);
2065 phba
->work_hba_events
&= ~WORKER_MBOX_TMO
;
2067 pmbox
= phba
->sli
.mbox_active
;
2070 /* Mbox cmd <mbxCommand> timeout */
2071 lpfc_printf_log(phba
,
2074 "%d:0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
2079 phba
->sli
.mbox_active
);
2081 phba
->sli
.mbox_active
= NULL
;
2082 if (pmbox
->mbox_cmpl
) {
2083 mb
->mbxStatus
= MBX_NOT_FINISHED
;
2084 spin_unlock_irq(phba
->host
->host_lock
);
2085 (pmbox
->mbox_cmpl
) (phba
, pmbox
);
2086 spin_lock_irq(phba
->host
->host_lock
);
2088 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
2090 spin_unlock_irq(phba
->host
->host_lock
);
2091 lpfc_mbox_abort(phba
);
2096 lpfc_sli_issue_mbox(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmbox
, uint32_t flag
)
2099 struct lpfc_sli
*psli
;
2100 uint32_t status
, evtctr
;
2103 unsigned long drvr_flag
= 0;
2104 volatile uint32_t word0
, ldata
;
2105 void __iomem
*to_slim
;
2109 spin_lock_irqsave(phba
->host
->host_lock
, drvr_flag
);
2113 status
= MBX_SUCCESS
;
2115 if (phba
->hba_state
== LPFC_HBA_ERROR
) {
2116 spin_unlock_irqrestore(phba
->host
->host_lock
, drvr_flag
);
2118 /* Mbox command <mbxCommand> cannot issue */
2119 LOG_MBOX_CANNOT_ISSUE_DATA( phba
, mb
, psli
, flag
)
2120 return (MBX_NOT_FINISHED
);
2123 if (mb
->mbxCommand
!= MBX_KILL_BOARD
&& flag
& MBX_NOWAIT
&&
2124 !(readl(phba
->HCregaddr
) & HC_MBINT_ENA
)) {
2125 spin_unlock_irqrestore(phba
->host
->host_lock
, drvr_flag
);
2126 LOG_MBOX_CANNOT_ISSUE_DATA( phba
, mb
, psli
, flag
)
2127 return (MBX_NOT_FINISHED
);
2130 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
2131 /* Polling for a mbox command when another one is already active
2132 * is not allowed in SLI. Also, the driver must have established
2133 * SLI2 mode to queue and process multiple mbox commands.
2136 if (flag
& MBX_POLL
) {
2137 spin_unlock_irqrestore(phba
->host
->host_lock
,
2140 /* Mbox command <mbxCommand> cannot issue */
2141 LOG_MBOX_CANNOT_ISSUE_DATA( phba
, mb
, psli
, flag
)
2142 return (MBX_NOT_FINISHED
);
2145 if (!(psli
->sli_flag
& LPFC_SLI2_ACTIVE
)) {
2146 spin_unlock_irqrestore(phba
->host
->host_lock
,
2148 /* Mbox command <mbxCommand> cannot issue */
2149 LOG_MBOX_CANNOT_ISSUE_DATA( phba
, mb
, psli
, flag
)
2150 return (MBX_NOT_FINISHED
);
2153 /* Handle STOP IOCB processing flag. This is only meaningful
2154 * if we are not polling for mbox completion.
2156 if (flag
& MBX_STOP_IOCB
) {
2157 flag
&= ~MBX_STOP_IOCB
;
2158 /* Now flag each ring */
2159 for (i
= 0; i
< psli
->num_rings
; i
++) {
2160 /* If the ring is active, flag it */
2161 if (psli
->ring
[i
].cmdringaddr
) {
2162 psli
->ring
[i
].flag
|=
2168 /* Another mailbox command is still being processed, queue this
2169 * command to be processed later.
2171 lpfc_mbox_put(phba
, pmbox
);
2173 /* Mbox cmd issue - BUSY */
2174 lpfc_printf_log(phba
,
2177 "%d:0308 Mbox cmd issue - BUSY Data: x%x x%x x%x x%x\n",
2184 psli
->slistat
.mbox_busy
++;
2185 spin_unlock_irqrestore(phba
->host
->host_lock
,
2191 /* Handle STOP IOCB processing flag. This is only meaningful
2192 * if we are not polling for mbox completion.
2194 if (flag
& MBX_STOP_IOCB
) {
2195 flag
&= ~MBX_STOP_IOCB
;
2196 if (flag
== MBX_NOWAIT
) {
2197 /* Now flag each ring */
2198 for (i
= 0; i
< psli
->num_rings
; i
++) {
2199 /* If the ring is active, flag it */
2200 if (psli
->ring
[i
].cmdringaddr
) {
2201 psli
->ring
[i
].flag
|=
2208 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
2210 /* If we are not polling, we MUST be in SLI2 mode */
2211 if (flag
!= MBX_POLL
) {
2212 if (!(psli
->sli_flag
& LPFC_SLI2_ACTIVE
) &&
2213 (mb
->mbxCommand
!= MBX_KILL_BOARD
)) {
2214 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
2215 spin_unlock_irqrestore(phba
->host
->host_lock
,
2217 /* Mbox command <mbxCommand> cannot issue */
2218 LOG_MBOX_CANNOT_ISSUE_DATA( phba
, mb
, psli
, flag
);
2219 return (MBX_NOT_FINISHED
);
2221 /* timeout active mbox command */
2222 mod_timer(&psli
->mbox_tmo
, (jiffies
+
2223 (HZ
* lpfc_mbox_tmo_val(phba
, mb
->mbxCommand
))));
2226 /* Mailbox cmd <cmd> issue */
2227 lpfc_printf_log(phba
,
2230 "%d:0309 Mailbox cmd x%x issue Data: x%x x%x x%x\n",
2237 psli
->slistat
.mbox_cmd
++;
2238 evtctr
= psli
->slistat
.mbox_event
;
2240 /* next set own bit for the adapter and copy over command word */
2241 mb
->mbxOwner
= OWN_CHIP
;
2243 if (psli
->sli_flag
& LPFC_SLI2_ACTIVE
) {
2244 /* First copy command data to host SLIM area */
2245 lpfc_sli_pcimem_bcopy(mb
, &phba
->slim2p
->mbx
, MAILBOX_CMD_SIZE
);
2247 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
2248 /* copy command data into host mbox for cmpl */
2249 lpfc_sli_pcimem_bcopy(mb
, &phba
->slim2p
->mbx
,
2253 /* First copy mbox command data to HBA SLIM, skip past first
2255 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
2256 lpfc_memcpy_to_slim(to_slim
, &mb
->un
.varWords
[0],
2257 MAILBOX_CMD_SIZE
- sizeof (uint32_t));
2259 /* Next copy over first word, with mbxOwner set */
2260 ldata
= *((volatile uint32_t *)mb
);
2261 to_slim
= phba
->MBslimaddr
;
2262 writel(ldata
, to_slim
);
2263 readl(to_slim
); /* flush */
2265 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
2266 /* switch over to host mailbox */
2267 psli
->sli_flag
|= LPFC_SLI2_ACTIVE
;
2272 /* interrupt board to doit right away */
2273 writel(CA_MBATT
, phba
->CAregaddr
);
2274 readl(phba
->CAregaddr
); /* flush */
2278 /* Don't wait for it to finish, just return */
2279 psli
->mbox_active
= pmbox
;
2283 psli
->mbox_active
= NULL
;
2284 if (psli
->sli_flag
& LPFC_SLI2_ACTIVE
) {
2285 /* First read mbox status word */
2286 word0
= *((volatile uint32_t *)&phba
->slim2p
->mbx
);
2287 word0
= le32_to_cpu(word0
);
2289 /* First read mbox status word */
2290 word0
= readl(phba
->MBslimaddr
);
2293 /* Read the HBA Host Attention Register */
2294 ha_copy
= readl(phba
->HAregaddr
);
2296 i
= lpfc_mbox_tmo_val(phba
, mb
->mbxCommand
);
2297 i
*= 1000; /* Convert to ms */
2299 /* Wait for command to complete */
2300 while (((word0
& OWN_CHIP
) == OWN_CHIP
) ||
2301 (!(ha_copy
& HA_MBATT
) &&
2302 (phba
->hba_state
> LPFC_WARM_START
))) {
2304 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
2305 spin_unlock_irqrestore(phba
->host
->host_lock
,
2307 return (MBX_NOT_FINISHED
);
2310 /* Check if we took a mbox interrupt while we were
2312 if (((word0
& OWN_CHIP
) != OWN_CHIP
)
2313 && (evtctr
!= psli
->slistat
.mbox_event
))
2316 spin_unlock_irqrestore(phba
->host
->host_lock
,
2319 /* Can be in interrupt context, do not sleep */
2320 /* (or might be called with interrupts disabled) */
2323 spin_lock_irqsave(phba
->host
->host_lock
, drvr_flag
);
2325 if (psli
->sli_flag
& LPFC_SLI2_ACTIVE
) {
2326 /* First copy command data */
2327 word0
= *((volatile uint32_t *)
2328 &phba
->slim2p
->mbx
);
2329 word0
= le32_to_cpu(word0
);
2330 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
2332 volatile uint32_t slimword0
;
2333 /* Check real SLIM for any errors */
2334 slimword0
= readl(phba
->MBslimaddr
);
2335 slimmb
= (MAILBOX_t
*) & slimword0
;
2336 if (((slimword0
& OWN_CHIP
) != OWN_CHIP
)
2337 && slimmb
->mbxStatus
) {
2344 /* First copy command data */
2345 word0
= readl(phba
->MBslimaddr
);
2347 /* Read the HBA Host Attention Register */
2348 ha_copy
= readl(phba
->HAregaddr
);
2351 if (psli
->sli_flag
& LPFC_SLI2_ACTIVE
) {
2352 /* copy results back to user */
2353 lpfc_sli_pcimem_bcopy(&phba
->slim2p
->mbx
, mb
,
2356 /* First copy command data */
2357 lpfc_memcpy_from_slim(mb
, phba
->MBslimaddr
,
2359 if ((mb
->mbxCommand
== MBX_DUMP_MEMORY
) &&
2361 lpfc_memcpy_from_slim((void *)pmbox
->context2
,
2362 phba
->MBslimaddr
+ DMP_RSP_OFFSET
,
2363 mb
->un
.varDmp
.word_cnt
);
2367 writel(HA_MBATT
, phba
->HAregaddr
);
2368 readl(phba
->HAregaddr
); /* flush */
2370 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
2371 status
= mb
->mbxStatus
;
2374 spin_unlock_irqrestore(phba
->host
->host_lock
, drvr_flag
);
2379 lpfc_sli_ringtx_put(struct lpfc_hba
* phba
, struct lpfc_sli_ring
* pring
,
2380 struct lpfc_iocbq
* piocb
)
2382 /* Insert the caller's iocb in the txq tail for later processing. */
2383 list_add_tail(&piocb
->list
, &pring
->txq
);
2388 static struct lpfc_iocbq
*
2389 lpfc_sli_next_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2390 struct lpfc_iocbq
** piocb
)
2392 struct lpfc_iocbq
* nextiocb
;
2394 nextiocb
= lpfc_sli_ringtx_get(phba
, pring
);
2404 lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2405 struct lpfc_iocbq
*piocb
, uint32_t flag
)
2407 struct lpfc_iocbq
*nextiocb
;
2411 * We should never get an IOCB if we are in a < LINK_DOWN state
2413 if (unlikely(phba
->hba_state
< LPFC_LINK_DOWN
))
2417 * Check to see if we are blocking IOCB processing because of a
2418 * outstanding mbox command.
2420 if (unlikely(pring
->flag
& LPFC_STOP_IOCB_MBX
))
2423 if (unlikely(phba
->hba_state
== LPFC_LINK_DOWN
)) {
2425 * Only CREATE_XRI, CLOSE_XRI, ABORT_XRI, and QUE_RING_BUF
2426 * can be issued if the link is not up.
2428 switch (piocb
->iocb
.ulpCommand
) {
2429 case CMD_QUE_RING_BUF_CN
:
2430 case CMD_QUE_RING_BUF64_CN
:
2432 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
2433 * completion, iocb_cmpl MUST be 0.
2435 if (piocb
->iocb_cmpl
)
2436 piocb
->iocb_cmpl
= NULL
;
2438 case CMD_CREATE_XRI_CR
:
2445 * For FCP commands, we must be in a state where we can process link
2448 } else if (unlikely(pring
->ringno
== phba
->sli
.fcp_ring
&&
2449 !(phba
->sli
.sli_flag
& LPFC_PROCESS_LA
)))
2452 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
2453 (nextiocb
= lpfc_sli_next_iocb(phba
, pring
, &piocb
)))
2454 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
2457 lpfc_sli_update_ring(phba
, pring
);
2459 lpfc_sli_update_full_ring(phba
, pring
);
2462 return IOCB_SUCCESS
;
2467 pring
->stats
.iocb_cmd_delay
++;
2471 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
2472 lpfc_sli_ringtx_put(phba
, pring
, piocb
);
2473 return IOCB_SUCCESS
;
2480 lpfc_extra_ring_setup( struct lpfc_hba
*phba
)
2482 struct lpfc_sli
*psli
;
2483 struct lpfc_sli_ring
*pring
;
2487 /* Adjust cmd/rsp ring iocb entries more evenly */
2489 /* Take some away from the FCP ring */
2490 pring
= &psli
->ring
[psli
->fcp_ring
];
2491 pring
->numCiocb
-= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
2492 pring
->numRiocb
-= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
2493 pring
->numCiocb
-= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
2494 pring
->numRiocb
-= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
2496 /* and give them to the extra ring */
2497 pring
= &psli
->ring
[psli
->extra_ring
];
2499 pring
->numCiocb
+= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
2500 pring
->numRiocb
+= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
2501 pring
->numCiocb
+= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
2502 pring
->numRiocb
+= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
2504 /* Setup default profile for this ring */
2505 pring
->iotag_max
= 4096;
2506 pring
->num_mask
= 1;
2507 pring
->prt
[0].profile
= 0; /* Mask 0 */
2508 pring
->prt
[0].rctl
= phba
->cfg_multi_ring_rctl
;
2509 pring
->prt
[0].type
= phba
->cfg_multi_ring_type
;
2510 pring
->prt
[0].lpfc_sli_rcv_unsol_event
= NULL
;
2515 lpfc_sli_setup(struct lpfc_hba
*phba
)
2518 struct lpfc_sli
*psli
= &phba
->sli
;
2519 struct lpfc_sli_ring
*pring
;
2521 psli
->num_rings
= MAX_CONFIGURED_RINGS
;
2523 psli
->fcp_ring
= LPFC_FCP_RING
;
2524 psli
->next_ring
= LPFC_FCP_NEXT_RING
;
2525 psli
->extra_ring
= LPFC_EXTRA_RING
;
2527 psli
->iocbq_lookup
= NULL
;
2528 psli
->iocbq_lookup_len
= 0;
2529 psli
->last_iotag
= 0;
2531 for (i
= 0; i
< psli
->num_rings
; i
++) {
2532 pring
= &psli
->ring
[i
];
2534 case LPFC_FCP_RING
: /* ring 0 - FCP */
2535 /* numCiocb and numRiocb are used in config_port */
2536 pring
->numCiocb
= SLI2_IOCB_CMD_R0_ENTRIES
;
2537 pring
->numRiocb
= SLI2_IOCB_RSP_R0_ENTRIES
;
2538 pring
->numCiocb
+= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
2539 pring
->numRiocb
+= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
2540 pring
->numCiocb
+= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
2541 pring
->numRiocb
+= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
2542 pring
->iotag_ctr
= 0;
2544 (phba
->cfg_hba_queue_depth
* 2);
2545 pring
->fast_iotag
= pring
->iotag_max
;
2546 pring
->num_mask
= 0;
2548 case LPFC_EXTRA_RING
: /* ring 1 - EXTRA */
2549 /* numCiocb and numRiocb are used in config_port */
2550 pring
->numCiocb
= SLI2_IOCB_CMD_R1_ENTRIES
;
2551 pring
->numRiocb
= SLI2_IOCB_RSP_R1_ENTRIES
;
2552 pring
->num_mask
= 0;
2554 case LPFC_ELS_RING
: /* ring 2 - ELS / CT */
2555 /* numCiocb and numRiocb are used in config_port */
2556 pring
->numCiocb
= SLI2_IOCB_CMD_R2_ENTRIES
;
2557 pring
->numRiocb
= SLI2_IOCB_RSP_R2_ENTRIES
;
2558 pring
->fast_iotag
= 0;
2559 pring
->iotag_ctr
= 0;
2560 pring
->iotag_max
= 4096;
2561 pring
->num_mask
= 4;
2562 pring
->prt
[0].profile
= 0; /* Mask 0 */
2563 pring
->prt
[0].rctl
= FC_ELS_REQ
;
2564 pring
->prt
[0].type
= FC_ELS_DATA
;
2565 pring
->prt
[0].lpfc_sli_rcv_unsol_event
=
2566 lpfc_els_unsol_event
;
2567 pring
->prt
[1].profile
= 0; /* Mask 1 */
2568 pring
->prt
[1].rctl
= FC_ELS_RSP
;
2569 pring
->prt
[1].type
= FC_ELS_DATA
;
2570 pring
->prt
[1].lpfc_sli_rcv_unsol_event
=
2571 lpfc_els_unsol_event
;
2572 pring
->prt
[2].profile
= 0; /* Mask 2 */
2573 /* NameServer Inquiry */
2574 pring
->prt
[2].rctl
= FC_UNSOL_CTL
;
2576 pring
->prt
[2].type
= FC_COMMON_TRANSPORT_ULP
;
2577 pring
->prt
[2].lpfc_sli_rcv_unsol_event
=
2578 lpfc_ct_unsol_event
;
2579 pring
->prt
[3].profile
= 0; /* Mask 3 */
2580 /* NameServer response */
2581 pring
->prt
[3].rctl
= FC_SOL_CTL
;
2583 pring
->prt
[3].type
= FC_COMMON_TRANSPORT_ULP
;
2584 pring
->prt
[3].lpfc_sli_rcv_unsol_event
=
2585 lpfc_ct_unsol_event
;
2588 totiocb
+= (pring
->numCiocb
+ pring
->numRiocb
);
2590 if (totiocb
> MAX_SLI2_IOCB
) {
2591 /* Too many cmd / rsp ring entries in SLI2 SLIM */
2592 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2593 "%d:0462 Too many cmd / rsp ring entries in "
2594 "SLI2 SLIM Data: x%x x%x\n",
2595 phba
->brd_no
, totiocb
, MAX_SLI2_IOCB
);
2597 if (phba
->cfg_multi_ring_support
== 2)
2598 lpfc_extra_ring_setup(phba
);
2604 lpfc_sli_queue_setup(struct lpfc_hba
* phba
)
2606 struct lpfc_sli
*psli
;
2607 struct lpfc_sli_ring
*pring
;
2611 spin_lock_irq(phba
->host
->host_lock
);
2612 INIT_LIST_HEAD(&psli
->mboxq
);
2613 /* Initialize list headers for txq and txcmplq as double linked lists */
2614 for (i
= 0; i
< psli
->num_rings
; i
++) {
2615 pring
= &psli
->ring
[i
];
2617 pring
->next_cmdidx
= 0;
2618 pring
->local_getidx
= 0;
2620 INIT_LIST_HEAD(&pring
->txq
);
2621 INIT_LIST_HEAD(&pring
->txcmplq
);
2622 INIT_LIST_HEAD(&pring
->iocb_continueq
);
2623 INIT_LIST_HEAD(&pring
->postbufq
);
2625 spin_unlock_irq(phba
->host
->host_lock
);
2630 lpfc_sli_hba_down(struct lpfc_hba
* phba
)
2632 struct lpfc_sli
*psli
;
2633 struct lpfc_sli_ring
*pring
;
2635 struct lpfc_iocbq
*iocb
, *next_iocb
;
2636 IOCB_t
*icmd
= NULL
;
2638 unsigned long flags
= 0;
2641 lpfc_hba_down_prep(phba
);
2643 spin_lock_irqsave(phba
->host
->host_lock
, flags
);
2645 for (i
= 0; i
< psli
->num_rings
; i
++) {
2646 pring
= &psli
->ring
[i
];
2647 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
2650 * Error everything on the txq since these iocbs have not been
2651 * given to the FW yet.
2655 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
2656 list_del_init(&iocb
->list
);
2657 if (iocb
->iocb_cmpl
) {
2659 icmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
2660 icmd
->un
.ulpWord
[4] = IOERR_SLI_DOWN
;
2661 spin_unlock_irqrestore(phba
->host
->host_lock
,
2663 (iocb
->iocb_cmpl
) (phba
, iocb
, iocb
);
2664 spin_lock_irqsave(phba
->host
->host_lock
, flags
);
2666 lpfc_sli_release_iocbq(phba
, iocb
);
2669 INIT_LIST_HEAD(&(pring
->txq
));
2673 spin_unlock_irqrestore(phba
->host
->host_lock
, flags
);
2675 /* Return any active mbox cmds */
2676 del_timer_sync(&psli
->mbox_tmo
);
2677 spin_lock_irqsave(phba
->host
->host_lock
, flags
);
2678 phba
->work_hba_events
&= ~WORKER_MBOX_TMO
;
2679 if (psli
->mbox_active
) {
2680 pmb
= psli
->mbox_active
;
2681 pmb
->mb
.mbxStatus
= MBX_NOT_FINISHED
;
2682 if (pmb
->mbox_cmpl
) {
2683 spin_unlock_irqrestore(phba
->host
->host_lock
, flags
);
2684 pmb
->mbox_cmpl(phba
,pmb
);
2685 spin_lock_irqsave(phba
->host
->host_lock
, flags
);
2688 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
2689 psli
->mbox_active
= NULL
;
2691 /* Return any pending mbox cmds */
2692 while ((pmb
= lpfc_mbox_get(phba
)) != NULL
) {
2693 pmb
->mb
.mbxStatus
= MBX_NOT_FINISHED
;
2694 if (pmb
->mbox_cmpl
) {
2695 spin_unlock_irqrestore(phba
->host
->host_lock
, flags
);
2696 pmb
->mbox_cmpl(phba
,pmb
);
2697 spin_lock_irqsave(phba
->host
->host_lock
, flags
);
2701 INIT_LIST_HEAD(&psli
->mboxq
);
2703 spin_unlock_irqrestore(phba
->host
->host_lock
, flags
);
2709 lpfc_sli_pcimem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
2711 uint32_t *src
= srcp
;
2712 uint32_t *dest
= destp
;
2716 for (i
= 0; i
< (int)cnt
; i
+= sizeof (uint32_t)) {
2718 ldata
= le32_to_cpu(ldata
);
2726 lpfc_sli_ringpostbuf_put(struct lpfc_hba
* phba
, struct lpfc_sli_ring
* pring
,
2727 struct lpfc_dmabuf
* mp
)
2729 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
2731 list_add_tail(&mp
->list
, &pring
->postbufq
);
2733 pring
->postbufq_cnt
++;
2738 struct lpfc_dmabuf
*
2739 lpfc_sli_ringpostbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2742 struct lpfc_dmabuf
*mp
, *next_mp
;
2743 struct list_head
*slp
= &pring
->postbufq
;
2745 /* Search postbufq, from the begining, looking for a match on phys */
2746 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
2747 if (mp
->phys
== phys
) {
2748 list_del_init(&mp
->list
);
2749 pring
->postbufq_cnt
--;
2754 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2755 "%d:0410 Cannot find virtual addr for mapped buf on "
2756 "ring %d Data x%llx x%p x%p x%x\n",
2757 phba
->brd_no
, pring
->ringno
, (unsigned long long)phys
,
2758 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
2763 lpfc_sli_abort_elsreq_cmpl(struct lpfc_hba
* phba
, struct lpfc_iocbq
* cmdiocb
,
2764 struct lpfc_iocbq
* rspiocb
)
2766 struct lpfc_dmabuf
*buf_ptr
, *buf_ptr1
;
2767 /* Free the resources associated with the ELS_REQUEST64 IOCB the driver
2769 * In this case, context2 = cmd, context2->next = rsp, context3 = bpl
2771 if (cmdiocb
->context2
) {
2772 buf_ptr1
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
2774 /* Free the response IOCB before completing the abort
2777 list_remove_head((&buf_ptr1
->list
), buf_ptr
,
2778 struct lpfc_dmabuf
, list
);
2780 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
2783 lpfc_mbuf_free(phba
, buf_ptr1
->virt
, buf_ptr1
->phys
);
2787 if (cmdiocb
->context3
) {
2788 buf_ptr
= (struct lpfc_dmabuf
*) cmdiocb
->context3
;
2789 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
2793 lpfc_sli_release_iocbq(phba
, cmdiocb
);
2798 lpfc_sli_issue_abort_iotag32(struct lpfc_hba
* phba
,
2799 struct lpfc_sli_ring
* pring
,
2800 struct lpfc_iocbq
* cmdiocb
)
2802 struct lpfc_iocbq
*abtsiocbp
;
2803 IOCB_t
*icmd
= NULL
;
2804 IOCB_t
*iabt
= NULL
;
2806 /* issue ABTS for this IOCB based on iotag */
2807 abtsiocbp
= lpfc_sli_get_iocbq(phba
);
2808 if (abtsiocbp
== NULL
)
2811 iabt
= &abtsiocbp
->iocb
;
2812 icmd
= &cmdiocb
->iocb
;
2813 switch (icmd
->ulpCommand
) {
2814 case CMD_ELS_REQUEST64_CR
:
2815 /* Even though we abort the ELS command, the firmware may access
2816 * the BPL or other resources before it processes our
2817 * ABORT_MXRI64. Thus we must delay reusing the cmdiocb
2818 * resources till the actual abort request completes.
2820 abtsiocbp
->context1
= (void *)((unsigned long)icmd
->ulpCommand
);
2821 abtsiocbp
->context2
= cmdiocb
->context2
;
2822 abtsiocbp
->context3
= cmdiocb
->context3
;
2823 cmdiocb
->context2
= NULL
;
2824 cmdiocb
->context3
= NULL
;
2825 abtsiocbp
->iocb_cmpl
= lpfc_sli_abort_elsreq_cmpl
;
2828 lpfc_sli_release_iocbq(phba
, abtsiocbp
);
2832 iabt
->un
.amxri
.abortType
= ABORT_TYPE_ABTS
;
2833 iabt
->un
.amxri
.iotag32
= icmd
->un
.elsreq64
.bdl
.ulpIoTag32
;
2836 iabt
->ulpClass
= CLASS3
;
2837 iabt
->ulpCommand
= CMD_ABORT_MXRI64_CN
;
2839 if (lpfc_sli_issue_iocb(phba
, pring
, abtsiocbp
, 0) == IOCB_ERROR
) {
2840 lpfc_sli_release_iocbq(phba
, abtsiocbp
);
2848 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq
*iocbq
, uint16_t tgt_id
,
2849 uint64_t lun_id
, uint32_t ctx
,
2850 lpfc_ctx_cmd ctx_cmd
)
2852 struct lpfc_scsi_buf
*lpfc_cmd
;
2853 struct scsi_cmnd
*cmnd
;
2856 if (!(iocbq
->iocb_flag
& LPFC_IO_FCP
))
2859 lpfc_cmd
= container_of(iocbq
, struct lpfc_scsi_buf
, cur_iocbq
);
2860 cmnd
= lpfc_cmd
->pCmd
;
2867 if ((cmnd
->device
->id
== tgt_id
) &&
2868 (cmnd
->device
->lun
== lun_id
))
2872 if (cmnd
->device
->id
== tgt_id
)
2876 if (iocbq
->iocb
.ulpContext
== ctx
)
2883 printk(KERN_ERR
"%s: Unknown context cmd type, value %d\n",
2884 __FUNCTION__
, ctx_cmd
);
2892 lpfc_sli_sum_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2893 uint16_t tgt_id
, uint64_t lun_id
, lpfc_ctx_cmd ctx_cmd
)
2895 struct lpfc_iocbq
*iocbq
;
2898 for (i
= 1, sum
= 0; i
<= phba
->sli
.last_iotag
; i
++) {
2899 iocbq
= phba
->sli
.iocbq_lookup
[i
];
2901 if (lpfc_sli_validate_fcp_iocb (iocbq
, tgt_id
, lun_id
,
2910 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba
* phba
, struct lpfc_iocbq
* cmdiocb
,
2911 struct lpfc_iocbq
* rspiocb
)
2913 spin_lock_irq(phba
->host
->host_lock
);
2914 lpfc_sli_release_iocbq(phba
, cmdiocb
);
2915 spin_unlock_irq(phba
->host
->host_lock
);
2920 lpfc_sli_abort_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2921 uint16_t tgt_id
, uint64_t lun_id
, uint32_t ctx
,
2922 lpfc_ctx_cmd abort_cmd
)
2924 struct lpfc_iocbq
*iocbq
;
2925 struct lpfc_iocbq
*abtsiocb
;
2927 int errcnt
= 0, ret_val
= 0;
2930 for (i
= 1; i
<= phba
->sli
.last_iotag
; i
++) {
2931 iocbq
= phba
->sli
.iocbq_lookup
[i
];
2933 if (lpfc_sli_validate_fcp_iocb (iocbq
, tgt_id
, lun_id
,
2937 /* issue ABTS for this IOCB based on iotag */
2938 abtsiocb
= lpfc_sli_get_iocbq(phba
);
2939 if (abtsiocb
== NULL
) {
2945 abtsiocb
->iocb
.un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
2946 abtsiocb
->iocb
.un
.acxri
.abortContextTag
= cmd
->ulpContext
;
2947 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= cmd
->ulpIoTag
;
2948 abtsiocb
->iocb
.ulpLe
= 1;
2949 abtsiocb
->iocb
.ulpClass
= cmd
->ulpClass
;
2951 if (phba
->hba_state
>= LPFC_LINK_UP
)
2952 abtsiocb
->iocb
.ulpCommand
= CMD_ABORT_XRI_CN
;
2954 abtsiocb
->iocb
.ulpCommand
= CMD_CLOSE_XRI_CN
;
2956 /* Setup callback routine and issue the command. */
2957 abtsiocb
->iocb_cmpl
= lpfc_sli_abort_fcp_cmpl
;
2958 ret_val
= lpfc_sli_issue_iocb(phba
, pring
, abtsiocb
, 0);
2959 if (ret_val
== IOCB_ERROR
) {
2960 lpfc_sli_release_iocbq(phba
, abtsiocb
);
2970 lpfc_sli_wake_iocb_wait(struct lpfc_hba
*phba
,
2971 struct lpfc_iocbq
*cmdiocbq
,
2972 struct lpfc_iocbq
*rspiocbq
)
2974 wait_queue_head_t
*pdone_q
;
2975 unsigned long iflags
;
2977 spin_lock_irqsave(phba
->host
->host_lock
, iflags
);
2978 cmdiocbq
->iocb_flag
|= LPFC_IO_WAKE
;
2979 if (cmdiocbq
->context2
&& rspiocbq
)
2980 memcpy(&((struct lpfc_iocbq
*)cmdiocbq
->context2
)->iocb
,
2981 &rspiocbq
->iocb
, sizeof(IOCB_t
));
2983 pdone_q
= cmdiocbq
->context_un
.wait_queue
;
2984 spin_unlock_irqrestore(phba
->host
->host_lock
, iflags
);
2991 * Issue the caller's iocb and wait for its completion, but no longer than the
2992 * caller's timeout. Note that iocb_flags is cleared before the
2993 * lpfc_sli_issue_call since the wake routine sets a unique value and by
2994 * definition this is a wait function.
2997 lpfc_sli_issue_iocb_wait(struct lpfc_hba
* phba
,
2998 struct lpfc_sli_ring
* pring
,
2999 struct lpfc_iocbq
* piocb
,
3000 struct lpfc_iocbq
* prspiocbq
,
3003 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
3004 long timeleft
, timeout_req
= 0;
3005 int retval
= IOCB_SUCCESS
;
3009 * If the caller has provided a response iocbq buffer, then context2
3010 * is NULL or its an error.
3013 if (piocb
->context2
)
3015 piocb
->context2
= prspiocbq
;
3018 piocb
->iocb_cmpl
= lpfc_sli_wake_iocb_wait
;
3019 piocb
->context_un
.wait_queue
= &done_q
;
3020 piocb
->iocb_flag
&= ~LPFC_IO_WAKE
;
3022 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
3023 creg_val
= readl(phba
->HCregaddr
);
3024 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
3025 writel(creg_val
, phba
->HCregaddr
);
3026 readl(phba
->HCregaddr
); /* flush */
3029 retval
= lpfc_sli_issue_iocb(phba
, pring
, piocb
, 0);
3030 if (retval
== IOCB_SUCCESS
) {
3031 timeout_req
= timeout
* HZ
;
3032 spin_unlock_irq(phba
->host
->host_lock
);
3033 timeleft
= wait_event_timeout(done_q
,
3034 piocb
->iocb_flag
& LPFC_IO_WAKE
,
3036 spin_lock_irq(phba
->host
->host_lock
);
3038 if (timeleft
== 0) {
3039 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3040 "%d:0338 IOCB wait timeout error - no "
3041 "wake response Data x%x\n",
3042 phba
->brd_no
, timeout
);
3043 retval
= IOCB_TIMEDOUT
;
3044 } else if (!(piocb
->iocb_flag
& LPFC_IO_WAKE
)) {
3045 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3046 "%d:0330 IOCB wake NOT set, "
3047 "Data x%x x%lx\n", phba
->brd_no
,
3048 timeout
, (timeleft
/ jiffies
));
3049 retval
= IOCB_TIMEDOUT
;
3051 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3052 "%d:0331 IOCB wake signaled\n",
3056 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3057 "%d:0332 IOCB wait issue failed, Data x%x\n",
3058 phba
->brd_no
, retval
);
3059 retval
= IOCB_ERROR
;
3062 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
3063 creg_val
= readl(phba
->HCregaddr
);
3064 creg_val
&= ~(HC_R0INT_ENA
<< LPFC_FCP_RING
);
3065 writel(creg_val
, phba
->HCregaddr
);
3066 readl(phba
->HCregaddr
); /* flush */
3070 piocb
->context2
= NULL
;
3072 piocb
->context_un
.wait_queue
= NULL
;
3073 piocb
->iocb_cmpl
= NULL
;
3078 lpfc_sli_issue_mbox_wait(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmboxq
,
3081 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
3082 DECLARE_WAITQUEUE(wq_entry
, current
);
3083 uint32_t timeleft
= 0;
3086 /* The caller must leave context1 empty. */
3087 if (pmboxq
->context1
!= 0) {
3088 return (MBX_NOT_FINISHED
);
3091 /* setup wake call as IOCB callback */
3092 pmboxq
->mbox_cmpl
= lpfc_sli_wake_mbox_wait
;
3093 /* setup context field to pass wait_queue pointer to wake function */
3094 pmboxq
->context1
= &done_q
;
3096 /* start to sleep before we wait, to avoid races */
3097 set_current_state(TASK_INTERRUPTIBLE
);
3098 add_wait_queue(&done_q
, &wq_entry
);
3100 /* now issue the command */
3101 retval
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
3103 if (retval
== MBX_BUSY
|| retval
== MBX_SUCCESS
) {
3104 timeleft
= schedule_timeout(timeout
* HZ
);
3105 pmboxq
->context1
= NULL
;
3106 /* if schedule_timeout returns 0, we timed out and were not
3108 if ((timeleft
== 0) || signal_pending(current
))
3109 retval
= MBX_TIMEOUT
;
3111 retval
= MBX_SUCCESS
;
3115 set_current_state(TASK_RUNNING
);
3116 remove_wait_queue(&done_q
, &wq_entry
);
3121 lpfc_sli_flush_mbox_queue(struct lpfc_hba
* phba
)
3125 while (phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
&& !phba
->stopped
) {
3126 if (i
++ > LPFC_MBOX_TMO
* 1000)
3129 if (lpfc_sli_handle_mb_event(phba
) == 0)
3135 return (phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
) ? 1 : 0;
3139 lpfc_intr_handler(int irq
, void *dev_id
)
3141 struct lpfc_hba
*phba
;
3143 uint32_t work_ha_copy
;
3144 unsigned long status
;
3149 * Get the driver's phba structure from the dev_id and
3150 * assume the HBA is not interrupting.
3152 phba
= (struct lpfc_hba
*) dev_id
;
3154 if (unlikely(!phba
))
3157 phba
->sli
.slistat
.sli_intr
++;
3160 * Call the HBA to see if it is interrupting. If not, don't claim
3164 /* Ignore all interrupts during initialization. */
3165 if (unlikely(phba
->hba_state
< LPFC_LINK_DOWN
))
3169 * Read host attention register to determine interrupt source
3170 * Clear Attention Sources, except Error Attention (to
3171 * preserve status) and Link Attention
3173 spin_lock(phba
->host
->host_lock
);
3174 ha_copy
= readl(phba
->HAregaddr
);
3175 writel((ha_copy
& ~(HA_LATT
| HA_ERATT
)), phba
->HAregaddr
);
3176 readl(phba
->HAregaddr
); /* flush */
3177 spin_unlock(phba
->host
->host_lock
);
3179 if (unlikely(!ha_copy
))
3182 work_ha_copy
= ha_copy
& phba
->work_ha_mask
;
3184 if (unlikely(work_ha_copy
)) {
3185 if (work_ha_copy
& HA_LATT
) {
3186 if (phba
->sli
.sli_flag
& LPFC_PROCESS_LA
) {
3188 * Turn off Link Attention interrupts
3189 * until CLEAR_LA done
3191 spin_lock(phba
->host
->host_lock
);
3192 phba
->sli
.sli_flag
&= ~LPFC_PROCESS_LA
;
3193 control
= readl(phba
->HCregaddr
);
3194 control
&= ~HC_LAINT_ENA
;
3195 writel(control
, phba
->HCregaddr
);
3196 readl(phba
->HCregaddr
); /* flush */
3197 spin_unlock(phba
->host
->host_lock
);
3200 work_ha_copy
&= ~HA_LATT
;
3203 if (work_ha_copy
& ~(HA_ERATT
|HA_MBATT
|HA_LATT
)) {
3204 for (i
= 0; i
< phba
->sli
.num_rings
; i
++) {
3205 if (work_ha_copy
& (HA_RXATT
<< (4*i
))) {
3207 * Turn off Slow Rings interrupts
3209 spin_lock(phba
->host
->host_lock
);
3210 control
= readl(phba
->HCregaddr
);
3211 control
&= ~(HC_R0INT_ENA
<< i
);
3212 writel(control
, phba
->HCregaddr
);
3213 readl(phba
->HCregaddr
); /* flush */
3214 spin_unlock(phba
->host
->host_lock
);
3219 if (work_ha_copy
& HA_ERATT
) {
3220 phba
->hba_state
= LPFC_HBA_ERROR
;
3222 * There was a link/board error. Read the
3223 * status register to retrieve the error event
3226 phba
->sli
.slistat
.err_attn_event
++;
3227 /* Save status info */
3228 phba
->work_hs
= readl(phba
->HSregaddr
);
3229 phba
->work_status
[0] = readl(phba
->MBslimaddr
+ 0xa8);
3230 phba
->work_status
[1] = readl(phba
->MBslimaddr
+ 0xac);
3232 /* Clear Chip error bit */
3233 writel(HA_ERATT
, phba
->HAregaddr
);
3234 readl(phba
->HAregaddr
); /* flush */
3238 spin_lock(phba
->host
->host_lock
);
3239 phba
->work_ha
|= work_ha_copy
;
3240 if (phba
->work_wait
)
3241 wake_up(phba
->work_wait
);
3242 spin_unlock(phba
->host
->host_lock
);
3245 ha_copy
&= ~(phba
->work_ha_mask
);
3248 * Process all events on FCP ring. Take the optimized path for
3249 * FCP IO. Any other IO is slow path and is handled by
3250 * the worker thread.
3252 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
3253 status
>>= (4*LPFC_FCP_RING
);
3254 if (status
& HA_RXATT
)
3255 lpfc_sli_handle_fast_ring_event(phba
,
3256 &phba
->sli
.ring
[LPFC_FCP_RING
],
3259 if (phba
->cfg_multi_ring_support
== 2) {
3261 * Process all events on extra ring. Take the optimized path
3262 * for extra ring IO. Any other IO is slow path and is handled
3263 * by the worker thread.
3265 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
3266 status
>>= (4*LPFC_EXTRA_RING
);
3267 if (status
& HA_RXATT
) {
3268 lpfc_sli_handle_fast_ring_event(phba
,
3269 &phba
->sli
.ring
[LPFC_EXTRA_RING
],
3275 } /* lpfc_intr_handler */