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
->hbqslimp
.virt
+ hbqp
->hbqPutIdx
;
552 lpfc_sli_hbqbuf_free_all(struct lpfc_hba
*phba
)
554 struct lpfc_dmabuf
*dmabuf
, *next_dmabuf
;
555 struct hbq_dmabuf
*hbq_buf
;
557 /* Return all memory used by all HBQs */
558 list_for_each_entry_safe(dmabuf
, next_dmabuf
,
559 &phba
->hbq_buffer_list
, list
) {
560 hbq_buf
= container_of(dmabuf
, struct hbq_dmabuf
, dbuf
);
561 list_del(&hbq_buf
->dbuf
.list
);
562 lpfc_hbq_free(phba
, hbq_buf
->dbuf
.virt
, hbq_buf
->dbuf
.phys
);
568 lpfc_sli_hbq_to_firmware(struct lpfc_hba
*phba
, uint32_t hbqno
,
569 struct hbq_dmabuf
*hbq_buf
)
571 struct lpfc_hbq_entry
*hbqe
;
572 dma_addr_t physaddr
= hbq_buf
->dbuf
.phys
;
574 /* Get next HBQ entry slot to use */
575 hbqe
= lpfc_sli_next_hbq_slot(phba
, hbqno
);
577 struct hbq_s
*hbqp
= &phba
->hbqs
[hbqno
];
579 hbqe
->bde
.addrHigh
= le32_to_cpu(putPaddrHigh(physaddr
));
580 hbqe
->bde
.addrLow
= le32_to_cpu(putPaddrLow(physaddr
));
581 hbqe
->bde
.tus
.f
.bdeSize
= FCELSSIZE
;
582 hbqe
->bde
.tus
.f
.bdeFlags
= 0;
583 hbqe
->bde
.tus
.w
= le32_to_cpu(hbqe
->bde
.tus
.w
);
584 hbqe
->buffer_tag
= le32_to_cpu(hbq_buf
->tag
);
586 hbqp
->hbqPutIdx
= hbqp
->next_hbqPutIdx
;
587 writel(hbqp
->hbqPutIdx
, phba
->hbq_put
+ hbqno
);
589 readl(phba
->hbq_put
+ hbqno
);
590 list_add_tail(&hbq_buf
->dbuf
.list
, &phba
->hbq_buffer_list
);
594 static struct lpfc_hbq_init lpfc_els_hbq
= {
599 .ring_mask
= 1 << LPFC_ELS_RING
,
605 static struct lpfc_hbq_init
*lpfc_hbq_defs
[] = {
610 lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba
*phba
, uint32_t hbqno
, uint32_t count
)
612 uint32_t i
, start
, end
;
613 struct hbq_dmabuf
*hbq_buffer
;
615 start
= lpfc_hbq_defs
[hbqno
]->buffer_count
;
616 end
= count
+ lpfc_hbq_defs
[hbqno
]->buffer_count
;
617 if (end
> lpfc_hbq_defs
[hbqno
]->entry_count
) {
618 end
= lpfc_hbq_defs
[hbqno
]->entry_count
;
621 /* Populate HBQ entries */
622 for (i
= start
; i
< end
; i
++) {
623 hbq_buffer
= kmalloc(sizeof(struct hbq_dmabuf
),
627 hbq_buffer
->dbuf
.virt
= lpfc_hbq_alloc(phba
, MEM_PRI
,
628 &hbq_buffer
->dbuf
.phys
);
629 if (hbq_buffer
->dbuf
.virt
== NULL
)
631 hbq_buffer
->tag
= (i
| (hbqno
<< 16));
632 lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buffer
);
633 lpfc_hbq_defs
[hbqno
]->buffer_count
++;
639 lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
641 return(lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
642 lpfc_hbq_defs
[qno
]->add_count
));
646 lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
648 return(lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
649 lpfc_hbq_defs
[qno
]->init_count
));
653 lpfc_sli_hbqbuf_find(struct lpfc_hba
*phba
, uint32_t tag
)
655 struct lpfc_dmabuf
*d_buf
;
656 struct hbq_dmabuf
*hbq_buf
;
658 list_for_each_entry(d_buf
, &phba
->hbq_buffer_list
, list
) {
659 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
660 if ((hbq_buf
->tag
& 0xffff) == tag
) {
664 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
| LOG_VPORT
,
665 "1803 Bad hbq tag. Data: x%x x%x\n",
666 tag
, lpfc_hbq_defs
[tag
>> 16]->buffer_count
);
671 lpfc_sli_free_hbq(struct lpfc_hba
*phba
, struct hbq_dmabuf
*sp
)
676 hbqno
= sp
->tag
>> 16;
677 lpfc_sli_hbq_to_firmware(phba
, hbqno
, sp
);
682 lpfc_sli_chk_mbx_command(uint8_t mbxCommand
)
686 switch (mbxCommand
) {
690 case MBX_RUN_BIU_DIAG
:
693 case MBX_CONFIG_LINK
:
694 case MBX_CONFIG_RING
:
696 case MBX_READ_CONFIG
:
697 case MBX_READ_RCONFIG
:
699 case MBX_READ_STATUS
:
703 case MBX_READ_LNK_STAT
:
705 case MBX_UNREG_LOGIN
:
708 case MBX_DUMP_MEMORY
:
709 case MBX_DUMP_CONTEXT
:
714 case MBX_DEL_LD_ENTRY
:
715 case MBX_RUN_PROGRAM
:
720 case MBX_CONFIG_FARP
:
723 case MBX_RUN_BIU_DIAG64
:
724 case MBX_CONFIG_PORT
:
725 case MBX_READ_SPARM64
:
727 case MBX_REG_LOGIN64
:
729 case MBX_FLASH_WR_ULA
:
731 case MBX_LOAD_EXP_ROM
:
744 lpfc_sli_wake_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
746 wait_queue_head_t
*pdone_q
;
747 unsigned long drvr_flag
;
750 * If pdone_q is empty, the driver thread gave up waiting and
753 pmboxq
->mbox_flag
|= LPFC_MBX_WAKE
;
754 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
755 pdone_q
= (wait_queue_head_t
*) pmboxq
->context1
;
757 wake_up_interruptible(pdone_q
);
758 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
763 lpfc_sli_def_mbox_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
765 struct lpfc_dmabuf
*mp
;
769 mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
772 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
777 * If a REG_LOGIN succeeded after node is destroyed or node
778 * is in re-discovery driver need to cleanup the RPI.
780 if (!(phba
->pport
->load_flag
& FC_UNLOADING
) &&
781 pmb
->mb
.mbxCommand
== MBX_REG_LOGIN64
&&
782 !pmb
->mb
.mbxStatus
) {
784 rpi
= pmb
->mb
.un
.varWords
[0];
785 lpfc_unreg_login(phba
, pmb
->mb
.un
.varRegLogin
.vpi
, rpi
, pmb
);
786 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
787 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
788 if (rc
!= MBX_NOT_FINISHED
)
792 mempool_free(pmb
, phba
->mbox_mem_pool
);
797 lpfc_sli_handle_mb_event(struct lpfc_hba
*phba
)
804 phba
->sli
.slistat
.mbox_event
++;
806 /* Get all completed mailboxe buffers into the cmplq */
807 spin_lock_irq(&phba
->hbalock
);
808 list_splice_init(&phba
->sli
.mboxq_cmpl
, &cmplq
);
809 spin_unlock_irq(&phba
->hbalock
);
811 /* Get a Mailbox buffer to setup mailbox commands for callback */
813 list_remove_head(&cmplq
, pmb
, LPFC_MBOXQ_t
, list
);
819 if (pmbox
->mbxCommand
!= MBX_HEARTBEAT
) {
821 lpfc_debugfs_disc_trc(pmb
->vport
,
822 LPFC_DISC_TRC_MBOX_VPORT
,
823 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
824 (uint32_t)pmbox
->mbxCommand
,
825 pmbox
->un
.varWords
[0],
826 pmbox
->un
.varWords
[1]);
829 lpfc_debugfs_disc_trc(phba
->pport
,
831 "MBOX cmpl: cmd:x%x mb:x%x x%x",
832 (uint32_t)pmbox
->mbxCommand
,
833 pmbox
->un
.varWords
[0],
834 pmbox
->un
.varWords
[1]);
839 * It is a fatal error if unknown mbox command completion.
841 if (lpfc_sli_chk_mbx_command(pmbox
->mbxCommand
) ==
843 /* Unknow mailbox command compl */
844 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
845 "(%d):0323 Unknown Mailbox command "
847 pmb
->vport
? pmb
->vport
->vpi
: 0,
849 phba
->link_state
= LPFC_HBA_ERROR
;
850 phba
->work_hs
= HS_FFER3
;
851 lpfc_handle_eratt(phba
);
855 if (pmbox
->mbxStatus
) {
856 phba
->sli
.slistat
.mbox_stat_err
++;
857 if (pmbox
->mbxStatus
== MBXERR_NO_RESOURCES
) {
858 /* Mbox cmd cmpl error - RETRYing */
859 lpfc_printf_log(phba
, KERN_INFO
,
861 "(%d):0305 Mbox cmd cmpl "
862 "error - RETRYing Data: x%x "
864 pmb
->vport
? pmb
->vport
->vpi
:0,
867 pmbox
->un
.varWords
[0],
868 pmb
->vport
->port_state
);
869 pmbox
->mbxStatus
= 0;
870 pmbox
->mbxOwner
= OWN_HOST
;
871 spin_lock_irq(&phba
->hbalock
);
872 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
873 spin_unlock_irq(&phba
->hbalock
);
874 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
875 if (rc
== MBX_SUCCESS
)
880 /* Mailbox cmd <cmd> Cmpl <cmpl> */
881 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
882 "(%d):0307 Mailbox cmd x%x Cmpl x%p "
883 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
884 pmb
->vport
? pmb
->vport
->vpi
: 0,
887 *((uint32_t *) pmbox
),
888 pmbox
->un
.varWords
[0],
889 pmbox
->un
.varWords
[1],
890 pmbox
->un
.varWords
[2],
891 pmbox
->un
.varWords
[3],
892 pmbox
->un
.varWords
[4],
893 pmbox
->un
.varWords
[5],
894 pmbox
->un
.varWords
[6],
895 pmbox
->un
.varWords
[7]);
898 pmb
->mbox_cmpl(phba
,pmb
);
903 static struct lpfc_dmabuf
*
904 lpfc_sli_replace_hbqbuff(struct lpfc_hba
*phba
, uint32_t tag
)
906 struct hbq_dmabuf
*hbq_entry
, *new_hbq_entry
;
908 hbq_entry
= lpfc_sli_hbqbuf_find(phba
, tag
);
909 if (hbq_entry
== NULL
)
911 list_del(&hbq_entry
->dbuf
.list
);
912 new_hbq_entry
= kmalloc(sizeof(struct hbq_dmabuf
), GFP_ATOMIC
);
913 if (new_hbq_entry
== NULL
)
914 return &hbq_entry
->dbuf
;
915 new_hbq_entry
->dbuf
= hbq_entry
->dbuf
;
916 new_hbq_entry
->tag
= -1;
917 hbq_entry
->dbuf
.virt
= lpfc_hbq_alloc(phba
, 0, &hbq_entry
->dbuf
.phys
);
918 if (hbq_entry
->dbuf
.virt
== NULL
) {
919 kfree(new_hbq_entry
);
920 return &hbq_entry
->dbuf
;
922 lpfc_sli_free_hbq(phba
, hbq_entry
);
923 return &new_hbq_entry
->dbuf
;
927 lpfc_sli_process_unsol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
928 struct lpfc_iocbq
*saveq
)
936 irsp
= &(saveq
->iocb
);
937 if ((irsp
->ulpCommand
== CMD_RCV_ELS_REQ64_CX
)
938 || (irsp
->ulpCommand
== CMD_RCV_ELS_REQ_CX
)
939 || (irsp
->ulpCommand
== CMD_IOCB_RCV_ELS64_CX
)
940 || (irsp
->ulpCommand
== CMD_IOCB_RCV_CONT64_CX
)) {
945 (WORD5
*) & (saveq
->iocb
.un
.
947 Rctl
= w5p
->hcsw
.Rctl
;
948 Type
= w5p
->hcsw
.Type
;
950 /* Firmware Workaround */
951 if ((Rctl
== 0) && (pring
->ringno
== LPFC_ELS_RING
) &&
952 (irsp
->ulpCommand
== CMD_RCV_SEQUENCE64_CX
||
953 irsp
->ulpCommand
== CMD_IOCB_RCV_SEQ64_CX
)) {
956 w5p
->hcsw
.Rctl
= Rctl
;
957 w5p
->hcsw
.Type
= Type
;
961 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
962 if (irsp
->ulpBdeCount
!= 0)
963 saveq
->context2
= lpfc_sli_replace_hbqbuff(phba
,
964 irsp
->un
.ulpWord
[3]);
965 if (irsp
->ulpBdeCount
== 2)
966 saveq
->context3
= lpfc_sli_replace_hbqbuff(phba
,
967 irsp
->un
.ulpWord
[15]);
970 /* unSolicited Responses */
971 if (pring
->prt
[0].profile
) {
972 if (pring
->prt
[0].lpfc_sli_rcv_unsol_event
)
973 (pring
->prt
[0].lpfc_sli_rcv_unsol_event
) (phba
, pring
,
977 /* We must search, based on rctl / type
978 for the right routine */
979 for (i
= 0; i
< pring
->num_mask
;
981 if ((pring
->prt
[i
].rctl
==
985 if (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
986 (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
987 (phba
, pring
, saveq
);
994 /* Unexpected Rctl / Type received */
995 /* Ring <ringno> handler: unexpected
996 Rctl <Rctl> Type <Type> received */
997 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
998 "0313 Ring %d handler: unexpected Rctl x%x "
999 "Type x%x received\n",
1000 pring
->ringno
, Rctl
, Type
);
1005 static struct lpfc_iocbq
*
1006 lpfc_sli_iocbq_lookup(struct lpfc_hba
*phba
,
1007 struct lpfc_sli_ring
*pring
,
1008 struct lpfc_iocbq
*prspiocb
)
1010 struct lpfc_iocbq
*cmd_iocb
= NULL
;
1013 iotag
= prspiocb
->iocb
.ulpIoTag
;
1015 if (iotag
!= 0 && iotag
<= phba
->sli
.last_iotag
) {
1016 cmd_iocb
= phba
->sli
.iocbq_lookup
[iotag
];
1017 list_del_init(&cmd_iocb
->list
);
1018 pring
->txcmplq_cnt
--;
1022 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
1023 "0317 iotag x%x is out off "
1024 "range: max iotag x%x wd0 x%x\n",
1025 iotag
, phba
->sli
.last_iotag
,
1026 *(((uint32_t *) &prspiocb
->iocb
) + 7));
1031 lpfc_sli_process_sol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1032 struct lpfc_iocbq
*saveq
)
1034 struct lpfc_iocbq
*cmdiocbp
;
1036 unsigned long iflag
;
1038 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
1039 spin_lock_irqsave(&phba
->hbalock
, iflag
);
1040 cmdiocbp
= lpfc_sli_iocbq_lookup(phba
, pring
, saveq
);
1041 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1044 if (cmdiocbp
->iocb_cmpl
) {
1046 * Post all ELS completions to the worker thread.
1047 * All other are passed to the completion callback.
1049 if (pring
->ringno
== LPFC_ELS_RING
) {
1050 if (cmdiocbp
->iocb_flag
& LPFC_DRIVER_ABORTED
) {
1051 cmdiocbp
->iocb_flag
&=
1052 ~LPFC_DRIVER_ABORTED
;
1053 saveq
->iocb
.ulpStatus
=
1054 IOSTAT_LOCAL_REJECT
;
1055 saveq
->iocb
.un
.ulpWord
[4] =
1059 (cmdiocbp
->iocb_cmpl
) (phba
, cmdiocbp
, saveq
);
1061 lpfc_sli_release_iocbq(phba
, cmdiocbp
);
1064 * Unknown initiating command based on the response iotag.
1065 * This could be the case on the ELS ring because of
1068 if (pring
->ringno
!= LPFC_ELS_RING
) {
1070 * Ring <ringno> handler: unexpected completion IoTag
1073 lpfc_printf_vlog(cmdiocbp
->vport
, KERN_WARNING
, LOG_SLI
,
1074 "0322 Ring %d handler: "
1075 "unexpected completion IoTag x%x "
1076 "Data: x%x x%x x%x x%x\n",
1078 saveq
->iocb
.ulpIoTag
,
1079 saveq
->iocb
.ulpStatus
,
1080 saveq
->iocb
.un
.ulpWord
[4],
1081 saveq
->iocb
.ulpCommand
,
1082 saveq
->iocb
.ulpContext
);
1090 lpfc_sli_rsp_pointers_error(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1092 struct lpfc_pgp
*pgp
= (phba
->sli_rev
== 3) ?
1093 &phba
->slim2p
->mbx
.us
.s3_pgp
.port
[pring
->ringno
] :
1094 &phba
->slim2p
->mbx
.us
.s2
.port
[pring
->ringno
];
1096 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
1097 * rsp ring <portRspMax>
1099 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
1100 "0312 Ring %d handler: portRspPut %d "
1101 "is bigger then rsp ring %d\n",
1102 pring
->ringno
, le32_to_cpu(pgp
->rspPutInx
),
1105 phba
->link_state
= LPFC_HBA_ERROR
;
1108 * All error attention handlers are posted to
1111 phba
->work_ha
|= HA_ERATT
;
1112 phba
->work_hs
= HS_FFER3
;
1114 /* hbalock should already be held */
1115 if (phba
->work_wait
)
1116 lpfc_worker_wake_up(phba
);
1121 void lpfc_sli_poll_fcp_ring(struct lpfc_hba
*phba
)
1123 struct lpfc_sli
*psli
= &phba
->sli
;
1124 struct lpfc_sli_ring
*pring
= &psli
->ring
[LPFC_FCP_RING
];
1125 IOCB_t
*irsp
= NULL
;
1126 IOCB_t
*entry
= NULL
;
1127 struct lpfc_iocbq
*cmdiocbq
= NULL
;
1128 struct lpfc_iocbq rspiocbq
;
1129 struct lpfc_pgp
*pgp
;
1131 uint32_t portRspPut
, portRspMax
;
1133 uint32_t rsp_cmpl
= 0;
1135 unsigned long iflags
;
1137 pring
->stats
.iocb_event
++;
1139 pgp
= (phba
->sli_rev
== 3) ?
1140 &phba
->slim2p
->mbx
.us
.s3_pgp
.port
[pring
->ringno
] :
1141 &phba
->slim2p
->mbx
.us
.s2
.port
[pring
->ringno
];
1145 * The next available response entry should never exceed the maximum
1146 * entries. If it does, treat it as an adapter hardware error.
1148 portRspMax
= pring
->numRiocb
;
1149 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
1150 if (unlikely(portRspPut
>= portRspMax
)) {
1151 lpfc_sli_rsp_pointers_error(phba
, pring
);
1156 while (pring
->rspidx
!= portRspPut
) {
1157 entry
= lpfc_resp_iocb(phba
, pring
);
1158 if (++pring
->rspidx
>= portRspMax
)
1161 lpfc_sli_pcimem_bcopy((uint32_t *) entry
,
1162 (uint32_t *) &rspiocbq
.iocb
,
1163 phba
->iocb_rsp_size
);
1164 irsp
= &rspiocbq
.iocb
;
1165 type
= lpfc_sli_iocb_cmd_type(irsp
->ulpCommand
& CMD_IOCB_MASK
);
1166 pring
->stats
.iocb_rsp
++;
1169 if (unlikely(irsp
->ulpStatus
)) {
1170 /* Rsp ring <ringno> error: IOCB */
1171 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
1172 "0326 Rsp Ring %d error: IOCB Data: "
1173 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
1175 irsp
->un
.ulpWord
[0],
1176 irsp
->un
.ulpWord
[1],
1177 irsp
->un
.ulpWord
[2],
1178 irsp
->un
.ulpWord
[3],
1179 irsp
->un
.ulpWord
[4],
1180 irsp
->un
.ulpWord
[5],
1181 *(((uint32_t *) irsp
) + 6),
1182 *(((uint32_t *) irsp
) + 7));
1186 case LPFC_ABORT_IOCB
:
1189 * Idle exchange closed via ABTS from port. No iocb
1190 * resources need to be recovered.
1192 if (unlikely(irsp
->ulpCommand
== CMD_XRI_ABORTED_CX
)) {
1193 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
1194 "0314 IOCB cmd 0x%x "
1195 "processed. Skipping "
1201 spin_lock_irqsave(&phba
->hbalock
, iflags
);
1202 cmdiocbq
= lpfc_sli_iocbq_lookup(phba
, pring
,
1204 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
1205 if ((cmdiocbq
) && (cmdiocbq
->iocb_cmpl
)) {
1206 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
,
1211 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
1212 char adaptermsg
[LPFC_MAX_ADPTMSG
];
1213 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
1214 memcpy(&adaptermsg
[0], (uint8_t *) irsp
,
1216 dev_warn(&((phba
->pcidev
)->dev
), "lpfc%d: %s",
1217 phba
->brd_no
, adaptermsg
);
1219 /* Unknown IOCB command */
1220 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
1221 "0321 Unknown IOCB command "
1222 "Data: x%x, x%x x%x x%x x%x\n",
1223 type
, irsp
->ulpCommand
,
1232 * The response IOCB has been processed. Update the ring
1233 * pointer in SLIM. If the port response put pointer has not
1234 * been updated, sync the pgp->rspPutInx and fetch the new port
1235 * response put pointer.
1237 writel(pring
->rspidx
, &phba
->host_gp
[pring
->ringno
].rspGetInx
);
1239 if (pring
->rspidx
== portRspPut
)
1240 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
1243 ha_copy
= readl(phba
->HAregaddr
);
1244 ha_copy
>>= (LPFC_FCP_RING
* 4);
1246 if ((rsp_cmpl
> 0) && (ha_copy
& HA_R0RE_REQ
)) {
1247 spin_lock_irqsave(&phba
->hbalock
, iflags
);
1248 pring
->stats
.iocb_rsp_full
++;
1249 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (LPFC_FCP_RING
* 4));
1250 writel(status
, phba
->CAregaddr
);
1251 readl(phba
->CAregaddr
);
1252 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
1254 if ((ha_copy
& HA_R0CE_RSP
) &&
1255 (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
1256 spin_lock_irqsave(&phba
->hbalock
, iflags
);
1257 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
1258 pring
->stats
.iocb_cmd_empty
++;
1260 /* Force update of the local copy of cmdGetInx */
1261 pring
->local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
1262 lpfc_sli_resume_iocb(phba
, pring
);
1264 if ((pring
->lpfc_sli_cmd_available
))
1265 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
1267 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
1274 * This routine presumes LPFC_FCP_RING handling and doesn't bother
1275 * to check it explicitly.
1278 lpfc_sli_handle_fast_ring_event(struct lpfc_hba
*phba
,
1279 struct lpfc_sli_ring
*pring
, uint32_t mask
)
1281 struct lpfc_pgp
*pgp
= (phba
->sli_rev
== 3) ?
1282 &phba
->slim2p
->mbx
.us
.s3_pgp
.port
[pring
->ringno
] :
1283 &phba
->slim2p
->mbx
.us
.s2
.port
[pring
->ringno
];
1284 IOCB_t
*irsp
= NULL
;
1285 IOCB_t
*entry
= NULL
;
1286 struct lpfc_iocbq
*cmdiocbq
= NULL
;
1287 struct lpfc_iocbq rspiocbq
;
1289 uint32_t portRspPut
, portRspMax
;
1291 lpfc_iocb_type type
;
1292 unsigned long iflag
;
1293 uint32_t rsp_cmpl
= 0;
1295 spin_lock_irqsave(&phba
->hbalock
, iflag
);
1296 pring
->stats
.iocb_event
++;
1299 * The next available response entry should never exceed the maximum
1300 * entries. If it does, treat it as an adapter hardware error.
1302 portRspMax
= pring
->numRiocb
;
1303 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
1304 if (unlikely(portRspPut
>= portRspMax
)) {
1305 lpfc_sli_rsp_pointers_error(phba
, pring
);
1306 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1311 while (pring
->rspidx
!= portRspPut
) {
1313 * Fetch an entry off the ring and copy it into a local data
1314 * structure. The copy involves a byte-swap since the
1315 * network byte order and pci byte orders are different.
1317 entry
= lpfc_resp_iocb(phba
, pring
);
1318 phba
->last_completion_time
= jiffies
;
1320 if (++pring
->rspidx
>= portRspMax
)
1323 lpfc_sli_pcimem_bcopy((uint32_t *) entry
,
1324 (uint32_t *) &rspiocbq
.iocb
,
1325 phba
->iocb_rsp_size
);
1326 INIT_LIST_HEAD(&(rspiocbq
.list
));
1327 irsp
= &rspiocbq
.iocb
;
1329 type
= lpfc_sli_iocb_cmd_type(irsp
->ulpCommand
& CMD_IOCB_MASK
);
1330 pring
->stats
.iocb_rsp
++;
1333 if (unlikely(irsp
->ulpStatus
)) {
1335 * If resource errors reported from HBA, reduce
1336 * queuedepths of the SCSI device.
1338 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
1339 (irsp
->un
.ulpWord
[4] == IOERR_NO_RESOURCES
)) {
1340 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1341 lpfc_adjust_queue_depth(phba
);
1342 spin_lock_irqsave(&phba
->hbalock
, iflag
);
1345 /* Rsp ring <ringno> error: IOCB */
1346 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
1347 "0336 Rsp Ring %d error: IOCB Data: "
1348 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
1350 irsp
->un
.ulpWord
[0],
1351 irsp
->un
.ulpWord
[1],
1352 irsp
->un
.ulpWord
[2],
1353 irsp
->un
.ulpWord
[3],
1354 irsp
->un
.ulpWord
[4],
1355 irsp
->un
.ulpWord
[5],
1356 *(((uint32_t *) irsp
) + 6),
1357 *(((uint32_t *) irsp
) + 7));
1361 case LPFC_ABORT_IOCB
:
1364 * Idle exchange closed via ABTS from port. No iocb
1365 * resources need to be recovered.
1367 if (unlikely(irsp
->ulpCommand
== CMD_XRI_ABORTED_CX
)) {
1368 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
1369 "0333 IOCB cmd 0x%x"
1370 " processed. Skipping"
1376 cmdiocbq
= lpfc_sli_iocbq_lookup(phba
, pring
,
1378 if ((cmdiocbq
) && (cmdiocbq
->iocb_cmpl
)) {
1379 if (phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) {
1380 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
,
1383 spin_unlock_irqrestore(&phba
->hbalock
,
1385 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
,
1387 spin_lock_irqsave(&phba
->hbalock
,
1392 case LPFC_UNSOL_IOCB
:
1393 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1394 lpfc_sli_process_unsol_iocb(phba
, pring
, &rspiocbq
);
1395 spin_lock_irqsave(&phba
->hbalock
, iflag
);
1398 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
1399 char adaptermsg
[LPFC_MAX_ADPTMSG
];
1400 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
1401 memcpy(&adaptermsg
[0], (uint8_t *) irsp
,
1403 dev_warn(&((phba
->pcidev
)->dev
), "lpfc%d: %s",
1404 phba
->brd_no
, adaptermsg
);
1406 /* Unknown IOCB command */
1407 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
1408 "0334 Unknown IOCB command "
1409 "Data: x%x, x%x x%x x%x x%x\n",
1410 type
, irsp
->ulpCommand
,
1419 * The response IOCB has been processed. Update the ring
1420 * pointer in SLIM. If the port response put pointer has not
1421 * been updated, sync the pgp->rspPutInx and fetch the new port
1422 * response put pointer.
1424 writel(pring
->rspidx
, &phba
->host_gp
[pring
->ringno
].rspGetInx
);
1426 if (pring
->rspidx
== portRspPut
)
1427 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
1430 if ((rsp_cmpl
> 0) && (mask
& HA_R0RE_REQ
)) {
1431 pring
->stats
.iocb_rsp_full
++;
1432 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
1433 writel(status
, phba
->CAregaddr
);
1434 readl(phba
->CAregaddr
);
1436 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
1437 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
1438 pring
->stats
.iocb_cmd_empty
++;
1440 /* Force update of the local copy of cmdGetInx */
1441 pring
->local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
1442 lpfc_sli_resume_iocb(phba
, pring
);
1444 if ((pring
->lpfc_sli_cmd_available
))
1445 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
1449 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1454 lpfc_sli_handle_slow_ring_event(struct lpfc_hba
*phba
,
1455 struct lpfc_sli_ring
*pring
, uint32_t mask
)
1457 struct lpfc_pgp
*pgp
= (phba
->sli_rev
== 3) ?
1458 &phba
->slim2p
->mbx
.us
.s3_pgp
.port
[pring
->ringno
] :
1459 &phba
->slim2p
->mbx
.us
.s2
.port
[pring
->ringno
];
1461 IOCB_t
*irsp
= NULL
;
1462 struct lpfc_iocbq
*rspiocbp
= NULL
;
1463 struct lpfc_iocbq
*next_iocb
;
1464 struct lpfc_iocbq
*cmdiocbp
;
1465 struct lpfc_iocbq
*saveq
;
1466 uint8_t iocb_cmd_type
;
1467 lpfc_iocb_type type
;
1468 uint32_t status
, free_saveq
;
1469 uint32_t portRspPut
, portRspMax
;
1471 unsigned long iflag
;
1473 spin_lock_irqsave(&phba
->hbalock
, iflag
);
1474 pring
->stats
.iocb_event
++;
1477 * The next available response entry should never exceed the maximum
1478 * entries. If it does, treat it as an adapter hardware error.
1480 portRspMax
= pring
->numRiocb
;
1481 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
1482 if (portRspPut
>= portRspMax
) {
1484 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
1485 * rsp ring <portRspMax>
1487 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
1488 "0303 Ring %d handler: portRspPut %d "
1489 "is bigger then rsp ring %d\n",
1490 pring
->ringno
, portRspPut
, portRspMax
);
1492 phba
->link_state
= LPFC_HBA_ERROR
;
1493 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1495 phba
->work_hs
= HS_FFER3
;
1496 lpfc_handle_eratt(phba
);
1502 while (pring
->rspidx
!= portRspPut
) {
1504 * Build a completion list and call the appropriate handler.
1505 * The process is to get the next available response iocb, get
1506 * a free iocb from the list, copy the response data into the
1507 * free iocb, insert to the continuation list, and update the
1508 * next response index to slim. This process makes response
1509 * iocb's in the ring available to DMA as fast as possible but
1510 * pays a penalty for a copy operation. Since the iocb is
1511 * only 32 bytes, this penalty is considered small relative to
1512 * the PCI reads for register values and a slim write. When
1513 * the ulpLe field is set, the entire Command has been
1516 entry
= lpfc_resp_iocb(phba
, pring
);
1518 phba
->last_completion_time
= jiffies
;
1519 rspiocbp
= __lpfc_sli_get_iocbq(phba
);
1520 if (rspiocbp
== NULL
) {
1521 printk(KERN_ERR
"%s: out of buffers! Failing "
1522 "completion.\n", __FUNCTION__
);
1526 lpfc_sli_pcimem_bcopy(entry
, &rspiocbp
->iocb
,
1527 phba
->iocb_rsp_size
);
1528 irsp
= &rspiocbp
->iocb
;
1530 if (++pring
->rspidx
>= portRspMax
)
1533 if (pring
->ringno
== LPFC_ELS_RING
) {
1534 lpfc_debugfs_slow_ring_trc(phba
,
1535 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
1536 *(((uint32_t *) irsp
) + 4),
1537 *(((uint32_t *) irsp
) + 6),
1538 *(((uint32_t *) irsp
) + 7));
1541 writel(pring
->rspidx
, &phba
->host_gp
[pring
->ringno
].rspGetInx
);
1543 if (list_empty(&(pring
->iocb_continueq
))) {
1544 list_add(&rspiocbp
->list
, &(pring
->iocb_continueq
));
1546 list_add_tail(&rspiocbp
->list
,
1547 &(pring
->iocb_continueq
));
1550 pring
->iocb_continueq_cnt
++;
1553 * By default, the driver expects to free all resources
1554 * associated with this iocb completion.
1557 saveq
= list_get_first(&pring
->iocb_continueq
,
1558 struct lpfc_iocbq
, list
);
1559 irsp
= &(saveq
->iocb
);
1560 list_del_init(&pring
->iocb_continueq
);
1561 pring
->iocb_continueq_cnt
= 0;
1563 pring
->stats
.iocb_rsp
++;
1566 * If resource errors reported from HBA, reduce
1567 * queuedepths of the SCSI device.
1569 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
1570 (irsp
->un
.ulpWord
[4] == IOERR_NO_RESOURCES
)) {
1571 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1572 lpfc_adjust_queue_depth(phba
);
1573 spin_lock_irqsave(&phba
->hbalock
, iflag
);
1576 if (irsp
->ulpStatus
) {
1577 /* Rsp ring <ringno> error: IOCB */
1578 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
1579 "0328 Rsp Ring %d error: "
1584 "x%x x%x x%x x%x\n",
1586 irsp
->un
.ulpWord
[0],
1587 irsp
->un
.ulpWord
[1],
1588 irsp
->un
.ulpWord
[2],
1589 irsp
->un
.ulpWord
[3],
1590 irsp
->un
.ulpWord
[4],
1591 irsp
->un
.ulpWord
[5],
1592 *(((uint32_t *) irsp
) + 6),
1593 *(((uint32_t *) irsp
) + 7),
1594 *(((uint32_t *) irsp
) + 8),
1595 *(((uint32_t *) irsp
) + 9),
1596 *(((uint32_t *) irsp
) + 10),
1597 *(((uint32_t *) irsp
) + 11),
1598 *(((uint32_t *) irsp
) + 12),
1599 *(((uint32_t *) irsp
) + 13),
1600 *(((uint32_t *) irsp
) + 14),
1601 *(((uint32_t *) irsp
) + 15));
1605 * Fetch the IOCB command type and call the correct
1606 * completion routine. Solicited and Unsolicited
1607 * IOCBs on the ELS ring get freed back to the
1608 * lpfc_iocb_list by the discovery kernel thread.
1610 iocb_cmd_type
= irsp
->ulpCommand
& CMD_IOCB_MASK
;
1611 type
= lpfc_sli_iocb_cmd_type(iocb_cmd_type
);
1612 if (type
== LPFC_SOL_IOCB
) {
1613 spin_unlock_irqrestore(&phba
->hbalock
,
1615 rc
= lpfc_sli_process_sol_iocb(phba
, pring
,
1617 spin_lock_irqsave(&phba
->hbalock
, iflag
);
1618 } else if (type
== LPFC_UNSOL_IOCB
) {
1619 spin_unlock_irqrestore(&phba
->hbalock
,
1621 rc
= lpfc_sli_process_unsol_iocb(phba
, pring
,
1623 spin_lock_irqsave(&phba
->hbalock
, iflag
);
1624 } else if (type
== LPFC_ABORT_IOCB
) {
1625 if ((irsp
->ulpCommand
!= CMD_XRI_ABORTED_CX
) &&
1627 lpfc_sli_iocbq_lookup(phba
, pring
,
1629 /* Call the specified completion
1631 if (cmdiocbp
->iocb_cmpl
) {
1632 spin_unlock_irqrestore(
1635 (cmdiocbp
->iocb_cmpl
) (phba
,
1641 __lpfc_sli_release_iocbq(phba
,
1644 } else if (type
== LPFC_UNKNOWN_IOCB
) {
1645 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
1647 char adaptermsg
[LPFC_MAX_ADPTMSG
];
1649 memset(adaptermsg
, 0,
1651 memcpy(&adaptermsg
[0], (uint8_t *) irsp
,
1653 dev_warn(&((phba
->pcidev
)->dev
),
1655 phba
->brd_no
, adaptermsg
);
1657 /* Unknown IOCB command */
1658 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
1659 "0335 Unknown IOCB "
1660 "command Data: x%x "
1670 list_for_each_entry_safe(rspiocbp
, next_iocb
,
1671 &saveq
->list
, list
) {
1672 list_del(&rspiocbp
->list
);
1673 __lpfc_sli_release_iocbq(phba
,
1676 __lpfc_sli_release_iocbq(phba
, saveq
);
1682 * If the port response put pointer has not been updated, sync
1683 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
1684 * response put pointer.
1686 if (pring
->rspidx
== portRspPut
) {
1687 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
1689 } /* while (pring->rspidx != portRspPut) */
1691 if ((rspiocbp
!= NULL
) && (mask
& HA_R0RE_REQ
)) {
1692 /* At least one response entry has been freed */
1693 pring
->stats
.iocb_rsp_full
++;
1694 /* SET RxRE_RSP in Chip Att register */
1695 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
1696 writel(status
, phba
->CAregaddr
);
1697 readl(phba
->CAregaddr
); /* flush */
1699 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
1700 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
1701 pring
->stats
.iocb_cmd_empty
++;
1703 /* Force update of the local copy of cmdGetInx */
1704 pring
->local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
1705 lpfc_sli_resume_iocb(phba
, pring
);
1707 if ((pring
->lpfc_sli_cmd_available
))
1708 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
1712 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1717 lpfc_sli_abort_iocb_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1719 LIST_HEAD(completions
);
1720 struct lpfc_iocbq
*iocb
, *next_iocb
;
1723 if (pring
->ringno
== LPFC_ELS_RING
) {
1724 lpfc_fabric_abort_hba(phba
);
1727 /* Error everything on txq and txcmplq
1730 spin_lock_irq(&phba
->hbalock
);
1731 list_splice_init(&pring
->txq
, &completions
);
1734 /* Next issue ABTS for everything on the txcmplq */
1735 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
)
1736 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
1738 spin_unlock_irq(&phba
->hbalock
);
1740 while (!list_empty(&completions
)) {
1741 iocb
= list_get_first(&completions
, struct lpfc_iocbq
, list
);
1743 list_del_init(&iocb
->list
);
1745 if (!iocb
->iocb_cmpl
)
1746 lpfc_sli_release_iocbq(phba
, iocb
);
1748 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
1749 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
1750 (iocb
->iocb_cmpl
) (phba
, iocb
, iocb
);
1756 lpfc_sli_brdready(struct lpfc_hba
*phba
, uint32_t mask
)
1762 /* Read the HBA Host Status Register */
1763 status
= readl(phba
->HSregaddr
);
1766 * Check status register every 100ms for 5 retries, then every
1767 * 500ms for 5, then every 2.5 sec for 5, then reset board and
1768 * every 2.5 sec for 4.
1769 * Break our of the loop if errors occurred during init.
1771 while (((status
& mask
) != mask
) &&
1772 !(status
& HS_FFERM
) &&
1784 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
1785 lpfc_sli_brdrestart(phba
);
1787 /* Read the HBA Host Status Register */
1788 status
= readl(phba
->HSregaddr
);
1791 /* Check to see if any errors occurred during init */
1792 if ((status
& HS_FFERM
) || (i
>= 20)) {
1793 phba
->link_state
= LPFC_HBA_ERROR
;
1800 #define BARRIER_TEST_PATTERN (0xdeadbeef)
1802 void lpfc_reset_barrier(struct lpfc_hba
*phba
)
1804 uint32_t __iomem
*resp_buf
;
1805 uint32_t __iomem
*mbox_buf
;
1806 volatile uint32_t mbox
;
1811 pci_read_config_byte(phba
->pcidev
, PCI_HEADER_TYPE
, &hdrtype
);
1812 if (hdrtype
!= 0x80 ||
1813 (FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != HELIOS_JEDEC_ID
&&
1814 FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != THOR_JEDEC_ID
))
1818 * Tell the other part of the chip to suspend temporarily all
1821 resp_buf
= phba
->MBslimaddr
;
1823 /* Disable the error attention */
1824 hc_copy
= readl(phba
->HCregaddr
);
1825 writel((hc_copy
& ~HC_ERINT_ENA
), phba
->HCregaddr
);
1826 readl(phba
->HCregaddr
); /* flush */
1827 phba
->link_flag
|= LS_IGNORE_ERATT
;
1829 if (readl(phba
->HAregaddr
) & HA_ERATT
) {
1830 /* Clear Chip error bit */
1831 writel(HA_ERATT
, phba
->HAregaddr
);
1832 phba
->pport
->stopped
= 1;
1836 ((MAILBOX_t
*)&mbox
)->mbxCommand
= MBX_KILL_BOARD
;
1837 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_CHIP
;
1839 writel(BARRIER_TEST_PATTERN
, (resp_buf
+ 1));
1840 mbox_buf
= phba
->MBslimaddr
;
1841 writel(mbox
, mbox_buf
);
1844 readl(resp_buf
+ 1) != ~(BARRIER_TEST_PATTERN
) && i
< 50; i
++)
1847 if (readl(resp_buf
+ 1) != ~(BARRIER_TEST_PATTERN
)) {
1848 if (phba
->sli
.sli_flag
& LPFC_SLI2_ACTIVE
||
1849 phba
->pport
->stopped
)
1855 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_HOST
;
1856 for (i
= 0; readl(resp_buf
) != mbox
&& i
< 500; i
++)
1861 while (!(readl(phba
->HAregaddr
) & HA_ERATT
) && ++i
< 500)
1864 if (readl(phba
->HAregaddr
) & HA_ERATT
) {
1865 writel(HA_ERATT
, phba
->HAregaddr
);
1866 phba
->pport
->stopped
= 1;
1870 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
1871 writel(hc_copy
, phba
->HCregaddr
);
1872 readl(phba
->HCregaddr
); /* flush */
1876 lpfc_sli_brdkill(struct lpfc_hba
*phba
)
1878 struct lpfc_sli
*psli
;
1888 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
1889 "0329 Kill HBA Data: x%x x%x\n",
1890 phba
->pport
->port_state
, psli
->sli_flag
);
1892 if ((pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
,
1896 /* Disable the error attention */
1897 spin_lock_irq(&phba
->hbalock
);
1898 status
= readl(phba
->HCregaddr
);
1899 status
&= ~HC_ERINT_ENA
;
1900 writel(status
, phba
->HCregaddr
);
1901 readl(phba
->HCregaddr
); /* flush */
1902 phba
->link_flag
|= LS_IGNORE_ERATT
;
1903 spin_unlock_irq(&phba
->hbalock
);
1905 lpfc_kill_board(phba
, pmb
);
1906 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
1907 retval
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
1909 if (retval
!= MBX_SUCCESS
) {
1910 if (retval
!= MBX_BUSY
)
1911 mempool_free(pmb
, phba
->mbox_mem_pool
);
1912 spin_lock_irq(&phba
->hbalock
);
1913 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
1914 spin_unlock_irq(&phba
->hbalock
);
1918 psli
->sli_flag
&= ~LPFC_SLI2_ACTIVE
;
1920 mempool_free(pmb
, phba
->mbox_mem_pool
);
1922 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
1923 * attention every 100ms for 3 seconds. If we don't get ERATT after
1924 * 3 seconds we still set HBA_ERROR state because the status of the
1925 * board is now undefined.
1927 ha_copy
= readl(phba
->HAregaddr
);
1929 while ((i
++ < 30) && !(ha_copy
& HA_ERATT
)) {
1931 ha_copy
= readl(phba
->HAregaddr
);
1934 del_timer_sync(&psli
->mbox_tmo
);
1935 if (ha_copy
& HA_ERATT
) {
1936 writel(HA_ERATT
, phba
->HAregaddr
);
1937 phba
->pport
->stopped
= 1;
1939 spin_lock_irq(&phba
->hbalock
);
1940 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
1941 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
1942 spin_unlock_irq(&phba
->hbalock
);
1944 psli
->mbox_active
= NULL
;
1945 lpfc_hba_down_post(phba
);
1946 phba
->link_state
= LPFC_HBA_ERROR
;
1948 return ha_copy
& HA_ERATT
? 0 : 1;
1952 lpfc_sli_brdreset(struct lpfc_hba
*phba
)
1954 struct lpfc_sli
*psli
;
1955 struct lpfc_sli_ring
*pring
;
1962 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
1963 "0325 Reset HBA Data: x%x x%x\n",
1964 phba
->pport
->port_state
, psli
->sli_flag
);
1966 /* perform board reset */
1967 phba
->fc_eventTag
= 0;
1968 phba
->pport
->fc_myDID
= 0;
1969 phba
->pport
->fc_prevDID
= 0;
1971 /* Turn off parity checking and serr during the physical reset */
1972 pci_read_config_word(phba
->pcidev
, PCI_COMMAND
, &cfg_value
);
1973 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
,
1975 ~(PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
)));
1977 psli
->sli_flag
&= ~(LPFC_SLI2_ACTIVE
| LPFC_PROCESS_LA
);
1978 /* Now toggle INITFF bit in the Host Control Register */
1979 writel(HC_INITFF
, phba
->HCregaddr
);
1981 readl(phba
->HCregaddr
); /* flush */
1982 writel(0, phba
->HCregaddr
);
1983 readl(phba
->HCregaddr
); /* flush */
1985 /* Restore PCI cmd register */
1986 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, cfg_value
);
1988 /* Initialize relevant SLI info */
1989 for (i
= 0; i
< psli
->num_rings
; i
++) {
1990 pring
= &psli
->ring
[i
];
1993 pring
->next_cmdidx
= 0;
1994 pring
->local_getidx
= 0;
1996 pring
->missbufcnt
= 0;
1999 phba
->link_state
= LPFC_WARM_START
;
2004 lpfc_sli_brdrestart(struct lpfc_hba
*phba
)
2007 struct lpfc_sli
*psli
;
2009 volatile uint32_t word0
;
2010 void __iomem
*to_slim
;
2012 spin_lock_irq(&phba
->hbalock
);
2017 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
2018 "0337 Restart HBA Data: x%x x%x\n",
2019 phba
->pport
->port_state
, psli
->sli_flag
);
2022 mb
= (MAILBOX_t
*) &word0
;
2023 mb
->mbxCommand
= MBX_RESTART
;
2026 lpfc_reset_barrier(phba
);
2028 to_slim
= phba
->MBslimaddr
;
2029 writel(*(uint32_t *) mb
, to_slim
);
2030 readl(to_slim
); /* flush */
2032 /* Only skip post after fc_ffinit is completed */
2033 if (phba
->pport
->port_state
) {
2035 word0
= 1; /* This is really setting up word1 */
2038 word0
= 0; /* This is really setting up word1 */
2040 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
2041 writel(*(uint32_t *) mb
, to_slim
);
2042 readl(to_slim
); /* flush */
2044 lpfc_sli_brdreset(phba
);
2045 phba
->pport
->stopped
= 0;
2046 phba
->link_state
= LPFC_INIT_START
;
2048 spin_unlock_irq(&phba
->hbalock
);
2050 memset(&psli
->lnk_stat_offsets
, 0, sizeof(psli
->lnk_stat_offsets
));
2051 psli
->stats_start
= get_seconds();
2058 lpfc_hba_down_post(phba
);
2064 lpfc_sli_chipset_init(struct lpfc_hba
*phba
)
2066 uint32_t status
, i
= 0;
2068 /* Read the HBA Host Status Register */
2069 status
= readl(phba
->HSregaddr
);
2071 /* Check status register to see what current state is */
2073 while ((status
& (HS_FFRDY
| HS_MBRDY
)) != (HS_FFRDY
| HS_MBRDY
)) {
2075 /* Check every 100ms for 5 retries, then every 500ms for 5, then
2076 * every 2.5 sec for 5, then reset board and every 2.5 sec for
2080 /* Adapter failed to init, timeout, status reg
2082 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2083 "0436 Adapter failed to init, "
2084 "timeout, status reg x%x\n", status
);
2085 phba
->link_state
= LPFC_HBA_ERROR
;
2089 /* Check to see if any errors occurred during init */
2090 if (status
& HS_FFERM
) {
2091 /* ERROR: During chipset initialization */
2092 /* Adapter failed to init, chipset, status reg
2094 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2095 "0437 Adapter failed to init, "
2096 "chipset, status reg x%x\n", status
);
2097 phba
->link_state
= LPFC_HBA_ERROR
;
2103 } else if (i
<= 10) {
2111 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
2112 lpfc_sli_brdrestart(phba
);
2114 /* Read the HBA Host Status Register */
2115 status
= readl(phba
->HSregaddr
);
2118 /* Check to see if any errors occurred during init */
2119 if (status
& HS_FFERM
) {
2120 /* ERROR: During chipset initialization */
2121 /* Adapter failed to init, chipset, status reg <status> */
2122 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2123 "0438 Adapter failed to init, chipset, "
2124 "status reg x%x\n", status
);
2125 phba
->link_state
= LPFC_HBA_ERROR
;
2129 /* Clear all interrupt enable conditions */
2130 writel(0, phba
->HCregaddr
);
2131 readl(phba
->HCregaddr
); /* flush */
2133 /* setup host attn register */
2134 writel(0xffffffff, phba
->HAregaddr
);
2135 readl(phba
->HAregaddr
); /* flush */
2140 lpfc_sli_hbq_count(void)
2142 return ARRAY_SIZE(lpfc_hbq_defs
);
2146 lpfc_sli_hbq_entry_count(void)
2148 int hbq_count
= lpfc_sli_hbq_count();
2152 for (i
= 0; i
< hbq_count
; ++i
)
2153 count
+= lpfc_hbq_defs
[i
]->entry_count
;
2158 lpfc_sli_hbq_size(void)
2160 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry
);
2164 lpfc_sli_hbq_setup(struct lpfc_hba
*phba
)
2166 int hbq_count
= lpfc_sli_hbq_count();
2170 uint32_t hbq_entry_index
;
2172 /* Get a Mailbox buffer to setup mailbox
2173 * commands for HBA initialization
2175 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2182 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
2183 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
2185 hbq_entry_index
= 0;
2186 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
) {
2187 phba
->hbqs
[hbqno
].next_hbqPutIdx
= 0;
2188 phba
->hbqs
[hbqno
].hbqPutIdx
= 0;
2189 phba
->hbqs
[hbqno
].local_hbqGetIdx
= 0;
2190 phba
->hbqs
[hbqno
].entry_count
=
2191 lpfc_hbq_defs
[hbqno
]->entry_count
;
2192 lpfc_config_hbq(phba
, lpfc_hbq_defs
[hbqno
], hbq_entry_index
,
2194 hbq_entry_index
+= phba
->hbqs
[hbqno
].entry_count
;
2196 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
2197 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
2198 mbxStatus <status>, ring <num> */
2200 lpfc_printf_log(phba
, KERN_ERR
,
2201 LOG_SLI
| LOG_VPORT
,
2202 "1805 Adapter failed to init. "
2203 "Data: x%x x%x x%x\n",
2205 pmbox
->mbxStatus
, hbqno
);
2207 phba
->link_state
= LPFC_HBA_ERROR
;
2208 mempool_free(pmb
, phba
->mbox_mem_pool
);
2212 phba
->hbq_count
= hbq_count
;
2214 mempool_free(pmb
, phba
->mbox_mem_pool
);
2216 /* Initially populate or replenish the HBQs */
2217 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
) {
2218 if (lpfc_sli_hbqbuf_init_hbqs(phba
, hbqno
))
2225 lpfc_do_config_port(struct lpfc_hba
*phba
, int sli_mode
)
2228 uint32_t resetcount
= 0, rc
= 0, done
= 0;
2230 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2232 phba
->link_state
= LPFC_HBA_ERROR
;
2236 phba
->sli_rev
= sli_mode
;
2237 while (resetcount
< 2 && !done
) {
2238 spin_lock_irq(&phba
->hbalock
);
2239 phba
->sli
.sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
2240 spin_unlock_irq(&phba
->hbalock
);
2241 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
2242 lpfc_sli_brdrestart(phba
);
2244 rc
= lpfc_sli_chipset_init(phba
);
2248 spin_lock_irq(&phba
->hbalock
);
2249 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
2250 spin_unlock_irq(&phba
->hbalock
);
2253 /* Call pre CONFIG_PORT mailbox command initialization. A
2254 * value of 0 means the call was successful. Any other
2255 * nonzero value is a failure, but if ERESTART is returned,
2256 * the driver may reset the HBA and try again.
2258 rc
= lpfc_config_port_prep(phba
);
2259 if (rc
== -ERESTART
) {
2260 phba
->link_state
= LPFC_LINK_UNKNOWN
;
2266 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
2267 lpfc_config_port(phba
, pmb
);
2268 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
2269 if (rc
!= MBX_SUCCESS
) {
2270 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2271 "0442 Adapter failed to init, mbxCmd x%x "
2272 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
2273 pmb
->mb
.mbxCommand
, pmb
->mb
.mbxStatus
, 0);
2274 spin_lock_irq(&phba
->hbalock
);
2275 phba
->sli
.sli_flag
&= ~LPFC_SLI2_ACTIVE
;
2276 spin_unlock_irq(&phba
->hbalock
);
2280 phba
->max_vpi
= (phba
->max_vpi
&&
2281 pmb
->mb
.un
.varCfgPort
.gmv
) != 0
2282 ? pmb
->mb
.un
.varCfgPort
.max_vpi
2289 goto do_prep_failed
;
2292 if ((pmb
->mb
.un
.varCfgPort
.sli_mode
== 3) &&
2293 (!pmb
->mb
.un
.varCfgPort
.cMA
)) {
2295 goto do_prep_failed
;
2300 mempool_free(pmb
, phba
->mbox_mem_pool
);
2305 lpfc_sli_hba_setup(struct lpfc_hba
*phba
)
2310 switch (lpfc_sli_mode
) {
2312 if (phba
->cfg_npiv_enable
) {
2313 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
2314 "1824 NPIV enabled: Override lpfc_sli_mode "
2315 "parameter (%d) to auto (0).\n",
2325 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
2326 "1819 Unrecognized lpfc_sli_mode "
2327 "parameter: %d.\n", lpfc_sli_mode
);
2332 rc
= lpfc_do_config_port(phba
, mode
);
2333 if (rc
&& lpfc_sli_mode
== 3)
2334 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
2335 "1820 Unable to select SLI-3. "
2336 "Not supported by adapter.\n");
2337 if (rc
&& mode
!= 2)
2338 rc
= lpfc_do_config_port(phba
, 2);
2340 goto lpfc_sli_hba_setup_error
;
2342 if (phba
->sli_rev
== 3) {
2343 phba
->iocb_cmd_size
= SLI3_IOCB_CMD_SIZE
;
2344 phba
->iocb_rsp_size
= SLI3_IOCB_RSP_SIZE
;
2345 phba
->sli3_options
|= LPFC_SLI3_ENABLED
;
2346 phba
->sli3_options
|= LPFC_SLI3_HBQ_ENABLED
;
2349 phba
->iocb_cmd_size
= SLI2_IOCB_CMD_SIZE
;
2350 phba
->iocb_rsp_size
= SLI2_IOCB_RSP_SIZE
;
2351 phba
->sli3_options
= 0;
2354 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
2355 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
2356 phba
->sli_rev
, phba
->max_vpi
);
2357 rc
= lpfc_sli_ring_map(phba
);
2360 goto lpfc_sli_hba_setup_error
;
2364 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
2365 rc
= lpfc_sli_hbq_setup(phba
);
2367 goto lpfc_sli_hba_setup_error
;
2370 phba
->sli
.sli_flag
|= LPFC_PROCESS_LA
;
2372 rc
= lpfc_config_port_post(phba
);
2374 goto lpfc_sli_hba_setup_error
;
2378 lpfc_sli_hba_setup_error
:
2379 phba
->link_state
= LPFC_HBA_ERROR
;
2380 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
2381 "0445 Firmware initialization failed\n");
2385 /*! lpfc_mbox_timeout
2389 * \param hba Pointer to per struct lpfc_hba structure
2390 * \param l1 Pointer to the driver's mailbox queue.
2396 * This routine handles mailbox timeout events at timer interrupt context.
2399 lpfc_mbox_timeout(unsigned long ptr
)
2401 struct lpfc_hba
*phba
= (struct lpfc_hba
*) ptr
;
2402 unsigned long iflag
;
2403 uint32_t tmo_posted
;
2405 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflag
);
2406 tmo_posted
= phba
->pport
->work_port_events
& WORKER_MBOX_TMO
;
2408 phba
->pport
->work_port_events
|= WORKER_MBOX_TMO
;
2409 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflag
);
2412 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2413 if (phba
->work_wait
)
2414 lpfc_worker_wake_up(phba
);
2415 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2420 lpfc_mbox_timeout_handler(struct lpfc_hba
*phba
)
2422 LPFC_MBOXQ_t
*pmbox
= phba
->sli
.mbox_active
;
2423 MAILBOX_t
*mb
= &pmbox
->mb
;
2424 struct lpfc_sli
*psli
= &phba
->sli
;
2425 struct lpfc_sli_ring
*pring
;
2427 if (!(phba
->pport
->work_port_events
& WORKER_MBOX_TMO
)) {
2431 /* Mbox cmd <mbxCommand> timeout */
2432 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
2433 "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
2435 phba
->pport
->port_state
,
2437 phba
->sli
.mbox_active
);
2439 /* Setting state unknown so lpfc_sli_abort_iocb_ring
2440 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
2441 * it to fail all oustanding SCSI IO.
2443 spin_lock_irq(&phba
->pport
->work_port_lock
);
2444 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
2445 spin_unlock_irq(&phba
->pport
->work_port_lock
);
2446 spin_lock_irq(&phba
->hbalock
);
2447 phba
->link_state
= LPFC_LINK_UNKNOWN
;
2448 phba
->pport
->fc_flag
|= FC_ESTABLISH_LINK
;
2449 psli
->sli_flag
&= ~LPFC_SLI2_ACTIVE
;
2450 spin_unlock_irq(&phba
->hbalock
);
2452 pring
= &psli
->ring
[psli
->fcp_ring
];
2453 lpfc_sli_abort_iocb_ring(phba
, pring
);
2455 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
2456 "0316 Resetting board due to mailbox timeout\n");
2458 * lpfc_offline calls lpfc_sli_hba_down which will clean up
2459 * on oustanding mailbox commands.
2461 lpfc_offline_prep(phba
);
2463 lpfc_sli_brdrestart(phba
);
2464 if (lpfc_online(phba
) == 0) /* Initialize the HBA */
2465 mod_timer(&phba
->fc_estabtmo
, jiffies
+ HZ
* 60);
2466 lpfc_unblock_mgmt_io(phba
);
2471 lpfc_sli_issue_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmbox
, uint32_t flag
)
2474 struct lpfc_sli
*psli
= &phba
->sli
;
2475 uint32_t status
, evtctr
;
2478 unsigned long drvr_flag
= 0;
2479 volatile uint32_t word0
, ldata
;
2480 void __iomem
*to_slim
;
2482 if (pmbox
->mbox_cmpl
&& pmbox
->mbox_cmpl
!= lpfc_sli_def_mbox_cmpl
&&
2483 pmbox
->mbox_cmpl
!= lpfc_sli_wake_mbox_wait
) {
2485 lpfc_printf_log(phba
, KERN_ERR
,
2486 LOG_MBOX
| LOG_VPORT
,
2487 "1806 Mbox x%x failed. No vport\n",
2488 pmbox
->mb
.mbxCommand
);
2490 return MBXERR_ERROR
;
2495 /* If the PCI channel is in offline state, do not post mbox. */
2496 if (unlikely(pci_channel_offline(phba
->pcidev
)))
2497 return MBX_NOT_FINISHED
;
2499 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
2504 status
= MBX_SUCCESS
;
2506 if (phba
->link_state
== LPFC_HBA_ERROR
) {
2507 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
2509 /* Mbox command <mbxCommand> cannot issue */
2510 LOG_MBOX_CANNOT_ISSUE_DATA(phba
, pmbox
, psli
, flag
)
2511 return MBX_NOT_FINISHED
;
2514 if (mb
->mbxCommand
!= MBX_KILL_BOARD
&& flag
& MBX_NOWAIT
&&
2515 !(readl(phba
->HCregaddr
) & HC_MBINT_ENA
)) {
2516 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
2517 LOG_MBOX_CANNOT_ISSUE_DATA(phba
, pmbox
, psli
, flag
)
2518 return MBX_NOT_FINISHED
;
2521 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
2522 /* Polling for a mbox command when another one is already active
2523 * is not allowed in SLI. Also, the driver must have established
2524 * SLI2 mode to queue and process multiple mbox commands.
2527 if (flag
& MBX_POLL
) {
2528 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
2530 /* Mbox command <mbxCommand> cannot issue */
2531 LOG_MBOX_CANNOT_ISSUE_DATA(phba
, pmbox
, psli
, flag
);
2532 return MBX_NOT_FINISHED
;
2535 if (!(psli
->sli_flag
& LPFC_SLI2_ACTIVE
)) {
2536 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
2537 /* Mbox command <mbxCommand> cannot issue */
2538 LOG_MBOX_CANNOT_ISSUE_DATA(phba
, pmbox
, psli
, flag
);
2539 return MBX_NOT_FINISHED
;
2542 /* Handle STOP IOCB processing flag. This is only meaningful
2543 * if we are not polling for mbox completion.
2545 if (flag
& MBX_STOP_IOCB
) {
2546 flag
&= ~MBX_STOP_IOCB
;
2547 /* Now flag each ring */
2548 for (i
= 0; i
< psli
->num_rings
; i
++) {
2549 /* If the ring is active, flag it */
2550 if (psli
->ring
[i
].cmdringaddr
) {
2551 psli
->ring
[i
].flag
|=
2557 /* Another mailbox command is still being processed, queue this
2558 * command to be processed later.
2560 lpfc_mbox_put(phba
, pmbox
);
2562 /* Mbox cmd issue - BUSY */
2563 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
2564 "(%d):0308 Mbox cmd issue - BUSY Data: "
2565 "x%x x%x x%x x%x\n",
2566 pmbox
->vport
? pmbox
->vport
->vpi
: 0xffffff,
2567 mb
->mbxCommand
, phba
->pport
->port_state
,
2568 psli
->sli_flag
, flag
);
2570 psli
->slistat
.mbox_busy
++;
2571 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
2574 lpfc_debugfs_disc_trc(pmbox
->vport
,
2575 LPFC_DISC_TRC_MBOX_VPORT
,
2576 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
2577 (uint32_t)mb
->mbxCommand
,
2578 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
2581 lpfc_debugfs_disc_trc(phba
->pport
,
2583 "MBOX Bsy: cmd:x%x mb:x%x x%x",
2584 (uint32_t)mb
->mbxCommand
,
2585 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
2591 /* Handle STOP IOCB processing flag. This is only meaningful
2592 * if we are not polling for mbox completion.
2594 if (flag
& MBX_STOP_IOCB
) {
2595 flag
&= ~MBX_STOP_IOCB
;
2596 if (flag
== MBX_NOWAIT
) {
2597 /* Now flag each ring */
2598 for (i
= 0; i
< psli
->num_rings
; i
++) {
2599 /* If the ring is active, flag it */
2600 if (psli
->ring
[i
].cmdringaddr
) {
2601 psli
->ring
[i
].flag
|=
2608 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
2610 /* If we are not polling, we MUST be in SLI2 mode */
2611 if (flag
!= MBX_POLL
) {
2612 if (!(psli
->sli_flag
& LPFC_SLI2_ACTIVE
) &&
2613 (mb
->mbxCommand
!= MBX_KILL_BOARD
)) {
2614 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
2615 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
2616 /* Mbox command <mbxCommand> cannot issue */
2617 LOG_MBOX_CANNOT_ISSUE_DATA(phba
, pmbox
, psli
, flag
);
2618 return MBX_NOT_FINISHED
;
2620 /* timeout active mbox command */
2621 mod_timer(&psli
->mbox_tmo
, (jiffies
+
2622 (HZ
* lpfc_mbox_tmo_val(phba
, mb
->mbxCommand
))));
2625 /* Mailbox cmd <cmd> issue */
2626 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
2627 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
2629 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
2630 mb
->mbxCommand
, phba
->pport
->port_state
,
2631 psli
->sli_flag
, flag
);
2633 if (mb
->mbxCommand
!= MBX_HEARTBEAT
) {
2635 lpfc_debugfs_disc_trc(pmbox
->vport
,
2636 LPFC_DISC_TRC_MBOX_VPORT
,
2637 "MBOX Send vport: cmd:x%x mb:x%x x%x",
2638 (uint32_t)mb
->mbxCommand
,
2639 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
2642 lpfc_debugfs_disc_trc(phba
->pport
,
2644 "MBOX Send: cmd:x%x mb:x%x x%x",
2645 (uint32_t)mb
->mbxCommand
,
2646 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
2650 psli
->slistat
.mbox_cmd
++;
2651 evtctr
= psli
->slistat
.mbox_event
;
2653 /* next set own bit for the adapter and copy over command word */
2654 mb
->mbxOwner
= OWN_CHIP
;
2656 if (psli
->sli_flag
& LPFC_SLI2_ACTIVE
) {
2657 /* First copy command data to host SLIM area */
2658 lpfc_sli_pcimem_bcopy(mb
, &phba
->slim2p
->mbx
, MAILBOX_CMD_SIZE
);
2660 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
2661 /* copy command data into host mbox for cmpl */
2662 lpfc_sli_pcimem_bcopy(mb
, &phba
->slim2p
->mbx
,
2666 /* First copy mbox command data to HBA SLIM, skip past first
2668 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
2669 lpfc_memcpy_to_slim(to_slim
, &mb
->un
.varWords
[0],
2670 MAILBOX_CMD_SIZE
- sizeof (uint32_t));
2672 /* Next copy over first word, with mbxOwner set */
2673 ldata
= *((volatile uint32_t *)mb
);
2674 to_slim
= phba
->MBslimaddr
;
2675 writel(ldata
, to_slim
);
2676 readl(to_slim
); /* flush */
2678 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
2679 /* switch over to host mailbox */
2680 psli
->sli_flag
|= LPFC_SLI2_ACTIVE
;
2685 /* interrupt board to doit right away */
2686 writel(CA_MBATT
, phba
->CAregaddr
);
2687 readl(phba
->CAregaddr
); /* flush */
2691 /* Don't wait for it to finish, just return */
2692 psli
->mbox_active
= pmbox
;
2696 psli
->mbox_active
= NULL
;
2697 if (psli
->sli_flag
& LPFC_SLI2_ACTIVE
) {
2698 /* First read mbox status word */
2699 word0
= *((volatile uint32_t *)&phba
->slim2p
->mbx
);
2700 word0
= le32_to_cpu(word0
);
2702 /* First read mbox status word */
2703 word0
= readl(phba
->MBslimaddr
);
2706 /* Read the HBA Host Attention Register */
2707 ha_copy
= readl(phba
->HAregaddr
);
2709 i
= lpfc_mbox_tmo_val(phba
, mb
->mbxCommand
);
2710 i
*= 1000; /* Convert to ms */
2712 /* Wait for command to complete */
2713 while (((word0
& OWN_CHIP
) == OWN_CHIP
) ||
2714 (!(ha_copy
& HA_MBATT
) &&
2715 (phba
->link_state
> LPFC_WARM_START
))) {
2717 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
2718 spin_unlock_irqrestore(&phba
->hbalock
,
2720 return MBX_NOT_FINISHED
;
2723 /* Check if we took a mbox interrupt while we were
2725 if (((word0
& OWN_CHIP
) != OWN_CHIP
)
2726 && (evtctr
!= psli
->slistat
.mbox_event
))
2729 spin_unlock_irqrestore(&phba
->hbalock
,
2734 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
2736 if (psli
->sli_flag
& LPFC_SLI2_ACTIVE
) {
2737 /* First copy command data */
2738 word0
= *((volatile uint32_t *)
2739 &phba
->slim2p
->mbx
);
2740 word0
= le32_to_cpu(word0
);
2741 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
2743 volatile uint32_t slimword0
;
2744 /* Check real SLIM for any errors */
2745 slimword0
= readl(phba
->MBslimaddr
);
2746 slimmb
= (MAILBOX_t
*) & slimword0
;
2747 if (((slimword0
& OWN_CHIP
) != OWN_CHIP
)
2748 && slimmb
->mbxStatus
) {
2755 /* First copy command data */
2756 word0
= readl(phba
->MBslimaddr
);
2758 /* Read the HBA Host Attention Register */
2759 ha_copy
= readl(phba
->HAregaddr
);
2762 if (psli
->sli_flag
& LPFC_SLI2_ACTIVE
) {
2763 /* copy results back to user */
2764 lpfc_sli_pcimem_bcopy(&phba
->slim2p
->mbx
, mb
,
2767 /* First copy command data */
2768 lpfc_memcpy_from_slim(mb
, phba
->MBslimaddr
,
2770 if ((mb
->mbxCommand
== MBX_DUMP_MEMORY
) &&
2772 lpfc_memcpy_from_slim((void *)pmbox
->context2
,
2773 phba
->MBslimaddr
+ DMP_RSP_OFFSET
,
2774 mb
->un
.varDmp
.word_cnt
);
2778 writel(HA_MBATT
, phba
->HAregaddr
);
2779 readl(phba
->HAregaddr
); /* flush */
2781 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
2782 status
= mb
->mbxStatus
;
2785 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
2790 * Caller needs to hold lock.
2793 __lpfc_sli_ringtx_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2794 struct lpfc_iocbq
*piocb
)
2796 /* Insert the caller's iocb in the txq tail for later processing. */
2797 list_add_tail(&piocb
->list
, &pring
->txq
);
2801 static struct lpfc_iocbq
*
2802 lpfc_sli_next_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2803 struct lpfc_iocbq
**piocb
)
2805 struct lpfc_iocbq
* nextiocb
;
2807 nextiocb
= lpfc_sli_ringtx_get(phba
, pring
);
2817 * Lockless version of lpfc_sli_issue_iocb.
2820 __lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2821 struct lpfc_iocbq
*piocb
, uint32_t flag
)
2823 struct lpfc_iocbq
*nextiocb
;
2826 if (piocb
->iocb_cmpl
&& (!piocb
->vport
) &&
2827 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
2828 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
2829 lpfc_printf_log(phba
, KERN_ERR
,
2830 LOG_SLI
| LOG_VPORT
,
2831 "1807 IOCB x%x failed. No vport\n",
2832 piocb
->iocb
.ulpCommand
);
2838 /* If the PCI channel is in offline state, do not post iocbs. */
2839 if (unlikely(pci_channel_offline(phba
->pcidev
)))
2843 * We should never get an IOCB if we are in a < LINK_DOWN state
2845 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
2849 * Check to see if we are blocking IOCB processing because of a
2850 * outstanding mbox command.
2852 if (unlikely(pring
->flag
& LPFC_STOP_IOCB_MBX
))
2855 if (unlikely(phba
->link_state
== LPFC_LINK_DOWN
)) {
2857 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
2858 * can be issued if the link is not up.
2860 switch (piocb
->iocb
.ulpCommand
) {
2861 case CMD_QUE_RING_BUF_CN
:
2862 case CMD_QUE_RING_BUF64_CN
:
2864 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
2865 * completion, iocb_cmpl MUST be 0.
2867 if (piocb
->iocb_cmpl
)
2868 piocb
->iocb_cmpl
= NULL
;
2870 case CMD_CREATE_XRI_CR
:
2871 case CMD_CLOSE_XRI_CN
:
2872 case CMD_CLOSE_XRI_CX
:
2879 * For FCP commands, we must be in a state where we can process link
2882 } else if (unlikely(pring
->ringno
== phba
->sli
.fcp_ring
&&
2883 !(phba
->sli
.sli_flag
& LPFC_PROCESS_LA
))) {
2887 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
2888 (nextiocb
= lpfc_sli_next_iocb(phba
, pring
, &piocb
)))
2889 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
2892 lpfc_sli_update_ring(phba
, pring
);
2894 lpfc_sli_update_full_ring(phba
, pring
);
2897 return IOCB_SUCCESS
;
2902 pring
->stats
.iocb_cmd_delay
++;
2906 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
2907 __lpfc_sli_ringtx_put(phba
, pring
, piocb
);
2908 return IOCB_SUCCESS
;
2916 lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2917 struct lpfc_iocbq
*piocb
, uint32_t flag
)
2919 unsigned long iflags
;
2922 spin_lock_irqsave(&phba
->hbalock
, iflags
);
2923 rc
= __lpfc_sli_issue_iocb(phba
, pring
, piocb
, flag
);
2924 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
2930 lpfc_extra_ring_setup( struct lpfc_hba
*phba
)
2932 struct lpfc_sli
*psli
;
2933 struct lpfc_sli_ring
*pring
;
2937 /* Adjust cmd/rsp ring iocb entries more evenly */
2939 /* Take some away from the FCP ring */
2940 pring
= &psli
->ring
[psli
->fcp_ring
];
2941 pring
->numCiocb
-= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
2942 pring
->numRiocb
-= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
2943 pring
->numCiocb
-= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
2944 pring
->numRiocb
-= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
2946 /* and give them to the extra ring */
2947 pring
= &psli
->ring
[psli
->extra_ring
];
2949 pring
->numCiocb
+= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
2950 pring
->numRiocb
+= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
2951 pring
->numCiocb
+= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
2952 pring
->numRiocb
+= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
2954 /* Setup default profile for this ring */
2955 pring
->iotag_max
= 4096;
2956 pring
->num_mask
= 1;
2957 pring
->prt
[0].profile
= 0; /* Mask 0 */
2958 pring
->prt
[0].rctl
= phba
->cfg_multi_ring_rctl
;
2959 pring
->prt
[0].type
= phba
->cfg_multi_ring_type
;
2960 pring
->prt
[0].lpfc_sli_rcv_unsol_event
= NULL
;
2965 lpfc_sli_setup(struct lpfc_hba
*phba
)
2967 int i
, totiocbsize
= 0;
2968 struct lpfc_sli
*psli
= &phba
->sli
;
2969 struct lpfc_sli_ring
*pring
;
2971 psli
->num_rings
= MAX_CONFIGURED_RINGS
;
2973 psli
->fcp_ring
= LPFC_FCP_RING
;
2974 psli
->next_ring
= LPFC_FCP_NEXT_RING
;
2975 psli
->extra_ring
= LPFC_EXTRA_RING
;
2977 psli
->iocbq_lookup
= NULL
;
2978 psli
->iocbq_lookup_len
= 0;
2979 psli
->last_iotag
= 0;
2981 for (i
= 0; i
< psli
->num_rings
; i
++) {
2982 pring
= &psli
->ring
[i
];
2984 case LPFC_FCP_RING
: /* ring 0 - FCP */
2985 /* numCiocb and numRiocb are used in config_port */
2986 pring
->numCiocb
= SLI2_IOCB_CMD_R0_ENTRIES
;
2987 pring
->numRiocb
= SLI2_IOCB_RSP_R0_ENTRIES
;
2988 pring
->numCiocb
+= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
2989 pring
->numRiocb
+= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
2990 pring
->numCiocb
+= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
2991 pring
->numRiocb
+= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
2992 pring
->sizeCiocb
= (phba
->sli_rev
== 3) ?
2993 SLI3_IOCB_CMD_SIZE
:
2995 pring
->sizeRiocb
= (phba
->sli_rev
== 3) ?
2996 SLI3_IOCB_RSP_SIZE
:
2998 pring
->iotag_ctr
= 0;
3000 (phba
->cfg_hba_queue_depth
* 2);
3001 pring
->fast_iotag
= pring
->iotag_max
;
3002 pring
->num_mask
= 0;
3004 case LPFC_EXTRA_RING
: /* ring 1 - EXTRA */
3005 /* numCiocb and numRiocb are used in config_port */
3006 pring
->numCiocb
= SLI2_IOCB_CMD_R1_ENTRIES
;
3007 pring
->numRiocb
= SLI2_IOCB_RSP_R1_ENTRIES
;
3008 pring
->sizeCiocb
= (phba
->sli_rev
== 3) ?
3009 SLI3_IOCB_CMD_SIZE
:
3011 pring
->sizeRiocb
= (phba
->sli_rev
== 3) ?
3012 SLI3_IOCB_RSP_SIZE
:
3014 pring
->iotag_max
= phba
->cfg_hba_queue_depth
;
3015 pring
->num_mask
= 0;
3017 case LPFC_ELS_RING
: /* ring 2 - ELS / CT */
3018 /* numCiocb and numRiocb are used in config_port */
3019 pring
->numCiocb
= SLI2_IOCB_CMD_R2_ENTRIES
;
3020 pring
->numRiocb
= SLI2_IOCB_RSP_R2_ENTRIES
;
3021 pring
->sizeCiocb
= (phba
->sli_rev
== 3) ?
3022 SLI3_IOCB_CMD_SIZE
:
3024 pring
->sizeRiocb
= (phba
->sli_rev
== 3) ?
3025 SLI3_IOCB_RSP_SIZE
:
3027 pring
->fast_iotag
= 0;
3028 pring
->iotag_ctr
= 0;
3029 pring
->iotag_max
= 4096;
3030 pring
->num_mask
= 4;
3031 pring
->prt
[0].profile
= 0; /* Mask 0 */
3032 pring
->prt
[0].rctl
= FC_ELS_REQ
;
3033 pring
->prt
[0].type
= FC_ELS_DATA
;
3034 pring
->prt
[0].lpfc_sli_rcv_unsol_event
=
3035 lpfc_els_unsol_event
;
3036 pring
->prt
[1].profile
= 0; /* Mask 1 */
3037 pring
->prt
[1].rctl
= FC_ELS_RSP
;
3038 pring
->prt
[1].type
= FC_ELS_DATA
;
3039 pring
->prt
[1].lpfc_sli_rcv_unsol_event
=
3040 lpfc_els_unsol_event
;
3041 pring
->prt
[2].profile
= 0; /* Mask 2 */
3042 /* NameServer Inquiry */
3043 pring
->prt
[2].rctl
= FC_UNSOL_CTL
;
3045 pring
->prt
[2].type
= FC_COMMON_TRANSPORT_ULP
;
3046 pring
->prt
[2].lpfc_sli_rcv_unsol_event
=
3047 lpfc_ct_unsol_event
;
3048 pring
->prt
[3].profile
= 0; /* Mask 3 */
3049 /* NameServer response */
3050 pring
->prt
[3].rctl
= FC_SOL_CTL
;
3052 pring
->prt
[3].type
= FC_COMMON_TRANSPORT_ULP
;
3053 pring
->prt
[3].lpfc_sli_rcv_unsol_event
=
3054 lpfc_ct_unsol_event
;
3057 totiocbsize
+= (pring
->numCiocb
* pring
->sizeCiocb
) +
3058 (pring
->numRiocb
* pring
->sizeRiocb
);
3060 if (totiocbsize
> MAX_SLIM_IOCB_SIZE
) {
3061 /* Too many cmd / rsp ring entries in SLI2 SLIM */
3062 printk(KERN_ERR
"%d:0462 Too many cmd / rsp ring entries in "
3063 "SLI2 SLIM Data: x%x x%lx\n",
3064 phba
->brd_no
, totiocbsize
,
3065 (unsigned long) MAX_SLIM_IOCB_SIZE
);
3067 if (phba
->cfg_multi_ring_support
== 2)
3068 lpfc_extra_ring_setup(phba
);
3074 lpfc_sli_queue_setup(struct lpfc_hba
*phba
)
3076 struct lpfc_sli
*psli
;
3077 struct lpfc_sli_ring
*pring
;
3081 spin_lock_irq(&phba
->hbalock
);
3082 INIT_LIST_HEAD(&psli
->mboxq
);
3083 INIT_LIST_HEAD(&psli
->mboxq_cmpl
);
3084 /* Initialize list headers for txq and txcmplq as double linked lists */
3085 for (i
= 0; i
< psli
->num_rings
; i
++) {
3086 pring
= &psli
->ring
[i
];
3088 pring
->next_cmdidx
= 0;
3089 pring
->local_getidx
= 0;
3091 INIT_LIST_HEAD(&pring
->txq
);
3092 INIT_LIST_HEAD(&pring
->txcmplq
);
3093 INIT_LIST_HEAD(&pring
->iocb_continueq
);
3094 INIT_LIST_HEAD(&pring
->postbufq
);
3096 spin_unlock_irq(&phba
->hbalock
);
3101 lpfc_sli_host_down(struct lpfc_vport
*vport
)
3103 LIST_HEAD(completions
);
3104 struct lpfc_hba
*phba
= vport
->phba
;
3105 struct lpfc_sli
*psli
= &phba
->sli
;
3106 struct lpfc_sli_ring
*pring
;
3107 struct lpfc_iocbq
*iocb
, *next_iocb
;
3109 unsigned long flags
= 0;
3110 uint16_t prev_pring_flag
;
3112 lpfc_cleanup_discovery_resources(vport
);
3114 spin_lock_irqsave(&phba
->hbalock
, flags
);
3115 for (i
= 0; i
< psli
->num_rings
; i
++) {
3116 pring
= &psli
->ring
[i
];
3117 prev_pring_flag
= pring
->flag
;
3118 if (pring
->ringno
== LPFC_ELS_RING
) /* Only slow rings */
3119 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
3121 * Error everything on the txq since these iocbs have not been
3122 * given to the FW yet.
3124 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
3125 if (iocb
->vport
!= vport
)
3127 list_move_tail(&iocb
->list
, &completions
);
3131 /* Next issue ABTS for everything on the txcmplq */
3132 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
,
3134 if (iocb
->vport
!= vport
)
3136 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
3139 pring
->flag
= prev_pring_flag
;
3142 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
3144 while (!list_empty(&completions
)) {
3145 list_remove_head(&completions
, iocb
, struct lpfc_iocbq
, list
);
3147 if (!iocb
->iocb_cmpl
)
3148 lpfc_sli_release_iocbq(phba
, iocb
);
3150 iocb
->iocb
.ulpStatus
= IOSTAT_LOCAL_REJECT
;
3151 iocb
->iocb
.un
.ulpWord
[4] = IOERR_SLI_DOWN
;
3152 (iocb
->iocb_cmpl
) (phba
, iocb
, iocb
);
3159 lpfc_sli_hba_down(struct lpfc_hba
*phba
)
3161 LIST_HEAD(completions
);
3162 struct lpfc_sli
*psli
= &phba
->sli
;
3163 struct lpfc_sli_ring
*pring
;
3165 struct lpfc_iocbq
*iocb
;
3168 unsigned long flags
= 0;
3170 lpfc_hba_down_prep(phba
);
3172 lpfc_fabric_abort_hba(phba
);
3174 spin_lock_irqsave(&phba
->hbalock
, flags
);
3175 for (i
= 0; i
< psli
->num_rings
; i
++) {
3176 pring
= &psli
->ring
[i
];
3177 if (pring
->ringno
== LPFC_ELS_RING
) /* Only slow rings */
3178 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
3181 * Error everything on the txq since these iocbs have not been
3182 * given to the FW yet.
3184 list_splice_init(&pring
->txq
, &completions
);
3188 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
3190 while (!list_empty(&completions
)) {
3191 list_remove_head(&completions
, iocb
, struct lpfc_iocbq
, list
);
3194 if (!iocb
->iocb_cmpl
)
3195 lpfc_sli_release_iocbq(phba
, iocb
);
3197 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
3198 cmd
->un
.ulpWord
[4] = IOERR_SLI_DOWN
;
3199 (iocb
->iocb_cmpl
) (phba
, iocb
, iocb
);
3203 /* Return any active mbox cmds */
3204 del_timer_sync(&psli
->mbox_tmo
);
3205 spin_lock_irqsave(&phba
->hbalock
, flags
);
3207 spin_lock(&phba
->pport
->work_port_lock
);
3208 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
3209 spin_unlock(&phba
->pport
->work_port_lock
);
3211 if (psli
->mbox_active
) {
3212 list_add_tail(&psli
->mbox_active
->list
, &completions
);
3213 psli
->mbox_active
= NULL
;
3214 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
3217 /* Return any pending or completed mbox cmds */
3218 list_splice_init(&phba
->sli
.mboxq
, &completions
);
3219 list_splice_init(&phba
->sli
.mboxq_cmpl
, &completions
);
3220 INIT_LIST_HEAD(&psli
->mboxq
);
3221 INIT_LIST_HEAD(&psli
->mboxq_cmpl
);
3223 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
3225 while (!list_empty(&completions
)) {
3226 list_remove_head(&completions
, pmb
, LPFC_MBOXQ_t
, list
);
3227 pmb
->mb
.mbxStatus
= MBX_NOT_FINISHED
;
3228 if (pmb
->mbox_cmpl
) {
3229 pmb
->mbox_cmpl(phba
,pmb
);
3236 lpfc_sli_pcimem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
3238 uint32_t *src
= srcp
;
3239 uint32_t *dest
= destp
;
3243 for (i
= 0; i
< (int)cnt
; i
+= sizeof (uint32_t)) {
3245 ldata
= le32_to_cpu(ldata
);
3253 lpfc_sli_ringpostbuf_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
3254 struct lpfc_dmabuf
*mp
)
3256 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
3258 spin_lock_irq(&phba
->hbalock
);
3259 list_add_tail(&mp
->list
, &pring
->postbufq
);
3260 pring
->postbufq_cnt
++;
3261 spin_unlock_irq(&phba
->hbalock
);
3266 struct lpfc_dmabuf
*
3267 lpfc_sli_ringpostbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
3270 struct lpfc_dmabuf
*mp
, *next_mp
;
3271 struct list_head
*slp
= &pring
->postbufq
;
3273 /* Search postbufq, from the begining, looking for a match on phys */
3274 spin_lock_irq(&phba
->hbalock
);
3275 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
3276 if (mp
->phys
== phys
) {
3277 list_del_init(&mp
->list
);
3278 pring
->postbufq_cnt
--;
3279 spin_unlock_irq(&phba
->hbalock
);
3284 spin_unlock_irq(&phba
->hbalock
);
3285 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3286 "0410 Cannot find virtual addr for mapped buf on "
3287 "ring %d Data x%llx x%p x%p x%x\n",
3288 pring
->ringno
, (unsigned long long)phys
,
3289 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
3294 lpfc_sli_abort_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
3295 struct lpfc_iocbq
*rspiocb
)
3297 IOCB_t
*irsp
= &rspiocb
->iocb
;
3298 uint16_t abort_iotag
, abort_context
;
3299 struct lpfc_iocbq
*abort_iocb
;
3300 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
3304 if (irsp
->ulpStatus
) {
3305 abort_context
= cmdiocb
->iocb
.un
.acxri
.abortContextTag
;
3306 abort_iotag
= cmdiocb
->iocb
.un
.acxri
.abortIoTag
;
3308 spin_lock_irq(&phba
->hbalock
);
3309 if (abort_iotag
!= 0 && abort_iotag
<= phba
->sli
.last_iotag
)
3310 abort_iocb
= phba
->sli
.iocbq_lookup
[abort_iotag
];
3312 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
| LOG_SLI
,
3313 "0327 Cannot abort els iocb %p "
3314 "with tag %x context %x, abort status %x, "
3316 abort_iocb
, abort_iotag
, abort_context
,
3317 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
3320 * make sure we have the right iocbq before taking it
3321 * off the txcmplq and try to call completion routine.
3324 abort_iocb
->iocb
.ulpContext
!= abort_context
||
3325 (abort_iocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) == 0)
3326 spin_unlock_irq(&phba
->hbalock
);
3328 list_del_init(&abort_iocb
->list
);
3329 pring
->txcmplq_cnt
--;
3330 spin_unlock_irq(&phba
->hbalock
);
3332 abort_iocb
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
3333 abort_iocb
->iocb
.ulpStatus
= IOSTAT_LOCAL_REJECT
;
3334 abort_iocb
->iocb
.un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
3335 (abort_iocb
->iocb_cmpl
)(phba
, abort_iocb
, abort_iocb
);
3339 lpfc_sli_release_iocbq(phba
, cmdiocb
);
3344 lpfc_ignore_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
3345 struct lpfc_iocbq
*rspiocb
)
3347 IOCB_t
*irsp
= &rspiocb
->iocb
;
3349 /* ELS cmd tag <ulpIoTag> completes */
3350 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
3351 "0133 Ignoring ELS cmd tag x%x completion Data: "
3353 irsp
->ulpIoTag
, irsp
->ulpStatus
,
3354 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
);
3355 if (cmdiocb
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
)
3356 lpfc_ct_free_iocb(phba
, cmdiocb
);
3358 lpfc_els_free_iocb(phba
, cmdiocb
);
3363 lpfc_sli_issue_abort_iotag(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
3364 struct lpfc_iocbq
*cmdiocb
)
3366 struct lpfc_vport
*vport
= cmdiocb
->vport
;
3367 struct lpfc_iocbq
*abtsiocbp
;
3368 IOCB_t
*icmd
= NULL
;
3369 IOCB_t
*iabt
= NULL
;
3370 int retval
= IOCB_ERROR
;
3373 * There are certain command types we don't want to abort. And we
3374 * don't want to abort commands that are already in the process of
3377 icmd
= &cmdiocb
->iocb
;
3378 if (icmd
->ulpCommand
== CMD_ABORT_XRI_CN
||
3379 icmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
3380 (cmdiocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) != 0)
3383 /* If we're unloading, don't abort iocb on the ELS ring, but change the
3384 * callback so that nothing happens when it finishes.
3386 if ((vport
->load_flag
& FC_UNLOADING
) &&
3387 (pring
->ringno
== LPFC_ELS_RING
)) {
3388 if (cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
)
3389 cmdiocb
->fabric_iocb_cmpl
= lpfc_ignore_els_cmpl
;
3391 cmdiocb
->iocb_cmpl
= lpfc_ignore_els_cmpl
;
3392 goto abort_iotag_exit
;
3395 /* issue ABTS for this IOCB based on iotag */
3396 abtsiocbp
= __lpfc_sli_get_iocbq(phba
);
3397 if (abtsiocbp
== NULL
)
3400 /* This signals the response to set the correct status
3401 * before calling the completion handler.
3403 cmdiocb
->iocb_flag
|= LPFC_DRIVER_ABORTED
;
3405 iabt
= &abtsiocbp
->iocb
;
3406 iabt
->un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
3407 iabt
->un
.acxri
.abortContextTag
= icmd
->ulpContext
;
3408 iabt
->un
.acxri
.abortIoTag
= icmd
->ulpIoTag
;
3410 iabt
->ulpClass
= icmd
->ulpClass
;
3412 if (phba
->link_state
>= LPFC_LINK_UP
)
3413 iabt
->ulpCommand
= CMD_ABORT_XRI_CN
;
3415 iabt
->ulpCommand
= CMD_CLOSE_XRI_CN
;
3417 abtsiocbp
->iocb_cmpl
= lpfc_sli_abort_els_cmpl
;
3419 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
3420 "0339 Abort xri x%x, original iotag x%x, "
3421 "abort cmd iotag x%x\n",
3422 iabt
->un
.acxri
.abortContextTag
,
3423 iabt
->un
.acxri
.abortIoTag
, abtsiocbp
->iotag
);
3424 retval
= __lpfc_sli_issue_iocb(phba
, pring
, abtsiocbp
, 0);
3428 * Caller to this routine should check for IOCB_ERROR
3429 * and handle it properly. This routine no longer removes
3430 * iocb off txcmplq and call compl in case of IOCB_ERROR.
3436 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq
*iocbq
, uint16_t tgt_id
,
3437 uint64_t lun_id
, uint32_t ctx
,
3438 lpfc_ctx_cmd ctx_cmd
)
3440 struct lpfc_scsi_buf
*lpfc_cmd
;
3441 struct scsi_cmnd
*cmnd
;
3444 if (!(iocbq
->iocb_flag
& LPFC_IO_FCP
))
3447 lpfc_cmd
= container_of(iocbq
, struct lpfc_scsi_buf
, cur_iocbq
);
3448 cmnd
= lpfc_cmd
->pCmd
;
3455 if ((cmnd
->device
->id
== tgt_id
) &&
3456 (cmnd
->device
->lun
== lun_id
))
3460 if (cmnd
->device
->id
== tgt_id
)
3464 if (iocbq
->iocb
.ulpContext
== ctx
)
3471 printk(KERN_ERR
"%s: Unknown context cmd type, value %d\n",
3472 __FUNCTION__
, ctx_cmd
);
3480 lpfc_sli_sum_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
3481 uint16_t tgt_id
, uint64_t lun_id
, lpfc_ctx_cmd ctx_cmd
)
3483 struct lpfc_iocbq
*iocbq
;
3486 for (i
= 1, sum
= 0; i
<= phba
->sli
.last_iotag
; i
++) {
3487 iocbq
= phba
->sli
.iocbq_lookup
[i
];
3489 if (lpfc_sli_validate_fcp_iocb (iocbq
, tgt_id
, lun_id
,
3498 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
3499 struct lpfc_iocbq
*rspiocb
)
3501 lpfc_sli_release_iocbq(phba
, cmdiocb
);
3506 lpfc_sli_abort_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
3507 uint16_t tgt_id
, uint64_t lun_id
, uint32_t ctx
,
3508 lpfc_ctx_cmd abort_cmd
)
3510 struct lpfc_iocbq
*iocbq
;
3511 struct lpfc_iocbq
*abtsiocb
;
3513 int errcnt
= 0, ret_val
= 0;
3516 for (i
= 1; i
<= phba
->sli
.last_iotag
; i
++) {
3517 iocbq
= phba
->sli
.iocbq_lookup
[i
];
3519 if (lpfc_sli_validate_fcp_iocb(iocbq
, tgt_id
, lun_id
, 0,
3523 /* issue ABTS for this IOCB based on iotag */
3524 abtsiocb
= lpfc_sli_get_iocbq(phba
);
3525 if (abtsiocb
== NULL
) {
3531 abtsiocb
->iocb
.un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
3532 abtsiocb
->iocb
.un
.acxri
.abortContextTag
= cmd
->ulpContext
;
3533 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= cmd
->ulpIoTag
;
3534 abtsiocb
->iocb
.ulpLe
= 1;
3535 abtsiocb
->iocb
.ulpClass
= cmd
->ulpClass
;
3536 abtsiocb
->vport
= phba
->pport
;
3538 if (lpfc_is_link_up(phba
))
3539 abtsiocb
->iocb
.ulpCommand
= CMD_ABORT_XRI_CN
;
3541 abtsiocb
->iocb
.ulpCommand
= CMD_CLOSE_XRI_CN
;
3543 /* Setup callback routine and issue the command. */
3544 abtsiocb
->iocb_cmpl
= lpfc_sli_abort_fcp_cmpl
;
3545 ret_val
= lpfc_sli_issue_iocb(phba
, pring
, abtsiocb
, 0);
3546 if (ret_val
== IOCB_ERROR
) {
3547 lpfc_sli_release_iocbq(phba
, abtsiocb
);
3557 lpfc_sli_wake_iocb_wait(struct lpfc_hba
*phba
,
3558 struct lpfc_iocbq
*cmdiocbq
,
3559 struct lpfc_iocbq
*rspiocbq
)
3561 wait_queue_head_t
*pdone_q
;
3562 unsigned long iflags
;
3564 spin_lock_irqsave(&phba
->hbalock
, iflags
);
3565 cmdiocbq
->iocb_flag
|= LPFC_IO_WAKE
;
3566 if (cmdiocbq
->context2
&& rspiocbq
)
3567 memcpy(&((struct lpfc_iocbq
*)cmdiocbq
->context2
)->iocb
,
3568 &rspiocbq
->iocb
, sizeof(IOCB_t
));
3570 pdone_q
= cmdiocbq
->context_un
.wait_queue
;
3573 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
3578 * Issue the caller's iocb and wait for its completion, but no longer than the
3579 * caller's timeout. Note that iocb_flags is cleared before the
3580 * lpfc_sli_issue_call since the wake routine sets a unique value and by
3581 * definition this is a wait function.
3585 lpfc_sli_issue_iocb_wait(struct lpfc_hba
*phba
,
3586 struct lpfc_sli_ring
*pring
,
3587 struct lpfc_iocbq
*piocb
,
3588 struct lpfc_iocbq
*prspiocbq
,
3591 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
3592 long timeleft
, timeout_req
= 0;
3593 int retval
= IOCB_SUCCESS
;
3597 * If the caller has provided a response iocbq buffer, then context2
3598 * is NULL or its an error.
3601 if (piocb
->context2
)
3603 piocb
->context2
= prspiocbq
;
3606 piocb
->iocb_cmpl
= lpfc_sli_wake_iocb_wait
;
3607 piocb
->context_un
.wait_queue
= &done_q
;
3608 piocb
->iocb_flag
&= ~LPFC_IO_WAKE
;
3610 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
3611 creg_val
= readl(phba
->HCregaddr
);
3612 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
3613 writel(creg_val
, phba
->HCregaddr
);
3614 readl(phba
->HCregaddr
); /* flush */
3617 retval
= lpfc_sli_issue_iocb(phba
, pring
, piocb
, 0);
3618 if (retval
== IOCB_SUCCESS
) {
3619 timeout_req
= timeout
* HZ
;
3620 timeleft
= wait_event_timeout(done_q
,
3621 piocb
->iocb_flag
& LPFC_IO_WAKE
,
3624 if (piocb
->iocb_flag
& LPFC_IO_WAKE
) {
3625 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3626 "0331 IOCB wake signaled\n");
3627 } else if (timeleft
== 0) {
3628 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3629 "0338 IOCB wait timeout error - no "
3630 "wake response Data x%x\n", timeout
);
3631 retval
= IOCB_TIMEDOUT
;
3633 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3634 "0330 IOCB wake NOT set, "
3636 timeout
, (timeleft
/ jiffies
));
3637 retval
= IOCB_TIMEDOUT
;
3640 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3641 ":0332 IOCB wait issue failed, Data x%x\n",
3643 retval
= IOCB_ERROR
;
3646 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
3647 creg_val
= readl(phba
->HCregaddr
);
3648 creg_val
&= ~(HC_R0INT_ENA
<< LPFC_FCP_RING
);
3649 writel(creg_val
, phba
->HCregaddr
);
3650 readl(phba
->HCregaddr
); /* flush */
3654 piocb
->context2
= NULL
;
3656 piocb
->context_un
.wait_queue
= NULL
;
3657 piocb
->iocb_cmpl
= NULL
;
3662 lpfc_sli_issue_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
,
3665 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
3669 /* The caller must leave context1 empty. */
3670 if (pmboxq
->context1
!= 0)
3671 return MBX_NOT_FINISHED
;
3673 /* setup wake call as IOCB callback */
3674 pmboxq
->mbox_cmpl
= lpfc_sli_wake_mbox_wait
;
3675 /* setup context field to pass wait_queue pointer to wake function */
3676 pmboxq
->context1
= &done_q
;
3678 /* now issue the command */
3679 retval
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
3681 if (retval
== MBX_BUSY
|| retval
== MBX_SUCCESS
) {
3682 wait_event_interruptible_timeout(done_q
,
3683 pmboxq
->mbox_flag
& LPFC_MBX_WAKE
,
3686 spin_lock_irqsave(&phba
->hbalock
, flag
);
3687 pmboxq
->context1
= NULL
;
3689 * if LPFC_MBX_WAKE flag is set the mailbox is completed
3690 * else do not free the resources.
3692 if (pmboxq
->mbox_flag
& LPFC_MBX_WAKE
)
3693 retval
= MBX_SUCCESS
;
3695 retval
= MBX_TIMEOUT
;
3696 pmboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
3698 spin_unlock_irqrestore(&phba
->hbalock
, flag
);
3705 lpfc_sli_flush_mbox_queue(struct lpfc_hba
* phba
)
3707 struct lpfc_vport
*vport
= phba
->pport
;
3711 while (phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
&& !vport
->stopped
) {
3712 if (i
++ > LPFC_MBOX_TMO
* 1000)
3716 * Call lpfc_sli_handle_mb_event only if a mailbox cmd
3717 * did finish. This way we won't get the misleading
3718 * "Stray Mailbox Interrupt" message.
3720 spin_lock_irq(&phba
->hbalock
);
3721 ha_copy
= phba
->work_ha
;
3722 phba
->work_ha
&= ~HA_MBATT
;
3723 spin_unlock_irq(&phba
->hbalock
);
3725 if (ha_copy
& HA_MBATT
)
3726 if (lpfc_sli_handle_mb_event(phba
) == 0)
3732 return (phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
) ? 1 : 0;
3736 lpfc_intr_handler(int irq
, void *dev_id
)
3738 struct lpfc_hba
*phba
;
3740 uint32_t work_ha_copy
;
3741 unsigned long status
;
3745 MAILBOX_t
*mbox
, *pmbox
;
3746 struct lpfc_vport
*vport
;
3747 struct lpfc_nodelist
*ndlp
;
3748 struct lpfc_dmabuf
*mp
;
3753 * Get the driver's phba structure from the dev_id and
3754 * assume the HBA is not interrupting.
3756 phba
= (struct lpfc_hba
*) dev_id
;
3758 if (unlikely(!phba
))
3761 /* If the pci channel is offline, ignore all the interrupts. */
3762 if (unlikely(pci_channel_offline(phba
->pcidev
)))
3765 phba
->sli
.slistat
.sli_intr
++;
3768 * Call the HBA to see if it is interrupting. If not, don't claim
3772 /* Ignore all interrupts during initialization. */
3773 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
3777 * Read host attention register to determine interrupt source
3778 * Clear Attention Sources, except Error Attention (to
3779 * preserve status) and Link Attention
3781 spin_lock(&phba
->hbalock
);
3782 ha_copy
= readl(phba
->HAregaddr
);
3783 /* If somebody is waiting to handle an eratt don't process it
3784 * here. The brdkill function will do this.
3786 if (phba
->link_flag
& LS_IGNORE_ERATT
)
3787 ha_copy
&= ~HA_ERATT
;
3788 writel((ha_copy
& ~(HA_LATT
| HA_ERATT
)), phba
->HAregaddr
);
3789 readl(phba
->HAregaddr
); /* flush */
3790 spin_unlock(&phba
->hbalock
);
3792 if (unlikely(!ha_copy
))
3795 work_ha_copy
= ha_copy
& phba
->work_ha_mask
;
3797 if (unlikely(work_ha_copy
)) {
3798 if (work_ha_copy
& HA_LATT
) {
3799 if (phba
->sli
.sli_flag
& LPFC_PROCESS_LA
) {
3801 * Turn off Link Attention interrupts
3802 * until CLEAR_LA done
3804 spin_lock(&phba
->hbalock
);
3805 phba
->sli
.sli_flag
&= ~LPFC_PROCESS_LA
;
3806 control
= readl(phba
->HCregaddr
);
3807 control
&= ~HC_LAINT_ENA
;
3808 writel(control
, phba
->HCregaddr
);
3809 readl(phba
->HCregaddr
); /* flush */
3810 spin_unlock(&phba
->hbalock
);
3813 work_ha_copy
&= ~HA_LATT
;
3816 if (work_ha_copy
& ~(HA_ERATT
|HA_MBATT
|HA_LATT
)) {
3818 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
3819 * the only slow ring.
3821 status
= (work_ha_copy
&
3822 (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
3823 status
>>= (4*LPFC_ELS_RING
);
3824 if (status
& HA_RXMASK
) {
3825 spin_lock(&phba
->hbalock
);
3826 control
= readl(phba
->HCregaddr
);
3828 lpfc_debugfs_slow_ring_trc(phba
,
3829 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
3831 (uint32_t)phba
->sli
.slistat
.sli_intr
);
3833 if (control
& (HC_R0INT_ENA
<< LPFC_ELS_RING
)) {
3834 lpfc_debugfs_slow_ring_trc(phba
,
3836 "pwork:x%x hawork:x%x wait:x%x",
3837 phba
->work_ha
, work_ha_copy
,
3838 (uint32_t)((unsigned long)
3842 ~(HC_R0INT_ENA
<< LPFC_ELS_RING
);
3843 writel(control
, phba
->HCregaddr
);
3844 readl(phba
->HCregaddr
); /* flush */
3847 lpfc_debugfs_slow_ring_trc(phba
,
3848 "ISR slow ring: pwork:"
3849 "x%x hawork:x%x wait:x%x",
3850 phba
->work_ha
, work_ha_copy
,
3851 (uint32_t)((unsigned long)
3854 spin_unlock(&phba
->hbalock
);
3858 if (work_ha_copy
& HA_ERATT
) {
3859 phba
->link_state
= LPFC_HBA_ERROR
;
3861 * There was a link/board error. Read the
3862 * status register to retrieve the error event
3865 phba
->sli
.slistat
.err_attn_event
++;
3866 /* Save status info */
3867 phba
->work_hs
= readl(phba
->HSregaddr
);
3868 phba
->work_status
[0] = readl(phba
->MBslimaddr
+ 0xa8);
3869 phba
->work_status
[1] = readl(phba
->MBslimaddr
+ 0xac);
3871 /* Clear Chip error bit */
3872 writel(HA_ERATT
, phba
->HAregaddr
);
3873 readl(phba
->HAregaddr
); /* flush */
3874 phba
->pport
->stopped
= 1;
3877 if ((work_ha_copy
& HA_MBATT
) &&
3878 (phba
->sli
.mbox_active
)) {
3879 pmb
= phba
->sli
.mbox_active
;
3881 mbox
= &phba
->slim2p
->mbx
;
3884 /* First check out the status word */
3885 lpfc_sli_pcimem_bcopy(mbox
, pmbox
, sizeof(uint32_t));
3886 if (pmbox
->mbxOwner
!= OWN_HOST
) {
3888 * Stray Mailbox Interrupt, mbxCommand <cmd>
3889 * mbxStatus <status>
3891 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
|
3893 "(%d):0304 Stray Mailbox "
3894 "Interrupt mbxCommand x%x "
3896 (vport
? vport
->vpi
: 0),
3900 phba
->last_completion_time
= jiffies
;
3901 del_timer_sync(&phba
->sli
.mbox_tmo
);
3903 phba
->sli
.mbox_active
= NULL
;
3904 if (pmb
->mbox_cmpl
) {
3905 lpfc_sli_pcimem_bcopy(mbox
, pmbox
,
3908 if (pmb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) {
3909 pmb
->mbox_flag
&= ~LPFC_MBX_IMED_UNREG
;
3911 lpfc_debugfs_disc_trc(vport
,
3912 LPFC_DISC_TRC_MBOX_VPORT
,
3913 "MBOX dflt rpi: : status:x%x rpi:x%x",
3914 (uint32_t)pmbox
->mbxStatus
,
3915 pmbox
->un
.varWords
[0], 0);
3917 if ( !pmbox
->mbxStatus
) {
3918 mp
= (struct lpfc_dmabuf
*)
3920 ndlp
= (struct lpfc_nodelist
*)
3923 /* Reg_LOGIN of dflt RPI was successful.
3924 * new lets get rid of the RPI using the
3927 lpfc_unreg_login(phba
, vport
->vpi
,
3928 pmbox
->un
.varWords
[0], pmb
);
3929 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
3931 pmb
->context2
= ndlp
;
3933 spin_lock(&phba
->hbalock
);
3934 phba
->sli
.sli_flag
&=
3935 ~LPFC_SLI_MBOX_ACTIVE
;
3936 spin_unlock(&phba
->hbalock
);
3937 goto send_current_mbox
;
3940 spin_lock(&phba
->pport
->work_port_lock
);
3941 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
3942 spin_unlock(&phba
->pport
->work_port_lock
);
3943 lpfc_mbox_cmpl_put(phba
, pmb
);
3945 if ((work_ha_copy
& HA_MBATT
) &&
3946 (phba
->sli
.mbox_active
== NULL
)) {
3948 spin_lock(&phba
->hbalock
);
3949 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
3950 pmb
= lpfc_mbox_get(phba
);
3951 spin_unlock(&phba
->hbalock
);
3953 /* Process next mailbox command if there is one */
3955 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
3956 if (rc
== MBX_NOT_FINISHED
) {
3957 pmb
->mb
.mbxStatus
= MBX_NOT_FINISHED
;
3958 lpfc_mbox_cmpl_put(phba
, pmb
);
3959 goto send_next_mbox
;
3962 /* Turn on IOCB processing */
3963 for (i
= 0; i
< phba
->sli
.num_rings
; i
++)
3964 lpfc_sli_turn_on_ring(phba
, i
);
3969 spin_lock(&phba
->hbalock
);
3970 phba
->work_ha
|= work_ha_copy
;
3971 if (phba
->work_wait
)
3972 lpfc_worker_wake_up(phba
);
3973 spin_unlock(&phba
->hbalock
);
3976 ha_copy
&= ~(phba
->work_ha_mask
);
3979 * Process all events on FCP ring. Take the optimized path for
3980 * FCP IO. Any other IO is slow path and is handled by
3981 * the worker thread.
3983 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
3984 status
>>= (4*LPFC_FCP_RING
);
3985 if (status
& HA_RXMASK
)
3986 lpfc_sli_handle_fast_ring_event(phba
,
3987 &phba
->sli
.ring
[LPFC_FCP_RING
],
3990 if (phba
->cfg_multi_ring_support
== 2) {
3992 * Process all events on extra ring. Take the optimized path
3993 * for extra ring IO. Any other IO is slow path and is handled
3994 * by the worker thread.
3996 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
3997 status
>>= (4*LPFC_EXTRA_RING
);
3998 if (status
& HA_RXMASK
) {
3999 lpfc_sli_handle_fast_ring_event(phba
,
4000 &phba
->sli
.ring
[LPFC_EXTRA_RING
],
4006 } /* lpfc_intr_handler */