1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2007 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/interrupt.h>
25 #include <linux/delay.h>
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_cmnd.h>
29 #include <scsi/scsi_device.h>
30 #include <scsi/scsi_host.h>
31 #include <scsi/scsi_transport_fc.h>
35 #include "lpfc_disc.h"
36 #include "lpfc_scsi.h"
38 #include "lpfc_crtn.h"
39 #include "lpfc_logmsg.h"
40 #include "lpfc_compat.h"
41 #include "lpfc_debugfs.h"
44 * Define macro to log: Mailbox command x%x cannot issue Data
45 * This allows multiple uses of lpfc_msgBlk0311
46 * w/o perturbing log msg utility.
48 #define LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag) \
49 lpfc_printf_log(phba, \
52 "(%d):0311 Mailbox command x%x cannot " \
53 "issue Data: x%x x%x x%x\n", \
54 pmbox->vport ? pmbox->vport->vpi : 0, \
55 pmbox->mb.mbxCommand, \
56 phba->pport->port_state, \
61 /* There are only four IOCB completion types. */
62 typedef enum _lpfc_iocb_type
{
69 /* SLI-2/SLI-3 provide different sized iocbs. Given a pointer
70 * to the start of the ring, and the slot number of the
71 * desired iocb entry, calc a pointer to that entry.
73 static inline IOCB_t
*
74 lpfc_cmd_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
76 return (IOCB_t
*) (((char *) pring
->cmdringaddr
) +
77 pring
->cmdidx
* phba
->iocb_cmd_size
);
80 static inline IOCB_t
*
81 lpfc_resp_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
83 return (IOCB_t
*) (((char *) pring
->rspringaddr
) +
84 pring
->rspidx
* phba
->iocb_rsp_size
);
87 static struct lpfc_iocbq
*
88 __lpfc_sli_get_iocbq(struct lpfc_hba
*phba
)
90 struct list_head
*lpfc_iocb_list
= &phba
->lpfc_iocb_list
;
91 struct lpfc_iocbq
* iocbq
= NULL
;
93 list_remove_head(lpfc_iocb_list
, iocbq
, struct lpfc_iocbq
, list
);
98 lpfc_sli_get_iocbq(struct lpfc_hba
*phba
)
100 struct lpfc_iocbq
* iocbq
= NULL
;
101 unsigned long iflags
;
103 spin_lock_irqsave(&phba
->hbalock
, iflags
);
104 iocbq
= __lpfc_sli_get_iocbq(phba
);
105 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
110 __lpfc_sli_release_iocbq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
112 size_t start_clean
= offsetof(struct lpfc_iocbq
, iocb
);
115 * Clean all volatile data fields, preserve iotag and node struct.
117 memset((char*)iocbq
+ start_clean
, 0, sizeof(*iocbq
) - start_clean
);
118 list_add_tail(&iocbq
->list
, &phba
->lpfc_iocb_list
);
122 lpfc_sli_release_iocbq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
124 unsigned long iflags
;
127 * Clean all volatile data fields, preserve iotag and node struct.
129 spin_lock_irqsave(&phba
->hbalock
, iflags
);
130 __lpfc_sli_release_iocbq(phba
, iocbq
);
131 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
135 * Translate the iocb command to an iocb command type used to decide the final
136 * disposition of each completed IOCB.
138 static lpfc_iocb_type
139 lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd
)
141 lpfc_iocb_type type
= LPFC_UNKNOWN_IOCB
;
143 if (iocb_cmnd
> CMD_MAX_IOCB_CMD
)
147 case CMD_XMIT_SEQUENCE_CR
:
148 case CMD_XMIT_SEQUENCE_CX
:
149 case CMD_XMIT_BCAST_CN
:
150 case CMD_XMIT_BCAST_CX
:
151 case CMD_ELS_REQUEST_CR
:
152 case CMD_ELS_REQUEST_CX
:
153 case CMD_CREATE_XRI_CR
:
154 case CMD_CREATE_XRI_CX
:
156 case CMD_XMIT_ELS_RSP_CX
:
158 case CMD_FCP_IWRITE_CR
:
159 case CMD_FCP_IWRITE_CX
:
160 case CMD_FCP_IREAD_CR
:
161 case CMD_FCP_IREAD_CX
:
162 case CMD_FCP_ICMND_CR
:
163 case CMD_FCP_ICMND_CX
:
164 case CMD_FCP_TSEND_CX
:
165 case CMD_FCP_TRSP_CX
:
166 case CMD_FCP_TRECEIVE_CX
:
167 case CMD_FCP_AUTO_TRSP_CX
:
168 case CMD_ADAPTER_MSG
:
169 case CMD_ADAPTER_DUMP
:
170 case CMD_XMIT_SEQUENCE64_CR
:
171 case CMD_XMIT_SEQUENCE64_CX
:
172 case CMD_XMIT_BCAST64_CN
:
173 case CMD_XMIT_BCAST64_CX
:
174 case CMD_ELS_REQUEST64_CR
:
175 case CMD_ELS_REQUEST64_CX
:
176 case CMD_FCP_IWRITE64_CR
:
177 case CMD_FCP_IWRITE64_CX
:
178 case CMD_FCP_IREAD64_CR
:
179 case CMD_FCP_IREAD64_CX
:
180 case CMD_FCP_ICMND64_CR
:
181 case CMD_FCP_ICMND64_CX
:
182 case CMD_FCP_TSEND64_CX
:
183 case CMD_FCP_TRSP64_CX
:
184 case CMD_FCP_TRECEIVE64_CX
:
185 case CMD_GEN_REQUEST64_CR
:
186 case CMD_GEN_REQUEST64_CX
:
187 case CMD_XMIT_ELS_RSP64_CX
:
188 type
= LPFC_SOL_IOCB
;
190 case CMD_ABORT_XRI_CN
:
191 case CMD_ABORT_XRI_CX
:
192 case CMD_CLOSE_XRI_CN
:
193 case CMD_CLOSE_XRI_CX
:
194 case CMD_XRI_ABORTED_CX
:
195 case CMD_ABORT_MXRI64_CN
:
196 type
= LPFC_ABORT_IOCB
;
198 case CMD_RCV_SEQUENCE_CX
:
199 case CMD_RCV_ELS_REQ_CX
:
200 case CMD_RCV_SEQUENCE64_CX
:
201 case CMD_RCV_ELS_REQ64_CX
:
202 case CMD_IOCB_RCV_SEQ64_CX
:
203 case CMD_IOCB_RCV_ELS64_CX
:
204 case CMD_IOCB_RCV_CONT64_CX
:
205 type
= LPFC_UNSOL_IOCB
;
208 type
= LPFC_UNKNOWN_IOCB
;
216 lpfc_sli_ring_map(struct lpfc_hba
*phba
)
218 struct lpfc_sli
*psli
= &phba
->sli
;
223 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
227 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
228 for (i
= 0; i
< psli
->num_rings
; i
++) {
229 lpfc_config_ring(phba
, i
, pmb
);
230 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
231 if (rc
!= MBX_SUCCESS
) {
232 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
233 "0446 Adapter failed to init (%d), "
234 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
236 rc
, pmbox
->mbxCommand
,
237 pmbox
->mbxStatus
, i
);
238 phba
->link_state
= LPFC_HBA_ERROR
;
243 mempool_free(pmb
, phba
->mbox_mem_pool
);
248 lpfc_sli_ringtxcmpl_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
249 struct lpfc_iocbq
*piocb
)
251 list_add_tail(&piocb
->list
, &pring
->txcmplq
);
252 pring
->txcmplq_cnt
++;
253 if ((unlikely(pring
->ringno
== LPFC_ELS_RING
)) &&
254 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
255 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
259 mod_timer(&piocb
->vport
->els_tmofunc
,
260 jiffies
+ HZ
* (phba
->fc_ratov
<< 1));
267 static struct lpfc_iocbq
*
268 lpfc_sli_ringtx_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
270 struct lpfc_iocbq
*cmd_iocb
;
272 list_remove_head((&pring
->txq
), cmd_iocb
, struct lpfc_iocbq
, list
);
273 if (cmd_iocb
!= NULL
)
279 lpfc_sli_next_iocb_slot (struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
281 struct lpfc_pgp
*pgp
= (phba
->sli_rev
== 3) ?
282 &phba
->slim2p
->mbx
.us
.s3_pgp
.port
[pring
->ringno
] :
283 &phba
->slim2p
->mbx
.us
.s2
.port
[pring
->ringno
];
284 uint32_t max_cmd_idx
= pring
->numCiocb
;
286 if ((pring
->next_cmdidx
== pring
->cmdidx
) &&
287 (++pring
->next_cmdidx
>= max_cmd_idx
))
288 pring
->next_cmdidx
= 0;
290 if (unlikely(pring
->local_getidx
== pring
->next_cmdidx
)) {
292 pring
->local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
294 if (unlikely(pring
->local_getidx
>= max_cmd_idx
)) {
295 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
296 "0315 Ring %d issue: portCmdGet %d "
297 "is bigger then cmd ring %d\n",
299 pring
->local_getidx
, max_cmd_idx
);
301 phba
->link_state
= LPFC_HBA_ERROR
;
303 * All error attention handlers are posted to
306 phba
->work_ha
|= HA_ERATT
;
307 phba
->work_hs
= HS_FFER3
;
309 /* hbalock should already be held */
311 lpfc_worker_wake_up(phba
);
316 if (pring
->local_getidx
== pring
->next_cmdidx
)
320 return lpfc_cmd_iocb(phba
, pring
);
324 lpfc_sli_next_iotag(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
326 struct lpfc_iocbq
**new_arr
;
327 struct lpfc_iocbq
**old_arr
;
329 struct lpfc_sli
*psli
= &phba
->sli
;
332 spin_lock_irq(&phba
->hbalock
);
333 iotag
= psli
->last_iotag
;
334 if(++iotag
< psli
->iocbq_lookup_len
) {
335 psli
->last_iotag
= iotag
;
336 psli
->iocbq_lookup
[iotag
] = iocbq
;
337 spin_unlock_irq(&phba
->hbalock
);
338 iocbq
->iotag
= iotag
;
340 } else if (psli
->iocbq_lookup_len
< (0xffff
341 - LPFC_IOCBQ_LOOKUP_INCREMENT
)) {
342 new_len
= psli
->iocbq_lookup_len
+ LPFC_IOCBQ_LOOKUP_INCREMENT
;
343 spin_unlock_irq(&phba
->hbalock
);
344 new_arr
= kzalloc(new_len
* sizeof (struct lpfc_iocbq
*),
347 spin_lock_irq(&phba
->hbalock
);
348 old_arr
= psli
->iocbq_lookup
;
349 if (new_len
<= psli
->iocbq_lookup_len
) {
350 /* highly unprobable case */
352 iotag
= psli
->last_iotag
;
353 if(++iotag
< psli
->iocbq_lookup_len
) {
354 psli
->last_iotag
= iotag
;
355 psli
->iocbq_lookup
[iotag
] = iocbq
;
356 spin_unlock_irq(&phba
->hbalock
);
357 iocbq
->iotag
= iotag
;
360 spin_unlock_irq(&phba
->hbalock
);
363 if (psli
->iocbq_lookup
)
364 memcpy(new_arr
, old_arr
,
365 ((psli
->last_iotag
+ 1) *
366 sizeof (struct lpfc_iocbq
*)));
367 psli
->iocbq_lookup
= new_arr
;
368 psli
->iocbq_lookup_len
= new_len
;
369 psli
->last_iotag
= iotag
;
370 psli
->iocbq_lookup
[iotag
] = iocbq
;
371 spin_unlock_irq(&phba
->hbalock
);
372 iocbq
->iotag
= iotag
;
377 spin_unlock_irq(&phba
->hbalock
);
379 lpfc_printf_log(phba
, KERN_ERR
,LOG_SLI
,
380 "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
387 lpfc_sli_submit_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
388 IOCB_t
*iocb
, struct lpfc_iocbq
*nextiocb
)
393 nextiocb
->iocb
.ulpIoTag
= (nextiocb
->iocb_cmpl
) ? nextiocb
->iotag
: 0;
395 if (pring
->ringno
== LPFC_ELS_RING
) {
396 lpfc_debugfs_slow_ring_trc(phba
,
397 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
398 *(((uint32_t *) &nextiocb
->iocb
) + 4),
399 *(((uint32_t *) &nextiocb
->iocb
) + 6),
400 *(((uint32_t *) &nextiocb
->iocb
) + 7));
404 * Issue iocb command to adapter
406 lpfc_sli_pcimem_bcopy(&nextiocb
->iocb
, iocb
, phba
->iocb_cmd_size
);
408 pring
->stats
.iocb_cmd
++;
411 * If there is no completion routine to call, we can release the
412 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
413 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
415 if (nextiocb
->iocb_cmpl
)
416 lpfc_sli_ringtxcmpl_put(phba
, pring
, nextiocb
);
418 __lpfc_sli_release_iocbq(phba
, nextiocb
);
421 * Let the HBA know what IOCB slot will be the next one the
422 * driver will put a command into.
424 pring
->cmdidx
= pring
->next_cmdidx
;
425 writel(pring
->cmdidx
, &phba
->host_gp
[pring
->ringno
].cmdPutInx
);
429 lpfc_sli_update_full_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
431 int ringno
= pring
->ringno
;
433 pring
->flag
|= LPFC_CALL_RING_AVAILABLE
;
438 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
439 * The HBA will tell us when an IOCB entry is available.
441 writel((CA_R0ATT
|CA_R0CE_REQ
) << (ringno
*4), phba
->CAregaddr
);
442 readl(phba
->CAregaddr
); /* flush */
444 pring
->stats
.iocb_cmd_full
++;
448 lpfc_sli_update_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
450 int ringno
= pring
->ringno
;
453 * Tell the HBA that there is work to do in this ring.
456 writel(CA_R0ATT
<< (ringno
* 4), phba
->CAregaddr
);
457 readl(phba
->CAregaddr
); /* flush */
461 lpfc_sli_resume_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
464 struct lpfc_iocbq
*nextiocb
;
468 * (a) there is anything on the txq to send
470 * (c) link attention events can be processed (fcp ring only)
471 * (d) IOCB processing is not blocked by the outstanding mbox command.
473 if (pring
->txq_cnt
&&
474 lpfc_is_link_up(phba
) &&
475 (pring
->ringno
!= phba
->sli
.fcp_ring
||
476 phba
->sli
.sli_flag
& LPFC_PROCESS_LA
) &&
477 !(pring
->flag
& LPFC_STOP_IOCB_MBX
)) {
479 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
480 (nextiocb
= lpfc_sli_ringtx_get(phba
, pring
)))
481 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
484 lpfc_sli_update_ring(phba
, pring
);
486 lpfc_sli_update_full_ring(phba
, pring
);
492 /* lpfc_sli_turn_on_ring is only called by lpfc_sli_handle_mb_event below */
494 lpfc_sli_turn_on_ring(struct lpfc_hba
*phba
, int ringno
)
496 struct lpfc_pgp
*pgp
= (phba
->sli_rev
== 3) ?
497 &phba
->slim2p
->mbx
.us
.s3_pgp
.port
[ringno
] :
498 &phba
->slim2p
->mbx
.us
.s2
.port
[ringno
];
499 unsigned long iflags
;
501 /* If the ring is active, flag it */
502 spin_lock_irqsave(&phba
->hbalock
, iflags
);
503 if (phba
->sli
.ring
[ringno
].cmdringaddr
) {
504 if (phba
->sli
.ring
[ringno
].flag
& LPFC_STOP_IOCB_MBX
) {
505 phba
->sli
.ring
[ringno
].flag
&= ~LPFC_STOP_IOCB_MBX
;
507 * Force update of the local copy of cmdGetInx
509 phba
->sli
.ring
[ringno
].local_getidx
510 = le32_to_cpu(pgp
->cmdGetInx
);
511 lpfc_sli_resume_iocb(phba
, &phba
->sli
.ring
[ringno
]);
514 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
517 struct lpfc_hbq_entry
*
518 lpfc_sli_next_hbq_slot(struct lpfc_hba
*phba
, uint32_t hbqno
)
520 struct hbq_s
*hbqp
= &phba
->hbqs
[hbqno
];
522 if (hbqp
->next_hbqPutIdx
== hbqp
->hbqPutIdx
&&
523 ++hbqp
->next_hbqPutIdx
>= hbqp
->entry_count
)
524 hbqp
->next_hbqPutIdx
= 0;
526 if (unlikely(hbqp
->local_hbqGetIdx
== hbqp
->next_hbqPutIdx
)) {
527 uint32_t raw_index
= phba
->hbq_get
[hbqno
];
528 uint32_t getidx
= le32_to_cpu(raw_index
);
530 hbqp
->local_hbqGetIdx
= getidx
;
532 if (unlikely(hbqp
->local_hbqGetIdx
>= hbqp
->entry_count
)) {
533 lpfc_printf_log(phba
, KERN_ERR
,
535 "1802 HBQ %d: local_hbqGetIdx "
536 "%u is > than hbqp->entry_count %u\n",
537 hbqno
, hbqp
->local_hbqGetIdx
,
540 phba
->link_state
= LPFC_HBA_ERROR
;
544 if (hbqp
->local_hbqGetIdx
== hbqp
->next_hbqPutIdx
)
548 return (struct lpfc_hbq_entry
*) phba
->hbqs
[hbqno
].hbq_virt
+
553 lpfc_sli_hbqbuf_free_all(struct lpfc_hba
*phba
)
555 struct lpfc_dmabuf
*dmabuf
, *next_dmabuf
;
556 struct hbq_dmabuf
*hbq_buf
;
559 hbq_count
= lpfc_sli_hbq_count();
560 /* Return all memory used by all HBQs */
561 for (i
= 0; i
< hbq_count
; ++i
) {
562 list_for_each_entry_safe(dmabuf
, next_dmabuf
,
563 &phba
->hbqs
[i
].hbq_buffer_list
, list
) {
564 hbq_buf
= container_of(dmabuf
, struct hbq_dmabuf
, dbuf
);
565 list_del(&hbq_buf
->dbuf
.list
);
566 (phba
->hbqs
[i
].hbq_free_buffer
)(phba
, hbq_buf
);
571 static struct lpfc_hbq_entry
*
572 lpfc_sli_hbq_to_firmware(struct lpfc_hba
*phba
, uint32_t hbqno
,
573 struct hbq_dmabuf
*hbq_buf
)
575 struct lpfc_hbq_entry
*hbqe
;
576 dma_addr_t physaddr
= hbq_buf
->dbuf
.phys
;
578 /* Get next HBQ entry slot to use */
579 hbqe
= lpfc_sli_next_hbq_slot(phba
, hbqno
);
581 struct hbq_s
*hbqp
= &phba
->hbqs
[hbqno
];
583 hbqe
->bde
.addrHigh
= le32_to_cpu(putPaddrHigh(physaddr
));
584 hbqe
->bde
.addrLow
= le32_to_cpu(putPaddrLow(physaddr
));
585 hbqe
->bde
.tus
.f
.bdeSize
= hbq_buf
->size
;
586 hbqe
->bde
.tus
.f
.bdeFlags
= 0;
587 hbqe
->bde
.tus
.w
= le32_to_cpu(hbqe
->bde
.tus
.w
);
588 hbqe
->buffer_tag
= le32_to_cpu(hbq_buf
->tag
);
590 hbqp
->hbqPutIdx
= hbqp
->next_hbqPutIdx
;
591 writel(hbqp
->hbqPutIdx
, phba
->hbq_put
+ hbqno
);
593 readl(phba
->hbq_put
+ hbqno
);
594 list_add_tail(&hbq_buf
->dbuf
.list
, &hbqp
->hbq_buffer_list
);
599 static struct lpfc_hbq_init lpfc_els_hbq
= {
604 .ring_mask
= (1 << LPFC_ELS_RING
),
610 static struct lpfc_hbq_init lpfc_extra_hbq
= {
615 .ring_mask
= (1 << LPFC_EXTRA_RING
),
621 struct lpfc_hbq_init
*lpfc_hbq_defs
[] = {
627 lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba
*phba
, uint32_t hbqno
, uint32_t count
)
629 uint32_t i
, start
, end
;
630 struct hbq_dmabuf
*hbq_buffer
;
632 if (!phba
->hbqs
[hbqno
].hbq_alloc_buffer
) {
636 start
= lpfc_hbq_defs
[hbqno
]->buffer_count
;
637 end
= count
+ lpfc_hbq_defs
[hbqno
]->buffer_count
;
638 if (end
> lpfc_hbq_defs
[hbqno
]->entry_count
) {
639 end
= lpfc_hbq_defs
[hbqno
]->entry_count
;
642 /* Populate HBQ entries */
643 for (i
= start
; i
< end
; i
++) {
644 hbq_buffer
= (phba
->hbqs
[hbqno
].hbq_alloc_buffer
)(phba
);
647 hbq_buffer
->tag
= (i
| (hbqno
<< 16));
648 if (lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buffer
))
649 lpfc_hbq_defs
[hbqno
]->buffer_count
++;
651 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
657 lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
659 return(lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
660 lpfc_hbq_defs
[qno
]->add_count
));
664 lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
666 return(lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
667 lpfc_hbq_defs
[qno
]->init_count
));
671 lpfc_sli_hbqbuf_find(struct lpfc_hba
*phba
, uint32_t tag
)
673 struct lpfc_dmabuf
*d_buf
;
674 struct hbq_dmabuf
*hbq_buf
;
678 if (hbqno
>= LPFC_MAX_HBQS
)
681 list_for_each_entry(d_buf
, &phba
->hbqs
[hbqno
].hbq_buffer_list
, list
) {
682 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
683 if (hbq_buf
->tag
== tag
) {
687 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
| LOG_VPORT
,
688 "1803 Bad hbq tag. Data: x%x x%x\n",
689 tag
, lpfc_hbq_defs
[tag
>> 16]->buffer_count
);
694 lpfc_sli_free_hbq(struct lpfc_hba
*phba
, struct hbq_dmabuf
*hbq_buffer
)
699 hbqno
= hbq_buffer
->tag
>> 16;
700 if (!lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buffer
)) {
701 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
707 lpfc_sli_chk_mbx_command(uint8_t mbxCommand
)
711 switch (mbxCommand
) {
715 case MBX_RUN_BIU_DIAG
:
718 case MBX_CONFIG_LINK
:
719 case MBX_CONFIG_RING
:
721 case MBX_READ_CONFIG
:
722 case MBX_READ_RCONFIG
:
724 case MBX_READ_STATUS
:
728 case MBX_READ_LNK_STAT
:
730 case MBX_UNREG_LOGIN
:
733 case MBX_DUMP_MEMORY
:
734 case MBX_DUMP_CONTEXT
:
739 case MBX_DEL_LD_ENTRY
:
740 case MBX_RUN_PROGRAM
:
745 case MBX_CONFIG_FARP
:
748 case MBX_RUN_BIU_DIAG64
:
749 case MBX_CONFIG_PORT
:
750 case MBX_READ_SPARM64
:
752 case MBX_REG_LOGIN64
:
754 case MBX_FLASH_WR_ULA
:
756 case MBX_LOAD_EXP_ROM
:
769 lpfc_sli_wake_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
771 wait_queue_head_t
*pdone_q
;
772 unsigned long drvr_flag
;
775 * If pdone_q is empty, the driver thread gave up waiting and
778 pmboxq
->mbox_flag
|= LPFC_MBX_WAKE
;
779 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
780 pdone_q
= (wait_queue_head_t
*) pmboxq
->context1
;
782 wake_up_interruptible(pdone_q
);
783 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
788 lpfc_sli_def_mbox_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
790 struct lpfc_dmabuf
*mp
;
794 mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
797 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
802 * If a REG_LOGIN succeeded after node is destroyed or node
803 * is in re-discovery driver need to cleanup the RPI.
805 if (!(phba
->pport
->load_flag
& FC_UNLOADING
) &&
806 pmb
->mb
.mbxCommand
== MBX_REG_LOGIN64
&&
807 !pmb
->mb
.mbxStatus
) {
809 rpi
= pmb
->mb
.un
.varWords
[0];
810 lpfc_unreg_login(phba
, pmb
->mb
.un
.varRegLogin
.vpi
, rpi
, pmb
);
811 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
812 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
813 if (rc
!= MBX_NOT_FINISHED
)
817 mempool_free(pmb
, phba
->mbox_mem_pool
);
822 lpfc_sli_handle_mb_event(struct lpfc_hba
*phba
)
829 phba
->sli
.slistat
.mbox_event
++;
831 /* Get all completed mailboxe buffers into the cmplq */
832 spin_lock_irq(&phba
->hbalock
);
833 list_splice_init(&phba
->sli
.mboxq_cmpl
, &cmplq
);
834 spin_unlock_irq(&phba
->hbalock
);
836 /* Get a Mailbox buffer to setup mailbox commands for callback */
838 list_remove_head(&cmplq
, pmb
, LPFC_MBOXQ_t
, list
);
844 if (pmbox
->mbxCommand
!= MBX_HEARTBEAT
) {
846 lpfc_debugfs_disc_trc(pmb
->vport
,
847 LPFC_DISC_TRC_MBOX_VPORT
,
848 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
849 (uint32_t)pmbox
->mbxCommand
,
850 pmbox
->un
.varWords
[0],
851 pmbox
->un
.varWords
[1]);
854 lpfc_debugfs_disc_trc(phba
->pport
,
856 "MBOX cmpl: cmd:x%x mb:x%x x%x",
857 (uint32_t)pmbox
->mbxCommand
,
858 pmbox
->un
.varWords
[0],
859 pmbox
->un
.varWords
[1]);
864 * It is a fatal error if unknown mbox command completion.
866 if (lpfc_sli_chk_mbx_command(pmbox
->mbxCommand
) ==
868 /* Unknow mailbox command compl */
869 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
870 "(%d):0323 Unknown Mailbox command "
872 pmb
->vport
? pmb
->vport
->vpi
: 0,
874 phba
->link_state
= LPFC_HBA_ERROR
;
875 phba
->work_hs
= HS_FFER3
;
876 lpfc_handle_eratt(phba
);
880 if (pmbox
->mbxStatus
) {
881 phba
->sli
.slistat
.mbox_stat_err
++;
882 if (pmbox
->mbxStatus
== MBXERR_NO_RESOURCES
) {
883 /* Mbox cmd cmpl error - RETRYing */
884 lpfc_printf_log(phba
, KERN_INFO
,
886 "(%d):0305 Mbox cmd cmpl "
887 "error - RETRYing Data: x%x "
889 pmb
->vport
? pmb
->vport
->vpi
:0,
892 pmbox
->un
.varWords
[0],
893 pmb
->vport
->port_state
);
894 pmbox
->mbxStatus
= 0;
895 pmbox
->mbxOwner
= OWN_HOST
;
896 spin_lock_irq(&phba
->hbalock
);
897 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
898 spin_unlock_irq(&phba
->hbalock
);
899 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
900 if (rc
== MBX_SUCCESS
)
905 /* Mailbox cmd <cmd> Cmpl <cmpl> */
906 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
907 "(%d):0307 Mailbox cmd x%x Cmpl x%p "
908 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
909 pmb
->vport
? pmb
->vport
->vpi
: 0,
912 *((uint32_t *) pmbox
),
913 pmbox
->un
.varWords
[0],
914 pmbox
->un
.varWords
[1],
915 pmbox
->un
.varWords
[2],
916 pmbox
->un
.varWords
[3],
917 pmbox
->un
.varWords
[4],
918 pmbox
->un
.varWords
[5],
919 pmbox
->un
.varWords
[6],
920 pmbox
->un
.varWords
[7]);
923 pmb
->mbox_cmpl(phba
,pmb
);
928 static struct lpfc_dmabuf
*
929 lpfc_sli_replace_hbqbuff(struct lpfc_hba
*phba
, uint32_t tag
)
931 struct hbq_dmabuf
*hbq_entry
, *new_hbq_entry
;
933 void *virt
; /* virtual address ptr */
934 dma_addr_t phys
; /* mapped address */
936 hbq_entry
= lpfc_sli_hbqbuf_find(phba
, tag
);
937 if (hbq_entry
== NULL
)
939 list_del(&hbq_entry
->dbuf
.list
);
942 new_hbq_entry
= (phba
->hbqs
[hbqno
].hbq_alloc_buffer
)(phba
);
943 if (new_hbq_entry
== NULL
)
944 return &hbq_entry
->dbuf
;
945 new_hbq_entry
->tag
= -1;
946 phys
= new_hbq_entry
->dbuf
.phys
;
947 virt
= new_hbq_entry
->dbuf
.virt
;
948 new_hbq_entry
->dbuf
.phys
= hbq_entry
->dbuf
.phys
;
949 new_hbq_entry
->dbuf
.virt
= hbq_entry
->dbuf
.virt
;
950 hbq_entry
->dbuf
.phys
= phys
;
951 hbq_entry
->dbuf
.virt
= virt
;
952 lpfc_sli_free_hbq(phba
, hbq_entry
);
953 return &new_hbq_entry
->dbuf
;
957 lpfc_sli_process_unsol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
958 struct lpfc_iocbq
*saveq
)
966 irsp
= &(saveq
->iocb
);
967 if ((irsp
->ulpCommand
== CMD_RCV_ELS_REQ64_CX
)
968 || (irsp
->ulpCommand
== CMD_RCV_ELS_REQ_CX
)
969 || (irsp
->ulpCommand
== CMD_IOCB_RCV_ELS64_CX
)
970 || (irsp
->ulpCommand
== CMD_IOCB_RCV_CONT64_CX
)) {
975 (WORD5
*) & (saveq
->iocb
.un
.
977 Rctl
= w5p
->hcsw
.Rctl
;
978 Type
= w5p
->hcsw
.Type
;
980 /* Firmware Workaround */
981 if ((Rctl
== 0) && (pring
->ringno
== LPFC_ELS_RING
) &&
982 (irsp
->ulpCommand
== CMD_RCV_SEQUENCE64_CX
||
983 irsp
->ulpCommand
== CMD_IOCB_RCV_SEQ64_CX
)) {
986 w5p
->hcsw
.Rctl
= Rctl
;
987 w5p
->hcsw
.Type
= Type
;
991 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
992 if (irsp
->ulpBdeCount
!= 0)
993 saveq
->context2
= lpfc_sli_replace_hbqbuff(phba
,
994 irsp
->un
.ulpWord
[3]);
995 if (irsp
->ulpBdeCount
== 2)
996 saveq
->context3
= lpfc_sli_replace_hbqbuff(phba
,
997 irsp
->unsli3
.sli3Words
[7]);
1000 /* unSolicited Responses */
1001 if (pring
->prt
[0].profile
) {
1002 if (pring
->prt
[0].lpfc_sli_rcv_unsol_event
)
1003 (pring
->prt
[0].lpfc_sli_rcv_unsol_event
) (phba
, pring
,
1007 /* We must search, based on rctl / type
1008 for the right routine */
1009 for (i
= 0; i
< pring
->num_mask
;
1011 if ((pring
->prt
[i
].rctl
==
1015 if (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
1016 (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
1017 (phba
, pring
, saveq
);
1024 /* Unexpected Rctl / Type received */
1025 /* Ring <ringno> handler: unexpected
1026 Rctl <Rctl> Type <Type> received */
1027 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
1028 "0313 Ring %d handler: unexpected Rctl x%x "
1029 "Type x%x received\n",
1030 pring
->ringno
, Rctl
, Type
);
1035 static struct lpfc_iocbq
*
1036 lpfc_sli_iocbq_lookup(struct lpfc_hba
*phba
,
1037 struct lpfc_sli_ring
*pring
,
1038 struct lpfc_iocbq
*prspiocb
)
1040 struct lpfc_iocbq
*cmd_iocb
= NULL
;
1043 iotag
= prspiocb
->iocb
.ulpIoTag
;
1045 if (iotag
!= 0 && iotag
<= phba
->sli
.last_iotag
) {
1046 cmd_iocb
= phba
->sli
.iocbq_lookup
[iotag
];
1047 list_del_init(&cmd_iocb
->list
);
1048 pring
->txcmplq_cnt
--;
1052 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
1053 "0317 iotag x%x is out off "
1054 "range: max iotag x%x wd0 x%x\n",
1055 iotag
, phba
->sli
.last_iotag
,
1056 *(((uint32_t *) &prspiocb
->iocb
) + 7));
1061 lpfc_sli_process_sol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1062 struct lpfc_iocbq
*saveq
)
1064 struct lpfc_iocbq
*cmdiocbp
;
1066 unsigned long iflag
;
1068 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
1069 spin_lock_irqsave(&phba
->hbalock
, iflag
);
1070 cmdiocbp
= lpfc_sli_iocbq_lookup(phba
, pring
, saveq
);
1071 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1074 if (cmdiocbp
->iocb_cmpl
) {
1076 * Post all ELS completions to the worker thread.
1077 * All other are passed to the completion callback.
1079 if (pring
->ringno
== LPFC_ELS_RING
) {
1080 if (cmdiocbp
->iocb_flag
& LPFC_DRIVER_ABORTED
) {
1081 cmdiocbp
->iocb_flag
&=
1082 ~LPFC_DRIVER_ABORTED
;
1083 saveq
->iocb
.ulpStatus
=
1084 IOSTAT_LOCAL_REJECT
;
1085 saveq
->iocb
.un
.ulpWord
[4] =
1089 (cmdiocbp
->iocb_cmpl
) (phba
, cmdiocbp
, saveq
);
1091 lpfc_sli_release_iocbq(phba
, cmdiocbp
);
1094 * Unknown initiating command based on the response iotag.
1095 * This could be the case on the ELS ring because of
1098 if (pring
->ringno
!= LPFC_ELS_RING
) {
1100 * Ring <ringno> handler: unexpected completion IoTag
1103 lpfc_printf_vlog(cmdiocbp
->vport
, KERN_WARNING
, LOG_SLI
,
1104 "0322 Ring %d handler: "
1105 "unexpected completion IoTag x%x "
1106 "Data: x%x x%x x%x x%x\n",
1108 saveq
->iocb
.ulpIoTag
,
1109 saveq
->iocb
.ulpStatus
,
1110 saveq
->iocb
.un
.ulpWord
[4],
1111 saveq
->iocb
.ulpCommand
,
1112 saveq
->iocb
.ulpContext
);
1120 lpfc_sli_rsp_pointers_error(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1122 struct lpfc_pgp
*pgp
= (phba
->sli_rev
== 3) ?
1123 &phba
->slim2p
->mbx
.us
.s3_pgp
.port
[pring
->ringno
] :
1124 &phba
->slim2p
->mbx
.us
.s2
.port
[pring
->ringno
];
1126 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
1127 * rsp ring <portRspMax>
1129 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
1130 "0312 Ring %d handler: portRspPut %d "
1131 "is bigger then rsp ring %d\n",
1132 pring
->ringno
, le32_to_cpu(pgp
->rspPutInx
),
1135 phba
->link_state
= LPFC_HBA_ERROR
;
1138 * All error attention handlers are posted to
1141 phba
->work_ha
|= HA_ERATT
;
1142 phba
->work_hs
= HS_FFER3
;
1144 /* hbalock should already be held */
1145 if (phba
->work_wait
)
1146 lpfc_worker_wake_up(phba
);
1151 void lpfc_sli_poll_fcp_ring(struct lpfc_hba
*phba
)
1153 struct lpfc_sli
*psli
= &phba
->sli
;
1154 struct lpfc_sli_ring
*pring
= &psli
->ring
[LPFC_FCP_RING
];
1155 IOCB_t
*irsp
= NULL
;
1156 IOCB_t
*entry
= NULL
;
1157 struct lpfc_iocbq
*cmdiocbq
= NULL
;
1158 struct lpfc_iocbq rspiocbq
;
1159 struct lpfc_pgp
*pgp
;
1161 uint32_t portRspPut
, portRspMax
;
1163 uint32_t rsp_cmpl
= 0;
1165 unsigned long iflags
;
1167 pring
->stats
.iocb_event
++;
1169 pgp
= (phba
->sli_rev
== 3) ?
1170 &phba
->slim2p
->mbx
.us
.s3_pgp
.port
[pring
->ringno
] :
1171 &phba
->slim2p
->mbx
.us
.s2
.port
[pring
->ringno
];
1175 * The next available response entry should never exceed the maximum
1176 * entries. If it does, treat it as an adapter hardware error.
1178 portRspMax
= pring
->numRiocb
;
1179 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
1180 if (unlikely(portRspPut
>= portRspMax
)) {
1181 lpfc_sli_rsp_pointers_error(phba
, pring
);
1186 while (pring
->rspidx
!= portRspPut
) {
1187 entry
= lpfc_resp_iocb(phba
, pring
);
1188 if (++pring
->rspidx
>= portRspMax
)
1191 lpfc_sli_pcimem_bcopy((uint32_t *) entry
,
1192 (uint32_t *) &rspiocbq
.iocb
,
1193 phba
->iocb_rsp_size
);
1194 irsp
= &rspiocbq
.iocb
;
1195 type
= lpfc_sli_iocb_cmd_type(irsp
->ulpCommand
& CMD_IOCB_MASK
);
1196 pring
->stats
.iocb_rsp
++;
1199 if (unlikely(irsp
->ulpStatus
)) {
1200 /* Rsp ring <ringno> error: IOCB */
1201 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
1202 "0326 Rsp Ring %d error: IOCB Data: "
1203 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
1205 irsp
->un
.ulpWord
[0],
1206 irsp
->un
.ulpWord
[1],
1207 irsp
->un
.ulpWord
[2],
1208 irsp
->un
.ulpWord
[3],
1209 irsp
->un
.ulpWord
[4],
1210 irsp
->un
.ulpWord
[5],
1211 *(((uint32_t *) irsp
) + 6),
1212 *(((uint32_t *) irsp
) + 7));
1216 case LPFC_ABORT_IOCB
:
1219 * Idle exchange closed via ABTS from port. No iocb
1220 * resources need to be recovered.
1222 if (unlikely(irsp
->ulpCommand
== CMD_XRI_ABORTED_CX
)) {
1223 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
1224 "0314 IOCB cmd 0x%x "
1225 "processed. Skipping "
1231 spin_lock_irqsave(&phba
->hbalock
, iflags
);
1232 cmdiocbq
= lpfc_sli_iocbq_lookup(phba
, pring
,
1234 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
1235 if ((cmdiocbq
) && (cmdiocbq
->iocb_cmpl
)) {
1236 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
,
1241 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
1242 char adaptermsg
[LPFC_MAX_ADPTMSG
];
1243 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
1244 memcpy(&adaptermsg
[0], (uint8_t *) irsp
,
1246 dev_warn(&((phba
->pcidev
)->dev
),
1248 phba
->brd_no
, adaptermsg
);
1250 /* Unknown IOCB command */
1251 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
1252 "0321 Unknown IOCB command "
1253 "Data: x%x, x%x x%x x%x x%x\n",
1254 type
, irsp
->ulpCommand
,
1263 * The response IOCB has been processed. Update the ring
1264 * pointer in SLIM. If the port response put pointer has not
1265 * been updated, sync the pgp->rspPutInx and fetch the new port
1266 * response put pointer.
1268 writel(pring
->rspidx
, &phba
->host_gp
[pring
->ringno
].rspGetInx
);
1270 if (pring
->rspidx
== portRspPut
)
1271 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
1274 ha_copy
= readl(phba
->HAregaddr
);
1275 ha_copy
>>= (LPFC_FCP_RING
* 4);
1277 if ((rsp_cmpl
> 0) && (ha_copy
& HA_R0RE_REQ
)) {
1278 spin_lock_irqsave(&phba
->hbalock
, iflags
);
1279 pring
->stats
.iocb_rsp_full
++;
1280 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (LPFC_FCP_RING
* 4));
1281 writel(status
, phba
->CAregaddr
);
1282 readl(phba
->CAregaddr
);
1283 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
1285 if ((ha_copy
& HA_R0CE_RSP
) &&
1286 (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
1287 spin_lock_irqsave(&phba
->hbalock
, iflags
);
1288 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
1289 pring
->stats
.iocb_cmd_empty
++;
1291 /* Force update of the local copy of cmdGetInx */
1292 pring
->local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
1293 lpfc_sli_resume_iocb(phba
, pring
);
1295 if ((pring
->lpfc_sli_cmd_available
))
1296 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
1298 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
1305 * This routine presumes LPFC_FCP_RING handling and doesn't bother
1306 * to check it explicitly.
1309 lpfc_sli_handle_fast_ring_event(struct lpfc_hba
*phba
,
1310 struct lpfc_sli_ring
*pring
, uint32_t mask
)
1312 struct lpfc_pgp
*pgp
= (phba
->sli_rev
== 3) ?
1313 &phba
->slim2p
->mbx
.us
.s3_pgp
.port
[pring
->ringno
] :
1314 &phba
->slim2p
->mbx
.us
.s2
.port
[pring
->ringno
];
1315 IOCB_t
*irsp
= NULL
;
1316 IOCB_t
*entry
= NULL
;
1317 struct lpfc_iocbq
*cmdiocbq
= NULL
;
1318 struct lpfc_iocbq rspiocbq
;
1320 uint32_t portRspPut
, portRspMax
;
1322 lpfc_iocb_type type
;
1323 unsigned long iflag
;
1324 uint32_t rsp_cmpl
= 0;
1326 spin_lock_irqsave(&phba
->hbalock
, iflag
);
1327 pring
->stats
.iocb_event
++;
1330 * The next available response entry should never exceed the maximum
1331 * entries. If it does, treat it as an adapter hardware error.
1333 portRspMax
= pring
->numRiocb
;
1334 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
1335 if (unlikely(portRspPut
>= portRspMax
)) {
1336 lpfc_sli_rsp_pointers_error(phba
, pring
);
1337 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1342 while (pring
->rspidx
!= portRspPut
) {
1344 * Fetch an entry off the ring and copy it into a local data
1345 * structure. The copy involves a byte-swap since the
1346 * network byte order and pci byte orders are different.
1348 entry
= lpfc_resp_iocb(phba
, pring
);
1349 phba
->last_completion_time
= jiffies
;
1351 if (++pring
->rspidx
>= portRspMax
)
1354 lpfc_sli_pcimem_bcopy((uint32_t *) entry
,
1355 (uint32_t *) &rspiocbq
.iocb
,
1356 phba
->iocb_rsp_size
);
1357 INIT_LIST_HEAD(&(rspiocbq
.list
));
1358 irsp
= &rspiocbq
.iocb
;
1360 type
= lpfc_sli_iocb_cmd_type(irsp
->ulpCommand
& CMD_IOCB_MASK
);
1361 pring
->stats
.iocb_rsp
++;
1364 if (unlikely(irsp
->ulpStatus
)) {
1366 * If resource errors reported from HBA, reduce
1367 * queuedepths of the SCSI device.
1369 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
1370 (irsp
->un
.ulpWord
[4] == IOERR_NO_RESOURCES
)) {
1371 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1372 lpfc_adjust_queue_depth(phba
);
1373 spin_lock_irqsave(&phba
->hbalock
, iflag
);
1376 /* Rsp ring <ringno> error: IOCB */
1377 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
1378 "0336 Rsp Ring %d error: IOCB Data: "
1379 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
1381 irsp
->un
.ulpWord
[0],
1382 irsp
->un
.ulpWord
[1],
1383 irsp
->un
.ulpWord
[2],
1384 irsp
->un
.ulpWord
[3],
1385 irsp
->un
.ulpWord
[4],
1386 irsp
->un
.ulpWord
[5],
1387 *(((uint32_t *) irsp
) + 6),
1388 *(((uint32_t *) irsp
) + 7));
1392 case LPFC_ABORT_IOCB
:
1395 * Idle exchange closed via ABTS from port. No iocb
1396 * resources need to be recovered.
1398 if (unlikely(irsp
->ulpCommand
== CMD_XRI_ABORTED_CX
)) {
1399 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
1400 "0333 IOCB cmd 0x%x"
1401 " processed. Skipping"
1407 cmdiocbq
= lpfc_sli_iocbq_lookup(phba
, pring
,
1409 if ((cmdiocbq
) && (cmdiocbq
->iocb_cmpl
)) {
1410 if (phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) {
1411 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
,
1414 spin_unlock_irqrestore(&phba
->hbalock
,
1416 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
,
1418 spin_lock_irqsave(&phba
->hbalock
,
1423 case LPFC_UNSOL_IOCB
:
1424 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1425 lpfc_sli_process_unsol_iocb(phba
, pring
, &rspiocbq
);
1426 spin_lock_irqsave(&phba
->hbalock
, iflag
);
1429 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
1430 char adaptermsg
[LPFC_MAX_ADPTMSG
];
1431 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
1432 memcpy(&adaptermsg
[0], (uint8_t *) irsp
,
1434 dev_warn(&((phba
->pcidev
)->dev
),
1436 phba
->brd_no
, adaptermsg
);
1438 /* Unknown IOCB command */
1439 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
1440 "0334 Unknown IOCB command "
1441 "Data: x%x, x%x x%x x%x x%x\n",
1442 type
, irsp
->ulpCommand
,
1451 * The response IOCB has been processed. Update the ring
1452 * pointer in SLIM. If the port response put pointer has not
1453 * been updated, sync the pgp->rspPutInx and fetch the new port
1454 * response put pointer.
1456 writel(pring
->rspidx
, &phba
->host_gp
[pring
->ringno
].rspGetInx
);
1458 if (pring
->rspidx
== portRspPut
)
1459 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
1462 if ((rsp_cmpl
> 0) && (mask
& HA_R0RE_REQ
)) {
1463 pring
->stats
.iocb_rsp_full
++;
1464 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
1465 writel(status
, phba
->CAregaddr
);
1466 readl(phba
->CAregaddr
);
1468 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
1469 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
1470 pring
->stats
.iocb_cmd_empty
++;
1472 /* Force update of the local copy of cmdGetInx */
1473 pring
->local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
1474 lpfc_sli_resume_iocb(phba
, pring
);
1476 if ((pring
->lpfc_sli_cmd_available
))
1477 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
1481 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1486 lpfc_sli_handle_slow_ring_event(struct lpfc_hba
*phba
,
1487 struct lpfc_sli_ring
*pring
, uint32_t mask
)
1489 struct lpfc_pgp
*pgp
= (phba
->sli_rev
== 3) ?
1490 &phba
->slim2p
->mbx
.us
.s3_pgp
.port
[pring
->ringno
] :
1491 &phba
->slim2p
->mbx
.us
.s2
.port
[pring
->ringno
];
1493 IOCB_t
*irsp
= NULL
;
1494 struct lpfc_iocbq
*rspiocbp
= NULL
;
1495 struct lpfc_iocbq
*next_iocb
;
1496 struct lpfc_iocbq
*cmdiocbp
;
1497 struct lpfc_iocbq
*saveq
;
1498 uint8_t iocb_cmd_type
;
1499 lpfc_iocb_type type
;
1500 uint32_t status
, free_saveq
;
1501 uint32_t portRspPut
, portRspMax
;
1503 unsigned long iflag
;
1505 spin_lock_irqsave(&phba
->hbalock
, iflag
);
1506 pring
->stats
.iocb_event
++;
1509 * The next available response entry should never exceed the maximum
1510 * entries. If it does, treat it as an adapter hardware error.
1512 portRspMax
= pring
->numRiocb
;
1513 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
1514 if (portRspPut
>= portRspMax
) {
1516 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
1517 * rsp ring <portRspMax>
1519 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
1520 "0303 Ring %d handler: portRspPut %d "
1521 "is bigger then rsp ring %d\n",
1522 pring
->ringno
, portRspPut
, portRspMax
);
1524 phba
->link_state
= LPFC_HBA_ERROR
;
1525 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1527 phba
->work_hs
= HS_FFER3
;
1528 lpfc_handle_eratt(phba
);
1534 while (pring
->rspidx
!= portRspPut
) {
1536 * Build a completion list and call the appropriate handler.
1537 * The process is to get the next available response iocb, get
1538 * a free iocb from the list, copy the response data into the
1539 * free iocb, insert to the continuation list, and update the
1540 * next response index to slim. This process makes response
1541 * iocb's in the ring available to DMA as fast as possible but
1542 * pays a penalty for a copy operation. Since the iocb is
1543 * only 32 bytes, this penalty is considered small relative to
1544 * the PCI reads for register values and a slim write. When
1545 * the ulpLe field is set, the entire Command has been
1548 entry
= lpfc_resp_iocb(phba
, pring
);
1550 phba
->last_completion_time
= jiffies
;
1551 rspiocbp
= __lpfc_sli_get_iocbq(phba
);
1552 if (rspiocbp
== NULL
) {
1553 printk(KERN_ERR
"%s: out of buffers! Failing "
1554 "completion.\n", __FUNCTION__
);
1558 lpfc_sli_pcimem_bcopy(entry
, &rspiocbp
->iocb
,
1559 phba
->iocb_rsp_size
);
1560 irsp
= &rspiocbp
->iocb
;
1562 if (++pring
->rspidx
>= portRspMax
)
1565 if (pring
->ringno
== LPFC_ELS_RING
) {
1566 lpfc_debugfs_slow_ring_trc(phba
,
1567 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
1568 *(((uint32_t *) irsp
) + 4),
1569 *(((uint32_t *) irsp
) + 6),
1570 *(((uint32_t *) irsp
) + 7));
1573 writel(pring
->rspidx
, &phba
->host_gp
[pring
->ringno
].rspGetInx
);
1575 if (list_empty(&(pring
->iocb_continueq
))) {
1576 list_add(&rspiocbp
->list
, &(pring
->iocb_continueq
));
1578 list_add_tail(&rspiocbp
->list
,
1579 &(pring
->iocb_continueq
));
1582 pring
->iocb_continueq_cnt
++;
1585 * By default, the driver expects to free all resources
1586 * associated with this iocb completion.
1589 saveq
= list_get_first(&pring
->iocb_continueq
,
1590 struct lpfc_iocbq
, list
);
1591 irsp
= &(saveq
->iocb
);
1592 list_del_init(&pring
->iocb_continueq
);
1593 pring
->iocb_continueq_cnt
= 0;
1595 pring
->stats
.iocb_rsp
++;
1598 * If resource errors reported from HBA, reduce
1599 * queuedepths of the SCSI device.
1601 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
1602 (irsp
->un
.ulpWord
[4] == IOERR_NO_RESOURCES
)) {
1603 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1604 lpfc_adjust_queue_depth(phba
);
1605 spin_lock_irqsave(&phba
->hbalock
, iflag
);
1608 if (irsp
->ulpStatus
) {
1609 /* Rsp ring <ringno> error: IOCB */
1610 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
1611 "0328 Rsp Ring %d error: "
1616 "x%x x%x x%x x%x\n",
1618 irsp
->un
.ulpWord
[0],
1619 irsp
->un
.ulpWord
[1],
1620 irsp
->un
.ulpWord
[2],
1621 irsp
->un
.ulpWord
[3],
1622 irsp
->un
.ulpWord
[4],
1623 irsp
->un
.ulpWord
[5],
1624 *(((uint32_t *) irsp
) + 6),
1625 *(((uint32_t *) irsp
) + 7),
1626 *(((uint32_t *) irsp
) + 8),
1627 *(((uint32_t *) irsp
) + 9),
1628 *(((uint32_t *) irsp
) + 10),
1629 *(((uint32_t *) irsp
) + 11),
1630 *(((uint32_t *) irsp
) + 12),
1631 *(((uint32_t *) irsp
) + 13),
1632 *(((uint32_t *) irsp
) + 14),
1633 *(((uint32_t *) irsp
) + 15));
1637 * Fetch the IOCB command type and call the correct
1638 * completion routine. Solicited and Unsolicited
1639 * IOCBs on the ELS ring get freed back to the
1640 * lpfc_iocb_list by the discovery kernel thread.
1642 iocb_cmd_type
= irsp
->ulpCommand
& CMD_IOCB_MASK
;
1643 type
= lpfc_sli_iocb_cmd_type(iocb_cmd_type
);
1644 if (type
== LPFC_SOL_IOCB
) {
1645 spin_unlock_irqrestore(&phba
->hbalock
,
1647 rc
= lpfc_sli_process_sol_iocb(phba
, pring
,
1649 spin_lock_irqsave(&phba
->hbalock
, iflag
);
1650 } else if (type
== LPFC_UNSOL_IOCB
) {
1651 spin_unlock_irqrestore(&phba
->hbalock
,
1653 rc
= lpfc_sli_process_unsol_iocb(phba
, pring
,
1655 spin_lock_irqsave(&phba
->hbalock
, iflag
);
1656 } else if (type
== LPFC_ABORT_IOCB
) {
1657 if ((irsp
->ulpCommand
!= CMD_XRI_ABORTED_CX
) &&
1659 lpfc_sli_iocbq_lookup(phba
, pring
,
1661 /* Call the specified completion
1663 if (cmdiocbp
->iocb_cmpl
) {
1664 spin_unlock_irqrestore(
1667 (cmdiocbp
->iocb_cmpl
) (phba
,
1673 __lpfc_sli_release_iocbq(phba
,
1676 } else if (type
== LPFC_UNKNOWN_IOCB
) {
1677 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
1679 char adaptermsg
[LPFC_MAX_ADPTMSG
];
1681 memset(adaptermsg
, 0,
1683 memcpy(&adaptermsg
[0], (uint8_t *) irsp
,
1685 dev_warn(&((phba
->pcidev
)->dev
),
1687 phba
->brd_no
, adaptermsg
);
1689 /* Unknown IOCB command */
1690 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
1691 "0335 Unknown IOCB "
1692 "command Data: x%x "
1702 list_for_each_entry_safe(rspiocbp
, next_iocb
,
1703 &saveq
->list
, list
) {
1704 list_del(&rspiocbp
->list
);
1705 __lpfc_sli_release_iocbq(phba
,
1708 __lpfc_sli_release_iocbq(phba
, saveq
);
1714 * If the port response put pointer has not been updated, sync
1715 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
1716 * response put pointer.
1718 if (pring
->rspidx
== portRspPut
) {
1719 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
1721 } /* while (pring->rspidx != portRspPut) */
1723 if ((rspiocbp
!= NULL
) && (mask
& HA_R0RE_REQ
)) {
1724 /* At least one response entry has been freed */
1725 pring
->stats
.iocb_rsp_full
++;
1726 /* SET RxRE_RSP in Chip Att register */
1727 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
1728 writel(status
, phba
->CAregaddr
);
1729 readl(phba
->CAregaddr
); /* flush */
1731 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
1732 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
1733 pring
->stats
.iocb_cmd_empty
++;
1735 /* Force update of the local copy of cmdGetInx */
1736 pring
->local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
1737 lpfc_sli_resume_iocb(phba
, pring
);
1739 if ((pring
->lpfc_sli_cmd_available
))
1740 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
1744 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1749 lpfc_sli_abort_iocb_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1751 LIST_HEAD(completions
);
1752 struct lpfc_iocbq
*iocb
, *next_iocb
;
1755 if (pring
->ringno
== LPFC_ELS_RING
) {
1756 lpfc_fabric_abort_hba(phba
);
1759 /* Error everything on txq and txcmplq
1762 spin_lock_irq(&phba
->hbalock
);
1763 list_splice_init(&pring
->txq
, &completions
);
1766 /* Next issue ABTS for everything on the txcmplq */
1767 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
)
1768 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
1770 spin_unlock_irq(&phba
->hbalock
);
1772 while (!list_empty(&completions
)) {
1773 iocb
= list_get_first(&completions
, struct lpfc_iocbq
, list
);
1775 list_del_init(&iocb
->list
);
1777 if (!iocb
->iocb_cmpl
)
1778 lpfc_sli_release_iocbq(phba
, iocb
);
1780 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
1781 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
1782 (iocb
->iocb_cmpl
) (phba
, iocb
, iocb
);
1788 lpfc_sli_brdready(struct lpfc_hba
*phba
, uint32_t mask
)
1794 /* Read the HBA Host Status Register */
1795 status
= readl(phba
->HSregaddr
);
1798 * Check status register every 100ms for 5 retries, then every
1799 * 500ms for 5, then every 2.5 sec for 5, then reset board and
1800 * every 2.5 sec for 4.
1801 * Break our of the loop if errors occurred during init.
1803 while (((status
& mask
) != mask
) &&
1804 !(status
& HS_FFERM
) &&
1816 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
1817 lpfc_sli_brdrestart(phba
);
1819 /* Read the HBA Host Status Register */
1820 status
= readl(phba
->HSregaddr
);
1823 /* Check to see if any errors occurred during init */
1824 if ((status
& HS_FFERM
) || (i
>= 20)) {
1825 phba
->link_state
= LPFC_HBA_ERROR
;
1832 #define BARRIER_TEST_PATTERN (0xdeadbeef)
1834 void lpfc_reset_barrier(struct lpfc_hba
*phba
)
1836 uint32_t __iomem
*resp_buf
;
1837 uint32_t __iomem
*mbox_buf
;
1838 volatile uint32_t mbox
;
1843 pci_read_config_byte(phba
->pcidev
, PCI_HEADER_TYPE
, &hdrtype
);
1844 if (hdrtype
!= 0x80 ||
1845 (FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != HELIOS_JEDEC_ID
&&
1846 FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != THOR_JEDEC_ID
))
1850 * Tell the other part of the chip to suspend temporarily all
1853 resp_buf
= phba
->MBslimaddr
;
1855 /* Disable the error attention */
1856 hc_copy
= readl(phba
->HCregaddr
);
1857 writel((hc_copy
& ~HC_ERINT_ENA
), phba
->HCregaddr
);
1858 readl(phba
->HCregaddr
); /* flush */
1859 phba
->link_flag
|= LS_IGNORE_ERATT
;
1861 if (readl(phba
->HAregaddr
) & HA_ERATT
) {
1862 /* Clear Chip error bit */
1863 writel(HA_ERATT
, phba
->HAregaddr
);
1864 phba
->pport
->stopped
= 1;
1868 ((MAILBOX_t
*)&mbox
)->mbxCommand
= MBX_KILL_BOARD
;
1869 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_CHIP
;
1871 writel(BARRIER_TEST_PATTERN
, (resp_buf
+ 1));
1872 mbox_buf
= phba
->MBslimaddr
;
1873 writel(mbox
, mbox_buf
);
1876 readl(resp_buf
+ 1) != ~(BARRIER_TEST_PATTERN
) && i
< 50; i
++)
1879 if (readl(resp_buf
+ 1) != ~(BARRIER_TEST_PATTERN
)) {
1880 if (phba
->sli
.sli_flag
& LPFC_SLI2_ACTIVE
||
1881 phba
->pport
->stopped
)
1887 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_HOST
;
1888 for (i
= 0; readl(resp_buf
) != mbox
&& i
< 500; i
++)
1893 while (!(readl(phba
->HAregaddr
) & HA_ERATT
) && ++i
< 500)
1896 if (readl(phba
->HAregaddr
) & HA_ERATT
) {
1897 writel(HA_ERATT
, phba
->HAregaddr
);
1898 phba
->pport
->stopped
= 1;
1902 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
1903 writel(hc_copy
, phba
->HCregaddr
);
1904 readl(phba
->HCregaddr
); /* flush */
1908 lpfc_sli_brdkill(struct lpfc_hba
*phba
)
1910 struct lpfc_sli
*psli
;
1920 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
1921 "0329 Kill HBA Data: x%x x%x\n",
1922 phba
->pport
->port_state
, psli
->sli_flag
);
1924 if ((pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
,
1928 /* Disable the error attention */
1929 spin_lock_irq(&phba
->hbalock
);
1930 status
= readl(phba
->HCregaddr
);
1931 status
&= ~HC_ERINT_ENA
;
1932 writel(status
, phba
->HCregaddr
);
1933 readl(phba
->HCregaddr
); /* flush */
1934 phba
->link_flag
|= LS_IGNORE_ERATT
;
1935 spin_unlock_irq(&phba
->hbalock
);
1937 lpfc_kill_board(phba
, pmb
);
1938 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
1939 retval
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
1941 if (retval
!= MBX_SUCCESS
) {
1942 if (retval
!= MBX_BUSY
)
1943 mempool_free(pmb
, phba
->mbox_mem_pool
);
1944 spin_lock_irq(&phba
->hbalock
);
1945 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
1946 spin_unlock_irq(&phba
->hbalock
);
1950 psli
->sli_flag
&= ~LPFC_SLI2_ACTIVE
;
1952 mempool_free(pmb
, phba
->mbox_mem_pool
);
1954 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
1955 * attention every 100ms for 3 seconds. If we don't get ERATT after
1956 * 3 seconds we still set HBA_ERROR state because the status of the
1957 * board is now undefined.
1959 ha_copy
= readl(phba
->HAregaddr
);
1961 while ((i
++ < 30) && !(ha_copy
& HA_ERATT
)) {
1963 ha_copy
= readl(phba
->HAregaddr
);
1966 del_timer_sync(&psli
->mbox_tmo
);
1967 if (ha_copy
& HA_ERATT
) {
1968 writel(HA_ERATT
, phba
->HAregaddr
);
1969 phba
->pport
->stopped
= 1;
1971 spin_lock_irq(&phba
->hbalock
);
1972 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
1973 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
1974 spin_unlock_irq(&phba
->hbalock
);
1976 psli
->mbox_active
= NULL
;
1977 lpfc_hba_down_post(phba
);
1978 phba
->link_state
= LPFC_HBA_ERROR
;
1980 return ha_copy
& HA_ERATT
? 0 : 1;
1984 lpfc_sli_brdreset(struct lpfc_hba
*phba
)
1986 struct lpfc_sli
*psli
;
1987 struct lpfc_sli_ring
*pring
;
1994 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
1995 "0325 Reset HBA Data: x%x x%x\n",
1996 phba
->pport
->port_state
, psli
->sli_flag
);
1998 /* perform board reset */
1999 phba
->fc_eventTag
= 0;
2000 phba
->pport
->fc_myDID
= 0;
2001 phba
->pport
->fc_prevDID
= 0;
2003 /* Turn off parity checking and serr during the physical reset */
2004 pci_read_config_word(phba
->pcidev
, PCI_COMMAND
, &cfg_value
);
2005 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
,
2007 ~(PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
)));
2009 psli
->sli_flag
&= ~(LPFC_SLI2_ACTIVE
| LPFC_PROCESS_LA
);
2010 /* Now toggle INITFF bit in the Host Control Register */
2011 writel(HC_INITFF
, phba
->HCregaddr
);
2013 readl(phba
->HCregaddr
); /* flush */
2014 writel(0, phba
->HCregaddr
);
2015 readl(phba
->HCregaddr
); /* flush */
2017 /* Restore PCI cmd register */
2018 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, cfg_value
);
2020 /* Initialize relevant SLI info */
2021 for (i
= 0; i
< psli
->num_rings
; i
++) {
2022 pring
= &psli
->ring
[i
];
2025 pring
->next_cmdidx
= 0;
2026 pring
->local_getidx
= 0;
2028 pring
->missbufcnt
= 0;
2031 phba
->link_state
= LPFC_WARM_START
;
2036 lpfc_sli_brdrestart(struct lpfc_hba
*phba
)
2039 struct lpfc_sli
*psli
;
2041 volatile uint32_t word0
;
2042 void __iomem
*to_slim
;
2044 spin_lock_irq(&phba
->hbalock
);
2049 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
2050 "0337 Restart HBA Data: x%x x%x\n",
2051 phba
->pport
->port_state
, psli
->sli_flag
);
2054 mb
= (MAILBOX_t
*) &word0
;
2055 mb
->mbxCommand
= MBX_RESTART
;
2058 lpfc_reset_barrier(phba
);
2060 to_slim
= phba
->MBslimaddr
;
2061 writel(*(uint32_t *) mb
, to_slim
);
2062 readl(to_slim
); /* flush */
2064 /* Only skip post after fc_ffinit is completed */
2065 if (phba
->pport
->port_state
) {
2067 word0
= 1; /* This is really setting up word1 */
2070 word0
= 0; /* This is really setting up word1 */
2072 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
2073 writel(*(uint32_t *) mb
, to_slim
);
2074 readl(to_slim
); /* flush */
2076 lpfc_sli_brdreset(phba
);
2077 phba
->pport
->stopped
= 0;
2078 phba
->link_state
= LPFC_INIT_START
;
2080 spin_unlock_irq(&phba
->hbalock
);
2082 memset(&psli
->lnk_stat_offsets
, 0, sizeof(psli
->lnk_stat_offsets
));
2083 psli
->stats_start
= get_seconds();
2090 lpfc_hba_down_post(phba
);
2096 lpfc_sli_chipset_init(struct lpfc_hba
*phba
)
2098 uint32_t status
, i
= 0;
2100 /* Read the HBA Host Status Register */
2101 status
= readl(phba
->HSregaddr
);
2103 /* Check status register to see what current state is */
2105 while ((status
& (HS_FFRDY
| HS_MBRDY
)) != (HS_FFRDY
| HS_MBRDY
)) {
2107 /* Check every 100ms for 5 retries, then every 500ms for 5, then
2108 * every 2.5 sec for 5, then reset board and every 2.5 sec for
2112 /* Adapter failed to init, timeout, status reg
2114 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2115 "0436 Adapter failed to init, "
2116 "timeout, status reg x%x\n", status
);
2117 phba
->link_state
= LPFC_HBA_ERROR
;
2121 /* Check to see if any errors occurred during init */
2122 if (status
& HS_FFERM
) {
2123 /* ERROR: During chipset initialization */
2124 /* Adapter failed to init, chipset, status reg
2126 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2127 "0437 Adapter failed to init, "
2128 "chipset, status reg x%x\n", status
);
2129 phba
->link_state
= LPFC_HBA_ERROR
;
2135 } else if (i
<= 10) {
2143 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
2144 lpfc_sli_brdrestart(phba
);
2146 /* Read the HBA Host Status Register */
2147 status
= readl(phba
->HSregaddr
);
2150 /* Check to see if any errors occurred during init */
2151 if (status
& HS_FFERM
) {
2152 /* ERROR: During chipset initialization */
2153 /* Adapter failed to init, chipset, status reg <status> */
2154 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2155 "0438 Adapter failed to init, chipset, "
2156 "status reg x%x\n", status
);
2157 phba
->link_state
= LPFC_HBA_ERROR
;
2161 /* Clear all interrupt enable conditions */
2162 writel(0, phba
->HCregaddr
);
2163 readl(phba
->HCregaddr
); /* flush */
2165 /* setup host attn register */
2166 writel(0xffffffff, phba
->HAregaddr
);
2167 readl(phba
->HAregaddr
); /* flush */
2172 lpfc_sli_hbq_count(void)
2174 return ARRAY_SIZE(lpfc_hbq_defs
);
2178 lpfc_sli_hbq_entry_count(void)
2180 int hbq_count
= lpfc_sli_hbq_count();
2184 for (i
= 0; i
< hbq_count
; ++i
)
2185 count
+= lpfc_hbq_defs
[i
]->entry_count
;
2190 lpfc_sli_hbq_size(void)
2192 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry
);
2196 lpfc_sli_hbq_setup(struct lpfc_hba
*phba
)
2198 int hbq_count
= lpfc_sli_hbq_count();
2202 uint32_t hbq_entry_index
;
2204 /* Get a Mailbox buffer to setup mailbox
2205 * commands for HBA initialization
2207 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2214 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
2215 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
2217 hbq_entry_index
= 0;
2218 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
) {
2219 phba
->hbqs
[hbqno
].next_hbqPutIdx
= 0;
2220 phba
->hbqs
[hbqno
].hbqPutIdx
= 0;
2221 phba
->hbqs
[hbqno
].local_hbqGetIdx
= 0;
2222 phba
->hbqs
[hbqno
].entry_count
=
2223 lpfc_hbq_defs
[hbqno
]->entry_count
;
2224 lpfc_config_hbq(phba
, hbqno
, lpfc_hbq_defs
[hbqno
],
2225 hbq_entry_index
, pmb
);
2226 hbq_entry_index
+= phba
->hbqs
[hbqno
].entry_count
;
2228 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
2229 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
2230 mbxStatus <status>, ring <num> */
2232 lpfc_printf_log(phba
, KERN_ERR
,
2233 LOG_SLI
| LOG_VPORT
,
2234 "1805 Adapter failed to init. "
2235 "Data: x%x x%x x%x\n",
2237 pmbox
->mbxStatus
, hbqno
);
2239 phba
->link_state
= LPFC_HBA_ERROR
;
2240 mempool_free(pmb
, phba
->mbox_mem_pool
);
2244 phba
->hbq_count
= hbq_count
;
2246 mempool_free(pmb
, phba
->mbox_mem_pool
);
2248 /* Initially populate or replenish the HBQs */
2249 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
) {
2250 if (lpfc_sli_hbqbuf_init_hbqs(phba
, hbqno
))
2257 lpfc_do_config_port(struct lpfc_hba
*phba
, int sli_mode
)
2260 uint32_t resetcount
= 0, rc
= 0, done
= 0;
2262 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2264 phba
->link_state
= LPFC_HBA_ERROR
;
2268 phba
->sli_rev
= sli_mode
;
2269 while (resetcount
< 2 && !done
) {
2270 spin_lock_irq(&phba
->hbalock
);
2271 phba
->sli
.sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
2272 spin_unlock_irq(&phba
->hbalock
);
2273 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
2274 lpfc_sli_brdrestart(phba
);
2276 rc
= lpfc_sli_chipset_init(phba
);
2280 spin_lock_irq(&phba
->hbalock
);
2281 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
2282 spin_unlock_irq(&phba
->hbalock
);
2285 /* Call pre CONFIG_PORT mailbox command initialization. A
2286 * value of 0 means the call was successful. Any other
2287 * nonzero value is a failure, but if ERESTART is returned,
2288 * the driver may reset the HBA and try again.
2290 rc
= lpfc_config_port_prep(phba
);
2291 if (rc
== -ERESTART
) {
2292 phba
->link_state
= LPFC_LINK_UNKNOWN
;
2298 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
2299 lpfc_config_port(phba
, pmb
);
2300 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
2301 if (rc
!= MBX_SUCCESS
) {
2302 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2303 "0442 Adapter failed to init, mbxCmd x%x "
2304 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
2305 pmb
->mb
.mbxCommand
, pmb
->mb
.mbxStatus
, 0);
2306 spin_lock_irq(&phba
->hbalock
);
2307 phba
->sli
.sli_flag
&= ~LPFC_SLI2_ACTIVE
;
2308 spin_unlock_irq(&phba
->hbalock
);
2312 phba
->max_vpi
= (phba
->max_vpi
&&
2313 pmb
->mb
.un
.varCfgPort
.gmv
) != 0
2314 ? pmb
->mb
.un
.varCfgPort
.max_vpi
2321 goto do_prep_failed
;
2324 if ((pmb
->mb
.un
.varCfgPort
.sli_mode
== 3) &&
2325 (!pmb
->mb
.un
.varCfgPort
.cMA
)) {
2327 goto do_prep_failed
;
2332 mempool_free(pmb
, phba
->mbox_mem_pool
);
2337 lpfc_sli_hba_setup(struct lpfc_hba
*phba
)
2342 switch (lpfc_sli_mode
) {
2344 if (phba
->cfg_enable_npiv
) {
2345 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
2346 "1824 NPIV enabled: Override lpfc_sli_mode "
2347 "parameter (%d) to auto (0).\n",
2357 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
2358 "1819 Unrecognized lpfc_sli_mode "
2359 "parameter: %d.\n", lpfc_sli_mode
);
2364 rc
= lpfc_do_config_port(phba
, mode
);
2365 if (rc
&& lpfc_sli_mode
== 3)
2366 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
2367 "1820 Unable to select SLI-3. "
2368 "Not supported by adapter.\n");
2369 if (rc
&& mode
!= 2)
2370 rc
= lpfc_do_config_port(phba
, 2);
2372 goto lpfc_sli_hba_setup_error
;
2374 if (phba
->sli_rev
== 3) {
2375 phba
->iocb_cmd_size
= SLI3_IOCB_CMD_SIZE
;
2376 phba
->iocb_rsp_size
= SLI3_IOCB_RSP_SIZE
;
2377 phba
->sli3_options
|= LPFC_SLI3_ENABLED
;
2378 phba
->sli3_options
|= LPFC_SLI3_HBQ_ENABLED
;
2381 phba
->iocb_cmd_size
= SLI2_IOCB_CMD_SIZE
;
2382 phba
->iocb_rsp_size
= SLI2_IOCB_RSP_SIZE
;
2383 phba
->sli3_options
= 0;
2386 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
2387 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
2388 phba
->sli_rev
, phba
->max_vpi
);
2389 rc
= lpfc_sli_ring_map(phba
);
2392 goto lpfc_sli_hba_setup_error
;
2396 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
2397 rc
= lpfc_sli_hbq_setup(phba
);
2399 goto lpfc_sli_hba_setup_error
;
2402 phba
->sli
.sli_flag
|= LPFC_PROCESS_LA
;
2404 rc
= lpfc_config_port_post(phba
);
2406 goto lpfc_sli_hba_setup_error
;
2410 lpfc_sli_hba_setup_error
:
2411 phba
->link_state
= LPFC_HBA_ERROR
;
2412 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
2413 "0445 Firmware initialization failed\n");
2417 /*! lpfc_mbox_timeout
2421 * \param hba Pointer to per struct lpfc_hba structure
2422 * \param l1 Pointer to the driver's mailbox queue.
2428 * This routine handles mailbox timeout events at timer interrupt context.
2431 lpfc_mbox_timeout(unsigned long ptr
)
2433 struct lpfc_hba
*phba
= (struct lpfc_hba
*) ptr
;
2434 unsigned long iflag
;
2435 uint32_t tmo_posted
;
2437 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflag
);
2438 tmo_posted
= phba
->pport
->work_port_events
& WORKER_MBOX_TMO
;
2440 phba
->pport
->work_port_events
|= WORKER_MBOX_TMO
;
2441 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflag
);
2444 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2445 if (phba
->work_wait
)
2446 lpfc_worker_wake_up(phba
);
2447 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2452 lpfc_mbox_timeout_handler(struct lpfc_hba
*phba
)
2454 LPFC_MBOXQ_t
*pmbox
= phba
->sli
.mbox_active
;
2455 MAILBOX_t
*mb
= &pmbox
->mb
;
2456 struct lpfc_sli
*psli
= &phba
->sli
;
2457 struct lpfc_sli_ring
*pring
;
2459 if (!(phba
->pport
->work_port_events
& WORKER_MBOX_TMO
)) {
2463 /* Mbox cmd <mbxCommand> timeout */
2464 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
2465 "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
2467 phba
->pport
->port_state
,
2469 phba
->sli
.mbox_active
);
2471 /* Setting state unknown so lpfc_sli_abort_iocb_ring
2472 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
2473 * it to fail all oustanding SCSI IO.
2475 spin_lock_irq(&phba
->pport
->work_port_lock
);
2476 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
2477 spin_unlock_irq(&phba
->pport
->work_port_lock
);
2478 spin_lock_irq(&phba
->hbalock
);
2479 phba
->link_state
= LPFC_LINK_UNKNOWN
;
2480 phba
->pport
->fc_flag
|= FC_ESTABLISH_LINK
;
2481 psli
->sli_flag
&= ~LPFC_SLI2_ACTIVE
;
2482 spin_unlock_irq(&phba
->hbalock
);
2484 pring
= &psli
->ring
[psli
->fcp_ring
];
2485 lpfc_sli_abort_iocb_ring(phba
, pring
);
2487 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
2488 "0316 Resetting board due to mailbox timeout\n");
2490 * lpfc_offline calls lpfc_sli_hba_down which will clean up
2491 * on oustanding mailbox commands.
2493 lpfc_offline_prep(phba
);
2495 lpfc_sli_brdrestart(phba
);
2496 if (lpfc_online(phba
) == 0) /* Initialize the HBA */
2497 mod_timer(&phba
->fc_estabtmo
, jiffies
+ HZ
* 60);
2498 lpfc_unblock_mgmt_io(phba
);
2503 lpfc_sli_issue_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmbox
, uint32_t flag
)
2506 struct lpfc_sli
*psli
= &phba
->sli
;
2507 uint32_t status
, evtctr
;
2510 unsigned long drvr_flag
= 0;
2511 volatile uint32_t word0
, ldata
;
2512 void __iomem
*to_slim
;
2514 if (pmbox
->mbox_cmpl
&& pmbox
->mbox_cmpl
!= lpfc_sli_def_mbox_cmpl
&&
2515 pmbox
->mbox_cmpl
!= lpfc_sli_wake_mbox_wait
) {
2517 lpfc_printf_log(phba
, KERN_ERR
,
2518 LOG_MBOX
| LOG_VPORT
,
2519 "1806 Mbox x%x failed. No vport\n",
2520 pmbox
->mb
.mbxCommand
);
2522 return MBXERR_ERROR
;
2527 /* If the PCI channel is in offline state, do not post mbox. */
2528 if (unlikely(pci_channel_offline(phba
->pcidev
)))
2529 return MBX_NOT_FINISHED
;
2531 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
2536 status
= MBX_SUCCESS
;
2538 if (phba
->link_state
== LPFC_HBA_ERROR
) {
2539 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
2541 /* Mbox command <mbxCommand> cannot issue */
2542 LOG_MBOX_CANNOT_ISSUE_DATA(phba
, pmbox
, psli
, flag
)
2543 return MBX_NOT_FINISHED
;
2546 if (mb
->mbxCommand
!= MBX_KILL_BOARD
&& flag
& MBX_NOWAIT
&&
2547 !(readl(phba
->HCregaddr
) & HC_MBINT_ENA
)) {
2548 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
2549 LOG_MBOX_CANNOT_ISSUE_DATA(phba
, pmbox
, psli
, flag
)
2550 return MBX_NOT_FINISHED
;
2553 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
2554 /* Polling for a mbox command when another one is already active
2555 * is not allowed in SLI. Also, the driver must have established
2556 * SLI2 mode to queue and process multiple mbox commands.
2559 if (flag
& MBX_POLL
) {
2560 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
2562 /* Mbox command <mbxCommand> cannot issue */
2563 LOG_MBOX_CANNOT_ISSUE_DATA(phba
, pmbox
, psli
, flag
);
2564 return MBX_NOT_FINISHED
;
2567 if (!(psli
->sli_flag
& LPFC_SLI2_ACTIVE
)) {
2568 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
2569 /* Mbox command <mbxCommand> cannot issue */
2570 LOG_MBOX_CANNOT_ISSUE_DATA(phba
, pmbox
, psli
, flag
);
2571 return MBX_NOT_FINISHED
;
2574 /* Handle STOP IOCB processing flag. This is only meaningful
2575 * if we are not polling for mbox completion.
2577 if (flag
& MBX_STOP_IOCB
) {
2578 flag
&= ~MBX_STOP_IOCB
;
2579 /* Now flag each ring */
2580 for (i
= 0; i
< psli
->num_rings
; i
++) {
2581 /* If the ring is active, flag it */
2582 if (psli
->ring
[i
].cmdringaddr
) {
2583 psli
->ring
[i
].flag
|=
2589 /* Another mailbox command is still being processed, queue this
2590 * command to be processed later.
2592 lpfc_mbox_put(phba
, pmbox
);
2594 /* Mbox cmd issue - BUSY */
2595 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
2596 "(%d):0308 Mbox cmd issue - BUSY Data: "
2597 "x%x x%x x%x x%x\n",
2598 pmbox
->vport
? pmbox
->vport
->vpi
: 0xffffff,
2599 mb
->mbxCommand
, phba
->pport
->port_state
,
2600 psli
->sli_flag
, flag
);
2602 psli
->slistat
.mbox_busy
++;
2603 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
2606 lpfc_debugfs_disc_trc(pmbox
->vport
,
2607 LPFC_DISC_TRC_MBOX_VPORT
,
2608 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
2609 (uint32_t)mb
->mbxCommand
,
2610 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
2613 lpfc_debugfs_disc_trc(phba
->pport
,
2615 "MBOX Bsy: cmd:x%x mb:x%x x%x",
2616 (uint32_t)mb
->mbxCommand
,
2617 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
2623 /* Handle STOP IOCB processing flag. This is only meaningful
2624 * if we are not polling for mbox completion.
2626 if (flag
& MBX_STOP_IOCB
) {
2627 flag
&= ~MBX_STOP_IOCB
;
2628 if (flag
== MBX_NOWAIT
) {
2629 /* Now flag each ring */
2630 for (i
= 0; i
< psli
->num_rings
; i
++) {
2631 /* If the ring is active, flag it */
2632 if (psli
->ring
[i
].cmdringaddr
) {
2633 psli
->ring
[i
].flag
|=
2640 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
2642 /* If we are not polling, we MUST be in SLI2 mode */
2643 if (flag
!= MBX_POLL
) {
2644 if (!(psli
->sli_flag
& LPFC_SLI2_ACTIVE
) &&
2645 (mb
->mbxCommand
!= MBX_KILL_BOARD
)) {
2646 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
2647 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
2648 /* Mbox command <mbxCommand> cannot issue */
2649 LOG_MBOX_CANNOT_ISSUE_DATA(phba
, pmbox
, psli
, flag
);
2650 return MBX_NOT_FINISHED
;
2652 /* timeout active mbox command */
2653 mod_timer(&psli
->mbox_tmo
, (jiffies
+
2654 (HZ
* lpfc_mbox_tmo_val(phba
, mb
->mbxCommand
))));
2657 /* Mailbox cmd <cmd> issue */
2658 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
2659 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
2661 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
2662 mb
->mbxCommand
, phba
->pport
->port_state
,
2663 psli
->sli_flag
, flag
);
2665 if (mb
->mbxCommand
!= MBX_HEARTBEAT
) {
2667 lpfc_debugfs_disc_trc(pmbox
->vport
,
2668 LPFC_DISC_TRC_MBOX_VPORT
,
2669 "MBOX Send vport: cmd:x%x mb:x%x x%x",
2670 (uint32_t)mb
->mbxCommand
,
2671 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
2674 lpfc_debugfs_disc_trc(phba
->pport
,
2676 "MBOX Send: cmd:x%x mb:x%x x%x",
2677 (uint32_t)mb
->mbxCommand
,
2678 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
2682 psli
->slistat
.mbox_cmd
++;
2683 evtctr
= psli
->slistat
.mbox_event
;
2685 /* next set own bit for the adapter and copy over command word */
2686 mb
->mbxOwner
= OWN_CHIP
;
2688 if (psli
->sli_flag
& LPFC_SLI2_ACTIVE
) {
2689 /* First copy command data to host SLIM area */
2690 lpfc_sli_pcimem_bcopy(mb
, &phba
->slim2p
->mbx
, MAILBOX_CMD_SIZE
);
2692 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
2693 /* copy command data into host mbox for cmpl */
2694 lpfc_sli_pcimem_bcopy(mb
, &phba
->slim2p
->mbx
,
2698 /* First copy mbox command data to HBA SLIM, skip past first
2700 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
2701 lpfc_memcpy_to_slim(to_slim
, &mb
->un
.varWords
[0],
2702 MAILBOX_CMD_SIZE
- sizeof (uint32_t));
2704 /* Next copy over first word, with mbxOwner set */
2705 ldata
= *((volatile uint32_t *)mb
);
2706 to_slim
= phba
->MBslimaddr
;
2707 writel(ldata
, to_slim
);
2708 readl(to_slim
); /* flush */
2710 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
2711 /* switch over to host mailbox */
2712 psli
->sli_flag
|= LPFC_SLI2_ACTIVE
;
2717 /* interrupt board to doit right away */
2718 writel(CA_MBATT
, phba
->CAregaddr
);
2719 readl(phba
->CAregaddr
); /* flush */
2723 /* Don't wait for it to finish, just return */
2724 psli
->mbox_active
= pmbox
;
2728 psli
->mbox_active
= NULL
;
2729 if (psli
->sli_flag
& LPFC_SLI2_ACTIVE
) {
2730 /* First read mbox status word */
2731 word0
= *((volatile uint32_t *)&phba
->slim2p
->mbx
);
2732 word0
= le32_to_cpu(word0
);
2734 /* First read mbox status word */
2735 word0
= readl(phba
->MBslimaddr
);
2738 /* Read the HBA Host Attention Register */
2739 ha_copy
= readl(phba
->HAregaddr
);
2741 i
= lpfc_mbox_tmo_val(phba
, mb
->mbxCommand
);
2742 i
*= 1000; /* Convert to ms */
2744 /* Wait for command to complete */
2745 while (((word0
& OWN_CHIP
) == OWN_CHIP
) ||
2746 (!(ha_copy
& HA_MBATT
) &&
2747 (phba
->link_state
> LPFC_WARM_START
))) {
2749 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
2750 spin_unlock_irqrestore(&phba
->hbalock
,
2752 return MBX_NOT_FINISHED
;
2755 /* Check if we took a mbox interrupt while we were
2757 if (((word0
& OWN_CHIP
) != OWN_CHIP
)
2758 && (evtctr
!= psli
->slistat
.mbox_event
))
2761 spin_unlock_irqrestore(&phba
->hbalock
,
2766 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
2768 if (psli
->sli_flag
& LPFC_SLI2_ACTIVE
) {
2769 /* First copy command data */
2770 word0
= *((volatile uint32_t *)
2771 &phba
->slim2p
->mbx
);
2772 word0
= le32_to_cpu(word0
);
2773 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
2775 volatile uint32_t slimword0
;
2776 /* Check real SLIM for any errors */
2777 slimword0
= readl(phba
->MBslimaddr
);
2778 slimmb
= (MAILBOX_t
*) & slimword0
;
2779 if (((slimword0
& OWN_CHIP
) != OWN_CHIP
)
2780 && slimmb
->mbxStatus
) {
2787 /* First copy command data */
2788 word0
= readl(phba
->MBslimaddr
);
2790 /* Read the HBA Host Attention Register */
2791 ha_copy
= readl(phba
->HAregaddr
);
2794 if (psli
->sli_flag
& LPFC_SLI2_ACTIVE
) {
2795 /* copy results back to user */
2796 lpfc_sli_pcimem_bcopy(&phba
->slim2p
->mbx
, mb
,
2799 /* First copy command data */
2800 lpfc_memcpy_from_slim(mb
, phba
->MBslimaddr
,
2802 if ((mb
->mbxCommand
== MBX_DUMP_MEMORY
) &&
2804 lpfc_memcpy_from_slim((void *)pmbox
->context2
,
2805 phba
->MBslimaddr
+ DMP_RSP_OFFSET
,
2806 mb
->un
.varDmp
.word_cnt
);
2810 writel(HA_MBATT
, phba
->HAregaddr
);
2811 readl(phba
->HAregaddr
); /* flush */
2813 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
2814 status
= mb
->mbxStatus
;
2817 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
2822 * Caller needs to hold lock.
2825 __lpfc_sli_ringtx_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2826 struct lpfc_iocbq
*piocb
)
2828 /* Insert the caller's iocb in the txq tail for later processing. */
2829 list_add_tail(&piocb
->list
, &pring
->txq
);
2833 static struct lpfc_iocbq
*
2834 lpfc_sli_next_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2835 struct lpfc_iocbq
**piocb
)
2837 struct lpfc_iocbq
* nextiocb
;
2839 nextiocb
= lpfc_sli_ringtx_get(phba
, pring
);
2849 * Lockless version of lpfc_sli_issue_iocb.
2852 __lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2853 struct lpfc_iocbq
*piocb
, uint32_t flag
)
2855 struct lpfc_iocbq
*nextiocb
;
2858 if (piocb
->iocb_cmpl
&& (!piocb
->vport
) &&
2859 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
2860 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
2861 lpfc_printf_log(phba
, KERN_ERR
,
2862 LOG_SLI
| LOG_VPORT
,
2863 "1807 IOCB x%x failed. No vport\n",
2864 piocb
->iocb
.ulpCommand
);
2870 /* If the PCI channel is in offline state, do not post iocbs. */
2871 if (unlikely(pci_channel_offline(phba
->pcidev
)))
2875 * We should never get an IOCB if we are in a < LINK_DOWN state
2877 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
2881 * Check to see if we are blocking IOCB processing because of a
2882 * outstanding mbox command.
2884 if (unlikely(pring
->flag
& LPFC_STOP_IOCB_MBX
))
2887 if (unlikely(phba
->link_state
== LPFC_LINK_DOWN
)) {
2889 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
2890 * can be issued if the link is not up.
2892 switch (piocb
->iocb
.ulpCommand
) {
2893 case CMD_QUE_RING_BUF_CN
:
2894 case CMD_QUE_RING_BUF64_CN
:
2896 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
2897 * completion, iocb_cmpl MUST be 0.
2899 if (piocb
->iocb_cmpl
)
2900 piocb
->iocb_cmpl
= NULL
;
2902 case CMD_CREATE_XRI_CR
:
2903 case CMD_CLOSE_XRI_CN
:
2904 case CMD_CLOSE_XRI_CX
:
2911 * For FCP commands, we must be in a state where we can process link
2914 } else if (unlikely(pring
->ringno
== phba
->sli
.fcp_ring
&&
2915 !(phba
->sli
.sli_flag
& LPFC_PROCESS_LA
))) {
2919 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
2920 (nextiocb
= lpfc_sli_next_iocb(phba
, pring
, &piocb
)))
2921 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
2924 lpfc_sli_update_ring(phba
, pring
);
2926 lpfc_sli_update_full_ring(phba
, pring
);
2929 return IOCB_SUCCESS
;
2934 pring
->stats
.iocb_cmd_delay
++;
2938 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
2939 __lpfc_sli_ringtx_put(phba
, pring
, piocb
);
2940 return IOCB_SUCCESS
;
2948 lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2949 struct lpfc_iocbq
*piocb
, uint32_t flag
)
2951 unsigned long iflags
;
2954 spin_lock_irqsave(&phba
->hbalock
, iflags
);
2955 rc
= __lpfc_sli_issue_iocb(phba
, pring
, piocb
, flag
);
2956 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
2962 lpfc_extra_ring_setup( struct lpfc_hba
*phba
)
2964 struct lpfc_sli
*psli
;
2965 struct lpfc_sli_ring
*pring
;
2969 /* Adjust cmd/rsp ring iocb entries more evenly */
2971 /* Take some away from the FCP ring */
2972 pring
= &psli
->ring
[psli
->fcp_ring
];
2973 pring
->numCiocb
-= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
2974 pring
->numRiocb
-= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
2975 pring
->numCiocb
-= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
2976 pring
->numRiocb
-= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
2978 /* and give them to the extra ring */
2979 pring
= &psli
->ring
[psli
->extra_ring
];
2981 pring
->numCiocb
+= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
2982 pring
->numRiocb
+= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
2983 pring
->numCiocb
+= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
2984 pring
->numRiocb
+= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
2986 /* Setup default profile for this ring */
2987 pring
->iotag_max
= 4096;
2988 pring
->num_mask
= 1;
2989 pring
->prt
[0].profile
= 0; /* Mask 0 */
2990 pring
->prt
[0].rctl
= phba
->cfg_multi_ring_rctl
;
2991 pring
->prt
[0].type
= phba
->cfg_multi_ring_type
;
2992 pring
->prt
[0].lpfc_sli_rcv_unsol_event
= NULL
;
2997 lpfc_sli_setup(struct lpfc_hba
*phba
)
2999 int i
, totiocbsize
= 0;
3000 struct lpfc_sli
*psli
= &phba
->sli
;
3001 struct lpfc_sli_ring
*pring
;
3003 psli
->num_rings
= MAX_CONFIGURED_RINGS
;
3005 psli
->fcp_ring
= LPFC_FCP_RING
;
3006 psli
->next_ring
= LPFC_FCP_NEXT_RING
;
3007 psli
->extra_ring
= LPFC_EXTRA_RING
;
3009 psli
->iocbq_lookup
= NULL
;
3010 psli
->iocbq_lookup_len
= 0;
3011 psli
->last_iotag
= 0;
3013 for (i
= 0; i
< psli
->num_rings
; i
++) {
3014 pring
= &psli
->ring
[i
];
3016 case LPFC_FCP_RING
: /* ring 0 - FCP */
3017 /* numCiocb and numRiocb are used in config_port */
3018 pring
->numCiocb
= SLI2_IOCB_CMD_R0_ENTRIES
;
3019 pring
->numRiocb
= SLI2_IOCB_RSP_R0_ENTRIES
;
3020 pring
->numCiocb
+= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
3021 pring
->numRiocb
+= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
3022 pring
->numCiocb
+= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
3023 pring
->numRiocb
+= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
3024 pring
->sizeCiocb
= (phba
->sli_rev
== 3) ?
3025 SLI3_IOCB_CMD_SIZE
:
3027 pring
->sizeRiocb
= (phba
->sli_rev
== 3) ?
3028 SLI3_IOCB_RSP_SIZE
:
3030 pring
->iotag_ctr
= 0;
3032 (phba
->cfg_hba_queue_depth
* 2);
3033 pring
->fast_iotag
= pring
->iotag_max
;
3034 pring
->num_mask
= 0;
3036 case LPFC_EXTRA_RING
: /* ring 1 - EXTRA */
3037 /* numCiocb and numRiocb are used in config_port */
3038 pring
->numCiocb
= SLI2_IOCB_CMD_R1_ENTRIES
;
3039 pring
->numRiocb
= SLI2_IOCB_RSP_R1_ENTRIES
;
3040 pring
->sizeCiocb
= (phba
->sli_rev
== 3) ?
3041 SLI3_IOCB_CMD_SIZE
:
3043 pring
->sizeRiocb
= (phba
->sli_rev
== 3) ?
3044 SLI3_IOCB_RSP_SIZE
:
3046 pring
->iotag_max
= phba
->cfg_hba_queue_depth
;
3047 pring
->num_mask
= 0;
3049 case LPFC_ELS_RING
: /* ring 2 - ELS / CT */
3050 /* numCiocb and numRiocb are used in config_port */
3051 pring
->numCiocb
= SLI2_IOCB_CMD_R2_ENTRIES
;
3052 pring
->numRiocb
= SLI2_IOCB_RSP_R2_ENTRIES
;
3053 pring
->sizeCiocb
= (phba
->sli_rev
== 3) ?
3054 SLI3_IOCB_CMD_SIZE
:
3056 pring
->sizeRiocb
= (phba
->sli_rev
== 3) ?
3057 SLI3_IOCB_RSP_SIZE
:
3059 pring
->fast_iotag
= 0;
3060 pring
->iotag_ctr
= 0;
3061 pring
->iotag_max
= 4096;
3062 pring
->num_mask
= 4;
3063 pring
->prt
[0].profile
= 0; /* Mask 0 */
3064 pring
->prt
[0].rctl
= FC_ELS_REQ
;
3065 pring
->prt
[0].type
= FC_ELS_DATA
;
3066 pring
->prt
[0].lpfc_sli_rcv_unsol_event
=
3067 lpfc_els_unsol_event
;
3068 pring
->prt
[1].profile
= 0; /* Mask 1 */
3069 pring
->prt
[1].rctl
= FC_ELS_RSP
;
3070 pring
->prt
[1].type
= FC_ELS_DATA
;
3071 pring
->prt
[1].lpfc_sli_rcv_unsol_event
=
3072 lpfc_els_unsol_event
;
3073 pring
->prt
[2].profile
= 0; /* Mask 2 */
3074 /* NameServer Inquiry */
3075 pring
->prt
[2].rctl
= FC_UNSOL_CTL
;
3077 pring
->prt
[2].type
= FC_COMMON_TRANSPORT_ULP
;
3078 pring
->prt
[2].lpfc_sli_rcv_unsol_event
=
3079 lpfc_ct_unsol_event
;
3080 pring
->prt
[3].profile
= 0; /* Mask 3 */
3081 /* NameServer response */
3082 pring
->prt
[3].rctl
= FC_SOL_CTL
;
3084 pring
->prt
[3].type
= FC_COMMON_TRANSPORT_ULP
;
3085 pring
->prt
[3].lpfc_sli_rcv_unsol_event
=
3086 lpfc_ct_unsol_event
;
3089 totiocbsize
+= (pring
->numCiocb
* pring
->sizeCiocb
) +
3090 (pring
->numRiocb
* pring
->sizeRiocb
);
3092 if (totiocbsize
> MAX_SLIM_IOCB_SIZE
) {
3093 /* Too many cmd / rsp ring entries in SLI2 SLIM */
3094 printk(KERN_ERR
"%d:0462 Too many cmd / rsp ring entries in "
3095 "SLI2 SLIM Data: x%x x%lx\n",
3096 phba
->brd_no
, totiocbsize
,
3097 (unsigned long) MAX_SLIM_IOCB_SIZE
);
3099 if (phba
->cfg_multi_ring_support
== 2)
3100 lpfc_extra_ring_setup(phba
);
3106 lpfc_sli_queue_setup(struct lpfc_hba
*phba
)
3108 struct lpfc_sli
*psli
;
3109 struct lpfc_sli_ring
*pring
;
3113 spin_lock_irq(&phba
->hbalock
);
3114 INIT_LIST_HEAD(&psli
->mboxq
);
3115 INIT_LIST_HEAD(&psli
->mboxq_cmpl
);
3116 /* Initialize list headers for txq and txcmplq as double linked lists */
3117 for (i
= 0; i
< psli
->num_rings
; i
++) {
3118 pring
= &psli
->ring
[i
];
3120 pring
->next_cmdidx
= 0;
3121 pring
->local_getidx
= 0;
3123 INIT_LIST_HEAD(&pring
->txq
);
3124 INIT_LIST_HEAD(&pring
->txcmplq
);
3125 INIT_LIST_HEAD(&pring
->iocb_continueq
);
3126 INIT_LIST_HEAD(&pring
->postbufq
);
3128 spin_unlock_irq(&phba
->hbalock
);
3133 lpfc_sli_host_down(struct lpfc_vport
*vport
)
3135 LIST_HEAD(completions
);
3136 struct lpfc_hba
*phba
= vport
->phba
;
3137 struct lpfc_sli
*psli
= &phba
->sli
;
3138 struct lpfc_sli_ring
*pring
;
3139 struct lpfc_iocbq
*iocb
, *next_iocb
;
3141 unsigned long flags
= 0;
3142 uint16_t prev_pring_flag
;
3144 lpfc_cleanup_discovery_resources(vport
);
3146 spin_lock_irqsave(&phba
->hbalock
, flags
);
3147 for (i
= 0; i
< psli
->num_rings
; i
++) {
3148 pring
= &psli
->ring
[i
];
3149 prev_pring_flag
= pring
->flag
;
3150 if (pring
->ringno
== LPFC_ELS_RING
) /* Only slow rings */
3151 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
3153 * Error everything on the txq since these iocbs have not been
3154 * given to the FW yet.
3156 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
3157 if (iocb
->vport
!= vport
)
3159 list_move_tail(&iocb
->list
, &completions
);
3163 /* Next issue ABTS for everything on the txcmplq */
3164 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
,
3166 if (iocb
->vport
!= vport
)
3168 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
3171 pring
->flag
= prev_pring_flag
;
3174 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
3176 while (!list_empty(&completions
)) {
3177 list_remove_head(&completions
, iocb
, struct lpfc_iocbq
, list
);
3179 if (!iocb
->iocb_cmpl
)
3180 lpfc_sli_release_iocbq(phba
, iocb
);
3182 iocb
->iocb
.ulpStatus
= IOSTAT_LOCAL_REJECT
;
3183 iocb
->iocb
.un
.ulpWord
[4] = IOERR_SLI_DOWN
;
3184 (iocb
->iocb_cmpl
) (phba
, iocb
, iocb
);
3191 lpfc_sli_hba_down(struct lpfc_hba
*phba
)
3193 LIST_HEAD(completions
);
3194 struct lpfc_sli
*psli
= &phba
->sli
;
3195 struct lpfc_sli_ring
*pring
;
3197 struct lpfc_iocbq
*iocb
;
3200 unsigned long flags
= 0;
3202 lpfc_hba_down_prep(phba
);
3204 lpfc_fabric_abort_hba(phba
);
3206 spin_lock_irqsave(&phba
->hbalock
, flags
);
3207 for (i
= 0; i
< psli
->num_rings
; i
++) {
3208 pring
= &psli
->ring
[i
];
3209 if (pring
->ringno
== LPFC_ELS_RING
) /* Only slow rings */
3210 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
3213 * Error everything on the txq since these iocbs have not been
3214 * given to the FW yet.
3216 list_splice_init(&pring
->txq
, &completions
);
3220 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
3222 while (!list_empty(&completions
)) {
3223 list_remove_head(&completions
, iocb
, struct lpfc_iocbq
, list
);
3226 if (!iocb
->iocb_cmpl
)
3227 lpfc_sli_release_iocbq(phba
, iocb
);
3229 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
3230 cmd
->un
.ulpWord
[4] = IOERR_SLI_DOWN
;
3231 (iocb
->iocb_cmpl
) (phba
, iocb
, iocb
);
3235 /* Return any active mbox cmds */
3236 del_timer_sync(&psli
->mbox_tmo
);
3237 spin_lock_irqsave(&phba
->hbalock
, flags
);
3239 spin_lock(&phba
->pport
->work_port_lock
);
3240 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
3241 spin_unlock(&phba
->pport
->work_port_lock
);
3243 if (psli
->mbox_active
) {
3244 list_add_tail(&psli
->mbox_active
->list
, &completions
);
3245 psli
->mbox_active
= NULL
;
3246 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
3249 /* Return any pending or completed mbox cmds */
3250 list_splice_init(&phba
->sli
.mboxq
, &completions
);
3251 list_splice_init(&phba
->sli
.mboxq_cmpl
, &completions
);
3252 INIT_LIST_HEAD(&psli
->mboxq
);
3253 INIT_LIST_HEAD(&psli
->mboxq_cmpl
);
3255 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
3257 while (!list_empty(&completions
)) {
3258 list_remove_head(&completions
, pmb
, LPFC_MBOXQ_t
, list
);
3259 pmb
->mb
.mbxStatus
= MBX_NOT_FINISHED
;
3260 if (pmb
->mbox_cmpl
) {
3261 pmb
->mbox_cmpl(phba
,pmb
);
3268 lpfc_sli_pcimem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
3270 uint32_t *src
= srcp
;
3271 uint32_t *dest
= destp
;
3275 for (i
= 0; i
< (int)cnt
; i
+= sizeof (uint32_t)) {
3277 ldata
= le32_to_cpu(ldata
);
3285 lpfc_sli_ringpostbuf_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
3286 struct lpfc_dmabuf
*mp
)
3288 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
3290 spin_lock_irq(&phba
->hbalock
);
3291 list_add_tail(&mp
->list
, &pring
->postbufq
);
3292 pring
->postbufq_cnt
++;
3293 spin_unlock_irq(&phba
->hbalock
);
3298 struct lpfc_dmabuf
*
3299 lpfc_sli_ringpostbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
3302 struct lpfc_dmabuf
*mp
, *next_mp
;
3303 struct list_head
*slp
= &pring
->postbufq
;
3305 /* Search postbufq, from the begining, looking for a match on phys */
3306 spin_lock_irq(&phba
->hbalock
);
3307 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
3308 if (mp
->phys
== phys
) {
3309 list_del_init(&mp
->list
);
3310 pring
->postbufq_cnt
--;
3311 spin_unlock_irq(&phba
->hbalock
);
3316 spin_unlock_irq(&phba
->hbalock
);
3317 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3318 "0410 Cannot find virtual addr for mapped buf on "
3319 "ring %d Data x%llx x%p x%p x%x\n",
3320 pring
->ringno
, (unsigned long long)phys
,
3321 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
3326 lpfc_sli_abort_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
3327 struct lpfc_iocbq
*rspiocb
)
3329 IOCB_t
*irsp
= &rspiocb
->iocb
;
3330 uint16_t abort_iotag
, abort_context
;
3331 struct lpfc_iocbq
*abort_iocb
;
3332 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
3336 if (irsp
->ulpStatus
) {
3337 abort_context
= cmdiocb
->iocb
.un
.acxri
.abortContextTag
;
3338 abort_iotag
= cmdiocb
->iocb
.un
.acxri
.abortIoTag
;
3340 spin_lock_irq(&phba
->hbalock
);
3341 if (abort_iotag
!= 0 && abort_iotag
<= phba
->sli
.last_iotag
)
3342 abort_iocb
= phba
->sli
.iocbq_lookup
[abort_iotag
];
3344 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
| LOG_SLI
,
3345 "0327 Cannot abort els iocb %p "
3346 "with tag %x context %x, abort status %x, "
3348 abort_iocb
, abort_iotag
, abort_context
,
3349 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
3352 * make sure we have the right iocbq before taking it
3353 * off the txcmplq and try to call completion routine.
3356 abort_iocb
->iocb
.ulpContext
!= abort_context
||
3357 (abort_iocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) == 0)
3358 spin_unlock_irq(&phba
->hbalock
);
3360 list_del_init(&abort_iocb
->list
);
3361 pring
->txcmplq_cnt
--;
3362 spin_unlock_irq(&phba
->hbalock
);
3364 abort_iocb
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
3365 abort_iocb
->iocb
.ulpStatus
= IOSTAT_LOCAL_REJECT
;
3366 abort_iocb
->iocb
.un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
3367 (abort_iocb
->iocb_cmpl
)(phba
, abort_iocb
, abort_iocb
);
3371 lpfc_sli_release_iocbq(phba
, cmdiocb
);
3376 lpfc_ignore_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
3377 struct lpfc_iocbq
*rspiocb
)
3379 IOCB_t
*irsp
= &rspiocb
->iocb
;
3381 /* ELS cmd tag <ulpIoTag> completes */
3382 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
3383 "0133 Ignoring ELS cmd tag x%x completion Data: "
3385 irsp
->ulpIoTag
, irsp
->ulpStatus
,
3386 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
);
3387 if (cmdiocb
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
)
3388 lpfc_ct_free_iocb(phba
, cmdiocb
);
3390 lpfc_els_free_iocb(phba
, cmdiocb
);
3395 lpfc_sli_issue_abort_iotag(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
3396 struct lpfc_iocbq
*cmdiocb
)
3398 struct lpfc_vport
*vport
= cmdiocb
->vport
;
3399 struct lpfc_iocbq
*abtsiocbp
;
3400 IOCB_t
*icmd
= NULL
;
3401 IOCB_t
*iabt
= NULL
;
3402 int retval
= IOCB_ERROR
;
3405 * There are certain command types we don't want to abort. And we
3406 * don't want to abort commands that are already in the process of
3409 icmd
= &cmdiocb
->iocb
;
3410 if (icmd
->ulpCommand
== CMD_ABORT_XRI_CN
||
3411 icmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
3412 (cmdiocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) != 0)
3415 /* If we're unloading, don't abort iocb on the ELS ring, but change the
3416 * callback so that nothing happens when it finishes.
3418 if ((vport
->load_flag
& FC_UNLOADING
) &&
3419 (pring
->ringno
== LPFC_ELS_RING
)) {
3420 if (cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
)
3421 cmdiocb
->fabric_iocb_cmpl
= lpfc_ignore_els_cmpl
;
3423 cmdiocb
->iocb_cmpl
= lpfc_ignore_els_cmpl
;
3424 goto abort_iotag_exit
;
3427 /* issue ABTS for this IOCB based on iotag */
3428 abtsiocbp
= __lpfc_sli_get_iocbq(phba
);
3429 if (abtsiocbp
== NULL
)
3432 /* This signals the response to set the correct status
3433 * before calling the completion handler.
3435 cmdiocb
->iocb_flag
|= LPFC_DRIVER_ABORTED
;
3437 iabt
= &abtsiocbp
->iocb
;
3438 iabt
->un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
3439 iabt
->un
.acxri
.abortContextTag
= icmd
->ulpContext
;
3440 iabt
->un
.acxri
.abortIoTag
= icmd
->ulpIoTag
;
3442 iabt
->ulpClass
= icmd
->ulpClass
;
3444 if (phba
->link_state
>= LPFC_LINK_UP
)
3445 iabt
->ulpCommand
= CMD_ABORT_XRI_CN
;
3447 iabt
->ulpCommand
= CMD_CLOSE_XRI_CN
;
3449 abtsiocbp
->iocb_cmpl
= lpfc_sli_abort_els_cmpl
;
3451 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
3452 "0339 Abort xri x%x, original iotag x%x, "
3453 "abort cmd iotag x%x\n",
3454 iabt
->un
.acxri
.abortContextTag
,
3455 iabt
->un
.acxri
.abortIoTag
, abtsiocbp
->iotag
);
3456 retval
= __lpfc_sli_issue_iocb(phba
, pring
, abtsiocbp
, 0);
3460 * Caller to this routine should check for IOCB_ERROR
3461 * and handle it properly. This routine no longer removes
3462 * iocb off txcmplq and call compl in case of IOCB_ERROR.
3468 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq
*iocbq
, struct lpfc_vport
*vport
,
3469 uint16_t tgt_id
, uint64_t lun_id
,
3470 lpfc_ctx_cmd ctx_cmd
)
3472 struct lpfc_scsi_buf
*lpfc_cmd
;
3473 struct scsi_cmnd
*cmnd
;
3476 if (!(iocbq
->iocb_flag
& LPFC_IO_FCP
))
3479 if (iocbq
->vport
!= vport
)
3482 lpfc_cmd
= container_of(iocbq
, struct lpfc_scsi_buf
, cur_iocbq
);
3483 cmnd
= lpfc_cmd
->pCmd
;
3490 if ((cmnd
->device
->id
== tgt_id
) &&
3491 (cmnd
->device
->lun
== lun_id
))
3495 if (cmnd
->device
->id
== tgt_id
)
3502 printk(KERN_ERR
"%s: Unknown context cmd type, value %d\n",
3503 __FUNCTION__
, ctx_cmd
);
3511 lpfc_sli_sum_iocb(struct lpfc_vport
*vport
, uint16_t tgt_id
, uint64_t lun_id
,
3512 lpfc_ctx_cmd ctx_cmd
)
3514 struct lpfc_hba
*phba
= vport
->phba
;
3515 struct lpfc_iocbq
*iocbq
;
3518 for (i
= 1, sum
= 0; i
<= phba
->sli
.last_iotag
; i
++) {
3519 iocbq
= phba
->sli
.iocbq_lookup
[i
];
3521 if (lpfc_sli_validate_fcp_iocb (iocbq
, vport
, tgt_id
, lun_id
,
3530 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
3531 struct lpfc_iocbq
*rspiocb
)
3533 lpfc_sli_release_iocbq(phba
, cmdiocb
);
3538 lpfc_sli_abort_iocb(struct lpfc_vport
*vport
, struct lpfc_sli_ring
*pring
,
3539 uint16_t tgt_id
, uint64_t lun_id
, lpfc_ctx_cmd abort_cmd
)
3541 struct lpfc_hba
*phba
= vport
->phba
;
3542 struct lpfc_iocbq
*iocbq
;
3543 struct lpfc_iocbq
*abtsiocb
;
3545 int errcnt
= 0, ret_val
= 0;
3548 for (i
= 1; i
<= phba
->sli
.last_iotag
; i
++) {
3549 iocbq
= phba
->sli
.iocbq_lookup
[i
];
3551 if (lpfc_sli_validate_fcp_iocb(iocbq
, vport
, tgt_id
, lun_id
,
3555 /* issue ABTS for this IOCB based on iotag */
3556 abtsiocb
= lpfc_sli_get_iocbq(phba
);
3557 if (abtsiocb
== NULL
) {
3563 abtsiocb
->iocb
.un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
3564 abtsiocb
->iocb
.un
.acxri
.abortContextTag
= cmd
->ulpContext
;
3565 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= cmd
->ulpIoTag
;
3566 abtsiocb
->iocb
.ulpLe
= 1;
3567 abtsiocb
->iocb
.ulpClass
= cmd
->ulpClass
;
3568 abtsiocb
->vport
= phba
->pport
;
3570 if (lpfc_is_link_up(phba
))
3571 abtsiocb
->iocb
.ulpCommand
= CMD_ABORT_XRI_CN
;
3573 abtsiocb
->iocb
.ulpCommand
= CMD_CLOSE_XRI_CN
;
3575 /* Setup callback routine and issue the command. */
3576 abtsiocb
->iocb_cmpl
= lpfc_sli_abort_fcp_cmpl
;
3577 ret_val
= lpfc_sli_issue_iocb(phba
, pring
, abtsiocb
, 0);
3578 if (ret_val
== IOCB_ERROR
) {
3579 lpfc_sli_release_iocbq(phba
, abtsiocb
);
3589 lpfc_sli_wake_iocb_wait(struct lpfc_hba
*phba
,
3590 struct lpfc_iocbq
*cmdiocbq
,
3591 struct lpfc_iocbq
*rspiocbq
)
3593 wait_queue_head_t
*pdone_q
;
3594 unsigned long iflags
;
3596 spin_lock_irqsave(&phba
->hbalock
, iflags
);
3597 cmdiocbq
->iocb_flag
|= LPFC_IO_WAKE
;
3598 if (cmdiocbq
->context2
&& rspiocbq
)
3599 memcpy(&((struct lpfc_iocbq
*)cmdiocbq
->context2
)->iocb
,
3600 &rspiocbq
->iocb
, sizeof(IOCB_t
));
3602 pdone_q
= cmdiocbq
->context_un
.wait_queue
;
3605 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
3610 * Issue the caller's iocb and wait for its completion, but no longer than the
3611 * caller's timeout. Note that iocb_flags is cleared before the
3612 * lpfc_sli_issue_call since the wake routine sets a unique value and by
3613 * definition this is a wait function.
3617 lpfc_sli_issue_iocb_wait(struct lpfc_hba
*phba
,
3618 struct lpfc_sli_ring
*pring
,
3619 struct lpfc_iocbq
*piocb
,
3620 struct lpfc_iocbq
*prspiocbq
,
3623 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
3624 long timeleft
, timeout_req
= 0;
3625 int retval
= IOCB_SUCCESS
;
3629 * If the caller has provided a response iocbq buffer, then context2
3630 * is NULL or its an error.
3633 if (piocb
->context2
)
3635 piocb
->context2
= prspiocbq
;
3638 piocb
->iocb_cmpl
= lpfc_sli_wake_iocb_wait
;
3639 piocb
->context_un
.wait_queue
= &done_q
;
3640 piocb
->iocb_flag
&= ~LPFC_IO_WAKE
;
3642 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
3643 creg_val
= readl(phba
->HCregaddr
);
3644 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
3645 writel(creg_val
, phba
->HCregaddr
);
3646 readl(phba
->HCregaddr
); /* flush */
3649 retval
= lpfc_sli_issue_iocb(phba
, pring
, piocb
, 0);
3650 if (retval
== IOCB_SUCCESS
) {
3651 timeout_req
= timeout
* HZ
;
3652 timeleft
= wait_event_timeout(done_q
,
3653 piocb
->iocb_flag
& LPFC_IO_WAKE
,
3656 if (piocb
->iocb_flag
& LPFC_IO_WAKE
) {
3657 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3658 "0331 IOCB wake signaled\n");
3659 } else if (timeleft
== 0) {
3660 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3661 "0338 IOCB wait timeout error - no "
3662 "wake response Data x%x\n", timeout
);
3663 retval
= IOCB_TIMEDOUT
;
3665 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3666 "0330 IOCB wake NOT set, "
3668 timeout
, (timeleft
/ jiffies
));
3669 retval
= IOCB_TIMEDOUT
;
3672 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3673 ":0332 IOCB wait issue failed, Data x%x\n",
3675 retval
= IOCB_ERROR
;
3678 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
3679 creg_val
= readl(phba
->HCregaddr
);
3680 creg_val
&= ~(HC_R0INT_ENA
<< LPFC_FCP_RING
);
3681 writel(creg_val
, phba
->HCregaddr
);
3682 readl(phba
->HCregaddr
); /* flush */
3686 piocb
->context2
= NULL
;
3688 piocb
->context_un
.wait_queue
= NULL
;
3689 piocb
->iocb_cmpl
= NULL
;
3694 lpfc_sli_issue_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
,
3697 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
3701 /* The caller must leave context1 empty. */
3702 if (pmboxq
->context1
!= 0)
3703 return MBX_NOT_FINISHED
;
3705 /* setup wake call as IOCB callback */
3706 pmboxq
->mbox_cmpl
= lpfc_sli_wake_mbox_wait
;
3707 /* setup context field to pass wait_queue pointer to wake function */
3708 pmboxq
->context1
= &done_q
;
3710 /* now issue the command */
3711 retval
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
3713 if (retval
== MBX_BUSY
|| retval
== MBX_SUCCESS
) {
3714 wait_event_interruptible_timeout(done_q
,
3715 pmboxq
->mbox_flag
& LPFC_MBX_WAKE
,
3718 spin_lock_irqsave(&phba
->hbalock
, flag
);
3719 pmboxq
->context1
= NULL
;
3721 * if LPFC_MBX_WAKE flag is set the mailbox is completed
3722 * else do not free the resources.
3724 if (pmboxq
->mbox_flag
& LPFC_MBX_WAKE
)
3725 retval
= MBX_SUCCESS
;
3727 retval
= MBX_TIMEOUT
;
3728 pmboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
3730 spin_unlock_irqrestore(&phba
->hbalock
, flag
);
3737 lpfc_sli_flush_mbox_queue(struct lpfc_hba
* phba
)
3739 struct lpfc_vport
*vport
= phba
->pport
;
3743 while (phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
&& !vport
->stopped
) {
3744 if (i
++ > LPFC_MBOX_TMO
* 1000)
3748 * Call lpfc_sli_handle_mb_event only if a mailbox cmd
3749 * did finish. This way we won't get the misleading
3750 * "Stray Mailbox Interrupt" message.
3752 spin_lock_irq(&phba
->hbalock
);
3753 ha_copy
= phba
->work_ha
;
3754 phba
->work_ha
&= ~HA_MBATT
;
3755 spin_unlock_irq(&phba
->hbalock
);
3757 if (ha_copy
& HA_MBATT
)
3758 if (lpfc_sli_handle_mb_event(phba
) == 0)
3764 return (phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
) ? 1 : 0;
3768 lpfc_intr_handler(int irq
, void *dev_id
)
3770 struct lpfc_hba
*phba
;
3772 uint32_t work_ha_copy
;
3773 unsigned long status
;
3777 MAILBOX_t
*mbox
, *pmbox
;
3778 struct lpfc_vport
*vport
;
3779 struct lpfc_nodelist
*ndlp
;
3780 struct lpfc_dmabuf
*mp
;
3785 * Get the driver's phba structure from the dev_id and
3786 * assume the HBA is not interrupting.
3788 phba
= (struct lpfc_hba
*) dev_id
;
3790 if (unlikely(!phba
))
3793 /* If the pci channel is offline, ignore all the interrupts. */
3794 if (unlikely(pci_channel_offline(phba
->pcidev
)))
3797 phba
->sli
.slistat
.sli_intr
++;
3800 * Call the HBA to see if it is interrupting. If not, don't claim
3804 /* Ignore all interrupts during initialization. */
3805 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
3809 * Read host attention register to determine interrupt source
3810 * Clear Attention Sources, except Error Attention (to
3811 * preserve status) and Link Attention
3813 spin_lock(&phba
->hbalock
);
3814 ha_copy
= readl(phba
->HAregaddr
);
3815 /* If somebody is waiting to handle an eratt don't process it
3816 * here. The brdkill function will do this.
3818 if (phba
->link_flag
& LS_IGNORE_ERATT
)
3819 ha_copy
&= ~HA_ERATT
;
3820 writel((ha_copy
& ~(HA_LATT
| HA_ERATT
)), phba
->HAregaddr
);
3821 readl(phba
->HAregaddr
); /* flush */
3822 spin_unlock(&phba
->hbalock
);
3824 if (unlikely(!ha_copy
))
3827 work_ha_copy
= ha_copy
& phba
->work_ha_mask
;
3829 if (unlikely(work_ha_copy
)) {
3830 if (work_ha_copy
& HA_LATT
) {
3831 if (phba
->sli
.sli_flag
& LPFC_PROCESS_LA
) {
3833 * Turn off Link Attention interrupts
3834 * until CLEAR_LA done
3836 spin_lock(&phba
->hbalock
);
3837 phba
->sli
.sli_flag
&= ~LPFC_PROCESS_LA
;
3838 control
= readl(phba
->HCregaddr
);
3839 control
&= ~HC_LAINT_ENA
;
3840 writel(control
, phba
->HCregaddr
);
3841 readl(phba
->HCregaddr
); /* flush */
3842 spin_unlock(&phba
->hbalock
);
3845 work_ha_copy
&= ~HA_LATT
;
3848 if (work_ha_copy
& ~(HA_ERATT
|HA_MBATT
|HA_LATT
)) {
3850 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
3851 * the only slow ring.
3853 status
= (work_ha_copy
&
3854 (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
3855 status
>>= (4*LPFC_ELS_RING
);
3856 if (status
& HA_RXMASK
) {
3857 spin_lock(&phba
->hbalock
);
3858 control
= readl(phba
->HCregaddr
);
3860 lpfc_debugfs_slow_ring_trc(phba
,
3861 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
3863 (uint32_t)phba
->sli
.slistat
.sli_intr
);
3865 if (control
& (HC_R0INT_ENA
<< LPFC_ELS_RING
)) {
3866 lpfc_debugfs_slow_ring_trc(phba
,
3868 "pwork:x%x hawork:x%x wait:x%x",
3869 phba
->work_ha
, work_ha_copy
,
3870 (uint32_t)((unsigned long)
3874 ~(HC_R0INT_ENA
<< LPFC_ELS_RING
);
3875 writel(control
, phba
->HCregaddr
);
3876 readl(phba
->HCregaddr
); /* flush */
3879 lpfc_debugfs_slow_ring_trc(phba
,
3880 "ISR slow ring: pwork:"
3881 "x%x hawork:x%x wait:x%x",
3882 phba
->work_ha
, work_ha_copy
,
3883 (uint32_t)((unsigned long)
3886 spin_unlock(&phba
->hbalock
);
3890 if (work_ha_copy
& HA_ERATT
) {
3891 phba
->link_state
= LPFC_HBA_ERROR
;
3893 * There was a link/board error. Read the
3894 * status register to retrieve the error event
3897 phba
->sli
.slistat
.err_attn_event
++;
3898 /* Save status info */
3899 phba
->work_hs
= readl(phba
->HSregaddr
);
3900 phba
->work_status
[0] = readl(phba
->MBslimaddr
+ 0xa8);
3901 phba
->work_status
[1] = readl(phba
->MBslimaddr
+ 0xac);
3903 /* Clear Chip error bit */
3904 writel(HA_ERATT
, phba
->HAregaddr
);
3905 readl(phba
->HAregaddr
); /* flush */
3906 phba
->pport
->stopped
= 1;
3909 if ((work_ha_copy
& HA_MBATT
) &&
3910 (phba
->sli
.mbox_active
)) {
3911 pmb
= phba
->sli
.mbox_active
;
3913 mbox
= &phba
->slim2p
->mbx
;
3916 /* First check out the status word */
3917 lpfc_sli_pcimem_bcopy(mbox
, pmbox
, sizeof(uint32_t));
3918 if (pmbox
->mbxOwner
!= OWN_HOST
) {
3920 * Stray Mailbox Interrupt, mbxCommand <cmd>
3921 * mbxStatus <status>
3923 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
|
3925 "(%d):0304 Stray Mailbox "
3926 "Interrupt mbxCommand x%x "
3928 (vport
? vport
->vpi
: 0),
3932 phba
->last_completion_time
= jiffies
;
3933 del_timer_sync(&phba
->sli
.mbox_tmo
);
3935 phba
->sli
.mbox_active
= NULL
;
3936 if (pmb
->mbox_cmpl
) {
3937 lpfc_sli_pcimem_bcopy(mbox
, pmbox
,
3940 if (pmb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) {
3941 pmb
->mbox_flag
&= ~LPFC_MBX_IMED_UNREG
;
3943 lpfc_debugfs_disc_trc(vport
,
3944 LPFC_DISC_TRC_MBOX_VPORT
,
3945 "MBOX dflt rpi: : status:x%x rpi:x%x",
3946 (uint32_t)pmbox
->mbxStatus
,
3947 pmbox
->un
.varWords
[0], 0);
3949 if ( !pmbox
->mbxStatus
) {
3950 mp
= (struct lpfc_dmabuf
*)
3952 ndlp
= (struct lpfc_nodelist
*)
3955 /* Reg_LOGIN of dflt RPI was successful.
3956 * new lets get rid of the RPI using the
3959 lpfc_unreg_login(phba
, vport
->vpi
,
3960 pmbox
->un
.varWords
[0], pmb
);
3961 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
3963 pmb
->context2
= ndlp
;
3965 spin_lock(&phba
->hbalock
);
3966 phba
->sli
.sli_flag
&=
3967 ~LPFC_SLI_MBOX_ACTIVE
;
3968 spin_unlock(&phba
->hbalock
);
3969 goto send_current_mbox
;
3972 spin_lock(&phba
->pport
->work_port_lock
);
3973 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
3974 spin_unlock(&phba
->pport
->work_port_lock
);
3975 lpfc_mbox_cmpl_put(phba
, pmb
);
3977 if ((work_ha_copy
& HA_MBATT
) &&
3978 (phba
->sli
.mbox_active
== NULL
)) {
3980 spin_lock(&phba
->hbalock
);
3981 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
3982 pmb
= lpfc_mbox_get(phba
);
3983 spin_unlock(&phba
->hbalock
);
3985 /* Process next mailbox command if there is one */
3987 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
3988 if (rc
== MBX_NOT_FINISHED
) {
3989 pmb
->mb
.mbxStatus
= MBX_NOT_FINISHED
;
3990 lpfc_mbox_cmpl_put(phba
, pmb
);
3991 goto send_next_mbox
;
3994 /* Turn on IOCB processing */
3995 for (i
= 0; i
< phba
->sli
.num_rings
; i
++)
3996 lpfc_sli_turn_on_ring(phba
, i
);
4001 spin_lock(&phba
->hbalock
);
4002 phba
->work_ha
|= work_ha_copy
;
4003 if (phba
->work_wait
)
4004 lpfc_worker_wake_up(phba
);
4005 spin_unlock(&phba
->hbalock
);
4008 ha_copy
&= ~(phba
->work_ha_mask
);
4011 * Process all events on FCP ring. Take the optimized path for
4012 * FCP IO. Any other IO is slow path and is handled by
4013 * the worker thread.
4015 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
4016 status
>>= (4*LPFC_FCP_RING
);
4017 if (status
& HA_RXMASK
)
4018 lpfc_sli_handle_fast_ring_event(phba
,
4019 &phba
->sli
.ring
[LPFC_FCP_RING
],
4022 if (phba
->cfg_multi_ring_support
== 2) {
4024 * Process all events on extra ring. Take the optimized path
4025 * for extra ring IO. Any other IO is slow path and is handled
4026 * by the worker thread.
4028 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
4029 status
>>= (4*LPFC_EXTRA_RING
);
4030 if (status
& HA_RXMASK
) {
4031 lpfc_sli_handle_fast_ring_event(phba
,
4032 &phba
->sli
.ring
[LPFC_EXTRA_RING
],
4038 } /* lpfc_intr_handler */