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
;
2107 /* If the PCI channel is in offline state, do not post mbox. */
2108 if (unlikely(pci_channel_offline(phba
->pcidev
)))
2109 return MBX_NOT_FINISHED
;
2113 spin_lock_irqsave(phba
->host
->host_lock
, drvr_flag
);
2117 status
= MBX_SUCCESS
;
2119 if (phba
->hba_state
== LPFC_HBA_ERROR
) {
2120 spin_unlock_irqrestore(phba
->host
->host_lock
, drvr_flag
);
2122 /* Mbox command <mbxCommand> cannot issue */
2123 LOG_MBOX_CANNOT_ISSUE_DATA( phba
, mb
, psli
, flag
)
2124 return (MBX_NOT_FINISHED
);
2127 if (mb
->mbxCommand
!= MBX_KILL_BOARD
&& flag
& MBX_NOWAIT
&&
2128 !(readl(phba
->HCregaddr
) & HC_MBINT_ENA
)) {
2129 spin_unlock_irqrestore(phba
->host
->host_lock
, drvr_flag
);
2130 LOG_MBOX_CANNOT_ISSUE_DATA( phba
, mb
, psli
, flag
)
2131 return (MBX_NOT_FINISHED
);
2134 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
2135 /* Polling for a mbox command when another one is already active
2136 * is not allowed in SLI. Also, the driver must have established
2137 * SLI2 mode to queue and process multiple mbox commands.
2140 if (flag
& MBX_POLL
) {
2141 spin_unlock_irqrestore(phba
->host
->host_lock
,
2144 /* Mbox command <mbxCommand> cannot issue */
2145 LOG_MBOX_CANNOT_ISSUE_DATA( phba
, mb
, psli
, flag
)
2146 return (MBX_NOT_FINISHED
);
2149 if (!(psli
->sli_flag
& LPFC_SLI2_ACTIVE
)) {
2150 spin_unlock_irqrestore(phba
->host
->host_lock
,
2152 /* Mbox command <mbxCommand> cannot issue */
2153 LOG_MBOX_CANNOT_ISSUE_DATA( phba
, mb
, psli
, flag
)
2154 return (MBX_NOT_FINISHED
);
2157 /* Handle STOP IOCB processing flag. This is only meaningful
2158 * if we are not polling for mbox completion.
2160 if (flag
& MBX_STOP_IOCB
) {
2161 flag
&= ~MBX_STOP_IOCB
;
2162 /* Now flag each ring */
2163 for (i
= 0; i
< psli
->num_rings
; i
++) {
2164 /* If the ring is active, flag it */
2165 if (psli
->ring
[i
].cmdringaddr
) {
2166 psli
->ring
[i
].flag
|=
2172 /* Another mailbox command is still being processed, queue this
2173 * command to be processed later.
2175 lpfc_mbox_put(phba
, pmbox
);
2177 /* Mbox cmd issue - BUSY */
2178 lpfc_printf_log(phba
,
2181 "%d:0308 Mbox cmd issue - BUSY Data: x%x x%x x%x x%x\n",
2188 psli
->slistat
.mbox_busy
++;
2189 spin_unlock_irqrestore(phba
->host
->host_lock
,
2195 /* Handle STOP IOCB processing flag. This is only meaningful
2196 * if we are not polling for mbox completion.
2198 if (flag
& MBX_STOP_IOCB
) {
2199 flag
&= ~MBX_STOP_IOCB
;
2200 if (flag
== MBX_NOWAIT
) {
2201 /* Now flag each ring */
2202 for (i
= 0; i
< psli
->num_rings
; i
++) {
2203 /* If the ring is active, flag it */
2204 if (psli
->ring
[i
].cmdringaddr
) {
2205 psli
->ring
[i
].flag
|=
2212 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
2214 /* If we are not polling, we MUST be in SLI2 mode */
2215 if (flag
!= MBX_POLL
) {
2216 if (!(psli
->sli_flag
& LPFC_SLI2_ACTIVE
) &&
2217 (mb
->mbxCommand
!= MBX_KILL_BOARD
)) {
2218 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
2219 spin_unlock_irqrestore(phba
->host
->host_lock
,
2221 /* Mbox command <mbxCommand> cannot issue */
2222 LOG_MBOX_CANNOT_ISSUE_DATA( phba
, mb
, psli
, flag
);
2223 return (MBX_NOT_FINISHED
);
2225 /* timeout active mbox command */
2226 mod_timer(&psli
->mbox_tmo
, (jiffies
+
2227 (HZ
* lpfc_mbox_tmo_val(phba
, mb
->mbxCommand
))));
2230 /* Mailbox cmd <cmd> issue */
2231 lpfc_printf_log(phba
,
2234 "%d:0309 Mailbox cmd x%x issue Data: x%x x%x x%x\n",
2241 psli
->slistat
.mbox_cmd
++;
2242 evtctr
= psli
->slistat
.mbox_event
;
2244 /* next set own bit for the adapter and copy over command word */
2245 mb
->mbxOwner
= OWN_CHIP
;
2247 if (psli
->sli_flag
& LPFC_SLI2_ACTIVE
) {
2248 /* First copy command data to host SLIM area */
2249 lpfc_sli_pcimem_bcopy(mb
, &phba
->slim2p
->mbx
, MAILBOX_CMD_SIZE
);
2251 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
2252 /* copy command data into host mbox for cmpl */
2253 lpfc_sli_pcimem_bcopy(mb
, &phba
->slim2p
->mbx
,
2257 /* First copy mbox command data to HBA SLIM, skip past first
2259 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
2260 lpfc_memcpy_to_slim(to_slim
, &mb
->un
.varWords
[0],
2261 MAILBOX_CMD_SIZE
- sizeof (uint32_t));
2263 /* Next copy over first word, with mbxOwner set */
2264 ldata
= *((volatile uint32_t *)mb
);
2265 to_slim
= phba
->MBslimaddr
;
2266 writel(ldata
, to_slim
);
2267 readl(to_slim
); /* flush */
2269 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
2270 /* switch over to host mailbox */
2271 psli
->sli_flag
|= LPFC_SLI2_ACTIVE
;
2276 /* interrupt board to doit right away */
2277 writel(CA_MBATT
, phba
->CAregaddr
);
2278 readl(phba
->CAregaddr
); /* flush */
2282 /* Don't wait for it to finish, just return */
2283 psli
->mbox_active
= pmbox
;
2287 psli
->mbox_active
= NULL
;
2288 if (psli
->sli_flag
& LPFC_SLI2_ACTIVE
) {
2289 /* First read mbox status word */
2290 word0
= *((volatile uint32_t *)&phba
->slim2p
->mbx
);
2291 word0
= le32_to_cpu(word0
);
2293 /* First read mbox status word */
2294 word0
= readl(phba
->MBslimaddr
);
2297 /* Read the HBA Host Attention Register */
2298 ha_copy
= readl(phba
->HAregaddr
);
2300 i
= lpfc_mbox_tmo_val(phba
, mb
->mbxCommand
);
2301 i
*= 1000; /* Convert to ms */
2303 /* Wait for command to complete */
2304 while (((word0
& OWN_CHIP
) == OWN_CHIP
) ||
2305 (!(ha_copy
& HA_MBATT
) &&
2306 (phba
->hba_state
> LPFC_WARM_START
))) {
2308 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
2309 spin_unlock_irqrestore(phba
->host
->host_lock
,
2311 return (MBX_NOT_FINISHED
);
2314 /* Check if we took a mbox interrupt while we were
2316 if (((word0
& OWN_CHIP
) != OWN_CHIP
)
2317 && (evtctr
!= psli
->slistat
.mbox_event
))
2320 spin_unlock_irqrestore(phba
->host
->host_lock
,
2323 /* Can be in interrupt context, do not sleep */
2324 /* (or might be called with interrupts disabled) */
2327 spin_lock_irqsave(phba
->host
->host_lock
, drvr_flag
);
2329 if (psli
->sli_flag
& LPFC_SLI2_ACTIVE
) {
2330 /* First copy command data */
2331 word0
= *((volatile uint32_t *)
2332 &phba
->slim2p
->mbx
);
2333 word0
= le32_to_cpu(word0
);
2334 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
2336 volatile uint32_t slimword0
;
2337 /* Check real SLIM for any errors */
2338 slimword0
= readl(phba
->MBslimaddr
);
2339 slimmb
= (MAILBOX_t
*) & slimword0
;
2340 if (((slimword0
& OWN_CHIP
) != OWN_CHIP
)
2341 && slimmb
->mbxStatus
) {
2348 /* First copy command data */
2349 word0
= readl(phba
->MBslimaddr
);
2351 /* Read the HBA Host Attention Register */
2352 ha_copy
= readl(phba
->HAregaddr
);
2355 if (psli
->sli_flag
& LPFC_SLI2_ACTIVE
) {
2356 /* copy results back to user */
2357 lpfc_sli_pcimem_bcopy(&phba
->slim2p
->mbx
, mb
,
2360 /* First copy command data */
2361 lpfc_memcpy_from_slim(mb
, phba
->MBslimaddr
,
2363 if ((mb
->mbxCommand
== MBX_DUMP_MEMORY
) &&
2365 lpfc_memcpy_from_slim((void *)pmbox
->context2
,
2366 phba
->MBslimaddr
+ DMP_RSP_OFFSET
,
2367 mb
->un
.varDmp
.word_cnt
);
2371 writel(HA_MBATT
, phba
->HAregaddr
);
2372 readl(phba
->HAregaddr
); /* flush */
2374 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
2375 status
= mb
->mbxStatus
;
2378 spin_unlock_irqrestore(phba
->host
->host_lock
, drvr_flag
);
2383 lpfc_sli_ringtx_put(struct lpfc_hba
* phba
, struct lpfc_sli_ring
* pring
,
2384 struct lpfc_iocbq
* piocb
)
2386 /* Insert the caller's iocb in the txq tail for later processing. */
2387 list_add_tail(&piocb
->list
, &pring
->txq
);
2392 static struct lpfc_iocbq
*
2393 lpfc_sli_next_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2394 struct lpfc_iocbq
** piocb
)
2396 struct lpfc_iocbq
* nextiocb
;
2398 nextiocb
= lpfc_sli_ringtx_get(phba
, pring
);
2408 lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2409 struct lpfc_iocbq
*piocb
, uint32_t flag
)
2411 struct lpfc_iocbq
*nextiocb
;
2414 /* If the PCI channel is in offline state, do not post iocbs. */
2415 if (unlikely(pci_channel_offline(phba
->pcidev
)))
2419 * We should never get an IOCB if we are in a < LINK_DOWN state
2421 if (unlikely(phba
->hba_state
< LPFC_LINK_DOWN
))
2425 * Check to see if we are blocking IOCB processing because of a
2426 * outstanding mbox command.
2428 if (unlikely(pring
->flag
& LPFC_STOP_IOCB_MBX
))
2431 if (unlikely(phba
->hba_state
== LPFC_LINK_DOWN
)) {
2433 * Only CREATE_XRI, CLOSE_XRI, ABORT_XRI, and QUE_RING_BUF
2434 * can be issued if the link is not up.
2436 switch (piocb
->iocb
.ulpCommand
) {
2437 case CMD_QUE_RING_BUF_CN
:
2438 case CMD_QUE_RING_BUF64_CN
:
2440 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
2441 * completion, iocb_cmpl MUST be 0.
2443 if (piocb
->iocb_cmpl
)
2444 piocb
->iocb_cmpl
= NULL
;
2446 case CMD_CREATE_XRI_CR
:
2453 * For FCP commands, we must be in a state where we can process link
2456 } else if (unlikely(pring
->ringno
== phba
->sli
.fcp_ring
&&
2457 !(phba
->sli
.sli_flag
& LPFC_PROCESS_LA
)))
2460 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
2461 (nextiocb
= lpfc_sli_next_iocb(phba
, pring
, &piocb
)))
2462 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
2465 lpfc_sli_update_ring(phba
, pring
);
2467 lpfc_sli_update_full_ring(phba
, pring
);
2470 return IOCB_SUCCESS
;
2475 pring
->stats
.iocb_cmd_delay
++;
2479 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
2480 lpfc_sli_ringtx_put(phba
, pring
, piocb
);
2481 return IOCB_SUCCESS
;
2488 lpfc_extra_ring_setup( struct lpfc_hba
*phba
)
2490 struct lpfc_sli
*psli
;
2491 struct lpfc_sli_ring
*pring
;
2495 /* Adjust cmd/rsp ring iocb entries more evenly */
2497 /* Take some away from the FCP ring */
2498 pring
= &psli
->ring
[psli
->fcp_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 /* and give them to the extra ring */
2505 pring
= &psli
->ring
[psli
->extra_ring
];
2507 pring
->numCiocb
+= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
2508 pring
->numRiocb
+= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
2509 pring
->numCiocb
+= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
2510 pring
->numRiocb
+= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
2512 /* Setup default profile for this ring */
2513 pring
->iotag_max
= 4096;
2514 pring
->num_mask
= 1;
2515 pring
->prt
[0].profile
= 0; /* Mask 0 */
2516 pring
->prt
[0].rctl
= phba
->cfg_multi_ring_rctl
;
2517 pring
->prt
[0].type
= phba
->cfg_multi_ring_type
;
2518 pring
->prt
[0].lpfc_sli_rcv_unsol_event
= NULL
;
2523 lpfc_sli_setup(struct lpfc_hba
*phba
)
2526 struct lpfc_sli
*psli
= &phba
->sli
;
2527 struct lpfc_sli_ring
*pring
;
2529 psli
->num_rings
= MAX_CONFIGURED_RINGS
;
2531 psli
->fcp_ring
= LPFC_FCP_RING
;
2532 psli
->next_ring
= LPFC_FCP_NEXT_RING
;
2533 psli
->extra_ring
= LPFC_EXTRA_RING
;
2535 psli
->iocbq_lookup
= NULL
;
2536 psli
->iocbq_lookup_len
= 0;
2537 psli
->last_iotag
= 0;
2539 for (i
= 0; i
< psli
->num_rings
; i
++) {
2540 pring
= &psli
->ring
[i
];
2542 case LPFC_FCP_RING
: /* ring 0 - FCP */
2543 /* numCiocb and numRiocb are used in config_port */
2544 pring
->numCiocb
= SLI2_IOCB_CMD_R0_ENTRIES
;
2545 pring
->numRiocb
= SLI2_IOCB_RSP_R0_ENTRIES
;
2546 pring
->numCiocb
+= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
2547 pring
->numRiocb
+= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
2548 pring
->numCiocb
+= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
2549 pring
->numRiocb
+= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
2550 pring
->iotag_ctr
= 0;
2552 (phba
->cfg_hba_queue_depth
* 2);
2553 pring
->fast_iotag
= pring
->iotag_max
;
2554 pring
->num_mask
= 0;
2556 case LPFC_EXTRA_RING
: /* ring 1 - EXTRA */
2557 /* numCiocb and numRiocb are used in config_port */
2558 pring
->numCiocb
= SLI2_IOCB_CMD_R1_ENTRIES
;
2559 pring
->numRiocb
= SLI2_IOCB_RSP_R1_ENTRIES
;
2560 pring
->num_mask
= 0;
2562 case LPFC_ELS_RING
: /* ring 2 - ELS / CT */
2563 /* numCiocb and numRiocb are used in config_port */
2564 pring
->numCiocb
= SLI2_IOCB_CMD_R2_ENTRIES
;
2565 pring
->numRiocb
= SLI2_IOCB_RSP_R2_ENTRIES
;
2566 pring
->fast_iotag
= 0;
2567 pring
->iotag_ctr
= 0;
2568 pring
->iotag_max
= 4096;
2569 pring
->num_mask
= 4;
2570 pring
->prt
[0].profile
= 0; /* Mask 0 */
2571 pring
->prt
[0].rctl
= FC_ELS_REQ
;
2572 pring
->prt
[0].type
= FC_ELS_DATA
;
2573 pring
->prt
[0].lpfc_sli_rcv_unsol_event
=
2574 lpfc_els_unsol_event
;
2575 pring
->prt
[1].profile
= 0; /* Mask 1 */
2576 pring
->prt
[1].rctl
= FC_ELS_RSP
;
2577 pring
->prt
[1].type
= FC_ELS_DATA
;
2578 pring
->prt
[1].lpfc_sli_rcv_unsol_event
=
2579 lpfc_els_unsol_event
;
2580 pring
->prt
[2].profile
= 0; /* Mask 2 */
2581 /* NameServer Inquiry */
2582 pring
->prt
[2].rctl
= FC_UNSOL_CTL
;
2584 pring
->prt
[2].type
= FC_COMMON_TRANSPORT_ULP
;
2585 pring
->prt
[2].lpfc_sli_rcv_unsol_event
=
2586 lpfc_ct_unsol_event
;
2587 pring
->prt
[3].profile
= 0; /* Mask 3 */
2588 /* NameServer response */
2589 pring
->prt
[3].rctl
= FC_SOL_CTL
;
2591 pring
->prt
[3].type
= FC_COMMON_TRANSPORT_ULP
;
2592 pring
->prt
[3].lpfc_sli_rcv_unsol_event
=
2593 lpfc_ct_unsol_event
;
2596 totiocb
+= (pring
->numCiocb
+ pring
->numRiocb
);
2598 if (totiocb
> MAX_SLI2_IOCB
) {
2599 /* Too many cmd / rsp ring entries in SLI2 SLIM */
2600 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2601 "%d:0462 Too many cmd / rsp ring entries in "
2602 "SLI2 SLIM Data: x%x x%x\n",
2603 phba
->brd_no
, totiocb
, MAX_SLI2_IOCB
);
2605 if (phba
->cfg_multi_ring_support
== 2)
2606 lpfc_extra_ring_setup(phba
);
2612 lpfc_sli_queue_setup(struct lpfc_hba
* phba
)
2614 struct lpfc_sli
*psli
;
2615 struct lpfc_sli_ring
*pring
;
2619 spin_lock_irq(phba
->host
->host_lock
);
2620 INIT_LIST_HEAD(&psli
->mboxq
);
2621 /* Initialize list headers for txq and txcmplq as double linked lists */
2622 for (i
= 0; i
< psli
->num_rings
; i
++) {
2623 pring
= &psli
->ring
[i
];
2625 pring
->next_cmdidx
= 0;
2626 pring
->local_getidx
= 0;
2628 INIT_LIST_HEAD(&pring
->txq
);
2629 INIT_LIST_HEAD(&pring
->txcmplq
);
2630 INIT_LIST_HEAD(&pring
->iocb_continueq
);
2631 INIT_LIST_HEAD(&pring
->postbufq
);
2633 spin_unlock_irq(phba
->host
->host_lock
);
2638 lpfc_sli_hba_down(struct lpfc_hba
* phba
)
2640 struct lpfc_sli
*psli
;
2641 struct lpfc_sli_ring
*pring
;
2643 struct lpfc_iocbq
*iocb
, *next_iocb
;
2644 IOCB_t
*icmd
= NULL
;
2646 unsigned long flags
= 0;
2649 lpfc_hba_down_prep(phba
);
2651 spin_lock_irqsave(phba
->host
->host_lock
, flags
);
2653 for (i
= 0; i
< psli
->num_rings
; i
++) {
2654 pring
= &psli
->ring
[i
];
2655 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
2658 * Error everything on the txq since these iocbs have not been
2659 * given to the FW yet.
2663 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
2664 list_del_init(&iocb
->list
);
2665 if (iocb
->iocb_cmpl
) {
2667 icmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
2668 icmd
->un
.ulpWord
[4] = IOERR_SLI_DOWN
;
2669 spin_unlock_irqrestore(phba
->host
->host_lock
,
2671 (iocb
->iocb_cmpl
) (phba
, iocb
, iocb
);
2672 spin_lock_irqsave(phba
->host
->host_lock
, flags
);
2674 lpfc_sli_release_iocbq(phba
, iocb
);
2677 INIT_LIST_HEAD(&(pring
->txq
));
2681 spin_unlock_irqrestore(phba
->host
->host_lock
, flags
);
2683 /* Return any active mbox cmds */
2684 del_timer_sync(&psli
->mbox_tmo
);
2685 spin_lock_irqsave(phba
->host
->host_lock
, flags
);
2686 phba
->work_hba_events
&= ~WORKER_MBOX_TMO
;
2687 if (psli
->mbox_active
) {
2688 pmb
= psli
->mbox_active
;
2689 pmb
->mb
.mbxStatus
= MBX_NOT_FINISHED
;
2690 if (pmb
->mbox_cmpl
) {
2691 spin_unlock_irqrestore(phba
->host
->host_lock
, flags
);
2692 pmb
->mbox_cmpl(phba
,pmb
);
2693 spin_lock_irqsave(phba
->host
->host_lock
, flags
);
2696 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
2697 psli
->mbox_active
= NULL
;
2699 /* Return any pending mbox cmds */
2700 while ((pmb
= lpfc_mbox_get(phba
)) != NULL
) {
2701 pmb
->mb
.mbxStatus
= MBX_NOT_FINISHED
;
2702 if (pmb
->mbox_cmpl
) {
2703 spin_unlock_irqrestore(phba
->host
->host_lock
, flags
);
2704 pmb
->mbox_cmpl(phba
,pmb
);
2705 spin_lock_irqsave(phba
->host
->host_lock
, flags
);
2709 INIT_LIST_HEAD(&psli
->mboxq
);
2711 spin_unlock_irqrestore(phba
->host
->host_lock
, flags
);
2717 lpfc_sli_pcimem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
2719 uint32_t *src
= srcp
;
2720 uint32_t *dest
= destp
;
2724 for (i
= 0; i
< (int)cnt
; i
+= sizeof (uint32_t)) {
2726 ldata
= le32_to_cpu(ldata
);
2734 lpfc_sli_ringpostbuf_put(struct lpfc_hba
* phba
, struct lpfc_sli_ring
* pring
,
2735 struct lpfc_dmabuf
* mp
)
2737 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
2739 list_add_tail(&mp
->list
, &pring
->postbufq
);
2741 pring
->postbufq_cnt
++;
2746 struct lpfc_dmabuf
*
2747 lpfc_sli_ringpostbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2750 struct lpfc_dmabuf
*mp
, *next_mp
;
2751 struct list_head
*slp
= &pring
->postbufq
;
2753 /* Search postbufq, from the begining, looking for a match on phys */
2754 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
2755 if (mp
->phys
== phys
) {
2756 list_del_init(&mp
->list
);
2757 pring
->postbufq_cnt
--;
2762 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2763 "%d:0410 Cannot find virtual addr for mapped buf on "
2764 "ring %d Data x%llx x%p x%p x%x\n",
2765 phba
->brd_no
, pring
->ringno
, (unsigned long long)phys
,
2766 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
2771 lpfc_sli_abort_elsreq_cmpl(struct lpfc_hba
* phba
, struct lpfc_iocbq
* cmdiocb
,
2772 struct lpfc_iocbq
* rspiocb
)
2774 struct lpfc_dmabuf
*buf_ptr
, *buf_ptr1
;
2775 /* Free the resources associated with the ELS_REQUEST64 IOCB the driver
2777 * In this case, context2 = cmd, context2->next = rsp, context3 = bpl
2779 if (cmdiocb
->context2
) {
2780 buf_ptr1
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
2782 /* Free the response IOCB before completing the abort
2785 list_remove_head((&buf_ptr1
->list
), buf_ptr
,
2786 struct lpfc_dmabuf
, list
);
2788 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
2791 lpfc_mbuf_free(phba
, buf_ptr1
->virt
, buf_ptr1
->phys
);
2795 if (cmdiocb
->context3
) {
2796 buf_ptr
= (struct lpfc_dmabuf
*) cmdiocb
->context3
;
2797 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
2801 lpfc_sli_release_iocbq(phba
, cmdiocb
);
2806 lpfc_sli_issue_abort_iotag32(struct lpfc_hba
* phba
,
2807 struct lpfc_sli_ring
* pring
,
2808 struct lpfc_iocbq
* cmdiocb
)
2810 struct lpfc_iocbq
*abtsiocbp
;
2811 IOCB_t
*icmd
= NULL
;
2812 IOCB_t
*iabt
= NULL
;
2814 /* issue ABTS for this IOCB based on iotag */
2815 abtsiocbp
= lpfc_sli_get_iocbq(phba
);
2816 if (abtsiocbp
== NULL
)
2819 iabt
= &abtsiocbp
->iocb
;
2820 icmd
= &cmdiocb
->iocb
;
2821 switch (icmd
->ulpCommand
) {
2822 case CMD_ELS_REQUEST64_CR
:
2823 /* Even though we abort the ELS command, the firmware may access
2824 * the BPL or other resources before it processes our
2825 * ABORT_MXRI64. Thus we must delay reusing the cmdiocb
2826 * resources till the actual abort request completes.
2828 abtsiocbp
->context1
= (void *)((unsigned long)icmd
->ulpCommand
);
2829 abtsiocbp
->context2
= cmdiocb
->context2
;
2830 abtsiocbp
->context3
= cmdiocb
->context3
;
2831 cmdiocb
->context2
= NULL
;
2832 cmdiocb
->context3
= NULL
;
2833 abtsiocbp
->iocb_cmpl
= lpfc_sli_abort_elsreq_cmpl
;
2836 lpfc_sli_release_iocbq(phba
, abtsiocbp
);
2840 iabt
->un
.amxri
.abortType
= ABORT_TYPE_ABTS
;
2841 iabt
->un
.amxri
.iotag32
= icmd
->un
.elsreq64
.bdl
.ulpIoTag32
;
2844 iabt
->ulpClass
= CLASS3
;
2845 iabt
->ulpCommand
= CMD_ABORT_MXRI64_CN
;
2847 if (lpfc_sli_issue_iocb(phba
, pring
, abtsiocbp
, 0) == IOCB_ERROR
) {
2848 lpfc_sli_release_iocbq(phba
, abtsiocbp
);
2856 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq
*iocbq
, uint16_t tgt_id
,
2857 uint64_t lun_id
, uint32_t ctx
,
2858 lpfc_ctx_cmd ctx_cmd
)
2860 struct lpfc_scsi_buf
*lpfc_cmd
;
2861 struct scsi_cmnd
*cmnd
;
2864 if (!(iocbq
->iocb_flag
& LPFC_IO_FCP
))
2867 lpfc_cmd
= container_of(iocbq
, struct lpfc_scsi_buf
, cur_iocbq
);
2868 cmnd
= lpfc_cmd
->pCmd
;
2875 if ((cmnd
->device
->id
== tgt_id
) &&
2876 (cmnd
->device
->lun
== lun_id
))
2880 if (cmnd
->device
->id
== tgt_id
)
2884 if (iocbq
->iocb
.ulpContext
== ctx
)
2891 printk(KERN_ERR
"%s: Unknown context cmd type, value %d\n",
2892 __FUNCTION__
, ctx_cmd
);
2900 lpfc_sli_sum_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2901 uint16_t tgt_id
, uint64_t lun_id
, lpfc_ctx_cmd ctx_cmd
)
2903 struct lpfc_iocbq
*iocbq
;
2906 for (i
= 1, sum
= 0; i
<= phba
->sli
.last_iotag
; i
++) {
2907 iocbq
= phba
->sli
.iocbq_lookup
[i
];
2909 if (lpfc_sli_validate_fcp_iocb (iocbq
, tgt_id
, lun_id
,
2918 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba
* phba
, struct lpfc_iocbq
* cmdiocb
,
2919 struct lpfc_iocbq
* rspiocb
)
2921 spin_lock_irq(phba
->host
->host_lock
);
2922 lpfc_sli_release_iocbq(phba
, cmdiocb
);
2923 spin_unlock_irq(phba
->host
->host_lock
);
2928 lpfc_sli_abort_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2929 uint16_t tgt_id
, uint64_t lun_id
, uint32_t ctx
,
2930 lpfc_ctx_cmd abort_cmd
)
2932 struct lpfc_iocbq
*iocbq
;
2933 struct lpfc_iocbq
*abtsiocb
;
2935 int errcnt
= 0, ret_val
= 0;
2938 for (i
= 1; i
<= phba
->sli
.last_iotag
; i
++) {
2939 iocbq
= phba
->sli
.iocbq_lookup
[i
];
2941 if (lpfc_sli_validate_fcp_iocb (iocbq
, tgt_id
, lun_id
,
2945 /* issue ABTS for this IOCB based on iotag */
2946 abtsiocb
= lpfc_sli_get_iocbq(phba
);
2947 if (abtsiocb
== NULL
) {
2953 abtsiocb
->iocb
.un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
2954 abtsiocb
->iocb
.un
.acxri
.abortContextTag
= cmd
->ulpContext
;
2955 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= cmd
->ulpIoTag
;
2956 abtsiocb
->iocb
.ulpLe
= 1;
2957 abtsiocb
->iocb
.ulpClass
= cmd
->ulpClass
;
2959 if (phba
->hba_state
>= LPFC_LINK_UP
)
2960 abtsiocb
->iocb
.ulpCommand
= CMD_ABORT_XRI_CN
;
2962 abtsiocb
->iocb
.ulpCommand
= CMD_CLOSE_XRI_CN
;
2964 /* Setup callback routine and issue the command. */
2965 abtsiocb
->iocb_cmpl
= lpfc_sli_abort_fcp_cmpl
;
2966 ret_val
= lpfc_sli_issue_iocb(phba
, pring
, abtsiocb
, 0);
2967 if (ret_val
== IOCB_ERROR
) {
2968 lpfc_sli_release_iocbq(phba
, abtsiocb
);
2978 lpfc_sli_wake_iocb_wait(struct lpfc_hba
*phba
,
2979 struct lpfc_iocbq
*cmdiocbq
,
2980 struct lpfc_iocbq
*rspiocbq
)
2982 wait_queue_head_t
*pdone_q
;
2983 unsigned long iflags
;
2985 spin_lock_irqsave(phba
->host
->host_lock
, iflags
);
2986 cmdiocbq
->iocb_flag
|= LPFC_IO_WAKE
;
2987 if (cmdiocbq
->context2
&& rspiocbq
)
2988 memcpy(&((struct lpfc_iocbq
*)cmdiocbq
->context2
)->iocb
,
2989 &rspiocbq
->iocb
, sizeof(IOCB_t
));
2991 pdone_q
= cmdiocbq
->context_un
.wait_queue
;
2992 spin_unlock_irqrestore(phba
->host
->host_lock
, iflags
);
2999 * Issue the caller's iocb and wait for its completion, but no longer than the
3000 * caller's timeout. Note that iocb_flags is cleared before the
3001 * lpfc_sli_issue_call since the wake routine sets a unique value and by
3002 * definition this is a wait function.
3005 lpfc_sli_issue_iocb_wait(struct lpfc_hba
* phba
,
3006 struct lpfc_sli_ring
* pring
,
3007 struct lpfc_iocbq
* piocb
,
3008 struct lpfc_iocbq
* prspiocbq
,
3011 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
3012 long timeleft
, timeout_req
= 0;
3013 int retval
= IOCB_SUCCESS
;
3017 * If the caller has provided a response iocbq buffer, then context2
3018 * is NULL or its an error.
3021 if (piocb
->context2
)
3023 piocb
->context2
= prspiocbq
;
3026 piocb
->iocb_cmpl
= lpfc_sli_wake_iocb_wait
;
3027 piocb
->context_un
.wait_queue
= &done_q
;
3028 piocb
->iocb_flag
&= ~LPFC_IO_WAKE
;
3030 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
3031 creg_val
= readl(phba
->HCregaddr
);
3032 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
3033 writel(creg_val
, phba
->HCregaddr
);
3034 readl(phba
->HCregaddr
); /* flush */
3037 retval
= lpfc_sli_issue_iocb(phba
, pring
, piocb
, 0);
3038 if (retval
== IOCB_SUCCESS
) {
3039 timeout_req
= timeout
* HZ
;
3040 spin_unlock_irq(phba
->host
->host_lock
);
3041 timeleft
= wait_event_timeout(done_q
,
3042 piocb
->iocb_flag
& LPFC_IO_WAKE
,
3044 spin_lock_irq(phba
->host
->host_lock
);
3046 if (timeleft
== 0) {
3047 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3048 "%d:0338 IOCB wait timeout error - no "
3049 "wake response Data x%x\n",
3050 phba
->brd_no
, timeout
);
3051 retval
= IOCB_TIMEDOUT
;
3052 } else if (!(piocb
->iocb_flag
& LPFC_IO_WAKE
)) {
3053 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3054 "%d:0330 IOCB wake NOT set, "
3055 "Data x%x x%lx\n", phba
->brd_no
,
3056 timeout
, (timeleft
/ jiffies
));
3057 retval
= IOCB_TIMEDOUT
;
3059 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3060 "%d:0331 IOCB wake signaled\n",
3064 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3065 "%d:0332 IOCB wait issue failed, Data x%x\n",
3066 phba
->brd_no
, retval
);
3067 retval
= IOCB_ERROR
;
3070 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
3071 creg_val
= readl(phba
->HCregaddr
);
3072 creg_val
&= ~(HC_R0INT_ENA
<< LPFC_FCP_RING
);
3073 writel(creg_val
, phba
->HCregaddr
);
3074 readl(phba
->HCregaddr
); /* flush */
3078 piocb
->context2
= NULL
;
3080 piocb
->context_un
.wait_queue
= NULL
;
3081 piocb
->iocb_cmpl
= NULL
;
3086 lpfc_sli_issue_mbox_wait(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmboxq
,
3089 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
3090 DECLARE_WAITQUEUE(wq_entry
, current
);
3091 uint32_t timeleft
= 0;
3094 /* The caller must leave context1 empty. */
3095 if (pmboxq
->context1
!= 0) {
3096 return (MBX_NOT_FINISHED
);
3099 /* setup wake call as IOCB callback */
3100 pmboxq
->mbox_cmpl
= lpfc_sli_wake_mbox_wait
;
3101 /* setup context field to pass wait_queue pointer to wake function */
3102 pmboxq
->context1
= &done_q
;
3104 /* start to sleep before we wait, to avoid races */
3105 set_current_state(TASK_INTERRUPTIBLE
);
3106 add_wait_queue(&done_q
, &wq_entry
);
3108 /* now issue the command */
3109 retval
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
3111 if (retval
== MBX_BUSY
|| retval
== MBX_SUCCESS
) {
3112 timeleft
= schedule_timeout(timeout
* HZ
);
3113 pmboxq
->context1
= NULL
;
3114 /* if schedule_timeout returns 0, we timed out and were not
3116 if ((timeleft
== 0) || signal_pending(current
))
3117 retval
= MBX_TIMEOUT
;
3119 retval
= MBX_SUCCESS
;
3123 set_current_state(TASK_RUNNING
);
3124 remove_wait_queue(&done_q
, &wq_entry
);
3129 lpfc_sli_flush_mbox_queue(struct lpfc_hba
* phba
)
3133 while (phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
&& !phba
->stopped
) {
3134 if (i
++ > LPFC_MBOX_TMO
* 1000)
3137 if (lpfc_sli_handle_mb_event(phba
) == 0)
3143 return (phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
) ? 1 : 0;
3147 lpfc_intr_handler(int irq
, void *dev_id
)
3149 struct lpfc_hba
*phba
;
3151 uint32_t work_ha_copy
;
3152 unsigned long status
;
3157 * Get the driver's phba structure from the dev_id and
3158 * assume the HBA is not interrupting.
3160 phba
= (struct lpfc_hba
*) dev_id
;
3162 if (unlikely(!phba
))
3165 /* If the pci channel is offline, ignore all the interrupts. */
3166 if (unlikely(pci_channel_offline(phba
->pcidev
)))
3169 phba
->sli
.slistat
.sli_intr
++;
3172 * Call the HBA to see if it is interrupting. If not, don't claim
3176 /* Ignore all interrupts during initialization. */
3177 if (unlikely(phba
->hba_state
< LPFC_LINK_DOWN
))
3181 * Read host attention register to determine interrupt source
3182 * Clear Attention Sources, except Error Attention (to
3183 * preserve status) and Link Attention
3185 spin_lock(phba
->host
->host_lock
);
3186 ha_copy
= readl(phba
->HAregaddr
);
3187 writel((ha_copy
& ~(HA_LATT
| HA_ERATT
)), phba
->HAregaddr
);
3188 readl(phba
->HAregaddr
); /* flush */
3189 spin_unlock(phba
->host
->host_lock
);
3191 if (unlikely(!ha_copy
))
3194 work_ha_copy
= ha_copy
& phba
->work_ha_mask
;
3196 if (unlikely(work_ha_copy
)) {
3197 if (work_ha_copy
& HA_LATT
) {
3198 if (phba
->sli
.sli_flag
& LPFC_PROCESS_LA
) {
3200 * Turn off Link Attention interrupts
3201 * until CLEAR_LA done
3203 spin_lock(phba
->host
->host_lock
);
3204 phba
->sli
.sli_flag
&= ~LPFC_PROCESS_LA
;
3205 control
= readl(phba
->HCregaddr
);
3206 control
&= ~HC_LAINT_ENA
;
3207 writel(control
, phba
->HCregaddr
);
3208 readl(phba
->HCregaddr
); /* flush */
3209 spin_unlock(phba
->host
->host_lock
);
3212 work_ha_copy
&= ~HA_LATT
;
3215 if (work_ha_copy
& ~(HA_ERATT
|HA_MBATT
|HA_LATT
)) {
3216 for (i
= 0; i
< phba
->sli
.num_rings
; i
++) {
3217 if (work_ha_copy
& (HA_RXATT
<< (4*i
))) {
3219 * Turn off Slow Rings interrupts
3221 spin_lock(phba
->host
->host_lock
);
3222 control
= readl(phba
->HCregaddr
);
3223 control
&= ~(HC_R0INT_ENA
<< i
);
3224 writel(control
, phba
->HCregaddr
);
3225 readl(phba
->HCregaddr
); /* flush */
3226 spin_unlock(phba
->host
->host_lock
);
3231 if (work_ha_copy
& HA_ERATT
) {
3232 phba
->hba_state
= LPFC_HBA_ERROR
;
3234 * There was a link/board error. Read the
3235 * status register to retrieve the error event
3238 phba
->sli
.slistat
.err_attn_event
++;
3239 /* Save status info */
3240 phba
->work_hs
= readl(phba
->HSregaddr
);
3241 phba
->work_status
[0] = readl(phba
->MBslimaddr
+ 0xa8);
3242 phba
->work_status
[1] = readl(phba
->MBslimaddr
+ 0xac);
3244 /* Clear Chip error bit */
3245 writel(HA_ERATT
, phba
->HAregaddr
);
3246 readl(phba
->HAregaddr
); /* flush */
3250 spin_lock(phba
->host
->host_lock
);
3251 phba
->work_ha
|= work_ha_copy
;
3252 if (phba
->work_wait
)
3253 wake_up(phba
->work_wait
);
3254 spin_unlock(phba
->host
->host_lock
);
3257 ha_copy
&= ~(phba
->work_ha_mask
);
3260 * Process all events on FCP ring. Take the optimized path for
3261 * FCP IO. Any other IO is slow path and is handled by
3262 * the worker thread.
3264 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
3265 status
>>= (4*LPFC_FCP_RING
);
3266 if (status
& HA_RXATT
)
3267 lpfc_sli_handle_fast_ring_event(phba
,
3268 &phba
->sli
.ring
[LPFC_FCP_RING
],
3271 if (phba
->cfg_multi_ring_support
== 2) {
3273 * Process all events on extra ring. Take the optimized path
3274 * for extra ring IO. Any other IO is slow path and is handled
3275 * by the worker thread.
3277 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
3278 status
>>= (4*LPFC_EXTRA_RING
);
3279 if (status
& HA_RXATT
) {
3280 lpfc_sli_handle_fast_ring_event(phba
,
3281 &phba
->sli
.ring
[LPFC_EXTRA_RING
],
3287 } /* lpfc_intr_handler */