1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2008 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/interrupt.h>
25 #include <linux/delay.h>
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_cmnd.h>
29 #include <scsi/scsi_device.h>
30 #include <scsi/scsi_host.h>
31 #include <scsi/scsi_transport_fc.h>
35 #include "lpfc_disc.h"
36 #include "lpfc_scsi.h"
38 #include "lpfc_crtn.h"
39 #include "lpfc_logmsg.h"
40 #include "lpfc_compat.h"
41 #include "lpfc_debugfs.h"
44 * Define macro to log: Mailbox command x%x cannot issue Data
45 * This allows multiple uses of lpfc_msgBlk0311
46 * w/o perturbing log msg utility.
48 #define LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag) \
49 lpfc_printf_log(phba, \
52 "(%d):0311 Mailbox command x%x cannot " \
53 "issue Data: x%x x%x x%x\n", \
54 pmbox->vport ? pmbox->vport->vpi : 0, \
55 pmbox->mb.mbxCommand, \
56 phba->pport->port_state, \
61 /* There are only four IOCB completion types. */
62 typedef enum _lpfc_iocb_type
{
69 /* SLI-2/SLI-3 provide different sized iocbs. Given a pointer
70 * to the start of the ring, and the slot number of the
71 * desired iocb entry, calc a pointer to that entry.
73 static inline IOCB_t
*
74 lpfc_cmd_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
76 return (IOCB_t
*) (((char *) pring
->cmdringaddr
) +
77 pring
->cmdidx
* phba
->iocb_cmd_size
);
80 static inline IOCB_t
*
81 lpfc_resp_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
83 return (IOCB_t
*) (((char *) pring
->rspringaddr
) +
84 pring
->rspidx
* phba
->iocb_rsp_size
);
87 static struct lpfc_iocbq
*
88 __lpfc_sli_get_iocbq(struct lpfc_hba
*phba
)
90 struct list_head
*lpfc_iocb_list
= &phba
->lpfc_iocb_list
;
91 struct lpfc_iocbq
* iocbq
= NULL
;
93 list_remove_head(lpfc_iocb_list
, iocbq
, struct lpfc_iocbq
, list
);
98 lpfc_sli_get_iocbq(struct lpfc_hba
*phba
)
100 struct lpfc_iocbq
* iocbq
= NULL
;
101 unsigned long iflags
;
103 spin_lock_irqsave(&phba
->hbalock
, iflags
);
104 iocbq
= __lpfc_sli_get_iocbq(phba
);
105 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
110 __lpfc_sli_release_iocbq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
112 size_t start_clean
= offsetof(struct lpfc_iocbq
, iocb
);
115 * Clean all volatile data fields, preserve iotag and node struct.
117 memset((char*)iocbq
+ start_clean
, 0, sizeof(*iocbq
) - start_clean
);
118 list_add_tail(&iocbq
->list
, &phba
->lpfc_iocb_list
);
122 lpfc_sli_release_iocbq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
124 unsigned long iflags
;
127 * Clean all volatile data fields, preserve iotag and node struct.
129 spin_lock_irqsave(&phba
->hbalock
, iflags
);
130 __lpfc_sli_release_iocbq(phba
, iocbq
);
131 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
135 * Translate the iocb command to an iocb command type used to decide the final
136 * disposition of each completed IOCB.
138 static lpfc_iocb_type
139 lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd
)
141 lpfc_iocb_type type
= LPFC_UNKNOWN_IOCB
;
143 if (iocb_cmnd
> CMD_MAX_IOCB_CMD
)
147 case CMD_XMIT_SEQUENCE_CR
:
148 case CMD_XMIT_SEQUENCE_CX
:
149 case CMD_XMIT_BCAST_CN
:
150 case CMD_XMIT_BCAST_CX
:
151 case CMD_ELS_REQUEST_CR
:
152 case CMD_ELS_REQUEST_CX
:
153 case CMD_CREATE_XRI_CR
:
154 case CMD_CREATE_XRI_CX
:
156 case CMD_XMIT_ELS_RSP_CX
:
158 case CMD_FCP_IWRITE_CR
:
159 case CMD_FCP_IWRITE_CX
:
160 case CMD_FCP_IREAD_CR
:
161 case CMD_FCP_IREAD_CX
:
162 case CMD_FCP_ICMND_CR
:
163 case CMD_FCP_ICMND_CX
:
164 case CMD_FCP_TSEND_CX
:
165 case CMD_FCP_TRSP_CX
:
166 case CMD_FCP_TRECEIVE_CX
:
167 case CMD_FCP_AUTO_TRSP_CX
:
168 case CMD_ADAPTER_MSG
:
169 case CMD_ADAPTER_DUMP
:
170 case CMD_XMIT_SEQUENCE64_CR
:
171 case CMD_XMIT_SEQUENCE64_CX
:
172 case CMD_XMIT_BCAST64_CN
:
173 case CMD_XMIT_BCAST64_CX
:
174 case CMD_ELS_REQUEST64_CR
:
175 case CMD_ELS_REQUEST64_CX
:
176 case CMD_FCP_IWRITE64_CR
:
177 case CMD_FCP_IWRITE64_CX
:
178 case CMD_FCP_IREAD64_CR
:
179 case CMD_FCP_IREAD64_CX
:
180 case CMD_FCP_ICMND64_CR
:
181 case CMD_FCP_ICMND64_CX
:
182 case CMD_FCP_TSEND64_CX
:
183 case CMD_FCP_TRSP64_CX
:
184 case CMD_FCP_TRECEIVE64_CX
:
185 case CMD_GEN_REQUEST64_CR
:
186 case CMD_GEN_REQUEST64_CX
:
187 case CMD_XMIT_ELS_RSP64_CX
:
188 type
= LPFC_SOL_IOCB
;
190 case CMD_ABORT_XRI_CN
:
191 case CMD_ABORT_XRI_CX
:
192 case CMD_CLOSE_XRI_CN
:
193 case CMD_CLOSE_XRI_CX
:
194 case CMD_XRI_ABORTED_CX
:
195 case CMD_ABORT_MXRI64_CN
:
196 type
= LPFC_ABORT_IOCB
;
198 case CMD_RCV_SEQUENCE_CX
:
199 case CMD_RCV_ELS_REQ_CX
:
200 case CMD_RCV_SEQUENCE64_CX
:
201 case CMD_RCV_ELS_REQ64_CX
:
202 case CMD_ASYNC_STATUS
:
203 case CMD_IOCB_RCV_SEQ64_CX
:
204 case CMD_IOCB_RCV_ELS64_CX
:
205 case CMD_IOCB_RCV_CONT64_CX
:
206 case CMD_IOCB_RET_XRI64_CX
:
207 type
= LPFC_UNSOL_IOCB
;
209 case CMD_IOCB_XMIT_MSEQ64_CR
:
210 case CMD_IOCB_XMIT_MSEQ64_CX
:
211 case CMD_IOCB_RCV_SEQ_LIST64_CX
:
212 case CMD_IOCB_RCV_ELS_LIST64_CX
:
213 case CMD_IOCB_CLOSE_EXTENDED_CN
:
214 case CMD_IOCB_ABORT_EXTENDED_CN
:
215 case CMD_IOCB_RET_HBQE64_CN
:
216 case CMD_IOCB_FCP_IBIDIR64_CR
:
217 case CMD_IOCB_FCP_IBIDIR64_CX
:
218 case CMD_IOCB_FCP_ITASKMGT64_CX
:
219 case CMD_IOCB_LOGENTRY_CN
:
220 case CMD_IOCB_LOGENTRY_ASYNC_CN
:
221 printk("%s - Unhandled SLI-3 Command x%x\n",
222 __FUNCTION__
, iocb_cmnd
);
223 type
= LPFC_UNKNOWN_IOCB
;
226 type
= LPFC_UNKNOWN_IOCB
;
234 lpfc_sli_ring_map(struct lpfc_hba
*phba
)
236 struct lpfc_sli
*psli
= &phba
->sli
;
241 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
245 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
246 for (i
= 0; i
< psli
->num_rings
; i
++) {
247 lpfc_config_ring(phba
, i
, pmb
);
248 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
249 if (rc
!= MBX_SUCCESS
) {
250 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
251 "0446 Adapter failed to init (%d), "
252 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
254 rc
, pmbox
->mbxCommand
,
255 pmbox
->mbxStatus
, i
);
256 phba
->link_state
= LPFC_HBA_ERROR
;
261 mempool_free(pmb
, phba
->mbox_mem_pool
);
266 lpfc_sli_ringtxcmpl_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
267 struct lpfc_iocbq
*piocb
)
269 list_add_tail(&piocb
->list
, &pring
->txcmplq
);
270 pring
->txcmplq_cnt
++;
271 if ((unlikely(pring
->ringno
== LPFC_ELS_RING
)) &&
272 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
273 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
277 mod_timer(&piocb
->vport
->els_tmofunc
,
278 jiffies
+ HZ
* (phba
->fc_ratov
<< 1));
285 static struct lpfc_iocbq
*
286 lpfc_sli_ringtx_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
288 struct lpfc_iocbq
*cmd_iocb
;
290 list_remove_head((&pring
->txq
), cmd_iocb
, struct lpfc_iocbq
, list
);
291 if (cmd_iocb
!= NULL
)
297 lpfc_sli_next_iocb_slot (struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
299 struct lpfc_pgp
*pgp
= (phba
->sli_rev
== 3) ?
300 &phba
->slim2p
->mbx
.us
.s3_pgp
.port
[pring
->ringno
] :
301 &phba
->slim2p
->mbx
.us
.s2
.port
[pring
->ringno
];
302 uint32_t max_cmd_idx
= pring
->numCiocb
;
304 if ((pring
->next_cmdidx
== pring
->cmdidx
) &&
305 (++pring
->next_cmdidx
>= max_cmd_idx
))
306 pring
->next_cmdidx
= 0;
308 if (unlikely(pring
->local_getidx
== pring
->next_cmdidx
)) {
310 pring
->local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
312 if (unlikely(pring
->local_getidx
>= max_cmd_idx
)) {
313 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
314 "0315 Ring %d issue: portCmdGet %d "
315 "is bigger then cmd ring %d\n",
317 pring
->local_getidx
, max_cmd_idx
);
319 phba
->link_state
= LPFC_HBA_ERROR
;
321 * All error attention handlers are posted to
324 phba
->work_ha
|= HA_ERATT
;
325 phba
->work_hs
= HS_FFER3
;
327 /* hbalock should already be held */
329 lpfc_worker_wake_up(phba
);
334 if (pring
->local_getidx
== pring
->next_cmdidx
)
338 return lpfc_cmd_iocb(phba
, pring
);
342 lpfc_sli_next_iotag(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
344 struct lpfc_iocbq
**new_arr
;
345 struct lpfc_iocbq
**old_arr
;
347 struct lpfc_sli
*psli
= &phba
->sli
;
350 spin_lock_irq(&phba
->hbalock
);
351 iotag
= psli
->last_iotag
;
352 if(++iotag
< psli
->iocbq_lookup_len
) {
353 psli
->last_iotag
= iotag
;
354 psli
->iocbq_lookup
[iotag
] = iocbq
;
355 spin_unlock_irq(&phba
->hbalock
);
356 iocbq
->iotag
= iotag
;
358 } else if (psli
->iocbq_lookup_len
< (0xffff
359 - LPFC_IOCBQ_LOOKUP_INCREMENT
)) {
360 new_len
= psli
->iocbq_lookup_len
+ LPFC_IOCBQ_LOOKUP_INCREMENT
;
361 spin_unlock_irq(&phba
->hbalock
);
362 new_arr
= kzalloc(new_len
* sizeof (struct lpfc_iocbq
*),
365 spin_lock_irq(&phba
->hbalock
);
366 old_arr
= psli
->iocbq_lookup
;
367 if (new_len
<= psli
->iocbq_lookup_len
) {
368 /* highly unprobable case */
370 iotag
= psli
->last_iotag
;
371 if(++iotag
< psli
->iocbq_lookup_len
) {
372 psli
->last_iotag
= iotag
;
373 psli
->iocbq_lookup
[iotag
] = iocbq
;
374 spin_unlock_irq(&phba
->hbalock
);
375 iocbq
->iotag
= iotag
;
378 spin_unlock_irq(&phba
->hbalock
);
381 if (psli
->iocbq_lookup
)
382 memcpy(new_arr
, old_arr
,
383 ((psli
->last_iotag
+ 1) *
384 sizeof (struct lpfc_iocbq
*)));
385 psli
->iocbq_lookup
= new_arr
;
386 psli
->iocbq_lookup_len
= new_len
;
387 psli
->last_iotag
= iotag
;
388 psli
->iocbq_lookup
[iotag
] = iocbq
;
389 spin_unlock_irq(&phba
->hbalock
);
390 iocbq
->iotag
= iotag
;
395 spin_unlock_irq(&phba
->hbalock
);
397 lpfc_printf_log(phba
, KERN_ERR
,LOG_SLI
,
398 "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
405 lpfc_sli_submit_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
406 IOCB_t
*iocb
, struct lpfc_iocbq
*nextiocb
)
411 nextiocb
->iocb
.ulpIoTag
= (nextiocb
->iocb_cmpl
) ? nextiocb
->iotag
: 0;
413 if (pring
->ringno
== LPFC_ELS_RING
) {
414 lpfc_debugfs_slow_ring_trc(phba
,
415 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
416 *(((uint32_t *) &nextiocb
->iocb
) + 4),
417 *(((uint32_t *) &nextiocb
->iocb
) + 6),
418 *(((uint32_t *) &nextiocb
->iocb
) + 7));
422 * Issue iocb command to adapter
424 lpfc_sli_pcimem_bcopy(&nextiocb
->iocb
, iocb
, phba
->iocb_cmd_size
);
426 pring
->stats
.iocb_cmd
++;
429 * If there is no completion routine to call, we can release the
430 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
431 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
433 if (nextiocb
->iocb_cmpl
)
434 lpfc_sli_ringtxcmpl_put(phba
, pring
, nextiocb
);
436 __lpfc_sli_release_iocbq(phba
, nextiocb
);
439 * Let the HBA know what IOCB slot will be the next one the
440 * driver will put a command into.
442 pring
->cmdidx
= pring
->next_cmdidx
;
443 writel(pring
->cmdidx
, &phba
->host_gp
[pring
->ringno
].cmdPutInx
);
447 lpfc_sli_update_full_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
449 int ringno
= pring
->ringno
;
451 pring
->flag
|= LPFC_CALL_RING_AVAILABLE
;
456 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
457 * The HBA will tell us when an IOCB entry is available.
459 writel((CA_R0ATT
|CA_R0CE_REQ
) << (ringno
*4), phba
->CAregaddr
);
460 readl(phba
->CAregaddr
); /* flush */
462 pring
->stats
.iocb_cmd_full
++;
466 lpfc_sli_update_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
468 int ringno
= pring
->ringno
;
471 * Tell the HBA that there is work to do in this ring.
474 writel(CA_R0ATT
<< (ringno
* 4), phba
->CAregaddr
);
475 readl(phba
->CAregaddr
); /* flush */
479 lpfc_sli_resume_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
482 struct lpfc_iocbq
*nextiocb
;
486 * (a) there is anything on the txq to send
488 * (c) link attention events can be processed (fcp ring only)
489 * (d) IOCB processing is not blocked by the outstanding mbox command.
491 if (pring
->txq_cnt
&&
492 lpfc_is_link_up(phba
) &&
493 (pring
->ringno
!= phba
->sli
.fcp_ring
||
494 phba
->sli
.sli_flag
& LPFC_PROCESS_LA
)) {
496 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
497 (nextiocb
= lpfc_sli_ringtx_get(phba
, pring
)))
498 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
501 lpfc_sli_update_ring(phba
, pring
);
503 lpfc_sli_update_full_ring(phba
, pring
);
509 static struct lpfc_hbq_entry
*
510 lpfc_sli_next_hbq_slot(struct lpfc_hba
*phba
, uint32_t hbqno
)
512 struct hbq_s
*hbqp
= &phba
->hbqs
[hbqno
];
514 if (hbqp
->next_hbqPutIdx
== hbqp
->hbqPutIdx
&&
515 ++hbqp
->next_hbqPutIdx
>= hbqp
->entry_count
)
516 hbqp
->next_hbqPutIdx
= 0;
518 if (unlikely(hbqp
->local_hbqGetIdx
== hbqp
->next_hbqPutIdx
)) {
519 uint32_t raw_index
= phba
->hbq_get
[hbqno
];
520 uint32_t getidx
= le32_to_cpu(raw_index
);
522 hbqp
->local_hbqGetIdx
= getidx
;
524 if (unlikely(hbqp
->local_hbqGetIdx
>= hbqp
->entry_count
)) {
525 lpfc_printf_log(phba
, KERN_ERR
,
527 "1802 HBQ %d: local_hbqGetIdx "
528 "%u is > than hbqp->entry_count %u\n",
529 hbqno
, hbqp
->local_hbqGetIdx
,
532 phba
->link_state
= LPFC_HBA_ERROR
;
536 if (hbqp
->local_hbqGetIdx
== hbqp
->next_hbqPutIdx
)
540 return (struct lpfc_hbq_entry
*) phba
->hbqs
[hbqno
].hbq_virt
+
545 lpfc_sli_hbqbuf_free_all(struct lpfc_hba
*phba
)
547 struct lpfc_dmabuf
*dmabuf
, *next_dmabuf
;
548 struct hbq_dmabuf
*hbq_buf
;
553 hbq_count
= lpfc_sli_hbq_count();
554 /* Return all memory used by all HBQs */
555 spin_lock_irqsave(&phba
->hbalock
, flags
);
556 for (i
= 0; i
< hbq_count
; ++i
) {
557 list_for_each_entry_safe(dmabuf
, next_dmabuf
,
558 &phba
->hbqs
[i
].hbq_buffer_list
, list
) {
559 hbq_buf
= container_of(dmabuf
, struct hbq_dmabuf
, dbuf
);
560 list_del(&hbq_buf
->dbuf
.list
);
561 (phba
->hbqs
[i
].hbq_free_buffer
)(phba
, hbq_buf
);
563 phba
->hbqs
[i
].buffer_count
= 0;
565 /* Return all HBQ buffer that are in-fly */
566 list_for_each_entry_safe(dmabuf
, next_dmabuf
,
567 &phba
->hbqbuf_in_list
, list
) {
568 hbq_buf
= container_of(dmabuf
, struct hbq_dmabuf
, dbuf
);
569 list_del(&hbq_buf
->dbuf
.list
);
570 if (hbq_buf
->tag
== -1) {
571 (phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
)
574 hbqno
= hbq_buf
->tag
>> 16;
575 if (hbqno
>= LPFC_MAX_HBQS
)
576 (phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
)
579 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
,
584 /* Mark the HBQs not in use */
585 phba
->hbq_in_use
= 0;
586 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
589 static struct lpfc_hbq_entry
*
590 lpfc_sli_hbq_to_firmware(struct lpfc_hba
*phba
, uint32_t hbqno
,
591 struct hbq_dmabuf
*hbq_buf
)
593 struct lpfc_hbq_entry
*hbqe
;
594 dma_addr_t physaddr
= hbq_buf
->dbuf
.phys
;
596 /* Get next HBQ entry slot to use */
597 hbqe
= lpfc_sli_next_hbq_slot(phba
, hbqno
);
599 struct hbq_s
*hbqp
= &phba
->hbqs
[hbqno
];
601 hbqe
->bde
.addrHigh
= le32_to_cpu(putPaddrHigh(physaddr
));
602 hbqe
->bde
.addrLow
= le32_to_cpu(putPaddrLow(physaddr
));
603 hbqe
->bde
.tus
.f
.bdeSize
= hbq_buf
->size
;
604 hbqe
->bde
.tus
.f
.bdeFlags
= 0;
605 hbqe
->bde
.tus
.w
= le32_to_cpu(hbqe
->bde
.tus
.w
);
606 hbqe
->buffer_tag
= le32_to_cpu(hbq_buf
->tag
);
608 hbqp
->hbqPutIdx
= hbqp
->next_hbqPutIdx
;
609 writel(hbqp
->hbqPutIdx
, phba
->hbq_put
+ hbqno
);
611 readl(phba
->hbq_put
+ hbqno
);
612 list_add_tail(&hbq_buf
->dbuf
.list
, &hbqp
->hbq_buffer_list
);
617 static struct lpfc_hbq_init lpfc_els_hbq
= {
622 .ring_mask
= (1 << LPFC_ELS_RING
),
628 static struct lpfc_hbq_init lpfc_extra_hbq
= {
633 .ring_mask
= (1 << LPFC_EXTRA_RING
),
639 struct lpfc_hbq_init
*lpfc_hbq_defs
[] = {
645 lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba
*phba
, uint32_t hbqno
, uint32_t count
)
647 uint32_t i
, start
, end
;
649 struct hbq_dmabuf
*hbq_buffer
;
651 <<<<<<< HEAD
:drivers
/scsi
/lpfc
/lpfc_sli
.c
652 if (!phba
->hbqs
[hbqno
].hbq_alloc_buffer
) {
654 if (!phba
->hbqs
[hbqno
].hbq_alloc_buffer
)
655 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/lpfc
/lpfc_sli
.c
657 <<<<<<< HEAD
:drivers
/scsi
/lpfc
/lpfc_sli
.c
660 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/lpfc
/lpfc_sli
.c
662 start
= phba
->hbqs
[hbqno
].buffer_count
;
664 <<<<<<< HEAD
:drivers
/scsi
/lpfc
/lpfc_sli
.c
665 if (end
> lpfc_hbq_defs
[hbqno
]->entry_count
) {
667 if (end
> lpfc_hbq_defs
[hbqno
]->entry_count
)
668 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/lpfc
/lpfc_sli
.c
669 end
= lpfc_hbq_defs
[hbqno
]->entry_count
;
670 <<<<<<< HEAD
:drivers
/scsi
/lpfc
/lpfc_sli
.c
673 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/lpfc
/lpfc_sli
.c
675 /* Check whether HBQ is still in use */
676 spin_lock_irqsave(&phba
->hbalock
, flags
);
677 <<<<<<< HEAD
:drivers
/scsi
/lpfc
/lpfc_sli
.c
678 if (!phba
->hbq_in_use
) {
679 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
683 if (!phba
->hbq_in_use
)
685 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/lpfc
/lpfc_sli
.c
687 /* Populate HBQ entries */
688 for (i
= start
; i
< end
; i
++) {
689 hbq_buffer
= (phba
->hbqs
[hbqno
].hbq_alloc_buffer
)(phba
);
691 <<<<<<< HEAD
:drivers
/scsi
/lpfc
/lpfc_sli
.c
695 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/lpfc
/lpfc_sli
.c
696 hbq_buffer
->tag
= (i
| (hbqno
<< 16));
697 if (lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buffer
))
698 phba
->hbqs
[hbqno
].buffer_count
++;
700 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
703 <<<<<<< HEAD
:drivers
/scsi
/lpfc
/lpfc_sli
.c
706 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/lpfc
/lpfc_sli
.c
707 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
709 <<<<<<< HEAD
:drivers
/scsi
/lpfc
/lpfc_sli
.c
712 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
714 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/lpfc
/lpfc_sli
.c
718 lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
720 return(lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
721 lpfc_hbq_defs
[qno
]->add_count
));
725 lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
727 return(lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
728 lpfc_hbq_defs
[qno
]->init_count
));
731 static struct hbq_dmabuf
*
732 lpfc_sli_hbqbuf_find(struct lpfc_hba
*phba
, uint32_t tag
)
734 struct lpfc_dmabuf
*d_buf
;
735 struct hbq_dmabuf
*hbq_buf
;
739 if (hbqno
>= LPFC_MAX_HBQS
)
742 list_for_each_entry(d_buf
, &phba
->hbqs
[hbqno
].hbq_buffer_list
, list
) {
743 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
744 if (hbq_buf
->tag
== tag
) {
748 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
| LOG_VPORT
,
749 "1803 Bad hbq tag. Data: x%x x%x\n",
750 tag
, phba
->hbqs
[tag
>> 16].buffer_count
);
755 lpfc_sli_free_hbq(struct lpfc_hba
*phba
, struct hbq_dmabuf
*hbq_buffer
)
760 hbqno
= hbq_buffer
->tag
>> 16;
761 if (!lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buffer
)) {
762 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
768 lpfc_sli_chk_mbx_command(uint8_t mbxCommand
)
772 switch (mbxCommand
) {
776 case MBX_WRITE_VPARMS
:
777 case MBX_RUN_BIU_DIAG
:
780 case MBX_CONFIG_LINK
:
781 case MBX_CONFIG_RING
:
783 case MBX_READ_CONFIG
:
784 case MBX_READ_RCONFIG
:
786 case MBX_READ_STATUS
:
790 case MBX_READ_LNK_STAT
:
792 case MBX_UNREG_LOGIN
:
795 case MBX_DUMP_MEMORY
:
796 case MBX_DUMP_CONTEXT
:
801 case MBX_DEL_LD_ENTRY
:
802 case MBX_RUN_PROGRAM
:
804 case MBX_SET_VARIABLE
:
807 case MBX_CONFIG_FARP
:
810 case MBX_RUN_BIU_DIAG64
:
811 case MBX_CONFIG_PORT
:
812 case MBX_READ_SPARM64
:
814 case MBX_REG_LOGIN64
:
818 case MBX_LOAD_EXP_ROM
:
819 case MBX_ASYNCEVT_ENABLE
:
832 lpfc_sli_wake_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
834 wait_queue_head_t
*pdone_q
;
835 unsigned long drvr_flag
;
838 * If pdone_q is empty, the driver thread gave up waiting and
841 pmboxq
->mbox_flag
|= LPFC_MBX_WAKE
;
842 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
843 pdone_q
= (wait_queue_head_t
*) pmboxq
->context1
;
845 wake_up_interruptible(pdone_q
);
846 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
851 lpfc_sli_def_mbox_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
853 struct lpfc_dmabuf
*mp
;
857 mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
860 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
865 * If a REG_LOGIN succeeded after node is destroyed or node
866 * is in re-discovery driver need to cleanup the RPI.
868 if (!(phba
->pport
->load_flag
& FC_UNLOADING
) &&
869 pmb
->mb
.mbxCommand
== MBX_REG_LOGIN64
&&
870 !pmb
->mb
.mbxStatus
) {
872 rpi
= pmb
->mb
.un
.varWords
[0];
873 lpfc_unreg_login(phba
, pmb
->mb
.un
.varRegLogin
.vpi
, rpi
, pmb
);
874 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
875 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
876 if (rc
!= MBX_NOT_FINISHED
)
880 mempool_free(pmb
, phba
->mbox_mem_pool
);
885 lpfc_sli_handle_mb_event(struct lpfc_hba
*phba
)
892 phba
->sli
.slistat
.mbox_event
++;
894 /* Get all completed mailboxe buffers into the cmplq */
895 spin_lock_irq(&phba
->hbalock
);
896 list_splice_init(&phba
->sli
.mboxq_cmpl
, &cmplq
);
897 spin_unlock_irq(&phba
->hbalock
);
899 /* Get a Mailbox buffer to setup mailbox commands for callback */
901 list_remove_head(&cmplq
, pmb
, LPFC_MBOXQ_t
, list
);
907 if (pmbox
->mbxCommand
!= MBX_HEARTBEAT
) {
909 lpfc_debugfs_disc_trc(pmb
->vport
,
910 LPFC_DISC_TRC_MBOX_VPORT
,
911 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
912 (uint32_t)pmbox
->mbxCommand
,
913 pmbox
->un
.varWords
[0],
914 pmbox
->un
.varWords
[1]);
917 lpfc_debugfs_disc_trc(phba
->pport
,
919 "MBOX cmpl: cmd:x%x mb:x%x x%x",
920 (uint32_t)pmbox
->mbxCommand
,
921 pmbox
->un
.varWords
[0],
922 pmbox
->un
.varWords
[1]);
927 * It is a fatal error if unknown mbox command completion.
929 if (lpfc_sli_chk_mbx_command(pmbox
->mbxCommand
) ==
931 /* Unknow mailbox command compl */
932 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
933 "(%d):0323 Unknown Mailbox command "
935 pmb
->vport
? pmb
->vport
->vpi
: 0,
937 phba
->link_state
= LPFC_HBA_ERROR
;
938 phba
->work_hs
= HS_FFER3
;
939 lpfc_handle_eratt(phba
);
943 if (pmbox
->mbxStatus
) {
944 phba
->sli
.slistat
.mbox_stat_err
++;
945 if (pmbox
->mbxStatus
== MBXERR_NO_RESOURCES
) {
946 /* Mbox cmd cmpl error - RETRYing */
947 lpfc_printf_log(phba
, KERN_INFO
,
949 "(%d):0305 Mbox cmd cmpl "
950 "error - RETRYing Data: x%x "
952 pmb
->vport
? pmb
->vport
->vpi
:0,
955 pmbox
->un
.varWords
[0],
956 pmb
->vport
->port_state
);
957 pmbox
->mbxStatus
= 0;
958 pmbox
->mbxOwner
= OWN_HOST
;
959 spin_lock_irq(&phba
->hbalock
);
960 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
961 spin_unlock_irq(&phba
->hbalock
);
962 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
963 if (rc
== MBX_SUCCESS
)
968 /* Mailbox cmd <cmd> Cmpl <cmpl> */
969 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
970 "(%d):0307 Mailbox cmd x%x Cmpl x%p "
971 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
972 pmb
->vport
? pmb
->vport
->vpi
: 0,
975 *((uint32_t *) pmbox
),
976 pmbox
->un
.varWords
[0],
977 pmbox
->un
.varWords
[1],
978 pmbox
->un
.varWords
[2],
979 pmbox
->un
.varWords
[3],
980 pmbox
->un
.varWords
[4],
981 pmbox
->un
.varWords
[5],
982 pmbox
->un
.varWords
[6],
983 pmbox
->un
.varWords
[7]);
986 pmb
->mbox_cmpl(phba
,pmb
);
991 static struct lpfc_dmabuf
*
992 lpfc_sli_replace_hbqbuff(struct lpfc_hba
*phba
, uint32_t tag
)
994 struct hbq_dmabuf
*hbq_entry
, *new_hbq_entry
;
996 void *virt
; /* virtual address ptr */
997 dma_addr_t phys
; /* mapped address */
1000 /* Check whether HBQ is still in use */
1001 spin_lock_irqsave(&phba
->hbalock
, flags
);
1002 if (!phba
->hbq_in_use
) {
1003 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1007 hbq_entry
= lpfc_sli_hbqbuf_find(phba
, tag
);
1008 if (hbq_entry
== NULL
) {
1009 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1012 list_del(&hbq_entry
->dbuf
.list
);
1015 new_hbq_entry
= (phba
->hbqs
[hbqno
].hbq_alloc_buffer
)(phba
);
1016 if (new_hbq_entry
== NULL
) {
1017 list_add_tail(&hbq_entry
->dbuf
.list
, &phba
->hbqbuf_in_list
);
1018 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1019 return &hbq_entry
->dbuf
;
1021 new_hbq_entry
->tag
= -1;
1022 phys
= new_hbq_entry
->dbuf
.phys
;
1023 virt
= new_hbq_entry
->dbuf
.virt
;
1024 new_hbq_entry
->dbuf
.phys
= hbq_entry
->dbuf
.phys
;
1025 new_hbq_entry
->dbuf
.virt
= hbq_entry
->dbuf
.virt
;
1026 hbq_entry
->dbuf
.phys
= phys
;
1027 hbq_entry
->dbuf
.virt
= virt
;
1028 lpfc_sli_free_hbq(phba
, hbq_entry
);
1029 list_add_tail(&new_hbq_entry
->dbuf
.list
, &phba
->hbqbuf_in_list
);
1030 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1032 return &new_hbq_entry
->dbuf
;
1035 static struct lpfc_dmabuf
*
1036 lpfc_sli_get_buff(struct lpfc_hba
*phba
,
1037 struct lpfc_sli_ring
*pring
,
1040 if (tag
& QUE_BUFTAG_BIT
)
1041 return lpfc_sli_ring_taggedbuf_get(phba
, pring
, tag
);
1043 return lpfc_sli_replace_hbqbuff(phba
, tag
);
1047 lpfc_sli_process_unsol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1048 struct lpfc_iocbq
*saveq
)
1052 uint32_t Rctl
, Type
;
1054 struct lpfc_iocbq
*iocbq
;
1055 struct lpfc_dmabuf
*dmzbuf
;
1058 irsp
= &(saveq
->iocb
);
1060 if (irsp
->ulpStatus
== IOSTAT_NEED_BUFFER
)
1062 if (irsp
->ulpCommand
== CMD_ASYNC_STATUS
) {
1063 if (pring
->lpfc_sli_rcv_async_status
)
1064 pring
->lpfc_sli_rcv_async_status(phba
, pring
, saveq
);
1066 lpfc_printf_log(phba
,
1069 "0316 Ring %d handler: unexpected "
1070 "ASYNC_STATUS iocb received evt_code "
1073 irsp
->un
.asyncstat
.evt_code
);
1077 if ((irsp
->ulpCommand
== CMD_IOCB_RET_XRI64_CX
) &&
1078 (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
)) {
1079 if (irsp
->ulpBdeCount
> 0) {
1080 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
1081 irsp
->un
.ulpWord
[3]);
1082 lpfc_in_buf_free(phba
, dmzbuf
);
1085 if (irsp
->ulpBdeCount
> 1) {
1086 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
1087 irsp
->unsli3
.sli3Words
[3]);
1088 lpfc_in_buf_free(phba
, dmzbuf
);
1091 if (irsp
->ulpBdeCount
> 2) {
1092 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
1093 irsp
->unsli3
.sli3Words
[7]);
1094 lpfc_in_buf_free(phba
, dmzbuf
);
1100 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
1101 if (irsp
->ulpBdeCount
!= 0) {
1102 saveq
->context2
= lpfc_sli_get_buff(phba
, pring
,
1103 irsp
->un
.ulpWord
[3]);
1104 if (!saveq
->context2
)
1105 lpfc_printf_log(phba
,
1108 "0341 Ring %d Cannot find buffer for "
1109 "an unsolicited iocb. tag 0x%x\n",
1111 irsp
->un
.ulpWord
[3]);
1113 if (irsp
->ulpBdeCount
== 2) {
1114 saveq
->context3
= lpfc_sli_get_buff(phba
, pring
,
1115 irsp
->unsli3
.sli3Words
[7]);
1116 if (!saveq
->context3
)
1117 lpfc_printf_log(phba
,
1120 "0342 Ring %d Cannot find buffer for an"
1121 " unsolicited iocb. tag 0x%x\n",
1123 irsp
->unsli3
.sli3Words
[7]);
1125 list_for_each_entry(iocbq
, &saveq
->list
, list
) {
1126 irsp
= &(iocbq
->iocb
);
1127 if (irsp
->ulpBdeCount
!= 0) {
1128 iocbq
->context2
= lpfc_sli_get_buff(phba
, pring
,
1129 irsp
->un
.ulpWord
[3]);
1130 if (!iocbq
->context2
)
1131 lpfc_printf_log(phba
,
1134 "0343 Ring %d Cannot find "
1135 "buffer for an unsolicited iocb"
1136 ". tag 0x%x\n", pring
->ringno
,
1137 irsp
->un
.ulpWord
[3]);
1139 if (irsp
->ulpBdeCount
== 2) {
1140 iocbq
->context3
= lpfc_sli_get_buff(phba
, pring
,
1141 irsp
->unsli3
.sli3Words
[7]);
1142 if (!iocbq
->context3
)
1143 lpfc_printf_log(phba
,
1146 "0344 Ring %d Cannot find "
1147 "buffer for an unsolicited "
1150 irsp
->unsli3
.sli3Words
[7]);
1154 if (irsp
->ulpBdeCount
!= 0 &&
1155 (irsp
->ulpCommand
== CMD_IOCB_RCV_CONT64_CX
||
1156 irsp
->ulpStatus
== IOSTAT_INTERMED_RSP
)) {
1159 /* search continue save q for same XRI */
1160 list_for_each_entry(iocbq
, &pring
->iocb_continue_saveq
, clist
) {
1161 if (iocbq
->iocb
.ulpContext
== saveq
->iocb
.ulpContext
) {
1162 list_add_tail(&saveq
->list
, &iocbq
->list
);
1168 list_add_tail(&saveq
->clist
,
1169 &pring
->iocb_continue_saveq
);
1170 if (saveq
->iocb
.ulpStatus
!= IOSTAT_INTERMED_RSP
) {
1171 list_del_init(&iocbq
->clist
);
1173 irsp
= &(saveq
->iocb
);
1177 if ((irsp
->ulpCommand
== CMD_RCV_ELS_REQ64_CX
) ||
1178 (irsp
->ulpCommand
== CMD_RCV_ELS_REQ_CX
) ||
1179 (irsp
->ulpCommand
== CMD_IOCB_RCV_ELS64_CX
)) {
1183 w5p
= (WORD5
*)&(saveq
->iocb
.un
.ulpWord
[5]);
1184 Rctl
= w5p
->hcsw
.Rctl
;
1185 Type
= w5p
->hcsw
.Type
;
1187 /* Firmware Workaround */
1188 if ((Rctl
== 0) && (pring
->ringno
== LPFC_ELS_RING
) &&
1189 (irsp
->ulpCommand
== CMD_RCV_SEQUENCE64_CX
||
1190 irsp
->ulpCommand
== CMD_IOCB_RCV_SEQ64_CX
)) {
1193 w5p
->hcsw
.Rctl
= Rctl
;
1194 w5p
->hcsw
.Type
= Type
;
1198 /* unSolicited Responses */
1199 if (pring
->prt
[0].profile
) {
1200 if (pring
->prt
[0].lpfc_sli_rcv_unsol_event
)
1201 (pring
->prt
[0].lpfc_sli_rcv_unsol_event
) (phba
, pring
,
1205 /* We must search, based on rctl / type
1206 for the right routine */
1207 for (i
= 0; i
< pring
->num_mask
; i
++) {
1208 if ((pring
->prt
[i
].rctl
== Rctl
)
1209 && (pring
->prt
[i
].type
== Type
)) {
1210 if (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
1211 (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
1212 (phba
, pring
, saveq
);
1219 /* Unexpected Rctl / Type received */
1220 /* Ring <ringno> handler: unexpected
1221 Rctl <Rctl> Type <Type> received */
1222 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
1223 "0313 Ring %d handler: unexpected Rctl x%x "
1224 "Type x%x received\n",
1225 pring
->ringno
, Rctl
, Type
);
1230 static struct lpfc_iocbq
*
1231 lpfc_sli_iocbq_lookup(struct lpfc_hba
*phba
,
1232 struct lpfc_sli_ring
*pring
,
1233 struct lpfc_iocbq
*prspiocb
)
1235 struct lpfc_iocbq
*cmd_iocb
= NULL
;
1238 iotag
= prspiocb
->iocb
.ulpIoTag
;
1240 if (iotag
!= 0 && iotag
<= phba
->sli
.last_iotag
) {
1241 cmd_iocb
= phba
->sli
.iocbq_lookup
[iotag
];
1242 list_del_init(&cmd_iocb
->list
);
1243 pring
->txcmplq_cnt
--;
1247 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
1248 "0317 iotag x%x is out off "
1249 "range: max iotag x%x wd0 x%x\n",
1250 iotag
, phba
->sli
.last_iotag
,
1251 *(((uint32_t *) &prspiocb
->iocb
) + 7));
1256 lpfc_sli_process_sol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1257 struct lpfc_iocbq
*saveq
)
1259 struct lpfc_iocbq
*cmdiocbp
;
1261 unsigned long iflag
;
1263 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
1264 spin_lock_irqsave(&phba
->hbalock
, iflag
);
1265 cmdiocbp
= lpfc_sli_iocbq_lookup(phba
, pring
, saveq
);
1266 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1269 if (cmdiocbp
->iocb_cmpl
) {
1271 * Post all ELS completions to the worker thread.
1272 * All other are passed to the completion callback.
1274 if (pring
->ringno
== LPFC_ELS_RING
) {
1275 if (cmdiocbp
->iocb_flag
& LPFC_DRIVER_ABORTED
) {
1276 cmdiocbp
->iocb_flag
&=
1277 ~LPFC_DRIVER_ABORTED
;
1278 saveq
->iocb
.ulpStatus
=
1279 IOSTAT_LOCAL_REJECT
;
1280 saveq
->iocb
.un
.ulpWord
[4] =
1283 /* Firmware could still be in progress
1284 * of DMAing payload, so don't free data
1285 * buffer till after a hbeat.
1287 saveq
->iocb_flag
|= LPFC_DELAY_MEM_FREE
;
1290 (cmdiocbp
->iocb_cmpl
) (phba
, cmdiocbp
, saveq
);
1292 lpfc_sli_release_iocbq(phba
, cmdiocbp
);
1295 * Unknown initiating command based on the response iotag.
1296 * This could be the case on the ELS ring because of
1299 if (pring
->ringno
!= LPFC_ELS_RING
) {
1301 * Ring <ringno> handler: unexpected completion IoTag
1304 lpfc_printf_vlog(cmdiocbp
->vport
, KERN_WARNING
, LOG_SLI
,
1305 "0322 Ring %d handler: "
1306 "unexpected completion IoTag x%x "
1307 "Data: x%x x%x x%x x%x\n",
1309 saveq
->iocb
.ulpIoTag
,
1310 saveq
->iocb
.ulpStatus
,
1311 saveq
->iocb
.un
.ulpWord
[4],
1312 saveq
->iocb
.ulpCommand
,
1313 saveq
->iocb
.ulpContext
);
1321 lpfc_sli_rsp_pointers_error(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1323 struct lpfc_pgp
*pgp
= (phba
->sli_rev
== 3) ?
1324 &phba
->slim2p
->mbx
.us
.s3_pgp
.port
[pring
->ringno
] :
1325 &phba
->slim2p
->mbx
.us
.s2
.port
[pring
->ringno
];
1327 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
1328 * rsp ring <portRspMax>
1330 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
1331 "0312 Ring %d handler: portRspPut %d "
1332 "is bigger then rsp ring %d\n",
1333 pring
->ringno
, le32_to_cpu(pgp
->rspPutInx
),
1336 phba
->link_state
= LPFC_HBA_ERROR
;
1339 * All error attention handlers are posted to
1342 phba
->work_ha
|= HA_ERATT
;
1343 phba
->work_hs
= HS_FFER3
;
1345 /* hbalock should already be held */
1346 if (phba
->work_wait
)
1347 lpfc_worker_wake_up(phba
);
1352 void lpfc_sli_poll_fcp_ring(struct lpfc_hba
*phba
)
1354 struct lpfc_sli
*psli
= &phba
->sli
;
1355 struct lpfc_sli_ring
*pring
= &psli
->ring
[LPFC_FCP_RING
];
1356 IOCB_t
*irsp
= NULL
;
1357 IOCB_t
*entry
= NULL
;
1358 struct lpfc_iocbq
*cmdiocbq
= NULL
;
1359 struct lpfc_iocbq rspiocbq
;
1360 struct lpfc_pgp
*pgp
;
1362 uint32_t portRspPut
, portRspMax
;
1364 uint32_t rsp_cmpl
= 0;
1366 unsigned long iflags
;
1368 pring
->stats
.iocb_event
++;
1370 pgp
= (phba
->sli_rev
== 3) ?
1371 &phba
->slim2p
->mbx
.us
.s3_pgp
.port
[pring
->ringno
] :
1372 &phba
->slim2p
->mbx
.us
.s2
.port
[pring
->ringno
];
1376 * The next available response entry should never exceed the maximum
1377 * entries. If it does, treat it as an adapter hardware error.
1379 portRspMax
= pring
->numRiocb
;
1380 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
1381 if (unlikely(portRspPut
>= portRspMax
)) {
1382 lpfc_sli_rsp_pointers_error(phba
, pring
);
1387 while (pring
->rspidx
!= portRspPut
) {
1388 entry
= lpfc_resp_iocb(phba
, pring
);
1389 if (++pring
->rspidx
>= portRspMax
)
1392 lpfc_sli_pcimem_bcopy((uint32_t *) entry
,
1393 (uint32_t *) &rspiocbq
.iocb
,
1394 phba
->iocb_rsp_size
);
1395 irsp
= &rspiocbq
.iocb
;
1396 type
= lpfc_sli_iocb_cmd_type(irsp
->ulpCommand
& CMD_IOCB_MASK
);
1397 pring
->stats
.iocb_rsp
++;
1400 if (unlikely(irsp
->ulpStatus
)) {
1401 /* Rsp ring <ringno> error: IOCB */
1402 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
1403 "0326 Rsp Ring %d error: IOCB Data: "
1404 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
1406 irsp
->un
.ulpWord
[0],
1407 irsp
->un
.ulpWord
[1],
1408 irsp
->un
.ulpWord
[2],
1409 irsp
->un
.ulpWord
[3],
1410 irsp
->un
.ulpWord
[4],
1411 irsp
->un
.ulpWord
[5],
1412 *(((uint32_t *) irsp
) + 6),
1413 *(((uint32_t *) irsp
) + 7));
1417 case LPFC_ABORT_IOCB
:
1420 * Idle exchange closed via ABTS from port. No iocb
1421 * resources need to be recovered.
1423 if (unlikely(irsp
->ulpCommand
== CMD_XRI_ABORTED_CX
)) {
1424 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
1425 "0314 IOCB cmd 0x%x "
1426 "processed. Skipping "
1432 spin_lock_irqsave(&phba
->hbalock
, iflags
);
1433 cmdiocbq
= lpfc_sli_iocbq_lookup(phba
, pring
,
1435 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
1436 if ((cmdiocbq
) && (cmdiocbq
->iocb_cmpl
)) {
1437 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
,
1442 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
1443 char adaptermsg
[LPFC_MAX_ADPTMSG
];
1444 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
1445 memcpy(&adaptermsg
[0], (uint8_t *) irsp
,
1447 dev_warn(&((phba
->pcidev
)->dev
),
1449 phba
->brd_no
, adaptermsg
);
1451 /* Unknown IOCB command */
1452 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
1453 "0321 Unknown IOCB command "
1454 "Data: x%x, x%x x%x x%x x%x\n",
1455 type
, irsp
->ulpCommand
,
1464 * The response IOCB has been processed. Update the ring
1465 * pointer in SLIM. If the port response put pointer has not
1466 * been updated, sync the pgp->rspPutInx and fetch the new port
1467 * response put pointer.
1469 writel(pring
->rspidx
, &phba
->host_gp
[pring
->ringno
].rspGetInx
);
1471 if (pring
->rspidx
== portRspPut
)
1472 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
1475 ha_copy
= readl(phba
->HAregaddr
);
1476 ha_copy
>>= (LPFC_FCP_RING
* 4);
1478 if ((rsp_cmpl
> 0) && (ha_copy
& HA_R0RE_REQ
)) {
1479 spin_lock_irqsave(&phba
->hbalock
, iflags
);
1480 pring
->stats
.iocb_rsp_full
++;
1481 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (LPFC_FCP_RING
* 4));
1482 writel(status
, phba
->CAregaddr
);
1483 readl(phba
->CAregaddr
);
1484 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
1486 if ((ha_copy
& HA_R0CE_RSP
) &&
1487 (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
1488 spin_lock_irqsave(&phba
->hbalock
, iflags
);
1489 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
1490 pring
->stats
.iocb_cmd_empty
++;
1492 /* Force update of the local copy of cmdGetInx */
1493 pring
->local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
1494 lpfc_sli_resume_iocb(phba
, pring
);
1496 if ((pring
->lpfc_sli_cmd_available
))
1497 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
1499 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
1506 * This routine presumes LPFC_FCP_RING handling and doesn't bother
1507 * to check it explicitly.
1510 lpfc_sli_handle_fast_ring_event(struct lpfc_hba
*phba
,
1511 struct lpfc_sli_ring
*pring
, uint32_t mask
)
1513 struct lpfc_pgp
*pgp
= (phba
->sli_rev
== 3) ?
1514 &phba
->slim2p
->mbx
.us
.s3_pgp
.port
[pring
->ringno
] :
1515 &phba
->slim2p
->mbx
.us
.s2
.port
[pring
->ringno
];
1516 IOCB_t
*irsp
= NULL
;
1517 IOCB_t
*entry
= NULL
;
1518 struct lpfc_iocbq
*cmdiocbq
= NULL
;
1519 struct lpfc_iocbq rspiocbq
;
1521 uint32_t portRspPut
, portRspMax
;
1523 lpfc_iocb_type type
;
1524 unsigned long iflag
;
1525 uint32_t rsp_cmpl
= 0;
1527 spin_lock_irqsave(&phba
->hbalock
, iflag
);
1528 pring
->stats
.iocb_event
++;
1531 * The next available response entry should never exceed the maximum
1532 * entries. If it does, treat it as an adapter hardware error.
1534 portRspMax
= pring
->numRiocb
;
1535 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
1536 if (unlikely(portRspPut
>= portRspMax
)) {
1537 lpfc_sli_rsp_pointers_error(phba
, pring
);
1538 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1543 while (pring
->rspidx
!= portRspPut
) {
1545 * Fetch an entry off the ring and copy it into a local data
1546 * structure. The copy involves a byte-swap since the
1547 * network byte order and pci byte orders are different.
1549 entry
= lpfc_resp_iocb(phba
, pring
);
1550 phba
->last_completion_time
= jiffies
;
1552 if (++pring
->rspidx
>= portRspMax
)
1555 lpfc_sli_pcimem_bcopy((uint32_t *) entry
,
1556 (uint32_t *) &rspiocbq
.iocb
,
1557 phba
->iocb_rsp_size
);
1558 INIT_LIST_HEAD(&(rspiocbq
.list
));
1559 irsp
= &rspiocbq
.iocb
;
1561 type
= lpfc_sli_iocb_cmd_type(irsp
->ulpCommand
& CMD_IOCB_MASK
);
1562 pring
->stats
.iocb_rsp
++;
1565 if (unlikely(irsp
->ulpStatus
)) {
1567 * If resource errors reported from HBA, reduce
1568 * queuedepths of the SCSI device.
1570 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
1571 (irsp
->un
.ulpWord
[4] == IOERR_NO_RESOURCES
)) {
1572 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1573 lpfc_adjust_queue_depth(phba
);
1574 spin_lock_irqsave(&phba
->hbalock
, iflag
);
1577 /* Rsp ring <ringno> error: IOCB */
1578 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
1579 "0336 Rsp Ring %d error: IOCB Data: "
1580 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
1582 irsp
->un
.ulpWord
[0],
1583 irsp
->un
.ulpWord
[1],
1584 irsp
->un
.ulpWord
[2],
1585 irsp
->un
.ulpWord
[3],
1586 irsp
->un
.ulpWord
[4],
1587 irsp
->un
.ulpWord
[5],
1588 *(((uint32_t *) irsp
) + 6),
1589 *(((uint32_t *) irsp
) + 7));
1593 case LPFC_ABORT_IOCB
:
1596 * Idle exchange closed via ABTS from port. No iocb
1597 * resources need to be recovered.
1599 if (unlikely(irsp
->ulpCommand
== CMD_XRI_ABORTED_CX
)) {
1600 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
1601 "0333 IOCB cmd 0x%x"
1602 " processed. Skipping"
1608 cmdiocbq
= lpfc_sli_iocbq_lookup(phba
, pring
,
1610 if ((cmdiocbq
) && (cmdiocbq
->iocb_cmpl
)) {
1611 if (phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) {
1612 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
,
1615 spin_unlock_irqrestore(&phba
->hbalock
,
1617 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
,
1619 spin_lock_irqsave(&phba
->hbalock
,
1624 case LPFC_UNSOL_IOCB
:
1625 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1626 lpfc_sli_process_unsol_iocb(phba
, pring
, &rspiocbq
);
1627 spin_lock_irqsave(&phba
->hbalock
, iflag
);
1630 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
1631 char adaptermsg
[LPFC_MAX_ADPTMSG
];
1632 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
1633 memcpy(&adaptermsg
[0], (uint8_t *) irsp
,
1635 dev_warn(&((phba
->pcidev
)->dev
),
1637 phba
->brd_no
, adaptermsg
);
1639 /* Unknown IOCB command */
1640 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
1641 "0334 Unknown IOCB command "
1642 "Data: x%x, x%x x%x x%x x%x\n",
1643 type
, irsp
->ulpCommand
,
1652 * The response IOCB has been processed. Update the ring
1653 * pointer in SLIM. If the port response put pointer has not
1654 * been updated, sync the pgp->rspPutInx and fetch the new port
1655 * response put pointer.
1657 writel(pring
->rspidx
, &phba
->host_gp
[pring
->ringno
].rspGetInx
);
1659 if (pring
->rspidx
== portRspPut
)
1660 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
1663 if ((rsp_cmpl
> 0) && (mask
& HA_R0RE_REQ
)) {
1664 pring
->stats
.iocb_rsp_full
++;
1665 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
1666 writel(status
, phba
->CAregaddr
);
1667 readl(phba
->CAregaddr
);
1669 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
1670 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
1671 pring
->stats
.iocb_cmd_empty
++;
1673 /* Force update of the local copy of cmdGetInx */
1674 pring
->local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
1675 lpfc_sli_resume_iocb(phba
, pring
);
1677 if ((pring
->lpfc_sli_cmd_available
))
1678 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
1682 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1687 lpfc_sli_handle_slow_ring_event(struct lpfc_hba
*phba
,
1688 struct lpfc_sli_ring
*pring
, uint32_t mask
)
1690 struct lpfc_pgp
*pgp
= (phba
->sli_rev
== 3) ?
1691 &phba
->slim2p
->mbx
.us
.s3_pgp
.port
[pring
->ringno
] :
1692 &phba
->slim2p
->mbx
.us
.s2
.port
[pring
->ringno
];
1694 IOCB_t
*irsp
= NULL
;
1695 struct lpfc_iocbq
*rspiocbp
= NULL
;
1696 struct lpfc_iocbq
*next_iocb
;
1697 struct lpfc_iocbq
*cmdiocbp
;
1698 struct lpfc_iocbq
*saveq
;
1699 uint8_t iocb_cmd_type
;
1700 lpfc_iocb_type type
;
1701 uint32_t status
, free_saveq
;
1702 uint32_t portRspPut
, portRspMax
;
1704 unsigned long iflag
;
1706 spin_lock_irqsave(&phba
->hbalock
, iflag
);
1707 pring
->stats
.iocb_event
++;
1710 * The next available response entry should never exceed the maximum
1711 * entries. If it does, treat it as an adapter hardware error.
1713 portRspMax
= pring
->numRiocb
;
1714 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
1715 if (portRspPut
>= portRspMax
) {
1717 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
1718 * rsp ring <portRspMax>
1720 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
1721 "0303 Ring %d handler: portRspPut %d "
1722 "is bigger then rsp ring %d\n",
1723 pring
->ringno
, portRspPut
, portRspMax
);
1725 phba
->link_state
= LPFC_HBA_ERROR
;
1726 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1728 phba
->work_hs
= HS_FFER3
;
1729 lpfc_handle_eratt(phba
);
1735 while (pring
->rspidx
!= portRspPut
) {
1737 * Build a completion list and call the appropriate handler.
1738 * The process is to get the next available response iocb, get
1739 * a free iocb from the list, copy the response data into the
1740 * free iocb, insert to the continuation list, and update the
1741 * next response index to slim. This process makes response
1742 * iocb's in the ring available to DMA as fast as possible but
1743 * pays a penalty for a copy operation. Since the iocb is
1744 * only 32 bytes, this penalty is considered small relative to
1745 * the PCI reads for register values and a slim write. When
1746 * the ulpLe field is set, the entire Command has been
1749 entry
= lpfc_resp_iocb(phba
, pring
);
1751 phba
->last_completion_time
= jiffies
;
1752 rspiocbp
= __lpfc_sli_get_iocbq(phba
);
1753 if (rspiocbp
== NULL
) {
1754 printk(KERN_ERR
"%s: out of buffers! Failing "
1755 "completion.\n", __FUNCTION__
);
1759 lpfc_sli_pcimem_bcopy(entry
, &rspiocbp
->iocb
,
1760 phba
->iocb_rsp_size
);
1761 irsp
= &rspiocbp
->iocb
;
1763 if (++pring
->rspidx
>= portRspMax
)
1766 if (pring
->ringno
== LPFC_ELS_RING
) {
1767 lpfc_debugfs_slow_ring_trc(phba
,
1768 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
1769 *(((uint32_t *) irsp
) + 4),
1770 *(((uint32_t *) irsp
) + 6),
1771 *(((uint32_t *) irsp
) + 7));
1774 writel(pring
->rspidx
, &phba
->host_gp
[pring
->ringno
].rspGetInx
);
1776 list_add_tail(&rspiocbp
->list
, &(pring
->iocb_continueq
));
1778 pring
->iocb_continueq_cnt
++;
1781 * By default, the driver expects to free all resources
1782 * associated with this iocb completion.
1785 saveq
= list_get_first(&pring
->iocb_continueq
,
1786 struct lpfc_iocbq
, list
);
1787 irsp
= &(saveq
->iocb
);
1788 list_del_init(&pring
->iocb_continueq
);
1789 pring
->iocb_continueq_cnt
= 0;
1791 pring
->stats
.iocb_rsp
++;
1794 * If resource errors reported from HBA, reduce
1795 * queuedepths of the SCSI device.
1797 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
1798 (irsp
->un
.ulpWord
[4] == IOERR_NO_RESOURCES
)) {
1799 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1800 lpfc_adjust_queue_depth(phba
);
1801 spin_lock_irqsave(&phba
->hbalock
, iflag
);
1804 if (irsp
->ulpStatus
) {
1805 /* Rsp ring <ringno> error: IOCB */
1806 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
1807 "0328 Rsp Ring %d error: "
1812 "x%x x%x x%x x%x\n",
1814 irsp
->un
.ulpWord
[0],
1815 irsp
->un
.ulpWord
[1],
1816 irsp
->un
.ulpWord
[2],
1817 irsp
->un
.ulpWord
[3],
1818 irsp
->un
.ulpWord
[4],
1819 irsp
->un
.ulpWord
[5],
1820 *(((uint32_t *) irsp
) + 6),
1821 *(((uint32_t *) irsp
) + 7),
1822 *(((uint32_t *) irsp
) + 8),
1823 *(((uint32_t *) irsp
) + 9),
1824 *(((uint32_t *) irsp
) + 10),
1825 *(((uint32_t *) irsp
) + 11),
1826 *(((uint32_t *) irsp
) + 12),
1827 *(((uint32_t *) irsp
) + 13),
1828 *(((uint32_t *) irsp
) + 14),
1829 *(((uint32_t *) irsp
) + 15));
1833 * Fetch the IOCB command type and call the correct
1834 * completion routine. Solicited and Unsolicited
1835 * IOCBs on the ELS ring get freed back to the
1836 * lpfc_iocb_list by the discovery kernel thread.
1838 iocb_cmd_type
= irsp
->ulpCommand
& CMD_IOCB_MASK
;
1839 type
= lpfc_sli_iocb_cmd_type(iocb_cmd_type
);
1840 if (type
== LPFC_SOL_IOCB
) {
1841 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1842 rc
= lpfc_sli_process_sol_iocb(phba
, pring
,
1844 spin_lock_irqsave(&phba
->hbalock
, iflag
);
1845 } else if (type
== LPFC_UNSOL_IOCB
) {
1846 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1847 rc
= lpfc_sli_process_unsol_iocb(phba
, pring
,
1849 spin_lock_irqsave(&phba
->hbalock
, iflag
);
1852 } else if (type
== LPFC_ABORT_IOCB
) {
1853 if ((irsp
->ulpCommand
!= CMD_XRI_ABORTED_CX
) &&
1855 lpfc_sli_iocbq_lookup(phba
, pring
,
1857 /* Call the specified completion
1859 if (cmdiocbp
->iocb_cmpl
) {
1860 spin_unlock_irqrestore(
1863 (cmdiocbp
->iocb_cmpl
) (phba
,
1869 __lpfc_sli_release_iocbq(phba
,
1872 } else if (type
== LPFC_UNKNOWN_IOCB
) {
1873 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
1875 char adaptermsg
[LPFC_MAX_ADPTMSG
];
1877 memset(adaptermsg
, 0,
1879 memcpy(&adaptermsg
[0], (uint8_t *) irsp
,
1881 dev_warn(&((phba
->pcidev
)->dev
),
1883 phba
->brd_no
, adaptermsg
);
1885 /* Unknown IOCB command */
1886 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
1887 "0335 Unknown IOCB "
1888 "command Data: x%x "
1898 list_for_each_entry_safe(rspiocbp
, next_iocb
,
1899 &saveq
->list
, list
) {
1900 list_del(&rspiocbp
->list
);
1901 __lpfc_sli_release_iocbq(phba
,
1904 __lpfc_sli_release_iocbq(phba
, saveq
);
1910 * If the port response put pointer has not been updated, sync
1911 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
1912 * response put pointer.
1914 if (pring
->rspidx
== portRspPut
) {
1915 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
1917 } /* while (pring->rspidx != portRspPut) */
1919 if ((rspiocbp
!= NULL
) && (mask
& HA_R0RE_REQ
)) {
1920 /* At least one response entry has been freed */
1921 pring
->stats
.iocb_rsp_full
++;
1922 /* SET RxRE_RSP in Chip Att register */
1923 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
1924 writel(status
, phba
->CAregaddr
);
1925 readl(phba
->CAregaddr
); /* flush */
1927 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
1928 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
1929 pring
->stats
.iocb_cmd_empty
++;
1931 /* Force update of the local copy of cmdGetInx */
1932 pring
->local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
1933 lpfc_sli_resume_iocb(phba
, pring
);
1935 if ((pring
->lpfc_sli_cmd_available
))
1936 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
1940 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1945 lpfc_sli_abort_iocb_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1947 LIST_HEAD(completions
);
1948 struct lpfc_iocbq
*iocb
, *next_iocb
;
1951 if (pring
->ringno
== LPFC_ELS_RING
) {
1952 lpfc_fabric_abort_hba(phba
);
1955 /* Error everything on txq and txcmplq
1958 spin_lock_irq(&phba
->hbalock
);
1959 list_splice_init(&pring
->txq
, &completions
);
1962 /* Next issue ABTS for everything on the txcmplq */
1963 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
)
1964 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
1966 spin_unlock_irq(&phba
->hbalock
);
1968 while (!list_empty(&completions
)) {
1969 iocb
= list_get_first(&completions
, struct lpfc_iocbq
, list
);
1971 list_del_init(&iocb
->list
);
1973 if (!iocb
->iocb_cmpl
)
1974 lpfc_sli_release_iocbq(phba
, iocb
);
1976 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
1977 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
1978 (iocb
->iocb_cmpl
) (phba
, iocb
, iocb
);
1984 lpfc_sli_brdready(struct lpfc_hba
*phba
, uint32_t mask
)
1990 /* Read the HBA Host Status Register */
1991 status
= readl(phba
->HSregaddr
);
1994 * Check status register every 100ms for 5 retries, then every
1995 * 500ms for 5, then every 2.5 sec for 5, then reset board and
1996 * every 2.5 sec for 4.
1997 * Break our of the loop if errors occurred during init.
1999 while (((status
& mask
) != mask
) &&
2000 !(status
& HS_FFERM
) &&
2012 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
2013 lpfc_sli_brdrestart(phba
);
2015 /* Read the HBA Host Status Register */
2016 status
= readl(phba
->HSregaddr
);
2019 /* Check to see if any errors occurred during init */
2020 if ((status
& HS_FFERM
) || (i
>= 20)) {
2021 phba
->link_state
= LPFC_HBA_ERROR
;
2028 #define BARRIER_TEST_PATTERN (0xdeadbeef)
2030 void lpfc_reset_barrier(struct lpfc_hba
*phba
)
2032 uint32_t __iomem
*resp_buf
;
2033 uint32_t __iomem
*mbox_buf
;
2034 volatile uint32_t mbox
;
2039 pci_read_config_byte(phba
->pcidev
, PCI_HEADER_TYPE
, &hdrtype
);
2040 if (hdrtype
!= 0x80 ||
2041 (FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != HELIOS_JEDEC_ID
&&
2042 FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != THOR_JEDEC_ID
))
2046 * Tell the other part of the chip to suspend temporarily all
2049 resp_buf
= phba
->MBslimaddr
;
2051 /* Disable the error attention */
2052 hc_copy
= readl(phba
->HCregaddr
);
2053 writel((hc_copy
& ~HC_ERINT_ENA
), phba
->HCregaddr
);
2054 readl(phba
->HCregaddr
); /* flush */
2055 phba
->link_flag
|= LS_IGNORE_ERATT
;
2057 if (readl(phba
->HAregaddr
) & HA_ERATT
) {
2058 /* Clear Chip error bit */
2059 writel(HA_ERATT
, phba
->HAregaddr
);
2060 phba
->pport
->stopped
= 1;
2064 ((MAILBOX_t
*)&mbox
)->mbxCommand
= MBX_KILL_BOARD
;
2065 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_CHIP
;
2067 writel(BARRIER_TEST_PATTERN
, (resp_buf
+ 1));
2068 mbox_buf
= phba
->MBslimaddr
;
2069 writel(mbox
, mbox_buf
);
2072 readl(resp_buf
+ 1) != ~(BARRIER_TEST_PATTERN
) && i
< 50; i
++)
2075 if (readl(resp_buf
+ 1) != ~(BARRIER_TEST_PATTERN
)) {
2076 if (phba
->sli
.sli_flag
& LPFC_SLI2_ACTIVE
||
2077 phba
->pport
->stopped
)
2083 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_HOST
;
2084 for (i
= 0; readl(resp_buf
) != mbox
&& i
< 500; i
++)
2089 while (!(readl(phba
->HAregaddr
) & HA_ERATT
) && ++i
< 500)
2092 if (readl(phba
->HAregaddr
) & HA_ERATT
) {
2093 writel(HA_ERATT
, phba
->HAregaddr
);
2094 phba
->pport
->stopped
= 1;
2098 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
2099 writel(hc_copy
, phba
->HCregaddr
);
2100 readl(phba
->HCregaddr
); /* flush */
2104 lpfc_sli_brdkill(struct lpfc_hba
*phba
)
2106 struct lpfc_sli
*psli
;
2116 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
2117 "0329 Kill HBA Data: x%x x%x\n",
2118 phba
->pport
->port_state
, psli
->sli_flag
);
2120 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2124 /* Disable the error attention */
2125 spin_lock_irq(&phba
->hbalock
);
2126 status
= readl(phba
->HCregaddr
);
2127 status
&= ~HC_ERINT_ENA
;
2128 writel(status
, phba
->HCregaddr
);
2129 readl(phba
->HCregaddr
); /* flush */
2130 phba
->link_flag
|= LS_IGNORE_ERATT
;
2131 spin_unlock_irq(&phba
->hbalock
);
2133 lpfc_kill_board(phba
, pmb
);
2134 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
2135 retval
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
2137 if (retval
!= MBX_SUCCESS
) {
2138 if (retval
!= MBX_BUSY
)
2139 mempool_free(pmb
, phba
->mbox_mem_pool
);
2140 spin_lock_irq(&phba
->hbalock
);
2141 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
2142 spin_unlock_irq(&phba
->hbalock
);
2146 psli
->sli_flag
&= ~LPFC_SLI2_ACTIVE
;
2148 mempool_free(pmb
, phba
->mbox_mem_pool
);
2150 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
2151 * attention every 100ms for 3 seconds. If we don't get ERATT after
2152 * 3 seconds we still set HBA_ERROR state because the status of the
2153 * board is now undefined.
2155 ha_copy
= readl(phba
->HAregaddr
);
2157 while ((i
++ < 30) && !(ha_copy
& HA_ERATT
)) {
2159 ha_copy
= readl(phba
->HAregaddr
);
2162 del_timer_sync(&psli
->mbox_tmo
);
2163 if (ha_copy
& HA_ERATT
) {
2164 writel(HA_ERATT
, phba
->HAregaddr
);
2165 phba
->pport
->stopped
= 1;
2167 spin_lock_irq(&phba
->hbalock
);
2168 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
2169 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
2170 spin_unlock_irq(&phba
->hbalock
);
2172 psli
->mbox_active
= NULL
;
2173 lpfc_hba_down_post(phba
);
2174 phba
->link_state
= LPFC_HBA_ERROR
;
2176 return ha_copy
& HA_ERATT
? 0 : 1;
2180 lpfc_sli_brdreset(struct lpfc_hba
*phba
)
2182 struct lpfc_sli
*psli
;
2183 struct lpfc_sli_ring
*pring
;
2190 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
2191 "0325 Reset HBA Data: x%x x%x\n",
2192 phba
->pport
->port_state
, psli
->sli_flag
);
2194 /* perform board reset */
2195 phba
->fc_eventTag
= 0;
2196 phba
->pport
->fc_myDID
= 0;
2197 phba
->pport
->fc_prevDID
= 0;
2199 /* Turn off parity checking and serr during the physical reset */
2200 pci_read_config_word(phba
->pcidev
, PCI_COMMAND
, &cfg_value
);
2201 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
,
2203 ~(PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
)));
2205 psli
->sli_flag
&= ~(LPFC_SLI2_ACTIVE
| LPFC_PROCESS_LA
);
2206 /* Now toggle INITFF bit in the Host Control Register */
2207 writel(HC_INITFF
, phba
->HCregaddr
);
2209 readl(phba
->HCregaddr
); /* flush */
2210 writel(0, phba
->HCregaddr
);
2211 readl(phba
->HCregaddr
); /* flush */
2213 /* Restore PCI cmd register */
2214 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, cfg_value
);
2216 /* Initialize relevant SLI info */
2217 for (i
= 0; i
< psli
->num_rings
; i
++) {
2218 pring
= &psli
->ring
[i
];
2221 pring
->next_cmdidx
= 0;
2222 pring
->local_getidx
= 0;
2224 pring
->missbufcnt
= 0;
2227 phba
->link_state
= LPFC_WARM_START
;
2232 lpfc_sli_brdrestart(struct lpfc_hba
*phba
)
2235 struct lpfc_sli
*psli
;
2237 volatile uint32_t word0
;
2238 void __iomem
*to_slim
;
2240 spin_lock_irq(&phba
->hbalock
);
2245 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
2246 "0337 Restart HBA Data: x%x x%x\n",
2247 phba
->pport
->port_state
, psli
->sli_flag
);
2250 mb
= (MAILBOX_t
*) &word0
;
2251 mb
->mbxCommand
= MBX_RESTART
;
2254 lpfc_reset_barrier(phba
);
2256 to_slim
= phba
->MBslimaddr
;
2257 writel(*(uint32_t *) mb
, to_slim
);
2258 readl(to_slim
); /* flush */
2260 /* Only skip post after fc_ffinit is completed */
2261 if (phba
->pport
->port_state
) {
2263 word0
= 1; /* This is really setting up word1 */
2266 word0
= 0; /* This is really setting up word1 */
2268 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
2269 writel(*(uint32_t *) mb
, to_slim
);
2270 readl(to_slim
); /* flush */
2272 lpfc_sli_brdreset(phba
);
2273 phba
->pport
->stopped
= 0;
2274 phba
->link_state
= LPFC_INIT_START
;
2276 spin_unlock_irq(&phba
->hbalock
);
2278 memset(&psli
->lnk_stat_offsets
, 0, sizeof(psli
->lnk_stat_offsets
));
2279 psli
->stats_start
= get_seconds();
2286 lpfc_hba_down_post(phba
);
2292 lpfc_sli_chipset_init(struct lpfc_hba
*phba
)
2294 uint32_t status
, i
= 0;
2296 /* Read the HBA Host Status Register */
2297 status
= readl(phba
->HSregaddr
);
2299 /* Check status register to see what current state is */
2301 while ((status
& (HS_FFRDY
| HS_MBRDY
)) != (HS_FFRDY
| HS_MBRDY
)) {
2303 /* Check every 100ms for 5 retries, then every 500ms for 5, then
2304 * every 2.5 sec for 5, then reset board and every 2.5 sec for
2308 /* Adapter failed to init, timeout, status reg
2310 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2311 "0436 Adapter failed to init, "
2312 "timeout, status reg x%x, "
2313 "FW Data: A8 x%x AC x%x\n", status
,
2314 readl(phba
->MBslimaddr
+ 0xa8),
2315 readl(phba
->MBslimaddr
+ 0xac));
2316 phba
->link_state
= LPFC_HBA_ERROR
;
2320 /* Check to see if any errors occurred during init */
2321 if (status
& HS_FFERM
) {
2322 /* ERROR: During chipset initialization */
2323 /* Adapter failed to init, chipset, status reg
2325 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2326 "0437 Adapter failed to init, "
2327 "chipset, status reg x%x, "
2328 "FW Data: A8 x%x AC x%x\n", status
,
2329 readl(phba
->MBslimaddr
+ 0xa8),
2330 readl(phba
->MBslimaddr
+ 0xac));
2331 phba
->link_state
= LPFC_HBA_ERROR
;
2337 } else if (i
<= 10) {
2345 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
2346 lpfc_sli_brdrestart(phba
);
2348 /* Read the HBA Host Status Register */
2349 status
= readl(phba
->HSregaddr
);
2352 /* Check to see if any errors occurred during init */
2353 if (status
& HS_FFERM
) {
2354 /* ERROR: During chipset initialization */
2355 /* Adapter failed to init, chipset, status reg <status> */
2356 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2357 "0438 Adapter failed to init, chipset, "
2359 "FW Data: A8 x%x AC x%x\n", status
,
2360 readl(phba
->MBslimaddr
+ 0xa8),
2361 readl(phba
->MBslimaddr
+ 0xac));
2362 phba
->link_state
= LPFC_HBA_ERROR
;
2366 /* Clear all interrupt enable conditions */
2367 writel(0, phba
->HCregaddr
);
2368 readl(phba
->HCregaddr
); /* flush */
2370 /* setup host attn register */
2371 writel(0xffffffff, phba
->HAregaddr
);
2372 readl(phba
->HAregaddr
); /* flush */
2377 lpfc_sli_hbq_count(void)
2379 return ARRAY_SIZE(lpfc_hbq_defs
);
2383 lpfc_sli_hbq_entry_count(void)
2385 int hbq_count
= lpfc_sli_hbq_count();
2389 for (i
= 0; i
< hbq_count
; ++i
)
2390 count
+= lpfc_hbq_defs
[i
]->entry_count
;
2395 lpfc_sli_hbq_size(void)
2397 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry
);
2401 lpfc_sli_hbq_setup(struct lpfc_hba
*phba
)
2403 int hbq_count
= lpfc_sli_hbq_count();
2407 uint32_t hbq_entry_index
;
2409 /* Get a Mailbox buffer to setup mailbox
2410 * commands for HBA initialization
2412 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2419 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
2420 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
2421 phba
->hbq_in_use
= 1;
2423 hbq_entry_index
= 0;
2424 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
) {
2425 phba
->hbqs
[hbqno
].next_hbqPutIdx
= 0;
2426 phba
->hbqs
[hbqno
].hbqPutIdx
= 0;
2427 phba
->hbqs
[hbqno
].local_hbqGetIdx
= 0;
2428 phba
->hbqs
[hbqno
].entry_count
=
2429 lpfc_hbq_defs
[hbqno
]->entry_count
;
2430 lpfc_config_hbq(phba
, hbqno
, lpfc_hbq_defs
[hbqno
],
2431 hbq_entry_index
, pmb
);
2432 hbq_entry_index
+= phba
->hbqs
[hbqno
].entry_count
;
2434 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
2435 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
2436 mbxStatus <status>, ring <num> */
2438 lpfc_printf_log(phba
, KERN_ERR
,
2439 LOG_SLI
| LOG_VPORT
,
2440 "1805 Adapter failed to init. "
2441 "Data: x%x x%x x%x\n",
2443 pmbox
->mbxStatus
, hbqno
);
2445 phba
->link_state
= LPFC_HBA_ERROR
;
2446 mempool_free(pmb
, phba
->mbox_mem_pool
);
2450 phba
->hbq_count
= hbq_count
;
2452 mempool_free(pmb
, phba
->mbox_mem_pool
);
2454 /* Initially populate or replenish the HBQs */
2455 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
) {
2456 if (lpfc_sli_hbqbuf_init_hbqs(phba
, hbqno
))
2463 lpfc_do_config_port(struct lpfc_hba
*phba
, int sli_mode
)
2466 uint32_t resetcount
= 0, rc
= 0, done
= 0;
2468 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2470 phba
->link_state
= LPFC_HBA_ERROR
;
2474 phba
->sli_rev
= sli_mode
;
2475 while (resetcount
< 2 && !done
) {
2476 spin_lock_irq(&phba
->hbalock
);
2477 phba
->sli
.sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
2478 spin_unlock_irq(&phba
->hbalock
);
2479 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
2480 lpfc_sli_brdrestart(phba
);
2482 rc
= lpfc_sli_chipset_init(phba
);
2486 spin_lock_irq(&phba
->hbalock
);
2487 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
2488 spin_unlock_irq(&phba
->hbalock
);
2491 /* Call pre CONFIG_PORT mailbox command initialization. A
2492 * value of 0 means the call was successful. Any other
2493 * nonzero value is a failure, but if ERESTART is returned,
2494 * the driver may reset the HBA and try again.
2496 rc
= lpfc_config_port_prep(phba
);
2497 if (rc
== -ERESTART
) {
2498 phba
->link_state
= LPFC_LINK_UNKNOWN
;
2504 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
2505 lpfc_config_port(phba
, pmb
);
2506 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
2507 if (rc
!= MBX_SUCCESS
) {
2508 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2509 "0442 Adapter failed to init, mbxCmd x%x "
2510 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
2511 pmb
->mb
.mbxCommand
, pmb
->mb
.mbxStatus
, 0);
2512 spin_lock_irq(&phba
->hbalock
);
2513 phba
->sli
.sli_flag
&= ~LPFC_SLI2_ACTIVE
;
2514 spin_unlock_irq(&phba
->hbalock
);
2518 phba
->max_vpi
= (phba
->max_vpi
&&
2519 pmb
->mb
.un
.varCfgPort
.gmv
) != 0
2520 ? pmb
->mb
.un
.varCfgPort
.max_vpi
2527 goto do_prep_failed
;
2530 if ((pmb
->mb
.un
.varCfgPort
.sli_mode
== 3) &&
2531 (!pmb
->mb
.un
.varCfgPort
.cMA
)) {
2536 mempool_free(pmb
, phba
->mbox_mem_pool
);
2541 lpfc_sli_hba_setup(struct lpfc_hba
*phba
)
2546 switch (lpfc_sli_mode
) {
2548 if (phba
->cfg_enable_npiv
) {
2549 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
2550 "1824 NPIV enabled: Override lpfc_sli_mode "
2551 "parameter (%d) to auto (0).\n",
2561 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
2562 "1819 Unrecognized lpfc_sli_mode "
2563 "parameter: %d.\n", lpfc_sli_mode
);
2568 rc
= lpfc_do_config_port(phba
, mode
);
2569 if (rc
&& lpfc_sli_mode
== 3)
2570 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
2571 "1820 Unable to select SLI-3. "
2572 "Not supported by adapter.\n");
2573 if (rc
&& mode
!= 2)
2574 rc
= lpfc_do_config_port(phba
, 2);
2576 goto lpfc_sli_hba_setup_error
;
2578 if (phba
->sli_rev
== 3) {
2579 phba
->iocb_cmd_size
= SLI3_IOCB_CMD_SIZE
;
2580 phba
->iocb_rsp_size
= SLI3_IOCB_RSP_SIZE
;
2581 phba
->sli3_options
|= LPFC_SLI3_ENABLED
;
2582 phba
->sli3_options
|= LPFC_SLI3_HBQ_ENABLED
;
2585 phba
->iocb_cmd_size
= SLI2_IOCB_CMD_SIZE
;
2586 phba
->iocb_rsp_size
= SLI2_IOCB_RSP_SIZE
;
2587 phba
->sli3_options
= 0;
2590 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
2591 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
2592 phba
->sli_rev
, phba
->max_vpi
);
2593 rc
= lpfc_sli_ring_map(phba
);
2596 goto lpfc_sli_hba_setup_error
;
2600 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
2601 rc
= lpfc_sli_hbq_setup(phba
);
2603 goto lpfc_sli_hba_setup_error
;
2606 phba
->sli
.sli_flag
|= LPFC_PROCESS_LA
;
2608 rc
= lpfc_config_port_post(phba
);
2610 goto lpfc_sli_hba_setup_error
;
2614 lpfc_sli_hba_setup_error
:
2615 phba
->link_state
= LPFC_HBA_ERROR
;
2616 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
2617 "0445 Firmware initialization failed\n");
2621 /*! lpfc_mbox_timeout
2625 * \param hba Pointer to per struct lpfc_hba structure
2626 * \param l1 Pointer to the driver's mailbox queue.
2632 * This routine handles mailbox timeout events at timer interrupt context.
2635 lpfc_mbox_timeout(unsigned long ptr
)
2637 struct lpfc_hba
*phba
= (struct lpfc_hba
*) ptr
;
2638 unsigned long iflag
;
2639 uint32_t tmo_posted
;
2641 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflag
);
2642 tmo_posted
= phba
->pport
->work_port_events
& WORKER_MBOX_TMO
;
2644 phba
->pport
->work_port_events
|= WORKER_MBOX_TMO
;
2645 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflag
);
2648 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2649 if (phba
->work_wait
)
2650 lpfc_worker_wake_up(phba
);
2651 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2656 lpfc_mbox_timeout_handler(struct lpfc_hba
*phba
)
2658 LPFC_MBOXQ_t
*pmbox
= phba
->sli
.mbox_active
;
2659 MAILBOX_t
*mb
= &pmbox
->mb
;
2660 struct lpfc_sli
*psli
= &phba
->sli
;
2661 struct lpfc_sli_ring
*pring
;
2663 if (!(phba
->pport
->work_port_events
& WORKER_MBOX_TMO
)) {
2667 /* Mbox cmd <mbxCommand> timeout */
2668 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
2669 "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
2671 phba
->pport
->port_state
,
2673 phba
->sli
.mbox_active
);
2675 /* Setting state unknown so lpfc_sli_abort_iocb_ring
2676 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
2677 * it to fail all oustanding SCSI IO.
2679 spin_lock_irq(&phba
->pport
->work_port_lock
);
2680 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
2681 spin_unlock_irq(&phba
->pport
->work_port_lock
);
2682 spin_lock_irq(&phba
->hbalock
);
2683 phba
->link_state
= LPFC_LINK_UNKNOWN
;
2684 phba
->pport
->fc_flag
|= FC_ESTABLISH_LINK
;
2685 psli
->sli_flag
&= ~LPFC_SLI2_ACTIVE
;
2686 spin_unlock_irq(&phba
->hbalock
);
2688 pring
= &psli
->ring
[psli
->fcp_ring
];
2689 lpfc_sli_abort_iocb_ring(phba
, pring
);
2691 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
2692 "0345 Resetting board due to mailbox timeout\n");
2694 * lpfc_offline calls lpfc_sli_hba_down which will clean up
2695 * on oustanding mailbox commands.
2697 /* If resets are disabled then set error state and return. */
2698 if (!phba
->cfg_enable_hba_reset
) {
2699 phba
->link_state
= LPFC_HBA_ERROR
;
2702 lpfc_offline_prep(phba
);
2704 lpfc_sli_brdrestart(phba
);
2705 if (lpfc_online(phba
) == 0) /* Initialize the HBA */
2706 mod_timer(&phba
->fc_estabtmo
, jiffies
+ HZ
* 60);
2707 lpfc_unblock_mgmt_io(phba
);
2712 lpfc_sli_issue_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmbox
, uint32_t flag
)
2715 struct lpfc_sli
*psli
= &phba
->sli
;
2716 uint32_t status
, evtctr
;
2719 unsigned long timeout
;
2720 unsigned long drvr_flag
= 0;
2721 volatile uint32_t word0
, ldata
;
2722 void __iomem
*to_slim
;
2724 if (pmbox
->mbox_cmpl
&& pmbox
->mbox_cmpl
!= lpfc_sli_def_mbox_cmpl
&&
2725 pmbox
->mbox_cmpl
!= lpfc_sli_wake_mbox_wait
) {
2727 lpfc_printf_log(phba
, KERN_ERR
,
2728 LOG_MBOX
| LOG_VPORT
,
2729 "1806 Mbox x%x failed. No vport\n",
2730 pmbox
->mb
.mbxCommand
);
2732 return MBX_NOT_FINISHED
;
2737 /* If the PCI channel is in offline state, do not post mbox. */
2738 if (unlikely(pci_channel_offline(phba
->pcidev
)))
2739 return MBX_NOT_FINISHED
;
2741 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
2746 status
= MBX_SUCCESS
;
2748 if (phba
->link_state
== LPFC_HBA_ERROR
) {
2749 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
2751 /* Mbox command <mbxCommand> cannot issue */
2752 LOG_MBOX_CANNOT_ISSUE_DATA(phba
, pmbox
, psli
, flag
);
2753 return MBX_NOT_FINISHED
;
2756 if (mb
->mbxCommand
!= MBX_KILL_BOARD
&& flag
& MBX_NOWAIT
&&
2757 !(readl(phba
->HCregaddr
) & HC_MBINT_ENA
)) {
2758 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
2759 LOG_MBOX_CANNOT_ISSUE_DATA(phba
, pmbox
, psli
, flag
);
2760 return MBX_NOT_FINISHED
;
2763 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
2764 /* Polling for a mbox command when another one is already active
2765 * is not allowed in SLI. Also, the driver must have established
2766 * SLI2 mode to queue and process multiple mbox commands.
2769 if (flag
& MBX_POLL
) {
2770 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
2772 /* Mbox command <mbxCommand> cannot issue */
2773 LOG_MBOX_CANNOT_ISSUE_DATA(phba
, pmbox
, psli
, flag
);
2774 return MBX_NOT_FINISHED
;
2777 if (!(psli
->sli_flag
& LPFC_SLI2_ACTIVE
)) {
2778 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
2779 /* Mbox command <mbxCommand> cannot issue */
2780 LOG_MBOX_CANNOT_ISSUE_DATA(phba
, pmbox
, psli
, flag
);
2781 return MBX_NOT_FINISHED
;
2784 /* Another mailbox command is still being processed, queue this
2785 * command to be processed later.
2787 lpfc_mbox_put(phba
, pmbox
);
2789 /* Mbox cmd issue - BUSY */
2790 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
2791 "(%d):0308 Mbox cmd issue - BUSY Data: "
2792 "x%x x%x x%x x%x\n",
2793 pmbox
->vport
? pmbox
->vport
->vpi
: 0xffffff,
2794 mb
->mbxCommand
, phba
->pport
->port_state
,
2795 psli
->sli_flag
, flag
);
2797 psli
->slistat
.mbox_busy
++;
2798 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
2801 lpfc_debugfs_disc_trc(pmbox
->vport
,
2802 LPFC_DISC_TRC_MBOX_VPORT
,
2803 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
2804 (uint32_t)mb
->mbxCommand
,
2805 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
2808 lpfc_debugfs_disc_trc(phba
->pport
,
2810 "MBOX Bsy: cmd:x%x mb:x%x x%x",
2811 (uint32_t)mb
->mbxCommand
,
2812 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
2818 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
2820 /* If we are not polling, we MUST be in SLI2 mode */
2821 if (flag
!= MBX_POLL
) {
2822 if (!(psli
->sli_flag
& LPFC_SLI2_ACTIVE
) &&
2823 (mb
->mbxCommand
!= MBX_KILL_BOARD
)) {
2824 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
2825 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
2826 /* Mbox command <mbxCommand> cannot issue */
2827 LOG_MBOX_CANNOT_ISSUE_DATA(phba
, pmbox
, psli
, flag
);
2828 return MBX_NOT_FINISHED
;
2830 /* timeout active mbox command */
2831 mod_timer(&psli
->mbox_tmo
, (jiffies
+
2832 (HZ
* lpfc_mbox_tmo_val(phba
, mb
->mbxCommand
))));
2835 /* Mailbox cmd <cmd> issue */
2836 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
2837 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
2839 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
2840 mb
->mbxCommand
, phba
->pport
->port_state
,
2841 psli
->sli_flag
, flag
);
2843 if (mb
->mbxCommand
!= MBX_HEARTBEAT
) {
2845 lpfc_debugfs_disc_trc(pmbox
->vport
,
2846 LPFC_DISC_TRC_MBOX_VPORT
,
2847 "MBOX Send vport: cmd:x%x mb:x%x x%x",
2848 (uint32_t)mb
->mbxCommand
,
2849 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
2852 lpfc_debugfs_disc_trc(phba
->pport
,
2854 "MBOX Send: cmd:x%x mb:x%x x%x",
2855 (uint32_t)mb
->mbxCommand
,
2856 mb
->un
.varWords
[0], mb
->un
.varWords
[1]);
2860 psli
->slistat
.mbox_cmd
++;
2861 evtctr
= psli
->slistat
.mbox_event
;
2863 /* next set own bit for the adapter and copy over command word */
2864 mb
->mbxOwner
= OWN_CHIP
;
2866 if (psli
->sli_flag
& LPFC_SLI2_ACTIVE
) {
2867 /* First copy command data to host SLIM area */
2868 lpfc_sli_pcimem_bcopy(mb
, &phba
->slim2p
->mbx
, MAILBOX_CMD_SIZE
);
2870 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
2871 /* copy command data into host mbox for cmpl */
2872 lpfc_sli_pcimem_bcopy(mb
, &phba
->slim2p
->mbx
,
2876 /* First copy mbox command data to HBA SLIM, skip past first
2878 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
2879 lpfc_memcpy_to_slim(to_slim
, &mb
->un
.varWords
[0],
2880 MAILBOX_CMD_SIZE
- sizeof (uint32_t));
2882 /* Next copy over first word, with mbxOwner set */
2883 ldata
= *((volatile uint32_t *)mb
);
2884 to_slim
= phba
->MBslimaddr
;
2885 writel(ldata
, to_slim
);
2886 readl(to_slim
); /* flush */
2888 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
2889 /* switch over to host mailbox */
2890 psli
->sli_flag
|= LPFC_SLI2_ACTIVE
;
2898 /* Set up reference to mailbox command */
2899 psli
->mbox_active
= pmbox
;
2900 /* Interrupt board to do it */
2901 writel(CA_MBATT
, phba
->CAregaddr
);
2902 readl(phba
->CAregaddr
); /* flush */
2903 /* Don't wait for it to finish, just return */
2907 /* Set up null reference to mailbox command */
2908 psli
->mbox_active
= NULL
;
2909 /* Interrupt board to do it */
2910 writel(CA_MBATT
, phba
->CAregaddr
);
2911 readl(phba
->CAregaddr
); /* flush */
2913 if (psli
->sli_flag
& LPFC_SLI2_ACTIVE
) {
2914 /* First read mbox status word */
2915 word0
= *((volatile uint32_t *)&phba
->slim2p
->mbx
);
2916 word0
= le32_to_cpu(word0
);
2918 /* First read mbox status word */
2919 word0
= readl(phba
->MBslimaddr
);
2922 /* Read the HBA Host Attention Register */
2923 ha_copy
= readl(phba
->HAregaddr
);
2924 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
,
2928 /* Wait for command to complete */
2929 while (((word0
& OWN_CHIP
) == OWN_CHIP
) ||
2930 (!(ha_copy
& HA_MBATT
) &&
2931 (phba
->link_state
> LPFC_WARM_START
))) {
2932 if (time_after(jiffies
, timeout
)) {
2933 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
2934 spin_unlock_irqrestore(&phba
->hbalock
,
2936 return MBX_NOT_FINISHED
;
2939 /* Check if we took a mbox interrupt while we were
2941 if (((word0
& OWN_CHIP
) != OWN_CHIP
)
2942 && (evtctr
!= psli
->slistat
.mbox_event
))
2946 spin_unlock_irqrestore(&phba
->hbalock
,
2949 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
2952 if (psli
->sli_flag
& LPFC_SLI2_ACTIVE
) {
2953 /* First copy command data */
2954 word0
= *((volatile uint32_t *)
2955 &phba
->slim2p
->mbx
);
2956 word0
= le32_to_cpu(word0
);
2957 if (mb
->mbxCommand
== MBX_CONFIG_PORT
) {
2959 volatile uint32_t slimword0
;
2960 /* Check real SLIM for any errors */
2961 slimword0
= readl(phba
->MBslimaddr
);
2962 slimmb
= (MAILBOX_t
*) & slimword0
;
2963 if (((slimword0
& OWN_CHIP
) != OWN_CHIP
)
2964 && slimmb
->mbxStatus
) {
2971 /* First copy command data */
2972 word0
= readl(phba
->MBslimaddr
);
2974 /* Read the HBA Host Attention Register */
2975 ha_copy
= readl(phba
->HAregaddr
);
2978 if (psli
->sli_flag
& LPFC_SLI2_ACTIVE
) {
2979 /* copy results back to user */
2980 lpfc_sli_pcimem_bcopy(&phba
->slim2p
->mbx
, mb
,
2983 /* First copy command data */
2984 lpfc_memcpy_from_slim(mb
, phba
->MBslimaddr
,
2986 if ((mb
->mbxCommand
== MBX_DUMP_MEMORY
) &&
2988 lpfc_memcpy_from_slim((void *)pmbox
->context2
,
2989 phba
->MBslimaddr
+ DMP_RSP_OFFSET
,
2990 mb
->un
.varDmp
.word_cnt
);
2994 writel(HA_MBATT
, phba
->HAregaddr
);
2995 readl(phba
->HAregaddr
); /* flush */
2997 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
2998 status
= mb
->mbxStatus
;
3001 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
3006 * Caller needs to hold lock.
3009 __lpfc_sli_ringtx_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
3010 struct lpfc_iocbq
*piocb
)
3012 /* Insert the caller's iocb in the txq tail for later processing. */
3013 list_add_tail(&piocb
->list
, &pring
->txq
);
3017 static struct lpfc_iocbq
*
3018 lpfc_sli_next_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
3019 struct lpfc_iocbq
**piocb
)
3021 struct lpfc_iocbq
* nextiocb
;
3023 nextiocb
= lpfc_sli_ringtx_get(phba
, pring
);
3033 * Lockless version of lpfc_sli_issue_iocb.
3036 __lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
3037 struct lpfc_iocbq
*piocb
, uint32_t flag
)
3039 struct lpfc_iocbq
*nextiocb
;
3042 if (piocb
->iocb_cmpl
&& (!piocb
->vport
) &&
3043 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
3044 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
3045 lpfc_printf_log(phba
, KERN_ERR
,
3046 LOG_SLI
| LOG_VPORT
,
3047 "1807 IOCB x%x failed. No vport\n",
3048 piocb
->iocb
.ulpCommand
);
3054 /* If the PCI channel is in offline state, do not post iocbs. */
3055 if (unlikely(pci_channel_offline(phba
->pcidev
)))
3059 * We should never get an IOCB if we are in a < LINK_DOWN state
3061 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
3065 * Check to see if we are blocking IOCB processing because of a
3066 * outstanding event.
3068 if (unlikely(pring
->flag
& LPFC_STOP_IOCB_EVENT
))
3071 if (unlikely(phba
->link_state
== LPFC_LINK_DOWN
)) {
3073 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
3074 * can be issued if the link is not up.
3076 switch (piocb
->iocb
.ulpCommand
) {
3077 case CMD_QUE_RING_BUF_CN
:
3078 case CMD_QUE_RING_BUF64_CN
:
3080 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
3081 * completion, iocb_cmpl MUST be 0.
3083 if (piocb
->iocb_cmpl
)
3084 piocb
->iocb_cmpl
= NULL
;
3086 case CMD_CREATE_XRI_CR
:
3087 case CMD_CLOSE_XRI_CN
:
3088 case CMD_CLOSE_XRI_CX
:
3095 * For FCP commands, we must be in a state where we can process link
3098 } else if (unlikely(pring
->ringno
== phba
->sli
.fcp_ring
&&
3099 !(phba
->sli
.sli_flag
& LPFC_PROCESS_LA
))) {
3103 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
3104 (nextiocb
= lpfc_sli_next_iocb(phba
, pring
, &piocb
)))
3105 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
3108 lpfc_sli_update_ring(phba
, pring
);
3110 lpfc_sli_update_full_ring(phba
, pring
);
3113 return IOCB_SUCCESS
;
3118 pring
->stats
.iocb_cmd_delay
++;
3122 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
3123 __lpfc_sli_ringtx_put(phba
, pring
, piocb
);
3124 return IOCB_SUCCESS
;
3132 lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
3133 struct lpfc_iocbq
*piocb
, uint32_t flag
)
3135 unsigned long iflags
;
3138 spin_lock_irqsave(&phba
->hbalock
, iflags
);
3139 rc
= __lpfc_sli_issue_iocb(phba
, pring
, piocb
, flag
);
3140 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
3146 lpfc_extra_ring_setup( struct lpfc_hba
*phba
)
3148 struct lpfc_sli
*psli
;
3149 struct lpfc_sli_ring
*pring
;
3153 /* Adjust cmd/rsp ring iocb entries more evenly */
3155 /* Take some away from the FCP ring */
3156 pring
= &psli
->ring
[psli
->fcp_ring
];
3157 pring
->numCiocb
-= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
3158 pring
->numRiocb
-= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
3159 pring
->numCiocb
-= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
3160 pring
->numRiocb
-= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
3162 /* and give them to the extra ring */
3163 pring
= &psli
->ring
[psli
->extra_ring
];
3165 pring
->numCiocb
+= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
3166 pring
->numRiocb
+= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
3167 pring
->numCiocb
+= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
3168 pring
->numRiocb
+= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
3170 /* Setup default profile for this ring */
3171 pring
->iotag_max
= 4096;
3172 pring
->num_mask
= 1;
3173 pring
->prt
[0].profile
= 0; /* Mask 0 */
3174 pring
->prt
[0].rctl
= phba
->cfg_multi_ring_rctl
;
3175 pring
->prt
[0].type
= phba
->cfg_multi_ring_type
;
3176 pring
->prt
[0].lpfc_sli_rcv_unsol_event
= NULL
;
3181 lpfc_sli_async_event_handler(struct lpfc_hba
* phba
,
3182 struct lpfc_sli_ring
* pring
, struct lpfc_iocbq
* iocbq
)
3187 struct temp_event temp_event_data
;
3188 struct Scsi_Host
*shost
;
3190 icmd
= &iocbq
->iocb
;
3191 evt_code
= icmd
->un
.asyncstat
.evt_code
;
3192 temp
= icmd
->ulpContext
;
3194 if ((evt_code
!= ASYNC_TEMP_WARN
) &&
3195 (evt_code
!= ASYNC_TEMP_SAFE
)) {
3196 lpfc_printf_log(phba
,
3199 "0346 Ring %d handler: unexpected ASYNC_STATUS"
3202 icmd
->un
.asyncstat
.evt_code
);
3205 temp_event_data
.data
= (uint32_t)temp
;
3206 temp_event_data
.event_type
= FC_REG_TEMPERATURE_EVENT
;
3207 if (evt_code
== ASYNC_TEMP_WARN
) {
3208 temp_event_data
.event_code
= LPFC_THRESHOLD_TEMP
;
3209 lpfc_printf_log(phba
,
3212 "0347 Adapter is very hot, please take "
3213 "corrective action. temperature : %d Celsius\n",
3216 if (evt_code
== ASYNC_TEMP_SAFE
) {
3217 temp_event_data
.event_code
= LPFC_NORMAL_TEMP
;
3218 lpfc_printf_log(phba
,
3221 "0340 Adapter temperature is OK now. "
3222 "temperature : %d Celsius\n",
3226 /* Send temperature change event to applications */
3227 shost
= lpfc_shost_from_vport(phba
->pport
);
3228 fc_host_post_vendor_event(shost
, fc_get_event_number(),
3229 sizeof(temp_event_data
), (char *) &temp_event_data
,
3230 SCSI_NL_VID_TYPE_PCI
| PCI_VENDOR_ID_EMULEX
);
3236 lpfc_sli_setup(struct lpfc_hba
*phba
)
3238 int i
, totiocbsize
= 0;
3239 struct lpfc_sli
*psli
= &phba
->sli
;
3240 struct lpfc_sli_ring
*pring
;
3242 psli
->num_rings
= MAX_CONFIGURED_RINGS
;
3244 psli
->fcp_ring
= LPFC_FCP_RING
;
3245 psli
->next_ring
= LPFC_FCP_NEXT_RING
;
3246 psli
->extra_ring
= LPFC_EXTRA_RING
;
3248 psli
->iocbq_lookup
= NULL
;
3249 psli
->iocbq_lookup_len
= 0;
3250 psli
->last_iotag
= 0;
3252 for (i
= 0; i
< psli
->num_rings
; i
++) {
3253 pring
= &psli
->ring
[i
];
3255 case LPFC_FCP_RING
: /* ring 0 - FCP */
3256 /* numCiocb and numRiocb are used in config_port */
3257 pring
->numCiocb
= SLI2_IOCB_CMD_R0_ENTRIES
;
3258 pring
->numRiocb
= SLI2_IOCB_RSP_R0_ENTRIES
;
3259 pring
->numCiocb
+= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
3260 pring
->numRiocb
+= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
3261 pring
->numCiocb
+= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
3262 pring
->numRiocb
+= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
3263 pring
->sizeCiocb
= (phba
->sli_rev
== 3) ?
3264 SLI3_IOCB_CMD_SIZE
:
3266 pring
->sizeRiocb
= (phba
->sli_rev
== 3) ?
3267 SLI3_IOCB_RSP_SIZE
:
3269 pring
->iotag_ctr
= 0;
3271 (phba
->cfg_hba_queue_depth
* 2);
3272 pring
->fast_iotag
= pring
->iotag_max
;
3273 pring
->num_mask
= 0;
3275 case LPFC_EXTRA_RING
: /* ring 1 - EXTRA */
3276 /* numCiocb and numRiocb are used in config_port */
3277 pring
->numCiocb
= SLI2_IOCB_CMD_R1_ENTRIES
;
3278 pring
->numRiocb
= SLI2_IOCB_RSP_R1_ENTRIES
;
3279 pring
->sizeCiocb
= (phba
->sli_rev
== 3) ?
3280 SLI3_IOCB_CMD_SIZE
:
3282 pring
->sizeRiocb
= (phba
->sli_rev
== 3) ?
3283 SLI3_IOCB_RSP_SIZE
:
3285 pring
->iotag_max
= phba
->cfg_hba_queue_depth
;
3286 pring
->num_mask
= 0;
3288 case LPFC_ELS_RING
: /* ring 2 - ELS / CT */
3289 /* numCiocb and numRiocb are used in config_port */
3290 pring
->numCiocb
= SLI2_IOCB_CMD_R2_ENTRIES
;
3291 pring
->numRiocb
= SLI2_IOCB_RSP_R2_ENTRIES
;
3292 pring
->sizeCiocb
= (phba
->sli_rev
== 3) ?
3293 SLI3_IOCB_CMD_SIZE
:
3295 pring
->sizeRiocb
= (phba
->sli_rev
== 3) ?
3296 SLI3_IOCB_RSP_SIZE
:
3298 pring
->fast_iotag
= 0;
3299 pring
->iotag_ctr
= 0;
3300 pring
->iotag_max
= 4096;
3301 pring
->lpfc_sli_rcv_async_status
=
3302 lpfc_sli_async_event_handler
;
3303 pring
->num_mask
= 4;
3304 pring
->prt
[0].profile
= 0; /* Mask 0 */
3305 pring
->prt
[0].rctl
= FC_ELS_REQ
;
3306 pring
->prt
[0].type
= FC_ELS_DATA
;
3307 pring
->prt
[0].lpfc_sli_rcv_unsol_event
=
3308 lpfc_els_unsol_event
;
3309 pring
->prt
[1].profile
= 0; /* Mask 1 */
3310 pring
->prt
[1].rctl
= FC_ELS_RSP
;
3311 pring
->prt
[1].type
= FC_ELS_DATA
;
3312 pring
->prt
[1].lpfc_sli_rcv_unsol_event
=
3313 lpfc_els_unsol_event
;
3314 pring
->prt
[2].profile
= 0; /* Mask 2 */
3315 /* NameServer Inquiry */
3316 pring
->prt
[2].rctl
= FC_UNSOL_CTL
;
3318 pring
->prt
[2].type
= FC_COMMON_TRANSPORT_ULP
;
3319 pring
->prt
[2].lpfc_sli_rcv_unsol_event
=
3320 lpfc_ct_unsol_event
;
3321 pring
->prt
[3].profile
= 0; /* Mask 3 */
3322 /* NameServer response */
3323 pring
->prt
[3].rctl
= FC_SOL_CTL
;
3325 pring
->prt
[3].type
= FC_COMMON_TRANSPORT_ULP
;
3326 pring
->prt
[3].lpfc_sli_rcv_unsol_event
=
3327 lpfc_ct_unsol_event
;
3330 totiocbsize
+= (pring
->numCiocb
* pring
->sizeCiocb
) +
3331 (pring
->numRiocb
* pring
->sizeRiocb
);
3333 if (totiocbsize
> MAX_SLIM_IOCB_SIZE
) {
3334 /* Too many cmd / rsp ring entries in SLI2 SLIM */
3335 printk(KERN_ERR
"%d:0462 Too many cmd / rsp ring entries in "
3336 "SLI2 SLIM Data: x%x x%lx\n",
3337 phba
->brd_no
, totiocbsize
,
3338 (unsigned long) MAX_SLIM_IOCB_SIZE
);
3340 if (phba
->cfg_multi_ring_support
== 2)
3341 lpfc_extra_ring_setup(phba
);
3347 lpfc_sli_queue_setup(struct lpfc_hba
*phba
)
3349 struct lpfc_sli
*psli
;
3350 struct lpfc_sli_ring
*pring
;
3354 spin_lock_irq(&phba
->hbalock
);
3355 INIT_LIST_HEAD(&psli
->mboxq
);
3356 INIT_LIST_HEAD(&psli
->mboxq_cmpl
);
3357 /* Initialize list headers for txq and txcmplq as double linked lists */
3358 for (i
= 0; i
< psli
->num_rings
; i
++) {
3359 pring
= &psli
->ring
[i
];
3361 pring
->next_cmdidx
= 0;
3362 pring
->local_getidx
= 0;
3364 INIT_LIST_HEAD(&pring
->txq
);
3365 INIT_LIST_HEAD(&pring
->txcmplq
);
3366 INIT_LIST_HEAD(&pring
->iocb_continueq
);
3367 INIT_LIST_HEAD(&pring
->iocb_continue_saveq
);
3368 INIT_LIST_HEAD(&pring
->postbufq
);
3370 spin_unlock_irq(&phba
->hbalock
);
3375 lpfc_sli_host_down(struct lpfc_vport
*vport
)
3377 LIST_HEAD(completions
);
3378 struct lpfc_hba
*phba
= vport
->phba
;
3379 struct lpfc_sli
*psli
= &phba
->sli
;
3380 struct lpfc_sli_ring
*pring
;
3381 struct lpfc_iocbq
*iocb
, *next_iocb
;
3383 unsigned long flags
= 0;
3384 uint16_t prev_pring_flag
;
3386 lpfc_cleanup_discovery_resources(vport
);
3388 spin_lock_irqsave(&phba
->hbalock
, flags
);
3389 for (i
= 0; i
< psli
->num_rings
; i
++) {
3390 pring
= &psli
->ring
[i
];
3391 prev_pring_flag
= pring
->flag
;
3392 if (pring
->ringno
== LPFC_ELS_RING
) /* Only slow rings */
3393 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
3395 * Error everything on the txq since these iocbs have not been
3396 * given to the FW yet.
3398 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
3399 if (iocb
->vport
!= vport
)
3401 list_move_tail(&iocb
->list
, &completions
);
3405 /* Next issue ABTS for everything on the txcmplq */
3406 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
,
3408 if (iocb
->vport
!= vport
)
3410 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
3413 pring
->flag
= prev_pring_flag
;
3416 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
3418 while (!list_empty(&completions
)) {
3419 list_remove_head(&completions
, iocb
, struct lpfc_iocbq
, list
);
3421 if (!iocb
->iocb_cmpl
)
3422 lpfc_sli_release_iocbq(phba
, iocb
);
3424 iocb
->iocb
.ulpStatus
= IOSTAT_LOCAL_REJECT
;
3425 iocb
->iocb
.un
.ulpWord
[4] = IOERR_SLI_DOWN
;
3426 (iocb
->iocb_cmpl
) (phba
, iocb
, iocb
);
3433 lpfc_sli_hba_down(struct lpfc_hba
*phba
)
3435 LIST_HEAD(completions
);
3436 struct lpfc_sli
*psli
= &phba
->sli
;
3437 struct lpfc_sli_ring
*pring
;
3438 struct lpfc_dmabuf
*buf_ptr
;
3440 struct lpfc_iocbq
*iocb
;
3443 unsigned long flags
= 0;
3445 lpfc_hba_down_prep(phba
);
3447 lpfc_fabric_abort_hba(phba
);
3449 spin_lock_irqsave(&phba
->hbalock
, flags
);
3450 for (i
= 0; i
< psli
->num_rings
; i
++) {
3451 pring
= &psli
->ring
[i
];
3452 if (pring
->ringno
== LPFC_ELS_RING
) /* Only slow rings */
3453 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
3456 * Error everything on the txq since these iocbs have not been
3457 * given to the FW yet.
3459 list_splice_init(&pring
->txq
, &completions
);
3463 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
3465 while (!list_empty(&completions
)) {
3466 list_remove_head(&completions
, iocb
, struct lpfc_iocbq
, list
);
3469 if (!iocb
->iocb_cmpl
)
3470 lpfc_sli_release_iocbq(phba
, iocb
);
3472 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
3473 cmd
->un
.ulpWord
[4] = IOERR_SLI_DOWN
;
3474 (iocb
->iocb_cmpl
) (phba
, iocb
, iocb
);
3478 spin_lock_irqsave(&phba
->hbalock
, flags
);
3479 list_splice_init(&phba
->elsbuf
, &completions
);
3480 phba
->elsbuf_cnt
= 0;
3481 phba
->elsbuf_prev_cnt
= 0;
3482 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
3484 while (!list_empty(&completions
)) {
3485 list_remove_head(&completions
, buf_ptr
,
3486 struct lpfc_dmabuf
, list
);
3487 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
3491 /* Return any active mbox cmds */
3492 del_timer_sync(&psli
->mbox_tmo
);
3493 spin_lock_irqsave(&phba
->hbalock
, flags
);
3495 spin_lock(&phba
->pport
->work_port_lock
);
3496 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
3497 spin_unlock(&phba
->pport
->work_port_lock
);
3499 if (psli
->mbox_active
) {
3500 list_add_tail(&psli
->mbox_active
->list
, &completions
);
3501 psli
->mbox_active
= NULL
;
3502 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
3505 /* Return any pending or completed mbox cmds */
3506 list_splice_init(&phba
->sli
.mboxq
, &completions
);
3507 list_splice_init(&phba
->sli
.mboxq_cmpl
, &completions
);
3508 INIT_LIST_HEAD(&psli
->mboxq
);
3509 INIT_LIST_HEAD(&psli
->mboxq_cmpl
);
3511 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
3513 while (!list_empty(&completions
)) {
3514 list_remove_head(&completions
, pmb
, LPFC_MBOXQ_t
, list
);
3515 pmb
->mb
.mbxStatus
= MBX_NOT_FINISHED
;
3516 if (pmb
->mbox_cmpl
) {
3517 pmb
->mbox_cmpl(phba
,pmb
);
3524 lpfc_sli_pcimem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
3526 uint32_t *src
= srcp
;
3527 uint32_t *dest
= destp
;
3531 for (i
= 0; i
< (int)cnt
; i
+= sizeof (uint32_t)) {
3533 ldata
= le32_to_cpu(ldata
);
3541 lpfc_sli_ringpostbuf_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
3542 struct lpfc_dmabuf
*mp
)
3544 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
3546 spin_lock_irq(&phba
->hbalock
);
3547 list_add_tail(&mp
->list
, &pring
->postbufq
);
3548 pring
->postbufq_cnt
++;
3549 spin_unlock_irq(&phba
->hbalock
);
3554 lpfc_sli_get_buffer_tag(struct lpfc_hba
*phba
)
3556 spin_lock_irq(&phba
->hbalock
);
3557 phba
->buffer_tag_count
++;
3559 * Always set the QUE_BUFTAG_BIT to distiguish between
3560 * a tag assigned by HBQ.
3562 phba
->buffer_tag_count
|= QUE_BUFTAG_BIT
;
3563 spin_unlock_irq(&phba
->hbalock
);
3564 return phba
->buffer_tag_count
;
3567 struct lpfc_dmabuf
*
3568 lpfc_sli_ring_taggedbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
3571 struct lpfc_dmabuf
*mp
, *next_mp
;
3572 struct list_head
*slp
= &pring
->postbufq
;
3574 /* Search postbufq, from the begining, looking for a match on tag */
3575 spin_lock_irq(&phba
->hbalock
);
3576 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
3577 if (mp
->buffer_tag
== tag
) {
3578 list_del_init(&mp
->list
);
3579 pring
->postbufq_cnt
--;
3580 spin_unlock_irq(&phba
->hbalock
);
3585 spin_unlock_irq(&phba
->hbalock
);
3586 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3587 "0410 Cannot find virtual addr for buffer tag on "
3588 "ring %d Data x%lx x%p x%p x%x\n",
3589 pring
->ringno
, (unsigned long) tag
,
3590 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
3595 struct lpfc_dmabuf
*
3596 lpfc_sli_ringpostbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
3599 struct lpfc_dmabuf
*mp
, *next_mp
;
3600 struct list_head
*slp
= &pring
->postbufq
;
3602 /* Search postbufq, from the begining, looking for a match on phys */
3603 spin_lock_irq(&phba
->hbalock
);
3604 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
3605 if (mp
->phys
== phys
) {
3606 list_del_init(&mp
->list
);
3607 pring
->postbufq_cnt
--;
3608 spin_unlock_irq(&phba
->hbalock
);
3613 spin_unlock_irq(&phba
->hbalock
);
3614 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3615 "0410 Cannot find virtual addr for mapped buf on "
3616 "ring %d Data x%llx x%p x%p x%x\n",
3617 pring
->ringno
, (unsigned long long)phys
,
3618 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
3623 lpfc_sli_abort_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
3624 struct lpfc_iocbq
*rspiocb
)
3626 IOCB_t
*irsp
= &rspiocb
->iocb
;
3627 uint16_t abort_iotag
, abort_context
;
3628 struct lpfc_iocbq
*abort_iocb
;
3629 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
3633 if (irsp
->ulpStatus
) {
3634 abort_context
= cmdiocb
->iocb
.un
.acxri
.abortContextTag
;
3635 abort_iotag
= cmdiocb
->iocb
.un
.acxri
.abortIoTag
;
3637 spin_lock_irq(&phba
->hbalock
);
3638 if (abort_iotag
!= 0 && abort_iotag
<= phba
->sli
.last_iotag
)
3639 abort_iocb
= phba
->sli
.iocbq_lookup
[abort_iotag
];
3641 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
| LOG_SLI
,
3642 "0327 Cannot abort els iocb %p "
3643 "with tag %x context %x, abort status %x, "
3645 abort_iocb
, abort_iotag
, abort_context
,
3646 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
3649 * make sure we have the right iocbq before taking it
3650 * off the txcmplq and try to call completion routine.
3653 abort_iocb
->iocb
.ulpContext
!= abort_context
||
3654 (abort_iocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) == 0)
3655 spin_unlock_irq(&phba
->hbalock
);
3657 list_del_init(&abort_iocb
->list
);
3658 pring
->txcmplq_cnt
--;
3659 spin_unlock_irq(&phba
->hbalock
);
3661 /* Firmware could still be in progress of DMAing
3662 * payload, so don't free data buffer till after
3665 abort_iocb
->iocb_flag
|= LPFC_DELAY_MEM_FREE
;
3667 abort_iocb
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
3668 abort_iocb
->iocb
.ulpStatus
= IOSTAT_LOCAL_REJECT
;
3669 abort_iocb
->iocb
.un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
3670 (abort_iocb
->iocb_cmpl
)(phba
, abort_iocb
, abort_iocb
);
3674 lpfc_sli_release_iocbq(phba
, cmdiocb
);
3679 lpfc_ignore_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
3680 struct lpfc_iocbq
*rspiocb
)
3682 IOCB_t
*irsp
= &rspiocb
->iocb
;
3684 /* ELS cmd tag <ulpIoTag> completes */
3685 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
3686 "0133 Ignoring ELS cmd tag x%x completion Data: "
3688 irsp
->ulpIoTag
, irsp
->ulpStatus
,
3689 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
);
3690 if (cmdiocb
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
)
3691 lpfc_ct_free_iocb(phba
, cmdiocb
);
3693 lpfc_els_free_iocb(phba
, cmdiocb
);
3698 lpfc_sli_issue_abort_iotag(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
3699 struct lpfc_iocbq
*cmdiocb
)
3701 struct lpfc_vport
*vport
= cmdiocb
->vport
;
3702 struct lpfc_iocbq
*abtsiocbp
;
3703 IOCB_t
*icmd
= NULL
;
3704 IOCB_t
*iabt
= NULL
;
3705 int retval
= IOCB_ERROR
;
3708 * There are certain command types we don't want to abort. And we
3709 * don't want to abort commands that are already in the process of
3712 icmd
= &cmdiocb
->iocb
;
3713 if (icmd
->ulpCommand
== CMD_ABORT_XRI_CN
||
3714 icmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
3715 (cmdiocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) != 0)
3718 /* If we're unloading, don't abort iocb on the ELS ring, but change the
3719 * callback so that nothing happens when it finishes.
3721 if ((vport
->load_flag
& FC_UNLOADING
) &&
3722 (pring
->ringno
== LPFC_ELS_RING
)) {
3723 if (cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
)
3724 cmdiocb
->fabric_iocb_cmpl
= lpfc_ignore_els_cmpl
;
3726 cmdiocb
->iocb_cmpl
= lpfc_ignore_els_cmpl
;
3727 goto abort_iotag_exit
;
3730 /* issue ABTS for this IOCB based on iotag */
3731 abtsiocbp
= __lpfc_sli_get_iocbq(phba
);
3732 if (abtsiocbp
== NULL
)
3735 /* This signals the response to set the correct status
3736 * before calling the completion handler.
3738 cmdiocb
->iocb_flag
|= LPFC_DRIVER_ABORTED
;
3740 iabt
= &abtsiocbp
->iocb
;
3741 iabt
->un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
3742 iabt
->un
.acxri
.abortContextTag
= icmd
->ulpContext
;
3743 iabt
->un
.acxri
.abortIoTag
= icmd
->ulpIoTag
;
3745 iabt
->ulpClass
= icmd
->ulpClass
;
3747 if (phba
->link_state
>= LPFC_LINK_UP
)
3748 iabt
->ulpCommand
= CMD_ABORT_XRI_CN
;
3750 iabt
->ulpCommand
= CMD_CLOSE_XRI_CN
;
3752 abtsiocbp
->iocb_cmpl
= lpfc_sli_abort_els_cmpl
;
3754 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
3755 "0339 Abort xri x%x, original iotag x%x, "
3756 "abort cmd iotag x%x\n",
3757 iabt
->un
.acxri
.abortContextTag
,
3758 iabt
->un
.acxri
.abortIoTag
, abtsiocbp
->iotag
);
3759 retval
= __lpfc_sli_issue_iocb(phba
, pring
, abtsiocbp
, 0);
3763 * Caller to this routine should check for IOCB_ERROR
3764 * and handle it properly. This routine no longer removes
3765 * iocb off txcmplq and call compl in case of IOCB_ERROR.
3771 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq
*iocbq
, struct lpfc_vport
*vport
,
3772 uint16_t tgt_id
, uint64_t lun_id
,
3773 lpfc_ctx_cmd ctx_cmd
)
3775 struct lpfc_scsi_buf
*lpfc_cmd
;
3776 struct scsi_cmnd
*cmnd
;
3779 if (!(iocbq
->iocb_flag
& LPFC_IO_FCP
))
3782 if (iocbq
->vport
!= vport
)
3785 lpfc_cmd
= container_of(iocbq
, struct lpfc_scsi_buf
, cur_iocbq
);
3786 cmnd
= lpfc_cmd
->pCmd
;
3793 if ((cmnd
->device
->id
== tgt_id
) &&
3794 (cmnd
->device
->lun
== lun_id
))
3798 if (cmnd
->device
->id
== tgt_id
)
3805 printk(KERN_ERR
"%s: Unknown context cmd type, value %d\n",
3806 __FUNCTION__
, ctx_cmd
);
3814 lpfc_sli_sum_iocb(struct lpfc_vport
*vport
, uint16_t tgt_id
, uint64_t lun_id
,
3815 lpfc_ctx_cmd ctx_cmd
)
3817 struct lpfc_hba
*phba
= vport
->phba
;
3818 struct lpfc_iocbq
*iocbq
;
3821 for (i
= 1, sum
= 0; i
<= phba
->sli
.last_iotag
; i
++) {
3822 iocbq
= phba
->sli
.iocbq_lookup
[i
];
3824 if (lpfc_sli_validate_fcp_iocb (iocbq
, vport
, tgt_id
, lun_id
,
3833 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
3834 struct lpfc_iocbq
*rspiocb
)
3836 lpfc_sli_release_iocbq(phba
, cmdiocb
);
3841 lpfc_sli_abort_iocb(struct lpfc_vport
*vport
, struct lpfc_sli_ring
*pring
,
3842 uint16_t tgt_id
, uint64_t lun_id
, lpfc_ctx_cmd abort_cmd
)
3844 struct lpfc_hba
*phba
= vport
->phba
;
3845 struct lpfc_iocbq
*iocbq
;
3846 struct lpfc_iocbq
*abtsiocb
;
3848 int errcnt
= 0, ret_val
= 0;
3851 for (i
= 1; i
<= phba
->sli
.last_iotag
; i
++) {
3852 iocbq
= phba
->sli
.iocbq_lookup
[i
];
3854 if (lpfc_sli_validate_fcp_iocb(iocbq
, vport
, tgt_id
, lun_id
,
3858 /* issue ABTS for this IOCB based on iotag */
3859 abtsiocb
= lpfc_sli_get_iocbq(phba
);
3860 if (abtsiocb
== NULL
) {
3866 abtsiocb
->iocb
.un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
3867 abtsiocb
->iocb
.un
.acxri
.abortContextTag
= cmd
->ulpContext
;
3868 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= cmd
->ulpIoTag
;
3869 abtsiocb
->iocb
.ulpLe
= 1;
3870 abtsiocb
->iocb
.ulpClass
= cmd
->ulpClass
;
3871 abtsiocb
->vport
= phba
->pport
;
3873 if (lpfc_is_link_up(phba
))
3874 abtsiocb
->iocb
.ulpCommand
= CMD_ABORT_XRI_CN
;
3876 abtsiocb
->iocb
.ulpCommand
= CMD_CLOSE_XRI_CN
;
3878 /* Setup callback routine and issue the command. */
3879 abtsiocb
->iocb_cmpl
= lpfc_sli_abort_fcp_cmpl
;
3880 ret_val
= lpfc_sli_issue_iocb(phba
, pring
, abtsiocb
, 0);
3881 if (ret_val
== IOCB_ERROR
) {
3882 lpfc_sli_release_iocbq(phba
, abtsiocb
);
3892 lpfc_sli_wake_iocb_wait(struct lpfc_hba
*phba
,
3893 struct lpfc_iocbq
*cmdiocbq
,
3894 struct lpfc_iocbq
*rspiocbq
)
3896 wait_queue_head_t
*pdone_q
;
3897 unsigned long iflags
;
3899 spin_lock_irqsave(&phba
->hbalock
, iflags
);
3900 cmdiocbq
->iocb_flag
|= LPFC_IO_WAKE
;
3901 if (cmdiocbq
->context2
&& rspiocbq
)
3902 memcpy(&((struct lpfc_iocbq
*)cmdiocbq
->context2
)->iocb
,
3903 &rspiocbq
->iocb
, sizeof(IOCB_t
));
3905 pdone_q
= cmdiocbq
->context_un
.wait_queue
;
3908 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
3913 * Issue the caller's iocb and wait for its completion, but no longer than the
3914 * caller's timeout. Note that iocb_flags is cleared before the
3915 * lpfc_sli_issue_call since the wake routine sets a unique value and by
3916 * definition this is a wait function.
3920 lpfc_sli_issue_iocb_wait(struct lpfc_hba
*phba
,
3921 struct lpfc_sli_ring
*pring
,
3922 struct lpfc_iocbq
*piocb
,
3923 struct lpfc_iocbq
*prspiocbq
,
3926 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
3927 long timeleft
, timeout_req
= 0;
3928 int retval
= IOCB_SUCCESS
;
3932 * If the caller has provided a response iocbq buffer, then context2
3933 * is NULL or its an error.
3936 if (piocb
->context2
)
3938 piocb
->context2
= prspiocbq
;
3941 piocb
->iocb_cmpl
= lpfc_sli_wake_iocb_wait
;
3942 piocb
->context_un
.wait_queue
= &done_q
;
3943 piocb
->iocb_flag
&= ~LPFC_IO_WAKE
;
3945 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
3946 creg_val
= readl(phba
->HCregaddr
);
3947 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
3948 writel(creg_val
, phba
->HCregaddr
);
3949 readl(phba
->HCregaddr
); /* flush */
3952 retval
= lpfc_sli_issue_iocb(phba
, pring
, piocb
, 0);
3953 if (retval
== IOCB_SUCCESS
) {
3954 timeout_req
= timeout
* HZ
;
3955 timeleft
= wait_event_timeout(done_q
,
3956 piocb
->iocb_flag
& LPFC_IO_WAKE
,
3959 if (piocb
->iocb_flag
& LPFC_IO_WAKE
) {
3960 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3961 "0331 IOCB wake signaled\n");
3962 } else if (timeleft
== 0) {
3963 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3964 "0338 IOCB wait timeout error - no "
3965 "wake response Data x%x\n", timeout
);
3966 retval
= IOCB_TIMEDOUT
;
3968 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3969 "0330 IOCB wake NOT set, "
3971 timeout
, (timeleft
/ jiffies
));
3972 retval
= IOCB_TIMEDOUT
;
3975 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3976 ":0332 IOCB wait issue failed, Data x%x\n",
3978 retval
= IOCB_ERROR
;
3981 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
3982 creg_val
= readl(phba
->HCregaddr
);
3983 creg_val
&= ~(HC_R0INT_ENA
<< LPFC_FCP_RING
);
3984 writel(creg_val
, phba
->HCregaddr
);
3985 readl(phba
->HCregaddr
); /* flush */
3989 piocb
->context2
= NULL
;
3991 piocb
->context_un
.wait_queue
= NULL
;
3992 piocb
->iocb_cmpl
= NULL
;
3997 lpfc_sli_issue_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
,
4000 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
4004 /* The caller must leave context1 empty. */
4005 if (pmboxq
->context1
)
4006 return MBX_NOT_FINISHED
;
4008 /* setup wake call as IOCB callback */
4009 pmboxq
->mbox_cmpl
= lpfc_sli_wake_mbox_wait
;
4010 /* setup context field to pass wait_queue pointer to wake function */
4011 pmboxq
->context1
= &done_q
;
4013 /* now issue the command */
4014 retval
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
4016 if (retval
== MBX_BUSY
|| retval
== MBX_SUCCESS
) {
4017 wait_event_interruptible_timeout(done_q
,
4018 pmboxq
->mbox_flag
& LPFC_MBX_WAKE
,
4021 spin_lock_irqsave(&phba
->hbalock
, flag
);
4022 pmboxq
->context1
= NULL
;
4024 * if LPFC_MBX_WAKE flag is set the mailbox is completed
4025 * else do not free the resources.
4027 if (pmboxq
->mbox_flag
& LPFC_MBX_WAKE
)
4028 retval
= MBX_SUCCESS
;
4030 retval
= MBX_TIMEOUT
;
4031 pmboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
4033 spin_unlock_irqrestore(&phba
->hbalock
, flag
);
4040 lpfc_sli_flush_mbox_queue(struct lpfc_hba
* phba
)
4042 struct lpfc_vport
*vport
= phba
->pport
;
4046 while (phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
&& !vport
->stopped
) {
4047 if (i
++ > LPFC_MBOX_TMO
* 1000)
4051 * Call lpfc_sli_handle_mb_event only if a mailbox cmd
4052 * did finish. This way we won't get the misleading
4053 * "Stray Mailbox Interrupt" message.
4055 spin_lock_irq(&phba
->hbalock
);
4056 ha_copy
= phba
->work_ha
;
4057 phba
->work_ha
&= ~HA_MBATT
;
4058 spin_unlock_irq(&phba
->hbalock
);
4060 if (ha_copy
& HA_MBATT
)
4061 if (lpfc_sli_handle_mb_event(phba
) == 0)
4067 return (phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
) ? 1 : 0;
4071 lpfc_intr_handler(int irq
, void *dev_id
)
4073 struct lpfc_hba
*phba
;
4075 uint32_t work_ha_copy
;
4076 unsigned long status
;
4079 MAILBOX_t
*mbox
, *pmbox
;
4080 struct lpfc_vport
*vport
;
4081 struct lpfc_nodelist
*ndlp
;
4082 struct lpfc_dmabuf
*mp
;
4087 * Get the driver's phba structure from the dev_id and
4088 * assume the HBA is not interrupting.
4090 phba
= (struct lpfc_hba
*) dev_id
;
4092 if (unlikely(!phba
))
4095 /* If the pci channel is offline, ignore all the interrupts. */
4096 if (unlikely(pci_channel_offline(phba
->pcidev
)))
4099 phba
->sli
.slistat
.sli_intr
++;
4102 * Call the HBA to see if it is interrupting. If not, don't claim
4106 /* Ignore all interrupts during initialization. */
4107 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
4111 * Read host attention register to determine interrupt source
4112 * Clear Attention Sources, except Error Attention (to
4113 * preserve status) and Link Attention
4115 spin_lock(&phba
->hbalock
);
4116 ha_copy
= readl(phba
->HAregaddr
);
4117 /* If somebody is waiting to handle an eratt don't process it
4118 * here. The brdkill function will do this.
4120 if (phba
->link_flag
& LS_IGNORE_ERATT
)
4121 ha_copy
&= ~HA_ERATT
;
4122 writel((ha_copy
& ~(HA_LATT
| HA_ERATT
)), phba
->HAregaddr
);
4123 readl(phba
->HAregaddr
); /* flush */
4124 spin_unlock(&phba
->hbalock
);
4126 if (unlikely(!ha_copy
))
4129 work_ha_copy
= ha_copy
& phba
->work_ha_mask
;
4131 if (unlikely(work_ha_copy
)) {
4132 if (work_ha_copy
& HA_LATT
) {
4133 if (phba
->sli
.sli_flag
& LPFC_PROCESS_LA
) {
4135 * Turn off Link Attention interrupts
4136 * until CLEAR_LA done
4138 spin_lock(&phba
->hbalock
);
4139 phba
->sli
.sli_flag
&= ~LPFC_PROCESS_LA
;
4140 control
= readl(phba
->HCregaddr
);
4141 control
&= ~HC_LAINT_ENA
;
4142 writel(control
, phba
->HCregaddr
);
4143 readl(phba
->HCregaddr
); /* flush */
4144 spin_unlock(&phba
->hbalock
);
4147 work_ha_copy
&= ~HA_LATT
;
4150 if (work_ha_copy
& ~(HA_ERATT
|HA_MBATT
|HA_LATT
)) {
4152 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
4153 * the only slow ring.
4155 status
= (work_ha_copy
&
4156 (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
4157 status
>>= (4*LPFC_ELS_RING
);
4158 if (status
& HA_RXMASK
) {
4159 spin_lock(&phba
->hbalock
);
4160 control
= readl(phba
->HCregaddr
);
4162 lpfc_debugfs_slow_ring_trc(phba
,
4163 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
4165 (uint32_t)phba
->sli
.slistat
.sli_intr
);
4167 if (control
& (HC_R0INT_ENA
<< LPFC_ELS_RING
)) {
4168 lpfc_debugfs_slow_ring_trc(phba
,
4170 "pwork:x%x hawork:x%x wait:x%x",
4171 phba
->work_ha
, work_ha_copy
,
4172 (uint32_t)((unsigned long)
4176 ~(HC_R0INT_ENA
<< LPFC_ELS_RING
);
4177 writel(control
, phba
->HCregaddr
);
4178 readl(phba
->HCregaddr
); /* flush */
4181 lpfc_debugfs_slow_ring_trc(phba
,
4182 "ISR slow ring: pwork:"
4183 "x%x hawork:x%x wait:x%x",
4184 phba
->work_ha
, work_ha_copy
,
4185 (uint32_t)((unsigned long)
4188 spin_unlock(&phba
->hbalock
);
4192 if (work_ha_copy
& HA_ERATT
) {
4194 * There was a link/board error. Read the
4195 * status register to retrieve the error event
4198 phba
->sli
.slistat
.err_attn_event
++;
4199 /* Save status info */
4200 phba
->work_hs
= readl(phba
->HSregaddr
);
4201 phba
->work_status
[0] = readl(phba
->MBslimaddr
+ 0xa8);
4202 phba
->work_status
[1] = readl(phba
->MBslimaddr
+ 0xac);
4204 /* Clear Chip error bit */
4205 writel(HA_ERATT
, phba
->HAregaddr
);
4206 readl(phba
->HAregaddr
); /* flush */
4207 phba
->pport
->stopped
= 1;
4210 if ((work_ha_copy
& HA_MBATT
) &&
4211 (phba
->sli
.mbox_active
)) {
4212 pmb
= phba
->sli
.mbox_active
;
4214 mbox
= &phba
->slim2p
->mbx
;
4217 /* First check out the status word */
4218 lpfc_sli_pcimem_bcopy(mbox
, pmbox
, sizeof(uint32_t));
4219 if (pmbox
->mbxOwner
!= OWN_HOST
) {
4221 * Stray Mailbox Interrupt, mbxCommand <cmd>
4222 * mbxStatus <status>
4224 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
4226 "(%d):0304 Stray Mailbox "
4227 "Interrupt mbxCommand x%x "
4229 (vport
? vport
->vpi
: 0),
4232 /* clear mailbox attention bit */
4233 work_ha_copy
&= ~HA_MBATT
;
4235 phba
->last_completion_time
= jiffies
;
4236 del_timer(&phba
->sli
.mbox_tmo
);
4238 phba
->sli
.mbox_active
= NULL
;
4239 if (pmb
->mbox_cmpl
) {
4240 lpfc_sli_pcimem_bcopy(mbox
, pmbox
,
4243 if (pmb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) {
4244 pmb
->mbox_flag
&= ~LPFC_MBX_IMED_UNREG
;
4246 lpfc_debugfs_disc_trc(vport
,
4247 LPFC_DISC_TRC_MBOX_VPORT
,
4249 "status:x%x rpi:x%x",
4250 (uint32_t)pmbox
->mbxStatus
,
4251 pmbox
->un
.varWords
[0], 0);
4253 if (!pmbox
->mbxStatus
) {
4254 mp
= (struct lpfc_dmabuf
*)
4256 ndlp
= (struct lpfc_nodelist
*)
4259 /* Reg_LOGIN of dflt RPI was
4260 * successful. new lets get
4261 * rid of the RPI using the
4264 lpfc_unreg_login(phba
,
4266 pmbox
->un
.varWords
[0],
4269 lpfc_mbx_cmpl_dflt_rpi
;
4271 pmb
->context2
= ndlp
;
4273 spin_lock(&phba
->hbalock
);
4274 phba
->sli
.sli_flag
&=
4275 ~LPFC_SLI_MBOX_ACTIVE
;
4276 spin_unlock(&phba
->hbalock
);
4277 goto send_current_mbox
;
4280 spin_lock(&phba
->pport
->work_port_lock
);
4281 phba
->pport
->work_port_events
&=
4283 spin_unlock(&phba
->pport
->work_port_lock
);
4284 lpfc_mbox_cmpl_put(phba
, pmb
);
4287 if ((work_ha_copy
& HA_MBATT
) &&
4288 (phba
->sli
.mbox_active
== NULL
)) {
4290 spin_lock(&phba
->hbalock
);
4291 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
4292 pmb
= lpfc_mbox_get(phba
);
4293 spin_unlock(&phba
->hbalock
);
4295 /* Process next mailbox command if there is one */
4297 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
4298 if (rc
== MBX_NOT_FINISHED
) {
4299 pmb
->mb
.mbxStatus
= MBX_NOT_FINISHED
;
4300 lpfc_mbox_cmpl_put(phba
, pmb
);
4301 goto send_next_mbox
;
4307 spin_lock(&phba
->hbalock
);
4308 phba
->work_ha
|= work_ha_copy
;
4309 if (phba
->work_wait
)
4310 lpfc_worker_wake_up(phba
);
4311 spin_unlock(&phba
->hbalock
);
4314 ha_copy
&= ~(phba
->work_ha_mask
);
4317 * Process all events on FCP ring. Take the optimized path for
4318 * FCP IO. Any other IO is slow path and is handled by
4319 * the worker thread.
4321 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
4322 status
>>= (4*LPFC_FCP_RING
);
4323 if (status
& HA_RXMASK
)
4324 lpfc_sli_handle_fast_ring_event(phba
,
4325 &phba
->sli
.ring
[LPFC_FCP_RING
],
4328 if (phba
->cfg_multi_ring_support
== 2) {
4330 * Process all events on extra ring. Take the optimized path
4331 * for extra ring IO. Any other IO is slow path and is handled
4332 * by the worker thread.
4334 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
4335 status
>>= (4*LPFC_EXTRA_RING
);
4336 if (status
& HA_RXMASK
) {
4337 lpfc_sli_handle_fast_ring_event(phba
,
4338 &phba
->sli
.ring
[LPFC_EXTRA_RING
],
4344 } /* lpfc_intr_handler */