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>
36 #include "lpfc_disc.h"
37 #include "lpfc_scsi.h"
39 #include "lpfc_crtn.h"
40 #include "lpfc_logmsg.h"
41 #include "lpfc_compat.h"
42 #include "lpfc_debugfs.h"
45 * Define macro to log: Mailbox command x%x cannot issue Data
46 * This allows multiple uses of lpfc_msgBlk0311
47 * w/o perturbing log msg utility.
49 #define LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag) \
50 lpfc_printf_log(phba, \
53 "(%d):0311 Mailbox command x%x cannot " \
54 "issue Data: x%x x%x x%x\n", \
55 pmbox->vport ? pmbox->vport->vpi : 0, \
56 pmbox->mb.mbxCommand, \
57 phba->pport->port_state, \
62 /* There are only four IOCB completion types. */
63 typedef enum _lpfc_iocb_type {
71 * lpfc_cmd_iocb: Get next command iocb entry in the ring.
72 * @phba: Pointer to HBA context object.
73 * @pring: Pointer to driver SLI ring object.
75 * This function returns pointer to next command iocb entry
76 * in the command ring. The caller must hold hbalock to prevent
77 * other threads consume the next command iocb.
78 * SLI-2/SLI-3 provide different sized iocbs.
80 static inline IOCB_t *
81 lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
83 return (IOCB_t *) (((char *) pring->cmdringaddr) +
84 pring->cmdidx * phba->iocb_cmd_size);
88 * lpfc_resp_iocb: Get next response iocb entry in the ring.
89 * @phba: Pointer to HBA context object.
90 * @pring: Pointer to driver SLI ring object.
92 * This function returns pointer to next response iocb entry
93 * in the response ring. The caller must hold hbalock to make sure
94 * that no other thread consume the next response iocb.
95 * SLI-2/SLI-3 provide different sized iocbs.
97 static inline IOCB_t *
98 lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
100 return (IOCB_t *) (((char *) pring->rspringaddr) +
101 pring->rspidx * phba->iocb_rsp_size);
105 * __lpfc_sli_get_iocbq: Allocates an iocb object from iocb pool.
106 * @phba: Pointer to HBA context object.
108 * This function is called with hbalock held. This function
109 * allocates a new driver iocb object from the iocb pool. If the
110 * allocation is successful, it returns pointer to the newly
111 * allocated iocb object else it returns NULL.
113 static struct lpfc_iocbq *
114 __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
116 struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
117 struct lpfc_iocbq * iocbq = NULL;
119 list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
124 * lpfc_sli_get_iocbq: Allocates an iocb object from iocb pool.
125 * @phba: Pointer to HBA context object.
127 * This function is called with no lock held. This function
128 * allocates a new driver iocb object from the iocb pool. If the
129 * allocation is successful, it returns pointer to the newly
130 * allocated iocb object else it returns NULL.
133 lpfc_sli_get_iocbq(struct lpfc_hba *phba)
135 struct lpfc_iocbq * iocbq = NULL;
136 unsigned long iflags;
138 spin_lock_irqsave(&phba->hbalock, iflags);
139 iocbq = __lpfc_sli_get_iocbq(phba);
140 spin_unlock_irqrestore(&phba->hbalock, iflags);
145 * __lpfc_sli_release_iocbq: Release iocb to the iocb pool.
146 * @phba: Pointer to HBA context object.
147 * @iocbq: Pointer to driver iocb object.
149 * This function is called with hbalock held to release driver
150 * iocb object to the iocb pool. The iotag in the iocb object
151 * does not change for each use of the iocb object. This function
152 * clears all other fields of the iocb object when it is freed.
155 __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
157 size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
160 * Clean all volatile data fields, preserve iotag and node struct.
162 memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
163 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
167 * lpfc_sli_release_iocbq: Release iocb to the iocb pool.
168 * @phba: Pointer to HBA context object.
169 * @iocbq: Pointer to driver iocb object.
171 * This function is called with no lock held to release the iocb to
175 lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
177 unsigned long iflags;
180 * Clean all volatile data fields, preserve iotag and node struct.
182 spin_lock_irqsave(&phba->hbalock, iflags);
183 __lpfc_sli_release_iocbq(phba, iocbq);
184 spin_unlock_irqrestore(&phba->hbalock, iflags);
188 * lpfc_sli_iocb_cmd_type: Get the iocb type.
189 * @iocb_cmnd : iocb command code.
191 * This function is called by ring event handler function to get the iocb type.
192 * This function translates the iocb command to an iocb command type used to
193 * decide the final disposition of each completed IOCB.
194 * The function returns
195 * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
196 * LPFC_SOL_IOCB if it is a solicited iocb completion
197 * LPFC_ABORT_IOCB if it is an abort iocb
198 * LPFC_UNSOL_IOCB if it is an unsolicited iocb
200 * The caller is not required to hold any lock.
202 static lpfc_iocb_type
203 lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
205 lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
207 if (iocb_cmnd > CMD_MAX_IOCB_CMD)
211 case CMD_XMIT_SEQUENCE_CR:
212 case CMD_XMIT_SEQUENCE_CX:
213 case CMD_XMIT_BCAST_CN:
214 case CMD_XMIT_BCAST_CX:
215 case CMD_ELS_REQUEST_CR:
216 case CMD_ELS_REQUEST_CX:
217 case CMD_CREATE_XRI_CR:
218 case CMD_CREATE_XRI_CX:
220 case CMD_XMIT_ELS_RSP_CX:
222 case CMD_FCP_IWRITE_CR:
223 case CMD_FCP_IWRITE_CX:
224 case CMD_FCP_IREAD_CR:
225 case CMD_FCP_IREAD_CX:
226 case CMD_FCP_ICMND_CR:
227 case CMD_FCP_ICMND_CX:
228 case CMD_FCP_TSEND_CX:
229 case CMD_FCP_TRSP_CX:
230 case CMD_FCP_TRECEIVE_CX:
231 case CMD_FCP_AUTO_TRSP_CX:
232 case CMD_ADAPTER_MSG:
233 case CMD_ADAPTER_DUMP:
234 case CMD_XMIT_SEQUENCE64_CR:
235 case CMD_XMIT_SEQUENCE64_CX:
236 case CMD_XMIT_BCAST64_CN:
237 case CMD_XMIT_BCAST64_CX:
238 case CMD_ELS_REQUEST64_CR:
239 case CMD_ELS_REQUEST64_CX:
240 case CMD_FCP_IWRITE64_CR:
241 case CMD_FCP_IWRITE64_CX:
242 case CMD_FCP_IREAD64_CR:
243 case CMD_FCP_IREAD64_CX:
244 case CMD_FCP_ICMND64_CR:
245 case CMD_FCP_ICMND64_CX:
246 case CMD_FCP_TSEND64_CX:
247 case CMD_FCP_TRSP64_CX:
248 case CMD_FCP_TRECEIVE64_CX:
249 case CMD_GEN_REQUEST64_CR:
250 case CMD_GEN_REQUEST64_CX:
251 case CMD_XMIT_ELS_RSP64_CX:
252 type = LPFC_SOL_IOCB;
254 case CMD_ABORT_XRI_CN:
255 case CMD_ABORT_XRI_CX:
256 case CMD_CLOSE_XRI_CN:
257 case CMD_CLOSE_XRI_CX:
258 case CMD_XRI_ABORTED_CX:
259 case CMD_ABORT_MXRI64_CN:
260 type = LPFC_ABORT_IOCB;
262 case CMD_RCV_SEQUENCE_CX:
263 case CMD_RCV_ELS_REQ_CX:
264 case CMD_RCV_SEQUENCE64_CX:
265 case CMD_RCV_ELS_REQ64_CX:
266 case CMD_ASYNC_STATUS:
267 case CMD_IOCB_RCV_SEQ64_CX:
268 case CMD_IOCB_RCV_ELS64_CX:
269 case CMD_IOCB_RCV_CONT64_CX:
270 case CMD_IOCB_RET_XRI64_CX:
271 type = LPFC_UNSOL_IOCB;
273 case CMD_IOCB_XMIT_MSEQ64_CR:
274 case CMD_IOCB_XMIT_MSEQ64_CX:
275 case CMD_IOCB_RCV_SEQ_LIST64_CX:
276 case CMD_IOCB_RCV_ELS_LIST64_CX:
277 case CMD_IOCB_CLOSE_EXTENDED_CN:
278 case CMD_IOCB_ABORT_EXTENDED_CN:
279 case CMD_IOCB_RET_HBQE64_CN:
280 case CMD_IOCB_FCP_IBIDIR64_CR:
281 case CMD_IOCB_FCP_IBIDIR64_CX:
282 case CMD_IOCB_FCP_ITASKMGT64_CX:
283 case CMD_IOCB_LOGENTRY_CN:
284 case CMD_IOCB_LOGENTRY_ASYNC_CN:
285 printk("%s - Unhandled SLI-3 Command x%x\n",
286 __func__, iocb_cmnd);
287 type = LPFC_UNKNOWN_IOCB;
290 type = LPFC_UNKNOWN_IOCB;
298 * lpfc_sli_ring_map: Issue config_ring mbox for all rings.
299 * @phba: Pointer to HBA context object.
301 * This function is called from SLI initialization code
302 * to configure every ring of the HBA's SLI interface. The
303 * caller is not required to hold any lock. This function issues
304 * a config_ring mailbox command for each ring.
305 * This function returns zero if successful else returns a negative
309 lpfc_sli_ring_map(struct lpfc_hba *phba)
311 struct lpfc_sli *psli = &phba->sli;
316 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
320 phba->link_state = LPFC_INIT_MBX_CMDS;
321 for (i = 0; i < psli->num_rings; i++) {
322 lpfc_config_ring(phba, i, pmb);
323 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
324 if (rc != MBX_SUCCESS) {
325 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
326 "0446 Adapter failed to init (%d), "
327 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
329 rc, pmbox->mbxCommand,
330 pmbox->mbxStatus, i);
331 phba->link_state = LPFC_HBA_ERROR;
336 mempool_free(pmb, phba->mbox_mem_pool);
341 * lpfc_sli_ringtxcmpl_put: Adds new iocb to the txcmplq.
342 * @phba: Pointer to HBA context object.
343 * @pring: Pointer to driver SLI ring object.
344 * @piocb: Pointer to the driver iocb object.
346 * This function is called with hbalock held. The function adds the
347 * new iocb to txcmplq of the given ring. This function always returns
348 * 0. If this function is called for ELS ring, this function checks if
349 * there is a vport associated with the ELS command. This function also
350 * starts els_tmofunc timer if this is an ELS command.
353 lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
354 struct lpfc_iocbq *piocb)
356 list_add_tail(&piocb->list, &pring->txcmplq);
357 pring->txcmplq_cnt++;
358 if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
359 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
360 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
364 mod_timer(&piocb->vport->els_tmofunc,
365 jiffies + HZ * (phba->fc_ratov << 1));
373 * lpfc_sli_ringtx_get: Get first element of the txq.
374 * @phba: Pointer to HBA context object.
375 * @pring: Pointer to driver SLI ring object.
377 * This function is called with hbalock held to get next
378 * iocb in txq of the given ring. If there is any iocb in
379 * the txq, the function returns first iocb in the list after
380 * removing the iocb from the list, else it returns NULL.
382 static struct lpfc_iocbq *
383 lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
385 struct lpfc_iocbq *cmd_iocb;
387 list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
388 if (cmd_iocb != NULL)
394 * lpfc_sli_next_iocb_slot: Get next iocb slot in the ring.
395 * @phba: Pointer to HBA context object.
396 * @pring: Pointer to driver SLI ring object.
398 * This function is called with hbalock held and the caller must post the
399 * iocb without releasing the lock. If the caller releases the lock,
400 * iocb slot returned by the function is not guaranteed to be available.
401 * The function returns pointer to the next available iocb slot if there
402 * is available slot in the ring, else it returns NULL.
403 * If the get index of the ring is ahead of the put index, the function
404 * will post an error attention event to the worker thread to take the
405 * HBA to offline state.
408 lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
410 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
411 uint32_t max_cmd_idx = pring->numCiocb;
412 if ((pring->next_cmdidx == pring->cmdidx) &&
413 (++pring->next_cmdidx >= max_cmd_idx))
414 pring->next_cmdidx = 0;
416 if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
418 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
420 if (unlikely(pring->local_getidx >= max_cmd_idx)) {
421 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
422 "0315 Ring %d issue: portCmdGet %d "
423 "is bigger than cmd ring %d\n",
425 pring->local_getidx, max_cmd_idx);
427 phba->link_state = LPFC_HBA_ERROR;
429 * All error attention handlers are posted to
432 phba->work_ha |= HA_ERATT;
433 phba->work_hs = HS_FFER3;
435 lpfc_worker_wake_up(phba);
440 if (pring->local_getidx == pring->next_cmdidx)
444 return lpfc_cmd_iocb(phba, pring);
448 * lpfc_sli_next_iotag: Get an iotag for the iocb.
449 * @phba: Pointer to HBA context object.
450 * @iocbq: Pointer to driver iocb object.
452 * This function gets an iotag for the iocb. If there is no unused iotag and
453 * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
454 * array and assigns a new iotag.
455 * The function returns the allocated iotag if successful, else returns zero.
456 * Zero is not a valid iotag.
457 * The caller is not required to hold any lock.
460 lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
462 struct lpfc_iocbq **new_arr;
463 struct lpfc_iocbq **old_arr;
465 struct lpfc_sli *psli = &phba->sli;
468 spin_lock_irq(&phba->hbalock);
469 iotag = psli->last_iotag;
470 if(++iotag < psli->iocbq_lookup_len) {
471 psli->last_iotag = iotag;
472 psli->iocbq_lookup[iotag] = iocbq;
473 spin_unlock_irq(&phba->hbalock);
474 iocbq->iotag = iotag;
476 } else if (psli->iocbq_lookup_len < (0xffff
477 - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
478 new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
479 spin_unlock_irq(&phba->hbalock);
480 new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
483 spin_lock_irq(&phba->hbalock);
484 old_arr = psli->iocbq_lookup;
485 if (new_len <= psli->iocbq_lookup_len) {
486 /* highly unprobable case */
488 iotag = psli->last_iotag;
489 if(++iotag < psli->iocbq_lookup_len) {
490 psli->last_iotag = iotag;
491 psli->iocbq_lookup[iotag] = iocbq;
492 spin_unlock_irq(&phba->hbalock);
493 iocbq->iotag = iotag;
496 spin_unlock_irq(&phba->hbalock);
499 if (psli->iocbq_lookup)
500 memcpy(new_arr, old_arr,
501 ((psli->last_iotag + 1) *
502 sizeof (struct lpfc_iocbq *)));
503 psli->iocbq_lookup = new_arr;
504 psli->iocbq_lookup_len = new_len;
505 psli->last_iotag = iotag;
506 psli->iocbq_lookup[iotag] = iocbq;
507 spin_unlock_irq(&phba->hbalock);
508 iocbq->iotag = iotag;
513 spin_unlock_irq(&phba->hbalock);
515 lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
516 "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
523 * lpfc_sli_submit_iocb: Submit an iocb to the firmware.
524 * @phba: Pointer to HBA context object.
525 * @pring: Pointer to driver SLI ring object.
526 * @iocb: Pointer to iocb slot in the ring.
527 * @nextiocb: Pointer to driver iocb object which need to be
528 * posted to firmware.
530 * This function is called with hbalock held to post a new iocb to
531 * the firmware. This function copies the new iocb to ring iocb slot and
532 * updates the ring pointers. It adds the new iocb to txcmplq if there is
533 * a completion call back for this iocb else the function will free the
537 lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
538 IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
543 nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
546 if (pring->ringno == LPFC_ELS_RING) {
547 lpfc_debugfs_slow_ring_trc(phba,
548 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
549 *(((uint32_t *) &nextiocb->iocb) + 4),
550 *(((uint32_t *) &nextiocb->iocb) + 6),
551 *(((uint32_t *) &nextiocb->iocb) + 7));
555 * Issue iocb command to adapter
557 lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
559 pring->stats.iocb_cmd++;
562 * If there is no completion routine to call, we can release the
563 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
564 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
566 if (nextiocb->iocb_cmpl)
567 lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
569 __lpfc_sli_release_iocbq(phba, nextiocb);
572 * Let the HBA know what IOCB slot will be the next one the
573 * driver will put a command into.
575 pring->cmdidx = pring->next_cmdidx;
576 writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
580 * lpfc_sli_update_full_ring: Update the chip attention register.
581 * @phba: Pointer to HBA context object.
582 * @pring: Pointer to driver SLI ring object.
584 * The caller is not required to hold any lock for calling this function.
585 * This function updates the chip attention bits for the ring to inform firmware
586 * that there are pending work to be done for this ring and requests an
587 * interrupt when there is space available in the ring. This function is
588 * called when the driver is unable to post more iocbs to the ring due
589 * to unavailability of space in the ring.
592 lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
594 int ringno = pring->ringno;
596 pring->flag |= LPFC_CALL_RING_AVAILABLE;
601 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
602 * The HBA will tell us when an IOCB entry is available.
604 writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
605 readl(phba->CAregaddr); /* flush */
607 pring->stats.iocb_cmd_full++;
611 * lpfc_sli_update_ring: Update chip attention register.
612 * @phba: Pointer to HBA context object.
613 * @pring: Pointer to driver SLI ring object.
615 * This function updates the chip attention register bit for the
616 * given ring to inform HBA that there is more work to be done
617 * in this ring. The caller is not required to hold any lock.
620 lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
622 int ringno = pring->ringno;
625 * Tell the HBA that there is work to do in this ring.
627 if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
629 writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
630 readl(phba->CAregaddr); /* flush */
635 * lpfc_sli_resume_iocb: Process iocbs in the txq.
636 * @phba: Pointer to HBA context object.
637 * @pring: Pointer to driver SLI ring object.
639 * This function is called with hbalock held to post pending iocbs
640 * in the txq to the firmware. This function is called when driver
641 * detects space available in the ring.
644 lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
647 struct lpfc_iocbq *nextiocb;
651 * (a) there is anything on the txq to send
653 * (c) link attention events can be processed (fcp ring only)
654 * (d) IOCB processing is not blocked by the outstanding mbox command.
656 if (pring->txq_cnt &&
657 lpfc_is_link_up(phba) &&
658 (pring->ringno != phba->sli.fcp_ring ||
659 phba->sli.sli_flag & LPFC_PROCESS_LA)) {
661 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
662 (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
663 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
666 lpfc_sli_update_ring(phba, pring);
668 lpfc_sli_update_full_ring(phba, pring);
675 * lpfc_sli_next_hbq_slot: Get next hbq entry for the HBQ.
676 * @phba: Pointer to HBA context object.
677 * @hbqno: HBQ number.
679 * This function is called with hbalock held to get the next
680 * available slot for the given HBQ. If there is free slot
681 * available for the HBQ it will return pointer to the next available
682 * HBQ entry else it will return NULL.
684 static struct lpfc_hbq_entry *
685 lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
687 struct hbq_s *hbqp = &phba->hbqs[hbqno];
689 if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
690 ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
691 hbqp->next_hbqPutIdx = 0;
693 if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
694 uint32_t raw_index = phba->hbq_get[hbqno];
695 uint32_t getidx = le32_to_cpu(raw_index);
697 hbqp->local_hbqGetIdx = getidx;
699 if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
700 lpfc_printf_log(phba, KERN_ERR,
702 "1802 HBQ %d: local_hbqGetIdx "
703 "%u is > than hbqp->entry_count %u\n",
704 hbqno, hbqp->local_hbqGetIdx,
707 phba->link_state = LPFC_HBA_ERROR;
711 if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
715 return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
720 * lpfc_sli_hbqbuf_free_all: Free all the hbq buffers.
721 * @phba: Pointer to HBA context object.
723 * This function is called with no lock held to free all the
724 * hbq buffers while uninitializing the SLI interface. It also
725 * frees the HBQ buffers returned by the firmware but not yet
726 * processed by the upper layers.
729 lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
731 struct lpfc_dmabuf *dmabuf, *next_dmabuf;
732 struct hbq_dmabuf *hbq_buf;
737 hbq_count = lpfc_sli_hbq_count();
738 /* Return all memory used by all HBQs */
739 spin_lock_irqsave(&phba->hbalock, flags);
740 for (i = 0; i < hbq_count; ++i) {
741 list_for_each_entry_safe(dmabuf, next_dmabuf,
742 &phba->hbqs[i].hbq_buffer_list, list) {
743 hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
744 list_del(&hbq_buf->dbuf.list);
745 (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
747 phba->hbqs[i].buffer_count = 0;
749 /* Return all HBQ buffer that are in-fly */
750 list_for_each_entry_safe(dmabuf, next_dmabuf,
751 &phba->hbqbuf_in_list, list) {
752 hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
753 list_del(&hbq_buf->dbuf.list);
754 if (hbq_buf->tag == -1) {
755 (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
758 hbqno = hbq_buf->tag >> 16;
759 if (hbqno >= LPFC_MAX_HBQS)
760 (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
763 (phba->hbqs[hbqno].hbq_free_buffer)(phba,
768 /* Mark the HBQs not in use */
769 phba->hbq_in_use = 0;
770 spin_unlock_irqrestore(&phba->hbalock, flags);
774 * lpfc_sli_hbq_to_firmware: Post the hbq buffer to firmware.
775 * @phba: Pointer to HBA context object.
776 * @hbqno: HBQ number.
777 * @hbq_buf: Pointer to HBQ buffer.
779 * This function is called with the hbalock held to post a
780 * hbq buffer to the firmware. If the function finds an empty
781 * slot in the HBQ, it will post the buffer. The function will return
782 * pointer to the hbq entry if it successfully post the buffer
783 * else it will return NULL.
785 static struct lpfc_hbq_entry *
786 lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
787 struct hbq_dmabuf *hbq_buf)
789 struct lpfc_hbq_entry *hbqe;
790 dma_addr_t physaddr = hbq_buf->dbuf.phys;
792 /* Get next HBQ entry slot to use */
793 hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
795 struct hbq_s *hbqp = &phba->hbqs[hbqno];
797 hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
798 hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
799 hbqe->bde.tus.f.bdeSize = hbq_buf->size;
800 hbqe->bde.tus.f.bdeFlags = 0;
801 hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
802 hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
804 hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
805 writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
807 readl(phba->hbq_put + hbqno);
808 list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
813 /* HBQ for ELS and CT traffic. */
814 static struct lpfc_hbq_init lpfc_els_hbq = {
819 .ring_mask = (1 << LPFC_ELS_RING),
825 /* HBQ for the extra ring if needed */
826 static struct lpfc_hbq_init lpfc_extra_hbq = {
831 .ring_mask = (1 << LPFC_EXTRA_RING),
838 struct lpfc_hbq_init *lpfc_hbq_defs[] = {
844 * lpfc_sli_hbqbuf_fill_hbqs: Post more hbq buffers to HBQ.
845 * @phba: Pointer to HBA context object.
846 * @hbqno: HBQ number.
847 * @count: Number of HBQ buffers to be posted.
849 * This function is called with no lock held to post more hbq buffers to the
850 * given HBQ. The function returns the number of HBQ buffers successfully
854 lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
856 uint32_t i, posted = 0;
858 struct hbq_dmabuf *hbq_buffer;
859 LIST_HEAD(hbq_buf_list);
860 if (!phba->hbqs[hbqno].hbq_alloc_buffer)
863 if ((phba->hbqs[hbqno].buffer_count + count) >
864 lpfc_hbq_defs[hbqno]->entry_count)
865 count = lpfc_hbq_defs[hbqno]->entry_count -
866 phba->hbqs[hbqno].buffer_count;
869 /* Allocate HBQ entries */
870 for (i = 0; i < count; i++) {
871 hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
874 list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
876 /* Check whether HBQ is still in use */
877 spin_lock_irqsave(&phba->hbalock, flags);
878 if (!phba->hbq_in_use)
880 while (!list_empty(&hbq_buf_list)) {
881 list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
883 hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
885 if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
886 phba->hbqs[hbqno].buffer_count++;
889 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
891 spin_unlock_irqrestore(&phba->hbalock, flags);
894 spin_unlock_irqrestore(&phba->hbalock, flags);
895 while (!list_empty(&hbq_buf_list)) {
896 list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
898 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
904 * lpfc_sli_hbqbuf_add_hbqs: Post more HBQ buffers to firmware.
905 * @phba: Pointer to HBA context object.
908 * This function posts more buffers to the HBQ. This function
909 * is called with no lock held. The function returns the number of HBQ entries
910 * successfully allocated.
913 lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
915 return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
916 lpfc_hbq_defs[qno]->add_count));
920 * lpfc_sli_hbqbuf_init_hbqs: Post initial buffers to the HBQ.
921 * @phba: Pointer to HBA context object.
922 * @qno: HBQ queue number.
924 * This function is called from SLI initialization code path with
925 * no lock held to post initial HBQ buffers to firmware. The
926 * function returns the number of HBQ entries successfully allocated.
929 lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
931 return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
932 lpfc_hbq_defs[qno]->init_count));
936 * lpfc_sli_hbqbuf_find: Find the hbq buffer associated with a tag.
937 * @phba: Pointer to HBA context object.
938 * @tag: Tag of the hbq buffer.
940 * This function is called with hbalock held. This function searches
941 * for the hbq buffer associated with the given tag in the hbq buffer
942 * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
945 static struct hbq_dmabuf *
946 lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
948 struct lpfc_dmabuf *d_buf;
949 struct hbq_dmabuf *hbq_buf;
953 if (hbqno >= LPFC_MAX_HBQS)
956 list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
957 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
958 if (hbq_buf->tag == tag) {
962 lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
963 "1803 Bad hbq tag. Data: x%x x%x\n",
964 tag, phba->hbqs[tag >> 16].buffer_count);
969 * lpfc_sli_free_hbq: Give back the hbq buffer to firmware.
970 * @phba: Pointer to HBA context object.
971 * @hbq_buffer: Pointer to HBQ buffer.
973 * This function is called with hbalock. This function gives back
974 * the hbq buffer to firmware. If the HBQ does not have space to
975 * post the buffer, it will free the buffer.
978 lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
983 hbqno = hbq_buffer->tag >> 16;
984 if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
985 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
991 * lpfc_sli_chk_mbx_command: Check if the mailbox is a legitimate mailbox.
992 * @mbxCommand: mailbox command code.
994 * This function is called by the mailbox event handler function to verify
995 * that the completed mailbox command is a legitimate mailbox command. If the
996 * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
997 * and the mailbox event handler will take the HBA offline.
1000 lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
1004 switch (mbxCommand) {
1008 case MBX_WRITE_VPARMS:
1009 case MBX_RUN_BIU_DIAG:
1012 case MBX_CONFIG_LINK:
1013 case MBX_CONFIG_RING:
1014 case MBX_RESET_RING:
1015 case MBX_READ_CONFIG:
1016 case MBX_READ_RCONFIG:
1017 case MBX_READ_SPARM:
1018 case MBX_READ_STATUS:
1022 case MBX_READ_LNK_STAT:
1024 case MBX_UNREG_LOGIN:
1027 case MBX_DUMP_MEMORY:
1028 case MBX_DUMP_CONTEXT:
1031 case MBX_UPDATE_CFG:
1033 case MBX_DEL_LD_ENTRY:
1034 case MBX_RUN_PROGRAM:
1036 case MBX_SET_VARIABLE:
1037 case MBX_UNREG_D_ID:
1038 case MBX_KILL_BOARD:
1039 case MBX_CONFIG_FARP:
1042 case MBX_RUN_BIU_DIAG64:
1043 case MBX_CONFIG_PORT:
1044 case MBX_READ_SPARM64:
1045 case MBX_READ_RPI64:
1046 case MBX_REG_LOGIN64:
1050 case MBX_LOAD_EXP_ROM:
1051 case MBX_ASYNCEVT_ENABLE:
1055 case MBX_PORT_CAPABILITIES:
1056 case MBX_PORT_IOV_CONTROL:
1067 * lpfc_sli_wake_mbox_wait: Completion handler for mbox issued from
1068 * lpfc_sli_issue_mbox_wait.
1069 * @phba: Pointer to HBA context object.
1070 * @pmboxq: Pointer to mailbox command.
1072 * This is completion handler function for mailbox commands issued from
1073 * lpfc_sli_issue_mbox_wait function. This function is called by the
1074 * mailbox event handler function with no lock held. This function
1075 * will wake up thread waiting on the wait queue pointed by context1
1079 lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
1081 wait_queue_head_t *pdone_q;
1082 unsigned long drvr_flag;
1085 * If pdone_q is empty, the driver thread gave up waiting and
1086 * continued running.
1088 pmboxq->mbox_flag |= LPFC_MBX_WAKE;
1089 spin_lock_irqsave(&phba->hbalock, drvr_flag);
1090 pdone_q = (wait_queue_head_t *) pmboxq->context1;
1092 wake_up_interruptible(pdone_q);
1093 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1099 * lpfc_sli_def_mbox_cmpl: Default mailbox completion handler.
1100 * @phba: Pointer to HBA context object.
1101 * @pmb: Pointer to mailbox object.
1103 * This function is the default mailbox completion handler. It
1104 * frees the memory resources associated with the completed mailbox
1105 * command. If the completed command is a REG_LOGIN mailbox command,
1106 * this function will issue a UREG_LOGIN to re-claim the RPI.
1109 lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1111 struct lpfc_dmabuf *mp;
1115 mp = (struct lpfc_dmabuf *) (pmb->context1);
1118 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1123 * If a REG_LOGIN succeeded after node is destroyed or node
1124 * is in re-discovery driver need to cleanup the RPI.
1126 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1127 pmb->mb.mbxCommand == MBX_REG_LOGIN64 &&
1128 !pmb->mb.mbxStatus) {
1130 rpi = pmb->mb.un.varWords[0];
1131 lpfc_unreg_login(phba, pmb->mb.un.varRegLogin.vpi, rpi, pmb);
1132 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1133 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
1134 if (rc != MBX_NOT_FINISHED)
1138 mempool_free(pmb, phba->mbox_mem_pool);
1143 * lpfc_sli_handle_mb_event: Handle mailbox completions from firmware.
1144 * @phba: Pointer to HBA context object.
1146 * This function is called with no lock held. This function processes all
1147 * the completed mailbox commands and gives it to upper layers. The interrupt
1148 * service routine processes mailbox completion interrupt and adds completed
1149 * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
1150 * Worker thread call lpfc_sli_handle_mb_event, which will return the
1151 * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
1152 * function returns the mailbox commands to the upper layer by calling the
1153 * completion handler function of each mailbox.
1156 lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
1163 phba->sli.slistat.mbox_event++;
1165 /* Get all completed mailboxe buffers into the cmplq */
1166 spin_lock_irq(&phba->hbalock);
1167 list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
1168 spin_unlock_irq(&phba->hbalock);
1170 /* Get a Mailbox buffer to setup mailbox commands for callback */
1172 list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
1178 if (pmbox->mbxCommand != MBX_HEARTBEAT) {
1180 lpfc_debugfs_disc_trc(pmb->vport,
1181 LPFC_DISC_TRC_MBOX_VPORT,
1182 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
1183 (uint32_t)pmbox->mbxCommand,
1184 pmbox->un.varWords[0],
1185 pmbox->un.varWords[1]);
1188 lpfc_debugfs_disc_trc(phba->pport,
1190 "MBOX cmpl: cmd:x%x mb:x%x x%x",
1191 (uint32_t)pmbox->mbxCommand,
1192 pmbox->un.varWords[0],
1193 pmbox->un.varWords[1]);
1198 * It is a fatal error if unknown mbox command completion.
1200 if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
1202 /* Unknow mailbox command compl */
1203 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
1204 "(%d):0323 Unknown Mailbox command "
1206 pmb->vport ? pmb->vport->vpi : 0,
1208 phba->link_state = LPFC_HBA_ERROR;
1209 phba->work_hs = HS_FFER3;
1210 lpfc_handle_eratt(phba);
1214 if (pmbox->mbxStatus) {
1215 phba->sli.slistat.mbox_stat_err++;
1216 if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
1217 /* Mbox cmd cmpl error - RETRYing */
1218 lpfc_printf_log(phba, KERN_INFO,
1220 "(%d):0305 Mbox cmd cmpl "
1221 "error - RETRYing Data: x%x "
1223 pmb->vport ? pmb->vport->vpi :0,
1226 pmbox->un.varWords[0],
1227 pmb->vport->port_state);
1228 pmbox->mbxStatus = 0;
1229 pmbox->mbxOwner = OWN_HOST;
1230 spin_lock_irq(&phba->hbalock);
1231 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
1232 spin_unlock_irq(&phba->hbalock);
1233 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
1234 if (rc == MBX_SUCCESS)
1239 /* Mailbox cmd <cmd> Cmpl <cmpl> */
1240 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
1241 "(%d):0307 Mailbox cmd x%x Cmpl x%p "
1242 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
1243 pmb->vport ? pmb->vport->vpi : 0,
1246 *((uint32_t *) pmbox),
1247 pmbox->un.varWords[0],
1248 pmbox->un.varWords[1],
1249 pmbox->un.varWords[2],
1250 pmbox->un.varWords[3],
1251 pmbox->un.varWords[4],
1252 pmbox->un.varWords[5],
1253 pmbox->un.varWords[6],
1254 pmbox->un.varWords[7]);
1257 pmb->mbox_cmpl(phba,pmb);
1263 * lpfc_sli_get_buff: Get the buffer associated with the buffer tag.
1264 * @phba: Pointer to HBA context object.
1265 * @pring: Pointer to driver SLI ring object.
1268 * This function is called with no lock held. When QUE_BUFTAG_BIT bit
1269 * is set in the tag the buffer is posted for a particular exchange,
1270 * the function will return the buffer without replacing the buffer.
1271 * If the buffer is for unsolicited ELS or CT traffic, this function
1272 * returns the buffer and also posts another buffer to the firmware.
1274 static struct lpfc_dmabuf *
1275 lpfc_sli_get_buff(struct lpfc_hba *phba,
1276 struct lpfc_sli_ring *pring,
1279 struct hbq_dmabuf *hbq_entry;
1281 if (tag & QUE_BUFTAG_BIT)
1282 return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
1283 hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
1286 return &hbq_entry->dbuf;
1291 * lpfc_sli_process_unsol_iocb: Unsolicited iocb handler.
1292 * @phba: Pointer to HBA context object.
1293 * @pring: Pointer to driver SLI ring object.
1294 * @saveq: Pointer to the unsolicited iocb.
1296 * This function is called with no lock held by the ring event handler
1297 * when there is an unsolicited iocb posted to the response ring by the
1298 * firmware. This function gets the buffer associated with the iocbs
1299 * and calls the event handler for the ring. This function handles both
1300 * qring buffers and hbq buffers.
1301 * When the function returns 1 the caller can free the iocb object otherwise
1302 * upper layer functions will free the iocb objects.
1305 lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1306 struct lpfc_iocbq *saveq)
1310 uint32_t Rctl, Type;
1312 struct lpfc_iocbq *iocbq;
1313 struct lpfc_dmabuf *dmzbuf;
1316 irsp = &(saveq->iocb);
1318 if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
1319 if (pring->lpfc_sli_rcv_async_status)
1320 pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
1322 lpfc_printf_log(phba,
1325 "0316 Ring %d handler: unexpected "
1326 "ASYNC_STATUS iocb received evt_code "
1329 irsp->un.asyncstat.evt_code);
1333 if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
1334 (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
1335 if (irsp->ulpBdeCount > 0) {
1336 dmzbuf = lpfc_sli_get_buff(phba, pring,
1337 irsp->un.ulpWord[3]);
1338 lpfc_in_buf_free(phba, dmzbuf);
1341 if (irsp->ulpBdeCount > 1) {
1342 dmzbuf = lpfc_sli_get_buff(phba, pring,
1343 irsp->unsli3.sli3Words[3]);
1344 lpfc_in_buf_free(phba, dmzbuf);
1347 if (irsp->ulpBdeCount > 2) {
1348 dmzbuf = lpfc_sli_get_buff(phba, pring,
1349 irsp->unsli3.sli3Words[7]);
1350 lpfc_in_buf_free(phba, dmzbuf);
1356 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
1357 if (irsp->ulpBdeCount != 0) {
1358 saveq->context2 = lpfc_sli_get_buff(phba, pring,
1359 irsp->un.ulpWord[3]);
1360 if (!saveq->context2)
1361 lpfc_printf_log(phba,
1364 "0341 Ring %d Cannot find buffer for "
1365 "an unsolicited iocb. tag 0x%x\n",
1367 irsp->un.ulpWord[3]);
1369 if (irsp->ulpBdeCount == 2) {
1370 saveq->context3 = lpfc_sli_get_buff(phba, pring,
1371 irsp->unsli3.sli3Words[7]);
1372 if (!saveq->context3)
1373 lpfc_printf_log(phba,
1376 "0342 Ring %d Cannot find buffer for an"
1377 " unsolicited iocb. tag 0x%x\n",
1379 irsp->unsli3.sli3Words[7]);
1381 list_for_each_entry(iocbq, &saveq->list, list) {
1382 irsp = &(iocbq->iocb);
1383 if (irsp->ulpBdeCount != 0) {
1384 iocbq->context2 = lpfc_sli_get_buff(phba, pring,
1385 irsp->un.ulpWord[3]);
1386 if (!iocbq->context2)
1387 lpfc_printf_log(phba,
1390 "0343 Ring %d Cannot find "
1391 "buffer for an unsolicited iocb"
1392 ". tag 0x%x\n", pring->ringno,
1393 irsp->un.ulpWord[3]);
1395 if (irsp->ulpBdeCount == 2) {
1396 iocbq->context3 = lpfc_sli_get_buff(phba, pring,
1397 irsp->unsli3.sli3Words[7]);
1398 if (!iocbq->context3)
1399 lpfc_printf_log(phba,
1402 "0344 Ring %d Cannot find "
1403 "buffer for an unsolicited "
1406 irsp->unsli3.sli3Words[7]);
1410 if (irsp->ulpBdeCount != 0 &&
1411 (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
1412 irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
1415 /* search continue save q for same XRI */
1416 list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
1417 if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) {
1418 list_add_tail(&saveq->list, &iocbq->list);
1424 list_add_tail(&saveq->clist,
1425 &pring->iocb_continue_saveq);
1426 if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
1427 list_del_init(&iocbq->clist);
1429 irsp = &(saveq->iocb);
1433 if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
1434 (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
1435 (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
1439 w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
1440 Rctl = w5p->hcsw.Rctl;
1441 Type = w5p->hcsw.Type;
1443 /* Firmware Workaround */
1444 if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
1445 (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
1446 irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
1449 w5p->hcsw.Rctl = Rctl;
1450 w5p->hcsw.Type = Type;
1454 /* unSolicited Responses */
1455 if (pring->prt[0].profile) {
1456 if (pring->prt[0].lpfc_sli_rcv_unsol_event)
1457 (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
1461 /* We must search, based on rctl / type
1462 for the right routine */
1463 for (i = 0; i < pring->num_mask; i++) {
1464 if ((pring->prt[i].rctl == Rctl)
1465 && (pring->prt[i].type == Type)) {
1466 if (pring->prt[i].lpfc_sli_rcv_unsol_event)
1467 (pring->prt[i].lpfc_sli_rcv_unsol_event)
1468 (phba, pring, saveq);
1475 /* Unexpected Rctl / Type received */
1476 /* Ring <ringno> handler: unexpected
1477 Rctl <Rctl> Type <Type> received */
1478 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1479 "0313 Ring %d handler: unexpected Rctl x%x "
1480 "Type x%x received\n",
1481 pring->ringno, Rctl, Type);
1487 * lpfc_sli_iocbq_lookup: Find command iocb for the given response iocb.
1488 * @phba: Pointer to HBA context object.
1489 * @pring: Pointer to driver SLI ring object.
1490 * @prspiocb: Pointer to response iocb object.
1492 * This function looks up the iocb_lookup table to get the command iocb
1493 * corresponding to the given response iocb using the iotag of the
1494 * response iocb. This function is called with the hbalock held.
1495 * This function returns the command iocb object if it finds the command
1496 * iocb else returns NULL.
1498 static struct lpfc_iocbq *
1499 lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
1500 struct lpfc_sli_ring *pring,
1501 struct lpfc_iocbq *prspiocb)
1503 struct lpfc_iocbq *cmd_iocb = NULL;
1506 iotag = prspiocb->iocb.ulpIoTag;
1508 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
1509 cmd_iocb = phba->sli.iocbq_lookup[iotag];
1510 list_del_init(&cmd_iocb->list);
1511 pring->txcmplq_cnt--;
1515 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1516 "0317 iotag x%x is out off "
1517 "range: max iotag x%x wd0 x%x\n",
1518 iotag, phba->sli.last_iotag,
1519 *(((uint32_t *) &prspiocb->iocb) + 7));
1524 * lpfc_sli_process_sol_iocb: process solicited iocb completion.
1525 * @phba: Pointer to HBA context object.
1526 * @pring: Pointer to driver SLI ring object.
1527 * @saveq: Pointer to the response iocb to be processed.
1529 * This function is called by the ring event handler for non-fcp
1530 * rings when there is a new response iocb in the response ring.
1531 * The caller is not required to hold any locks. This function
1532 * gets the command iocb associated with the response iocb and
1533 * calls the completion handler for the command iocb. If there
1534 * is no completion handler, the function will free the resources
1535 * associated with command iocb. If the response iocb is for
1536 * an already aborted command iocb, the status of the completion
1537 * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
1538 * This function always returns 1.
1541 lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1542 struct lpfc_iocbq *saveq)
1544 struct lpfc_iocbq *cmdiocbp;
1546 unsigned long iflag;
1548 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
1549 spin_lock_irqsave(&phba->hbalock, iflag);
1550 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
1551 spin_unlock_irqrestore(&phba->hbalock, iflag);
1554 if (cmdiocbp->iocb_cmpl) {
1556 * If an ELS command failed send an event to mgmt
1559 if (saveq->iocb.ulpStatus &&
1560 (pring->ringno == LPFC_ELS_RING) &&
1561 (cmdiocbp->iocb.ulpCommand ==
1562 CMD_ELS_REQUEST64_CR))
1563 lpfc_send_els_failure_event(phba,
1567 * Post all ELS completions to the worker thread.
1568 * All other are passed to the completion callback.
1570 if (pring->ringno == LPFC_ELS_RING) {
1571 if (cmdiocbp->iocb_flag & LPFC_DRIVER_ABORTED) {
1572 cmdiocbp->iocb_flag &=
1573 ~LPFC_DRIVER_ABORTED;
1574 saveq->iocb.ulpStatus =
1575 IOSTAT_LOCAL_REJECT;
1576 saveq->iocb.un.ulpWord[4] =
1579 /* Firmware could still be in progress
1580 * of DMAing payload, so don't free data
1581 * buffer till after a hbeat.
1583 saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
1586 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
1588 lpfc_sli_release_iocbq(phba, cmdiocbp);
1591 * Unknown initiating command based on the response iotag.
1592 * This could be the case on the ELS ring because of
1595 if (pring->ringno != LPFC_ELS_RING) {
1597 * Ring <ringno> handler: unexpected completion IoTag
1600 lpfc_printf_vlog(cmdiocbp->vport, KERN_WARNING, LOG_SLI,
1601 "0322 Ring %d handler: "
1602 "unexpected completion IoTag x%x "
1603 "Data: x%x x%x x%x x%x\n",
1605 saveq->iocb.ulpIoTag,
1606 saveq->iocb.ulpStatus,
1607 saveq->iocb.un.ulpWord[4],
1608 saveq->iocb.ulpCommand,
1609 saveq->iocb.ulpContext);
1617 * lpfc_sli_rsp_pointers_error: Response ring pointer error handler.
1618 * @phba: Pointer to HBA context object.
1619 * @pring: Pointer to driver SLI ring object.
1621 * This function is called from the iocb ring event handlers when
1622 * put pointer is ahead of the get pointer for a ring. This function signal
1623 * an error attention condition to the worker thread and the worker
1624 * thread will transition the HBA to offline state.
1627 lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1629 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
1631 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
1632 * rsp ring <portRspMax>
1634 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1635 "0312 Ring %d handler: portRspPut %d "
1636 "is bigger than rsp ring %d\n",
1637 pring->ringno, le32_to_cpu(pgp->rspPutInx),
1640 phba->link_state = LPFC_HBA_ERROR;
1643 * All error attention handlers are posted to
1646 phba->work_ha |= HA_ERATT;
1647 phba->work_hs = HS_FFER3;
1649 lpfc_worker_wake_up(phba);
1655 * lpfc_poll_eratt: Error attention polling timer timeout handler.
1656 * @ptr: Pointer to address of HBA context object.
1658 * This function is invoked by the Error Attention polling timer when the
1659 * timer times out. It will check the SLI Error Attention register for
1660 * possible attention events. If so, it will post an Error Attention event
1661 * and wake up worker thread to process it. Otherwise, it will set up the
1662 * Error Attention polling timer for the next poll.
1664 void lpfc_poll_eratt(unsigned long ptr)
1666 struct lpfc_hba *phba;
1669 phba = (struct lpfc_hba *)ptr;
1671 /* Check chip HA register for error event */
1672 eratt = lpfc_sli_check_eratt(phba);
1675 /* Tell the worker thread there is work to do */
1676 lpfc_worker_wake_up(phba);
1678 /* Restart the timer for next eratt poll */
1679 mod_timer(&phba->eratt_poll, jiffies +
1680 HZ * LPFC_ERATT_POLL_INTERVAL);
1685 * lpfc_sli_poll_fcp_ring: Handle FCP ring completion in polling mode.
1686 * @phba: Pointer to HBA context object.
1688 * This function is called from lpfc_queuecommand, lpfc_poll_timeout,
1689 * lpfc_abort_handler and lpfc_slave_configure when FCP_RING_POLLING
1692 * The caller does not hold any lock.
1693 * The function processes each response iocb in the response ring until it
1694 * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
1695 * LE bit set. The function will call the completion handler of the command iocb
1696 * if the response iocb indicates a completion for a command iocb or it is
1697 * an abort completion.
1699 void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba)
1701 struct lpfc_sli *psli = &phba->sli;
1702 struct lpfc_sli_ring *pring = &psli->ring[LPFC_FCP_RING];
1703 IOCB_t *irsp = NULL;
1704 IOCB_t *entry = NULL;
1705 struct lpfc_iocbq *cmdiocbq = NULL;
1706 struct lpfc_iocbq rspiocbq;
1707 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
1709 uint32_t portRspPut, portRspMax;
1711 uint32_t rsp_cmpl = 0;
1713 unsigned long iflags;
1715 pring->stats.iocb_event++;
1718 * The next available response entry should never exceed the maximum
1719 * entries. If it does, treat it as an adapter hardware error.
1721 portRspMax = pring->numRiocb;
1722 portRspPut = le32_to_cpu(pgp->rspPutInx);
1723 if (unlikely(portRspPut >= portRspMax)) {
1724 lpfc_sli_rsp_pointers_error(phba, pring);
1729 while (pring->rspidx != portRspPut) {
1730 entry = lpfc_resp_iocb(phba, pring);
1731 if (++pring->rspidx >= portRspMax)
1734 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
1735 (uint32_t *) &rspiocbq.iocb,
1736 phba->iocb_rsp_size);
1737 irsp = &rspiocbq.iocb;
1738 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
1739 pring->stats.iocb_rsp++;
1742 if (unlikely(irsp->ulpStatus)) {
1743 /* Rsp ring <ringno> error: IOCB */
1744 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1745 "0326 Rsp Ring %d error: IOCB Data: "
1746 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
1748 irsp->un.ulpWord[0],
1749 irsp->un.ulpWord[1],
1750 irsp->un.ulpWord[2],
1751 irsp->un.ulpWord[3],
1752 irsp->un.ulpWord[4],
1753 irsp->un.ulpWord[5],
1754 *(uint32_t *)&irsp->un1,
1755 *((uint32_t *)&irsp->un1 + 1));
1759 case LPFC_ABORT_IOCB:
1762 * Idle exchange closed via ABTS from port. No iocb
1763 * resources need to be recovered.
1765 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
1766 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1767 "0314 IOCB cmd 0x%x "
1768 "processed. Skipping "
1774 spin_lock_irqsave(&phba->hbalock, iflags);
1775 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
1777 spin_unlock_irqrestore(&phba->hbalock, iflags);
1778 if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
1779 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1784 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1785 char adaptermsg[LPFC_MAX_ADPTMSG];
1786 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
1787 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1789 dev_warn(&((phba->pcidev)->dev),
1791 phba->brd_no, adaptermsg);
1793 /* Unknown IOCB command */
1794 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1795 "0321 Unknown IOCB command "
1796 "Data: x%x, x%x x%x x%x x%x\n",
1797 type, irsp->ulpCommand,
1806 * The response IOCB has been processed. Update the ring
1807 * pointer in SLIM. If the port response put pointer has not
1808 * been updated, sync the pgp->rspPutInx and fetch the new port
1809 * response put pointer.
1811 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
1813 if (pring->rspidx == portRspPut)
1814 portRspPut = le32_to_cpu(pgp->rspPutInx);
1817 ha_copy = readl(phba->HAregaddr);
1818 ha_copy >>= (LPFC_FCP_RING * 4);
1820 if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) {
1821 spin_lock_irqsave(&phba->hbalock, iflags);
1822 pring->stats.iocb_rsp_full++;
1823 status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4));
1824 writel(status, phba->CAregaddr);
1825 readl(phba->CAregaddr);
1826 spin_unlock_irqrestore(&phba->hbalock, iflags);
1828 if ((ha_copy & HA_R0CE_RSP) &&
1829 (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1830 spin_lock_irqsave(&phba->hbalock, iflags);
1831 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1832 pring->stats.iocb_cmd_empty++;
1834 /* Force update of the local copy of cmdGetInx */
1835 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1836 lpfc_sli_resume_iocb(phba, pring);
1838 if ((pring->lpfc_sli_cmd_available))
1839 (pring->lpfc_sli_cmd_available) (phba, pring);
1841 spin_unlock_irqrestore(&phba->hbalock, iflags);
1848 * lpfc_sli_handle_fast_ring_event: Handle ring events on FCP ring.
1849 * @phba: Pointer to HBA context object.
1850 * @pring: Pointer to driver SLI ring object.
1851 * @mask: Host attention register mask for this ring.
1853 * This function is called from the interrupt context when there is a ring
1854 * event for the fcp ring. The caller does not hold any lock.
1855 * The function processes each response iocb in the response ring until it
1856 * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
1857 * LE bit set. The function will call the completion handler of the command iocb
1858 * if the response iocb indicates a completion for a command iocb or it is
1859 * an abort completion. The function will call lpfc_sli_process_unsol_iocb
1860 * function if this is an unsolicited iocb.
1861 * This routine presumes LPFC_FCP_RING handling and doesn't bother
1862 * to check it explicitly. This function always returns 1.
1865 lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
1866 struct lpfc_sli_ring *pring, uint32_t mask)
1868 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
1869 IOCB_t *irsp = NULL;
1870 IOCB_t *entry = NULL;
1871 struct lpfc_iocbq *cmdiocbq = NULL;
1872 struct lpfc_iocbq rspiocbq;
1874 uint32_t portRspPut, portRspMax;
1876 lpfc_iocb_type type;
1877 unsigned long iflag;
1878 uint32_t rsp_cmpl = 0;
1880 spin_lock_irqsave(&phba->hbalock, iflag);
1881 pring->stats.iocb_event++;
1884 * The next available response entry should never exceed the maximum
1885 * entries. If it does, treat it as an adapter hardware error.
1887 portRspMax = pring->numRiocb;
1888 portRspPut = le32_to_cpu(pgp->rspPutInx);
1889 if (unlikely(portRspPut >= portRspMax)) {
1890 lpfc_sli_rsp_pointers_error(phba, pring);
1891 spin_unlock_irqrestore(&phba->hbalock, iflag);
1896 while (pring->rspidx != portRspPut) {
1898 * Fetch an entry off the ring and copy it into a local data
1899 * structure. The copy involves a byte-swap since the
1900 * network byte order and pci byte orders are different.
1902 entry = lpfc_resp_iocb(phba, pring);
1903 phba->last_completion_time = jiffies;
1905 if (++pring->rspidx >= portRspMax)
1908 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
1909 (uint32_t *) &rspiocbq.iocb,
1910 phba->iocb_rsp_size);
1911 INIT_LIST_HEAD(&(rspiocbq.list));
1912 irsp = &rspiocbq.iocb;
1914 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
1915 pring->stats.iocb_rsp++;
1918 if (unlikely(irsp->ulpStatus)) {
1920 * If resource errors reported from HBA, reduce
1921 * queuedepths of the SCSI device.
1923 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1924 (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
1925 spin_unlock_irqrestore(&phba->hbalock, iflag);
1926 lpfc_rampdown_queue_depth(phba);
1927 spin_lock_irqsave(&phba->hbalock, iflag);
1930 /* Rsp ring <ringno> error: IOCB */
1931 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1932 "0336 Rsp Ring %d error: IOCB Data: "
1933 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
1935 irsp->un.ulpWord[0],
1936 irsp->un.ulpWord[1],
1937 irsp->un.ulpWord[2],
1938 irsp->un.ulpWord[3],
1939 irsp->un.ulpWord[4],
1940 irsp->un.ulpWord[5],
1941 *(uint32_t *)&irsp->un1,
1942 *((uint32_t *)&irsp->un1 + 1));
1946 case LPFC_ABORT_IOCB:
1949 * Idle exchange closed via ABTS from port. No iocb
1950 * resources need to be recovered.
1952 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
1953 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1954 "0333 IOCB cmd 0x%x"
1955 " processed. Skipping"
1961 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
1963 if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
1964 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
1965 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1968 spin_unlock_irqrestore(&phba->hbalock,
1970 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1972 spin_lock_irqsave(&phba->hbalock,
1977 case LPFC_UNSOL_IOCB:
1978 spin_unlock_irqrestore(&phba->hbalock, iflag);
1979 lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
1980 spin_lock_irqsave(&phba->hbalock, iflag);
1983 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1984 char adaptermsg[LPFC_MAX_ADPTMSG];
1985 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
1986 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1988 dev_warn(&((phba->pcidev)->dev),
1990 phba->brd_no, adaptermsg);
1992 /* Unknown IOCB command */
1993 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1994 "0334 Unknown IOCB command "
1995 "Data: x%x, x%x x%x x%x x%x\n",
1996 type, irsp->ulpCommand,
2005 * The response IOCB has been processed. Update the ring
2006 * pointer in SLIM. If the port response put pointer has not
2007 * been updated, sync the pgp->rspPutInx and fetch the new port
2008 * response put pointer.
2010 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
2012 if (pring->rspidx == portRspPut)
2013 portRspPut = le32_to_cpu(pgp->rspPutInx);
2016 if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
2017 pring->stats.iocb_rsp_full++;
2018 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
2019 writel(status, phba->CAregaddr);
2020 readl(phba->CAregaddr);
2022 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
2023 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
2024 pring->stats.iocb_cmd_empty++;
2026 /* Force update of the local copy of cmdGetInx */
2027 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
2028 lpfc_sli_resume_iocb(phba, pring);
2030 if ((pring->lpfc_sli_cmd_available))
2031 (pring->lpfc_sli_cmd_available) (phba, pring);
2035 spin_unlock_irqrestore(&phba->hbalock, iflag);
2040 * lpfc_sli_handle_slow_ring_event: Handle ring events for non-FCP rings.
2041 * @phba: Pointer to HBA context object.
2042 * @pring: Pointer to driver SLI ring object.
2043 * @mask: Host attention register mask for this ring.
2045 * This function is called from the worker thread when there is a ring
2046 * event for non-fcp rings. The caller does not hold any lock .
2047 * The function processes each response iocb in the response ring until it
2048 * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
2049 * LE bit set. The function will call lpfc_sli_process_sol_iocb function if the
2050 * response iocb indicates a completion of a command iocb. The function
2051 * will call lpfc_sli_process_unsol_iocb function if this is an unsolicited
2052 * iocb. The function frees the resources or calls the completion handler if
2053 * this iocb is an abort completion. The function returns 0 when the allocated
2054 * iocbs are not freed, otherwise returns 1.
2057 lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
2058 struct lpfc_sli_ring *pring, uint32_t mask)
2060 struct lpfc_pgp *pgp;
2062 IOCB_t *irsp = NULL;
2063 struct lpfc_iocbq *rspiocbp = NULL;
2064 struct lpfc_iocbq *next_iocb;
2065 struct lpfc_iocbq *cmdiocbp;
2066 struct lpfc_iocbq *saveq;
2067 uint8_t iocb_cmd_type;
2068 lpfc_iocb_type type;
2069 uint32_t status, free_saveq;
2070 uint32_t portRspPut, portRspMax;
2072 unsigned long iflag;
2074 pgp = &phba->port_gp[pring->ringno];
2075 spin_lock_irqsave(&phba->hbalock, iflag);
2076 pring->stats.iocb_event++;
2079 * The next available response entry should never exceed the maximum
2080 * entries. If it does, treat it as an adapter hardware error.
2082 portRspMax = pring->numRiocb;
2083 portRspPut = le32_to_cpu(pgp->rspPutInx);
2084 if (portRspPut >= portRspMax) {
2086 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
2087 * rsp ring <portRspMax>
2089 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2090 "0303 Ring %d handler: portRspPut %d "
2091 "is bigger than rsp ring %d\n",
2092 pring->ringno, portRspPut, portRspMax);
2094 phba->link_state = LPFC_HBA_ERROR;
2095 spin_unlock_irqrestore(&phba->hbalock, iflag);
2097 phba->work_hs = HS_FFER3;
2098 lpfc_handle_eratt(phba);
2104 while (pring->rspidx != portRspPut) {
2106 * Build a completion list and call the appropriate handler.
2107 * The process is to get the next available response iocb, get
2108 * a free iocb from the list, copy the response data into the
2109 * free iocb, insert to the continuation list, and update the
2110 * next response index to slim. This process makes response
2111 * iocb's in the ring available to DMA as fast as possible but
2112 * pays a penalty for a copy operation. Since the iocb is
2113 * only 32 bytes, this penalty is considered small relative to
2114 * the PCI reads for register values and a slim write. When
2115 * the ulpLe field is set, the entire Command has been
2118 entry = lpfc_resp_iocb(phba, pring);
2120 phba->last_completion_time = jiffies;
2121 rspiocbp = __lpfc_sli_get_iocbq(phba);
2122 if (rspiocbp == NULL) {
2123 printk(KERN_ERR "%s: out of buffers! Failing "
2124 "completion.\n", __func__);
2128 lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
2129 phba->iocb_rsp_size);
2130 irsp = &rspiocbp->iocb;
2132 if (++pring->rspidx >= portRspMax)
2135 if (pring->ringno == LPFC_ELS_RING) {
2136 lpfc_debugfs_slow_ring_trc(phba,
2137 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
2138 *(((uint32_t *) irsp) + 4),
2139 *(((uint32_t *) irsp) + 6),
2140 *(((uint32_t *) irsp) + 7));
2143 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
2145 list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
2147 pring->iocb_continueq_cnt++;
2150 * By default, the driver expects to free all resources
2151 * associated with this iocb completion.
2154 saveq = list_get_first(&pring->iocb_continueq,
2155 struct lpfc_iocbq, list);
2156 irsp = &(saveq->iocb);
2157 list_del_init(&pring->iocb_continueq);
2158 pring->iocb_continueq_cnt = 0;
2160 pring->stats.iocb_rsp++;
2163 * If resource errors reported from HBA, reduce
2164 * queuedepths of the SCSI device.
2166 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
2167 (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
2168 spin_unlock_irqrestore(&phba->hbalock, iflag);
2169 lpfc_rampdown_queue_depth(phba);
2170 spin_lock_irqsave(&phba->hbalock, iflag);
2173 if (irsp->ulpStatus) {
2174 /* Rsp ring <ringno> error: IOCB */
2175 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
2176 "0328 Rsp Ring %d error: "
2181 "x%x x%x x%x x%x\n",
2183 irsp->un.ulpWord[0],
2184 irsp->un.ulpWord[1],
2185 irsp->un.ulpWord[2],
2186 irsp->un.ulpWord[3],
2187 irsp->un.ulpWord[4],
2188 irsp->un.ulpWord[5],
2189 *(((uint32_t *) irsp) + 6),
2190 *(((uint32_t *) irsp) + 7),
2191 *(((uint32_t *) irsp) + 8),
2192 *(((uint32_t *) irsp) + 9),
2193 *(((uint32_t *) irsp) + 10),
2194 *(((uint32_t *) irsp) + 11),
2195 *(((uint32_t *) irsp) + 12),
2196 *(((uint32_t *) irsp) + 13),
2197 *(((uint32_t *) irsp) + 14),
2198 *(((uint32_t *) irsp) + 15));
2202 * Fetch the IOCB command type and call the correct
2203 * completion routine. Solicited and Unsolicited
2204 * IOCBs on the ELS ring get freed back to the
2205 * lpfc_iocb_list by the discovery kernel thread.
2207 iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
2208 type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
2209 if (type == LPFC_SOL_IOCB) {
2210 spin_unlock_irqrestore(&phba->hbalock, iflag);
2211 rc = lpfc_sli_process_sol_iocb(phba, pring,
2213 spin_lock_irqsave(&phba->hbalock, iflag);
2214 } else if (type == LPFC_UNSOL_IOCB) {
2215 spin_unlock_irqrestore(&phba->hbalock, iflag);
2216 rc = lpfc_sli_process_unsol_iocb(phba, pring,
2218 spin_lock_irqsave(&phba->hbalock, iflag);
2221 } else if (type == LPFC_ABORT_IOCB) {
2222 if ((irsp->ulpCommand != CMD_XRI_ABORTED_CX) &&
2224 lpfc_sli_iocbq_lookup(phba, pring,
2226 /* Call the specified completion
2228 if (cmdiocbp->iocb_cmpl) {
2229 spin_unlock_irqrestore(
2232 (cmdiocbp->iocb_cmpl) (phba,
2238 __lpfc_sli_release_iocbq(phba,
2241 } else if (type == LPFC_UNKNOWN_IOCB) {
2242 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
2244 char adaptermsg[LPFC_MAX_ADPTMSG];
2246 memset(adaptermsg, 0,
2248 memcpy(&adaptermsg[0], (uint8_t *) irsp,
2250 dev_warn(&((phba->pcidev)->dev),
2252 phba->brd_no, adaptermsg);
2254 /* Unknown IOCB command */
2255 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2256 "0335 Unknown IOCB "
2257 "command Data: x%x "
2267 list_for_each_entry_safe(rspiocbp, next_iocb,
2268 &saveq->list, list) {
2269 list_del(&rspiocbp->list);
2270 __lpfc_sli_release_iocbq(phba,
2273 __lpfc_sli_release_iocbq(phba, saveq);
2279 * If the port response put pointer has not been updated, sync
2280 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
2281 * response put pointer.
2283 if (pring->rspidx == portRspPut) {
2284 portRspPut = le32_to_cpu(pgp->rspPutInx);
2286 } /* while (pring->rspidx != portRspPut) */
2288 if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
2289 /* At least one response entry has been freed */
2290 pring->stats.iocb_rsp_full++;
2291 /* SET RxRE_RSP in Chip Att register */
2292 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
2293 writel(status, phba->CAregaddr);
2294 readl(phba->CAregaddr); /* flush */
2296 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
2297 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
2298 pring->stats.iocb_cmd_empty++;
2300 /* Force update of the local copy of cmdGetInx */
2301 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
2302 lpfc_sli_resume_iocb(phba, pring);
2304 if ((pring->lpfc_sli_cmd_available))
2305 (pring->lpfc_sli_cmd_available) (phba, pring);
2309 spin_unlock_irqrestore(&phba->hbalock, iflag);
2314 * lpfc_sli_abort_iocb_ring: Abort all iocbs in the ring.
2315 * @phba: Pointer to HBA context object.
2316 * @pring: Pointer to driver SLI ring object.
2318 * This function aborts all iocbs in the given ring and frees all the iocb
2319 * objects in txq. This function issues an abort iocb for all the iocb commands
2320 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
2321 * the return of this function. The caller is not required to hold any locks.
2324 lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
2326 LIST_HEAD(completions);
2327 struct lpfc_iocbq *iocb, *next_iocb;
2330 if (pring->ringno == LPFC_ELS_RING) {
2331 lpfc_fabric_abort_hba(phba);
2334 /* Error everything on txq and txcmplq
2337 spin_lock_irq(&phba->hbalock);
2338 list_splice_init(&pring->txq, &completions);
2341 /* Next issue ABTS for everything on the txcmplq */
2342 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
2343 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
2345 spin_unlock_irq(&phba->hbalock);
2347 while (!list_empty(&completions)) {
2348 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
2350 list_del_init(&iocb->list);
2352 if (!iocb->iocb_cmpl)
2353 lpfc_sli_release_iocbq(phba, iocb);
2355 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2356 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
2357 (iocb->iocb_cmpl) (phba, iocb, iocb);
2363 * lpfc_sli_flush_fcp_rings: flush all iocbs in the fcp ring.
2364 * @phba: Pointer to HBA context object.
2366 * This function flushes all iocbs in the fcp ring and frees all the iocb
2367 * objects in txq and txcmplq. This function will not issue abort iocbs
2368 * for all the iocb commands in txcmplq, they will just be returned with
2369 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
2370 * slot has been permanently disabled.
2373 lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
2377 struct lpfc_iocbq *iocb;
2379 struct lpfc_sli *psli = &phba->sli;
2380 struct lpfc_sli_ring *pring;
2382 /* Currently, only one fcp ring */
2383 pring = &psli->ring[psli->fcp_ring];
2385 spin_lock_irq(&phba->hbalock);
2386 /* Retrieve everything on txq */
2387 list_splice_init(&pring->txq, &txq);
2390 /* Retrieve everything on the txcmplq */
2391 list_splice_init(&pring->txcmplq, &txcmplq);
2392 pring->txcmplq_cnt = 0;
2393 spin_unlock_irq(&phba->hbalock);
2396 while (!list_empty(&txq)) {
2397 iocb = list_get_first(&txq, struct lpfc_iocbq, list);
2399 list_del_init(&iocb->list);
2401 if (!iocb->iocb_cmpl)
2402 lpfc_sli_release_iocbq(phba, iocb);
2404 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2405 cmd->un.ulpWord[4] = IOERR_SLI_DOWN;
2406 (iocb->iocb_cmpl) (phba, iocb, iocb);
2410 /* Flush the txcmpq */
2411 while (!list_empty(&txcmplq)) {
2412 iocb = list_get_first(&txcmplq, struct lpfc_iocbq, list);
2414 list_del_init(&iocb->list);
2416 if (!iocb->iocb_cmpl)
2417 lpfc_sli_release_iocbq(phba, iocb);
2419 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2420 cmd->un.ulpWord[4] = IOERR_SLI_DOWN;
2421 (iocb->iocb_cmpl) (phba, iocb, iocb);
2427 * lpfc_sli_brdready: Check for host status bits.
2428 * @phba: Pointer to HBA context object.
2429 * @mask: Bit mask to be checked.
2431 * This function reads the host status register and compares
2432 * with the provided bit mask to check if HBA completed
2433 * the restart. This function will wait in a loop for the
2434 * HBA to complete restart. If the HBA does not restart within
2435 * 15 iterations, the function will reset the HBA again. The
2436 * function returns 1 when HBA fail to restart otherwise returns
2440 lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
2446 /* Read the HBA Host Status Register */
2447 status = readl(phba->HSregaddr);
2450 * Check status register every 100ms for 5 retries, then every
2451 * 500ms for 5, then every 2.5 sec for 5, then reset board and
2452 * every 2.5 sec for 4.
2453 * Break our of the loop if errors occurred during init.
2455 while (((status & mask) != mask) &&
2456 !(status & HS_FFERM) &&
2468 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
2469 lpfc_sli_brdrestart(phba);
2471 /* Read the HBA Host Status Register */
2472 status = readl(phba->HSregaddr);
2475 /* Check to see if any errors occurred during init */
2476 if ((status & HS_FFERM) || (i >= 20)) {
2477 phba->link_state = LPFC_HBA_ERROR;
2484 #define BARRIER_TEST_PATTERN (0xdeadbeef)
2487 * lpfc_reset_barrier: Make HBA ready for HBA reset.
2488 * @phba: Pointer to HBA context object.
2490 * This function is called before resetting an HBA. This
2491 * function requests HBA to quiesce DMAs before a reset.
2493 void lpfc_reset_barrier(struct lpfc_hba *phba)
2495 uint32_t __iomem *resp_buf;
2496 uint32_t __iomem *mbox_buf;
2497 volatile uint32_t mbox;
2502 pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
2503 if (hdrtype != 0x80 ||
2504 (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
2505 FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
2509 * Tell the other part of the chip to suspend temporarily all
2512 resp_buf = phba->MBslimaddr;
2514 /* Disable the error attention */
2515 hc_copy = readl(phba->HCregaddr);
2516 writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
2517 readl(phba->HCregaddr); /* flush */
2518 phba->link_flag |= LS_IGNORE_ERATT;
2520 if (readl(phba->HAregaddr) & HA_ERATT) {
2521 /* Clear Chip error bit */
2522 writel(HA_ERATT, phba->HAregaddr);
2523 phba->pport->stopped = 1;
2527 ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
2528 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
2530 writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
2531 mbox_buf = phba->MBslimaddr;
2532 writel(mbox, mbox_buf);
2535 readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
2538 if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
2539 if (phba->sli.sli_flag & LPFC_SLI2_ACTIVE ||
2540 phba->pport->stopped)
2546 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
2547 for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
2552 while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
2555 if (readl(phba->HAregaddr) & HA_ERATT) {
2556 writel(HA_ERATT, phba->HAregaddr);
2557 phba->pport->stopped = 1;
2561 phba->link_flag &= ~LS_IGNORE_ERATT;
2562 writel(hc_copy, phba->HCregaddr);
2563 readl(phba->HCregaddr); /* flush */
2567 * lpfc_sli_brdkill: Issue a kill_board mailbox command.
2568 * @phba: Pointer to HBA context object.
2570 * This function issues a kill_board mailbox command and waits for
2571 * the error attention interrupt. This function is called for stopping
2572 * the firmware processing. The caller is not required to hold any
2573 * locks. This function calls lpfc_hba_down_post function to free
2574 * any pending commands after the kill. The function will return 1 when it
2575 * fails to kill the board else will return 0.
2578 lpfc_sli_brdkill(struct lpfc_hba *phba)
2580 struct lpfc_sli *psli;
2590 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2591 "0329 Kill HBA Data: x%x x%x\n",
2592 phba->pport->port_state, psli->sli_flag);
2594 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2598 /* Disable the error attention */
2599 spin_lock_irq(&phba->hbalock);
2600 status = readl(phba->HCregaddr);
2601 status &= ~HC_ERINT_ENA;
2602 writel(status, phba->HCregaddr);
2603 readl(phba->HCregaddr); /* flush */
2604 phba->link_flag |= LS_IGNORE_ERATT;
2605 spin_unlock_irq(&phba->hbalock);
2607 lpfc_kill_board(phba, pmb);
2608 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2609 retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
2611 if (retval != MBX_SUCCESS) {
2612 if (retval != MBX_BUSY)
2613 mempool_free(pmb, phba->mbox_mem_pool);
2614 spin_lock_irq(&phba->hbalock);
2615 phba->link_flag &= ~LS_IGNORE_ERATT;
2616 spin_unlock_irq(&phba->hbalock);
2620 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
2622 mempool_free(pmb, phba->mbox_mem_pool);
2624 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
2625 * attention every 100ms for 3 seconds. If we don't get ERATT after
2626 * 3 seconds we still set HBA_ERROR state because the status of the
2627 * board is now undefined.
2629 ha_copy = readl(phba->HAregaddr);
2631 while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
2633 ha_copy = readl(phba->HAregaddr);
2636 del_timer_sync(&psli->mbox_tmo);
2637 if (ha_copy & HA_ERATT) {
2638 writel(HA_ERATT, phba->HAregaddr);
2639 phba->pport->stopped = 1;
2641 spin_lock_irq(&phba->hbalock);
2642 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2643 phba->link_flag &= ~LS_IGNORE_ERATT;
2644 spin_unlock_irq(&phba->hbalock);
2646 psli->mbox_active = NULL;
2647 lpfc_hba_down_post(phba);
2648 phba->link_state = LPFC_HBA_ERROR;
2650 return ha_copy & HA_ERATT ? 0 : 1;
2654 * lpfc_sli_brdreset: Reset the HBA.
2655 * @phba: Pointer to HBA context object.
2657 * This function resets the HBA by writing HC_INITFF to the control
2658 * register. After the HBA resets, this function resets all the iocb ring
2659 * indices. This function disables PCI layer parity checking during
2661 * This function returns 0 always.
2662 * The caller is not required to hold any locks.
2665 lpfc_sli_brdreset(struct lpfc_hba *phba)
2667 struct lpfc_sli *psli;
2668 struct lpfc_sli_ring *pring;
2675 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2676 "0325 Reset HBA Data: x%x x%x\n",
2677 phba->pport->port_state, psli->sli_flag);
2679 /* perform board reset */
2680 phba->fc_eventTag = 0;
2681 phba->pport->fc_myDID = 0;
2682 phba->pport->fc_prevDID = 0;
2684 /* Turn off parity checking and serr during the physical reset */
2685 pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
2686 pci_write_config_word(phba->pcidev, PCI_COMMAND,
2688 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
2690 psli->sli_flag &= ~(LPFC_SLI2_ACTIVE | LPFC_PROCESS_LA);
2691 /* Now toggle INITFF bit in the Host Control Register */
2692 writel(HC_INITFF, phba->HCregaddr);
2694 readl(phba->HCregaddr); /* flush */
2695 writel(0, phba->HCregaddr);
2696 readl(phba->HCregaddr); /* flush */
2698 /* Restore PCI cmd register */
2699 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
2701 /* Initialize relevant SLI info */
2702 for (i = 0; i < psli->num_rings; i++) {
2703 pring = &psli->ring[i];
2706 pring->next_cmdidx = 0;
2707 pring->local_getidx = 0;
2709 pring->missbufcnt = 0;
2712 phba->link_state = LPFC_WARM_START;
2717 * lpfc_sli_brdrestart: Restart the HBA.
2718 * @phba: Pointer to HBA context object.
2720 * This function is called in the SLI initialization code path to
2721 * restart the HBA. The caller is not required to hold any lock.
2722 * This function writes MBX_RESTART mailbox command to the SLIM and
2723 * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
2724 * function to free any pending commands. The function enables
2725 * POST only during the first initialization. The function returns zero.
2726 * The function does not guarantee completion of MBX_RESTART mailbox
2727 * command before the return of this function.
2730 lpfc_sli_brdrestart(struct lpfc_hba *phba)
2733 struct lpfc_sli *psli;
2734 volatile uint32_t word0;
2735 void __iomem *to_slim;
2737 spin_lock_irq(&phba->hbalock);
2742 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2743 "0337 Restart HBA Data: x%x x%x\n",
2744 phba->pport->port_state, psli->sli_flag);
2747 mb = (MAILBOX_t *) &word0;
2748 mb->mbxCommand = MBX_RESTART;
2751 lpfc_reset_barrier(phba);
2753 to_slim = phba->MBslimaddr;
2754 writel(*(uint32_t *) mb, to_slim);
2755 readl(to_slim); /* flush */
2757 /* Only skip post after fc_ffinit is completed */
2758 if (phba->pport->port_state)
2759 word0 = 1; /* This is really setting up word1 */
2761 word0 = 0; /* This is really setting up word1 */
2762 to_slim = phba->MBslimaddr + sizeof (uint32_t);
2763 writel(*(uint32_t *) mb, to_slim);
2764 readl(to_slim); /* flush */
2766 lpfc_sli_brdreset(phba);
2767 phba->pport->stopped = 0;
2768 phba->link_state = LPFC_INIT_START;
2770 spin_unlock_irq(&phba->hbalock);
2772 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
2773 psli->stats_start = get_seconds();
2775 /* Give the INITFF and Post time to settle. */
2778 lpfc_hba_down_post(phba);
2784 * lpfc_sli_chipset_init: Wait for the restart of the HBA after a restart.
2785 * @phba: Pointer to HBA context object.
2787 * This function is called after a HBA restart to wait for successful
2788 * restart of the HBA. Successful restart of the HBA is indicated by
2789 * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
2790 * iteration, the function will restart the HBA again. The function returns
2791 * zero if HBA successfully restarted else returns negative error code.
2794 lpfc_sli_chipset_init(struct lpfc_hba *phba)
2796 uint32_t status, i = 0;
2798 /* Read the HBA Host Status Register */
2799 status = readl(phba->HSregaddr);
2801 /* Check status register to see what current state is */
2803 while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
2805 /* Check every 100ms for 5 retries, then every 500ms for 5, then
2806 * every 2.5 sec for 5, then reset board and every 2.5 sec for
2810 /* Adapter failed to init, timeout, status reg
2812 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2813 "0436 Adapter failed to init, "
2814 "timeout, status reg x%x, "
2815 "FW Data: A8 x%x AC x%x\n", status,
2816 readl(phba->MBslimaddr + 0xa8),
2817 readl(phba->MBslimaddr + 0xac));
2818 phba->link_state = LPFC_HBA_ERROR;
2822 /* Check to see if any errors occurred during init */
2823 if (status & HS_FFERM) {
2824 /* ERROR: During chipset initialization */
2825 /* Adapter failed to init, chipset, status reg
2827 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2828 "0437 Adapter failed to init, "
2829 "chipset, status reg x%x, "
2830 "FW Data: A8 x%x AC x%x\n", status,
2831 readl(phba->MBslimaddr + 0xa8),
2832 readl(phba->MBslimaddr + 0xac));
2833 phba->link_state = LPFC_HBA_ERROR;
2839 } else if (i <= 10) {
2847 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
2848 lpfc_sli_brdrestart(phba);
2850 /* Read the HBA Host Status Register */
2851 status = readl(phba->HSregaddr);
2854 /* Check to see if any errors occurred during init */
2855 if (status & HS_FFERM) {
2856 /* ERROR: During chipset initialization */
2857 /* Adapter failed to init, chipset, status reg <status> */
2858 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2859 "0438 Adapter failed to init, chipset, "
2861 "FW Data: A8 x%x AC x%x\n", status,
2862 readl(phba->MBslimaddr + 0xa8),
2863 readl(phba->MBslimaddr + 0xac));
2864 phba->link_state = LPFC_HBA_ERROR;
2868 /* Clear all interrupt enable conditions */
2869 writel(0, phba->HCregaddr);
2870 readl(phba->HCregaddr); /* flush */
2872 /* setup host attn register */
2873 writel(0xffffffff, phba->HAregaddr);
2874 readl(phba->HAregaddr); /* flush */
2879 * lpfc_sli_hbq_count: Get the number of HBQs to be configured.
2881 * This function calculates and returns the number of HBQs required to be
2885 lpfc_sli_hbq_count(void)
2887 return ARRAY_SIZE(lpfc_hbq_defs);
2891 * lpfc_sli_hbq_entry_count: Calculate total number of hbq entries.
2893 * This function adds the number of hbq entries in every HBQ to get
2894 * the total number of hbq entries required for the HBA and returns
2898 lpfc_sli_hbq_entry_count(void)
2900 int hbq_count = lpfc_sli_hbq_count();
2904 for (i = 0; i < hbq_count; ++i)
2905 count += lpfc_hbq_defs[i]->entry_count;
2910 * lpfc_sli_hbq_size: Calculate memory required for all hbq entries.
2912 * This function calculates amount of memory required for all hbq entries
2913 * to be configured and returns the total memory required.
2916 lpfc_sli_hbq_size(void)
2918 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
2922 * lpfc_sli_hbq_setup: configure and initialize HBQs.
2923 * @phba: Pointer to HBA context object.
2925 * This function is called during the SLI initialization to configure
2926 * all the HBQs and post buffers to the HBQ. The caller is not
2927 * required to hold any locks. This function will return zero if successful
2928 * else it will return negative error code.
2931 lpfc_sli_hbq_setup(struct lpfc_hba *phba)
2933 int hbq_count = lpfc_sli_hbq_count();
2937 uint32_t hbq_entry_index;
2939 /* Get a Mailbox buffer to setup mailbox
2940 * commands for HBA initialization
2942 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2949 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
2950 phba->link_state = LPFC_INIT_MBX_CMDS;
2951 phba->hbq_in_use = 1;
2953 hbq_entry_index = 0;
2954 for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
2955 phba->hbqs[hbqno].next_hbqPutIdx = 0;
2956 phba->hbqs[hbqno].hbqPutIdx = 0;
2957 phba->hbqs[hbqno].local_hbqGetIdx = 0;
2958 phba->hbqs[hbqno].entry_count =
2959 lpfc_hbq_defs[hbqno]->entry_count;
2960 lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
2961 hbq_entry_index, pmb);
2962 hbq_entry_index += phba->hbqs[hbqno].entry_count;
2964 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
2965 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
2966 mbxStatus <status>, ring <num> */
2968 lpfc_printf_log(phba, KERN_ERR,
2969 LOG_SLI | LOG_VPORT,
2970 "1805 Adapter failed to init. "
2971 "Data: x%x x%x x%x\n",
2973 pmbox->mbxStatus, hbqno);
2975 phba->link_state = LPFC_HBA_ERROR;
2976 mempool_free(pmb, phba->mbox_mem_pool);