1 /*******************************************************************
 
   2  * This file is part of the Emulex Linux Device Driver for         *
 
   3  * Fibre Channel Host Bus Adapters.                                *
 
   4  * Copyright (C) 2004-2006 Emulex.  All rights reserved.           *
 
   5  * EMULEX and SLI are trademarks of Emulex.                        *
 
   7  * Portions Copyright (C) 2004-2005 Christoph Hellwig              *
 
   9  * This program is free software; you can redistribute it and/or   *
 
  10  * modify it under the terms of version 2 of the GNU General       *
 
  11  * Public License as published by the Free Software Foundation.    *
 
  12  * This program is distributed in the hope that it will be useful. *
 
  13  * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
 
  14  * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
 
  15  * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
 
  16  * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
 
  17  * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
 
  18  * more details, a copy of which can be found in the file COPYING  *
 
  19  * included with this package.                                     *
 
  20  *******************************************************************/
 
  22 #include <linux/blkdev.h>
 
  23 #include <linux/pci.h>
 
  24 #include <linux/kthread.h>
 
  25 #include <linux/interrupt.h>
 
  27 #include <scsi/scsi.h>
 
  28 #include <scsi/scsi_device.h>
 
  29 #include <scsi/scsi_host.h>
 
  30 #include <scsi/scsi_transport_fc.h>
 
  33 #include "lpfc_disc.h"
 
  35 #include "lpfc_scsi.h"
 
  37 #include "lpfc_logmsg.h"
 
  38 #include "lpfc_crtn.h"
 
  40 /* AlpaArray for assignment of scsid for scan-down and bind_method */
 
  41 static uint8_t lpfcAlpaArray[] = {
 
  42         0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
 
  43         0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
 
  44         0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
 
  45         0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
 
  46         0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
 
  47         0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
 
  48         0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
 
  49         0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
 
  50         0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
 
  51         0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
 
  52         0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
 
  53         0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
 
  54         0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
 
  57 static void lpfc_disc_timeout_handler(struct lpfc_hba *);
 
  60 lpfc_terminate_rport_io(struct fc_rport *rport)
 
  62         struct lpfc_rport_data *rdata;
 
  63         struct lpfc_nodelist * ndlp;
 
  64         struct lpfc_hba *phba;
 
  66         rdata = rport->dd_data;
 
  70                 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
 
  71                         printk(KERN_ERR "Cannot find remote node"
 
  72                         " to terminate I/O Data x%x\n",
 
  77         phba = ndlp->nlp_phba;
 
  79         spin_lock_irq(phba->host->host_lock);
 
  80         if (ndlp->nlp_sid != NLP_NO_SID) {
 
  81                 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
 
  82                         ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
 
  84         spin_unlock_irq(phba->host->host_lock);
 
  90  * This function will be called when dev_loss_tmo fire.
 
  93 lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
 
  95         struct lpfc_rport_data *rdata;
 
  96         struct lpfc_nodelist * ndlp;
 
  99         struct lpfc_hba *phba;
 
 101         rdata = rport->dd_data;
 
 105                 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
 
 106                         printk(KERN_ERR "Cannot find remote node"
 
 107                         " for rport in dev_loss_tmo_callbk x%x\n",
 
 112         name = (uint8_t *)&ndlp->nlp_portname;
 
 113         phba = ndlp->nlp_phba;
 
 115         spin_lock_irq(phba->host->host_lock);
 
 117         if (ndlp->nlp_sid != NLP_NO_SID) {
 
 119                 /* flush the target */
 
 120                 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
 
 121                         ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
 
 123         if (phba->fc_flag & FC_UNLOADING)
 
 126         spin_unlock_irq(phba->host->host_lock);
 
 129                 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
 
 130                                 "%d:0203 Devloss timeout on "
 
 131                                 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
 
 132                                 "NPort x%x Data: x%x x%x x%x\n",
 
 134                                 *name, *(name+1), *(name+2), *(name+3),
 
 135                                 *(name+4), *(name+5), *(name+6), *(name+7),
 
 136                                 ndlp->nlp_DID, ndlp->nlp_flag,
 
 137                                 ndlp->nlp_state, ndlp->nlp_rpi);
 
 139                 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
 
 140                                 "%d:0204 Devloss timeout on "
 
 141                                 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
 
 142                                 "NPort x%x Data: x%x x%x x%x\n",
 
 144                                 *name, *(name+1), *(name+2), *(name+3),
 
 145                                 *(name+4), *(name+5), *(name+6), *(name+7),
 
 146                                 ndlp->nlp_DID, ndlp->nlp_flag,
 
 147                                 ndlp->nlp_state, ndlp->nlp_rpi);
 
 153         if (!(phba->fc_flag & FC_UNLOADING))
 
 154                 lpfc_disc_state_machine(phba, ndlp, NULL, NLP_EVT_DEVICE_RM);
 
 160 lpfc_work_list_done(struct lpfc_hba * phba)
 
 162         struct lpfc_work_evt  *evtp = NULL;
 
 163         struct lpfc_nodelist  *ndlp;
 
 166         spin_lock_irq(phba->host->host_lock);
 
 167         while(!list_empty(&phba->work_list)) {
 
 168                 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
 
 170                 spin_unlock_irq(phba->host->host_lock);
 
 173                 case LPFC_EVT_ELS_RETRY:
 
 174                         ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
 
 175                         lpfc_els_retry_delay_handler(ndlp);
 
 178                 case LPFC_EVT_ONLINE:
 
 179                         if (phba->hba_state < LPFC_LINK_DOWN)
 
 180                                 *(int *)(evtp->evt_arg1)  = lpfc_online(phba);
 
 182                                 *(int *)(evtp->evt_arg1)  = 0;
 
 183                         complete((struct completion *)(evtp->evt_arg2));
 
 185                 case LPFC_EVT_OFFLINE:
 
 186                         if (phba->hba_state >= LPFC_LINK_DOWN)
 
 188                         lpfc_sli_brdrestart(phba);
 
 189                         *(int *)(evtp->evt_arg1) =
 
 190                                 lpfc_sli_brdready(phba,HS_FFRDY | HS_MBRDY);
 
 191                         complete((struct completion *)(evtp->evt_arg2));
 
 193                 case LPFC_EVT_WARM_START:
 
 194                         if (phba->hba_state >= LPFC_LINK_DOWN)
 
 196                         lpfc_reset_barrier(phba);
 
 197                         lpfc_sli_brdreset(phba);
 
 198                         lpfc_hba_down_post(phba);
 
 199                         *(int *)(evtp->evt_arg1) =
 
 200                                 lpfc_sli_brdready(phba, HS_MBRDY);
 
 201                         complete((struct completion *)(evtp->evt_arg2));
 
 204                         if (phba->hba_state >= LPFC_LINK_DOWN)
 
 206                         *(int *)(evtp->evt_arg1)
 
 207                                 = (phba->stopped) ? 0 : lpfc_sli_brdkill(phba);
 
 208                         complete((struct completion *)(evtp->evt_arg2));
 
 213                 spin_lock_irq(phba->host->host_lock);
 
 215         spin_unlock_irq(phba->host->host_lock);
 
 220 lpfc_work_done(struct lpfc_hba * phba)
 
 222         struct lpfc_sli_ring *pring;
 
 226         uint32_t work_hba_events;
 
 228         spin_lock_irq(phba->host->host_lock);
 
 229         ha_copy = phba->work_ha;
 
 231         work_hba_events=phba->work_hba_events;
 
 232         spin_unlock_irq(phba->host->host_lock);
 
 234         if (ha_copy & HA_ERATT)
 
 235                 lpfc_handle_eratt(phba);
 
 237         if (ha_copy & HA_MBATT)
 
 238                 lpfc_sli_handle_mb_event(phba);
 
 240         if (ha_copy & HA_LATT)
 
 241                 lpfc_handle_latt(phba);
 
 243         if (work_hba_events & WORKER_DISC_TMO)
 
 244                 lpfc_disc_timeout_handler(phba);
 
 246         if (work_hba_events & WORKER_ELS_TMO)
 
 247                 lpfc_els_timeout_handler(phba);
 
 249         if (work_hba_events & WORKER_MBOX_TMO)
 
 250                 lpfc_mbox_timeout_handler(phba);
 
 252         if (work_hba_events & WORKER_FDMI_TMO)
 
 253                 lpfc_fdmi_tmo_handler(phba);
 
 255         spin_lock_irq(phba->host->host_lock);
 
 256         phba->work_hba_events &= ~work_hba_events;
 
 257         spin_unlock_irq(phba->host->host_lock);
 
 259         for (i = 0; i < phba->sli.num_rings; i++, ha_copy >>= 4) {
 
 260                 pring = &phba->sli.ring[i];
 
 261                 if ((ha_copy & HA_RXATT)
 
 262                     || (pring->flag & LPFC_DEFERRED_RING_EVENT)) {
 
 263                         if (pring->flag & LPFC_STOP_IOCB_MASK) {
 
 264                                 pring->flag |= LPFC_DEFERRED_RING_EVENT;
 
 266                                 lpfc_sli_handle_slow_ring_event(phba, pring,
 
 269                                 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
 
 272                          * Turn on Ring interrupts
 
 274                         spin_lock_irq(phba->host->host_lock);
 
 275                         control = readl(phba->HCregaddr);
 
 276                         control |= (HC_R0INT_ENA << i);
 
 277                         writel(control, phba->HCregaddr);
 
 278                         readl(phba->HCregaddr); /* flush */
 
 279                         spin_unlock_irq(phba->host->host_lock);
 
 283         lpfc_work_list_done (phba);
 
 288 check_work_wait_done(struct lpfc_hba *phba) {
 
 290         spin_lock_irq(phba->host->host_lock);
 
 292             phba->work_hba_events ||
 
 293             (!list_empty(&phba->work_list)) ||
 
 294             kthread_should_stop()) {
 
 295                 spin_unlock_irq(phba->host->host_lock);
 
 298                 spin_unlock_irq(phba->host->host_lock);
 
 304 lpfc_do_work(void *p)
 
 306         struct lpfc_hba *phba = p;
 
 308         DECLARE_WAIT_QUEUE_HEAD_ONSTACK(work_waitq);
 
 310         set_user_nice(current, -20);
 
 311         phba->work_wait = &work_waitq;
 
 315                 rc = wait_event_interruptible(work_waitq,
 
 316                                                 check_work_wait_done(phba));
 
 319                 if (kthread_should_stop())
 
 322                 lpfc_work_done(phba);
 
 325         phba->work_wait = NULL;
 
 330  * This is only called to handle FC worker events. Since this a rare
 
 331  * occurance, we allocate a struct lpfc_work_evt structure here instead of
 
 332  * embedding it in the IOCB.
 
 335 lpfc_workq_post_event(struct lpfc_hba * phba, void *arg1, void *arg2,
 
 338         struct lpfc_work_evt  *evtp;
 
 341          * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
 
 342          * be queued to worker thread for processing
 
 344         evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_KERNEL);
 
 348         evtp->evt_arg1  = arg1;
 
 349         evtp->evt_arg2  = arg2;
 
 352         spin_lock_irq(phba->host->host_lock);
 
 353         list_add_tail(&evtp->evt_listp, &phba->work_list);
 
 355                 wake_up(phba->work_wait);
 
 356         spin_unlock_irq(phba->host->host_lock);
 
 362 lpfc_linkdown(struct lpfc_hba * phba)
 
 364         struct lpfc_sli       *psli;
 
 365         struct lpfc_nodelist  *ndlp, *next_ndlp;
 
 366         struct list_head *listp, *node_list[7];
 
 371         /* sysfs or selective reset may call this routine to clean up */
 
 372         if (phba->hba_state >= LPFC_LINK_DOWN) {
 
 373                 if (phba->hba_state == LPFC_LINK_DOWN)
 
 376                 spin_lock_irq(phba->host->host_lock);
 
 377                 phba->hba_state = LPFC_LINK_DOWN;
 
 378                 spin_unlock_irq(phba->host->host_lock);
 
 381         fc_host_post_event(phba->host, fc_get_event_number(),
 
 382                         FCH_EVT_LINKDOWN, 0);
 
 384         /* Clean up any firmware default rpi's */
 
 385         if ((mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
 
 386                 lpfc_unreg_did(phba, 0xffffffff, mb);
 
 387                 mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
 
 388                 if (lpfc_sli_issue_mbox(phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
 
 389                     == MBX_NOT_FINISHED) {
 
 390                         mempool_free( mb, phba->mbox_mem_pool);
 
 394         /* Cleanup any outstanding RSCN activity */
 
 395         lpfc_els_flush_rscn(phba);
 
 397         /* Cleanup any outstanding ELS commands */
 
 398         lpfc_els_flush_cmd(phba);
 
 400         /* Issue a LINK DOWN event to all nodes */
 
 401         node_list[0] = &phba->fc_npr_list;  /* MUST do this list first */
 
 402         node_list[1] = &phba->fc_nlpmap_list;
 
 403         node_list[2] = &phba->fc_nlpunmap_list;
 
 404         node_list[3] = &phba->fc_prli_list;
 
 405         node_list[4] = &phba->fc_reglogin_list;
 
 406         node_list[5] = &phba->fc_adisc_list;
 
 407         node_list[6] = &phba->fc_plogi_list;
 
 408         for (i = 0; i < 7; i++) {
 
 409                 listp = node_list[i];
 
 410                 if (list_empty(listp))
 
 413                 list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
 
 415                         rc = lpfc_disc_state_machine(phba, ndlp, NULL,
 
 416                                              NLP_EVT_DEVICE_RECOVERY);
 
 421         /* free any ndlp's on unused list */
 
 422         list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
 
 424                 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
 
 427         /* Setup myDID for link up if we are in pt2pt mode */
 
 428         if (phba->fc_flag & FC_PT2PT) {
 
 430                 if ((mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
 
 431                         lpfc_config_link(phba, mb);
 
 432                         mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
 
 433                         if (lpfc_sli_issue_mbox
 
 434                             (phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
 
 435                             == MBX_NOT_FINISHED) {
 
 436                                 mempool_free( mb, phba->mbox_mem_pool);
 
 439                 spin_lock_irq(phba->host->host_lock);
 
 440                 phba->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
 
 441                 spin_unlock_irq(phba->host->host_lock);
 
 443         spin_lock_irq(phba->host->host_lock);
 
 444         phba->fc_flag &= ~FC_LBIT;
 
 445         spin_unlock_irq(phba->host->host_lock);
 
 447         /* Turn off discovery timer if its running */
 
 448         lpfc_can_disctmo(phba);
 
 450         /* Must process IOCBs on all rings to handle ABORTed I/Os */
 
 455 lpfc_linkup(struct lpfc_hba * phba)
 
 457         struct lpfc_nodelist *ndlp, *next_ndlp;
 
 458         struct list_head *listp, *node_list[7];
 
 461         fc_host_post_event(phba->host, fc_get_event_number(),
 
 464         spin_lock_irq(phba->host->host_lock);
 
 465         phba->hba_state = LPFC_LINK_UP;
 
 466         phba->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
 
 467                            FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
 
 468         phba->fc_flag |= FC_NDISC_ACTIVE;
 
 469         phba->fc_ns_retry = 0;
 
 470         spin_unlock_irq(phba->host->host_lock);
 
 473         node_list[0] = &phba->fc_plogi_list;
 
 474         node_list[1] = &phba->fc_adisc_list;
 
 475         node_list[2] = &phba->fc_reglogin_list;
 
 476         node_list[3] = &phba->fc_prli_list;
 
 477         node_list[4] = &phba->fc_nlpunmap_list;
 
 478         node_list[5] = &phba->fc_nlpmap_list;
 
 479         node_list[6] = &phba->fc_npr_list;
 
 480         for (i = 0; i < 7; i++) {
 
 481                 listp = node_list[i];
 
 482                 if (list_empty(listp))
 
 485                 list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
 
 486                         if (phba->fc_flag & FC_LBIT) {
 
 487                                 if (ndlp->nlp_type & NLP_FABRIC) {
 
 488                                         /* On Linkup its safe to clean up the
 
 489                                          * ndlp from Fabric connections.
 
 491                                         lpfc_nlp_list(phba, ndlp,
 
 493                                 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
 
 494                                         /* Fail outstanding IO now since device
 
 495                                          * is marked for PLOGI.
 
 497                                         lpfc_unreg_rpi(phba, ndlp);
 
 503         /* free any ndlp's on unused list */
 
 504         list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
 
 506                 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
 
 513  * This routine handles processing a CLEAR_LA mailbox
 
 514  * command upon completion. It is setup in the LPFC_MBOXQ
 
 515  * as the completion routine when the command is
 
 516  * handed off to the SLI layer.
 
 519 lpfc_mbx_cmpl_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
 
 521         struct lpfc_sli *psli;
 
 527         /* Since we don't do discovery right now, turn these off here */
 
 528         psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
 
 529         psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
 
 530         psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
 
 532         /* Check for error */
 
 533         if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
 
 534                 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
 
 535                 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
 
 536                                 "%d:0320 CLEAR_LA mbxStatus error x%x hba "
 
 538                                 phba->brd_no, mb->mbxStatus, phba->hba_state);
 
 540                 phba->hba_state = LPFC_HBA_ERROR;
 
 544         if (phba->fc_flag & FC_ABORT_DISCOVERY)
 
 547         phba->num_disc_nodes = 0;
 
 548         /* go thru NPR list and issue ELS PLOGIs */
 
 549         if (phba->fc_npr_cnt) {
 
 550                 lpfc_els_disc_plogi(phba);
 
 553         if (!phba->num_disc_nodes) {
 
 554                 spin_lock_irq(phba->host->host_lock);
 
 555                 phba->fc_flag &= ~FC_NDISC_ACTIVE;
 
 556                 spin_unlock_irq(phba->host->host_lock);
 
 559         phba->hba_state = LPFC_HBA_READY;
 
 562         /* Device Discovery completes */
 
 563         lpfc_printf_log(phba,
 
 566                          "%d:0225 Device Discovery completes\n",
 
 569         mempool_free( pmb, phba->mbox_mem_pool);
 
 571         spin_lock_irq(phba->host->host_lock);
 
 572         phba->fc_flag &= ~FC_ABORT_DISCOVERY;
 
 573         if (phba->fc_flag & FC_ESTABLISH_LINK) {
 
 574                 phba->fc_flag &= ~FC_ESTABLISH_LINK;
 
 576         spin_unlock_irq(phba->host->host_lock);
 
 578         del_timer_sync(&phba->fc_estabtmo);
 
 580         lpfc_can_disctmo(phba);
 
 582         /* turn on Link Attention interrupts */
 
 583         spin_lock_irq(phba->host->host_lock);
 
 584         psli->sli_flag |= LPFC_PROCESS_LA;
 
 585         control = readl(phba->HCregaddr);
 
 586         control |= HC_LAINT_ENA;
 
 587         writel(control, phba->HCregaddr);
 
 588         readl(phba->HCregaddr); /* flush */
 
 589         spin_unlock_irq(phba->host->host_lock);
 
 595 lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
 
 597         struct lpfc_sli *psli = &phba->sli;
 
 600         if (pmb->mb.mbxStatus)
 
 603         mempool_free(pmb, phba->mbox_mem_pool);
 
 605         if (phba->fc_topology == TOPOLOGY_LOOP &&
 
 606                 phba->fc_flag & FC_PUBLIC_LOOP &&
 
 607                  !(phba->fc_flag & FC_LBIT)) {
 
 608                         /* Need to wait for FAN - use discovery timer
 
 609                          * for timeout.  hba_state is identically
 
 610                          * LPFC_LOCAL_CFG_LINK while waiting for FAN
 
 612                         lpfc_set_disctmo(phba);
 
 616         /* Start discovery by sending a FLOGI. hba_state is identically
 
 617          * LPFC_FLOGI while waiting for FLOGI cmpl
 
 619         phba->hba_state = LPFC_FLOGI;
 
 620         lpfc_set_disctmo(phba);
 
 621         lpfc_initial_flogi(phba);
 
 625         lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
 
 626                         "%d:0306 CONFIG_LINK mbxStatus error x%x "
 
 628                         phba->brd_no, pmb->mb.mbxStatus, phba->hba_state);
 
 632         phba->hba_state = LPFC_HBA_ERROR;
 
 634         lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
 
 635                         "%d:0200 CONFIG_LINK bad hba state x%x\n",
 
 636                         phba->brd_no, phba->hba_state);
 
 638         lpfc_clear_la(phba, pmb);
 
 639         pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
 
 640         rc = lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB));
 
 641         if (rc == MBX_NOT_FINISHED) {
 
 642                 mempool_free(pmb, phba->mbox_mem_pool);
 
 643                 lpfc_disc_flush_list(phba);
 
 644                 psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
 
 645                 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
 
 646                 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
 
 647                 phba->hba_state = LPFC_HBA_READY;
 
 653 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
 
 655         struct lpfc_sli *psli = &phba->sli;
 
 656         MAILBOX_t *mb = &pmb->mb;
 
 657         struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
 
 660         /* Check for error */
 
 662                 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
 
 663                 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
 
 664                                 "%d:0319 READ_SPARAM mbxStatus error x%x "
 
 666                                 phba->brd_no, mb->mbxStatus, phba->hba_state);
 
 669                 phba->hba_state = LPFC_HBA_ERROR;
 
 673         memcpy((uint8_t *) & phba->fc_sparam, (uint8_t *) mp->virt,
 
 674                sizeof (struct serv_parm));
 
 675         if (phba->cfg_soft_wwnn)
 
 676                 u64_to_wwn(phba->cfg_soft_wwnn, phba->fc_sparam.nodeName.u.wwn);
 
 677         if (phba->cfg_soft_wwpn)
 
 678                 u64_to_wwn(phba->cfg_soft_wwpn, phba->fc_sparam.portName.u.wwn);
 
 679         memcpy((uint8_t *) & phba->fc_nodename,
 
 680                (uint8_t *) & phba->fc_sparam.nodeName,
 
 681                sizeof (struct lpfc_name));
 
 682         memcpy((uint8_t *) & phba->fc_portname,
 
 683                (uint8_t *) & phba->fc_sparam.portName,
 
 684                sizeof (struct lpfc_name));
 
 685         lpfc_mbuf_free(phba, mp->virt, mp->phys);
 
 687         mempool_free( pmb, phba->mbox_mem_pool);
 
 691         pmb->context1 = NULL;
 
 692         lpfc_mbuf_free(phba, mp->virt, mp->phys);
 
 694         if (phba->hba_state != LPFC_CLEAR_LA) {
 
 695                 lpfc_clear_la(phba, pmb);
 
 696                 pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
 
 697                 if (lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB))
 
 698                     == MBX_NOT_FINISHED) {
 
 699                         mempool_free( pmb, phba->mbox_mem_pool);
 
 700                         lpfc_disc_flush_list(phba);
 
 701                         psli->ring[(psli->extra_ring)].flag &=
 
 702                             ~LPFC_STOP_IOCB_EVENT;
 
 703                         psli->ring[(psli->fcp_ring)].flag &=
 
 704                             ~LPFC_STOP_IOCB_EVENT;
 
 705                         psli->ring[(psli->next_ring)].flag &=
 
 706                             ~LPFC_STOP_IOCB_EVENT;
 
 707                         phba->hba_state = LPFC_HBA_READY;
 
 710                 mempool_free( pmb, phba->mbox_mem_pool);
 
 716 lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
 
 719         LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox;
 
 720         struct lpfc_dmabuf *mp;
 
 723         sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
 
 724         cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
 
 726         spin_lock_irq(phba->host->host_lock);
 
 727         switch (la->UlnkSpeed) {
 
 729                         phba->fc_linkspeed = LA_1GHZ_LINK;
 
 732                         phba->fc_linkspeed = LA_2GHZ_LINK;
 
 735                         phba->fc_linkspeed = LA_4GHZ_LINK;
 
 738                         phba->fc_linkspeed = LA_UNKNW_LINK;
 
 742         phba->fc_topology = la->topology;
 
 744         if (phba->fc_topology == TOPOLOGY_LOOP) {
 
 745         /* Get Loop Map information */
 
 748                         phba->fc_flag |= FC_LBIT;
 
 750                 phba->fc_myDID = la->granted_AL_PA;
 
 751                 i = la->un.lilpBde64.tus.f.bdeSize;
 
 754                         phba->alpa_map[0] = 0;
 
 756                         if (phba->cfg_log_verbose & LOG_LINK_EVENT) {
 
 767                                 numalpa = phba->alpa_map[0];
 
 769                                 while (j < numalpa) {
 
 770                                         memset(un.pamap, 0, 16);
 
 771                                         for (k = 1; j < numalpa; k++) {
 
 773                                                         phba->alpa_map[j + 1];
 
 778                                         /* Link Up Event ALPA map */
 
 779                                         lpfc_printf_log(phba,
 
 782                                                 "%d:1304 Link Up Event "
 
 783                                                 "ALPA map Data: x%x "
 
 786                                                 un.pa.wd1, un.pa.wd2,
 
 787                                                 un.pa.wd3, un.pa.wd4);
 
 792                 phba->fc_myDID = phba->fc_pref_DID;
 
 793                 phba->fc_flag |= FC_LBIT;
 
 795         spin_unlock_irq(phba->host->host_lock);
 
 799                 lpfc_read_sparam(phba, sparam_mbox);
 
 800                 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
 
 801                 rc = lpfc_sli_issue_mbox(phba, sparam_mbox,
 
 802                                                 (MBX_NOWAIT | MBX_STOP_IOCB));
 
 803                 if (rc == MBX_NOT_FINISHED) {
 
 804                         mp = (struct lpfc_dmabuf *) sparam_mbox->context1;
 
 805                         lpfc_mbuf_free(phba, mp->virt, mp->phys);
 
 807                         mempool_free(sparam_mbox, phba->mbox_mem_pool);
 
 809                                 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
 
 815                 phba->hba_state = LPFC_LOCAL_CFG_LINK;
 
 816                 lpfc_config_link(phba, cfglink_mbox);
 
 817                 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
 
 818                 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox,
 
 819                                                 (MBX_NOWAIT | MBX_STOP_IOCB));
 
 820                 if (rc == MBX_NOT_FINISHED)
 
 821                         mempool_free(cfglink_mbox, phba->mbox_mem_pool);
 
 826 lpfc_mbx_issue_link_down(struct lpfc_hba *phba) {
 
 828         struct lpfc_sli *psli = &phba->sli;
 
 832         /* turn on Link Attention interrupts - no CLEAR_LA needed */
 
 833         spin_lock_irq(phba->host->host_lock);
 
 834         psli->sli_flag |= LPFC_PROCESS_LA;
 
 835         control = readl(phba->HCregaddr);
 
 836         control |= HC_LAINT_ENA;
 
 837         writel(control, phba->HCregaddr);
 
 838         readl(phba->HCregaddr); /* flush */
 
 839         spin_unlock_irq(phba->host->host_lock);
 
 843  * This routine handles processing a READ_LA mailbox
 
 844  * command upon completion. It is setup in the LPFC_MBOXQ
 
 845  * as the completion routine when the command is
 
 846  * handed off to the SLI layer.
 
 849 lpfc_mbx_cmpl_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
 
 852         MAILBOX_t *mb = &pmb->mb;
 
 853         struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
 
 855         /* Check for error */
 
 857                 lpfc_printf_log(phba,
 
 860                                 "%d:1307 READ_LA mbox error x%x state x%x\n",
 
 862                                 mb->mbxStatus, phba->hba_state);
 
 863                 lpfc_mbx_issue_link_down(phba);
 
 864                 phba->hba_state = LPFC_HBA_ERROR;
 
 865                 goto lpfc_mbx_cmpl_read_la_free_mbuf;
 
 868         la = (READ_LA_VAR *) & pmb->mb.un.varReadLA;
 
 870         memcpy(&phba->alpa_map[0], mp->virt, 128);
 
 872         spin_lock_irq(phba->host->host_lock);
 
 874                 phba->fc_flag |= FC_BYPASSED_MODE;
 
 876                 phba->fc_flag &= ~FC_BYPASSED_MODE;
 
 877         spin_unlock_irq(phba->host->host_lock);
 
 879         if (((phba->fc_eventTag + 1) < la->eventTag) ||
 
 880              (phba->fc_eventTag == la->eventTag)) {
 
 881                 phba->fc_stat.LinkMultiEvent++;
 
 882                 if (la->attType == AT_LINK_UP) {
 
 883                         if (phba->fc_eventTag != 0)
 
 888         phba->fc_eventTag = la->eventTag;
 
 890         if (la->attType == AT_LINK_UP) {
 
 891                 phba->fc_stat.LinkUp++;
 
 892                 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
 
 893                                 "%d:1303 Link Up Event x%x received "
 
 894                                 "Data: x%x x%x x%x x%x\n",
 
 895                                 phba->brd_no, la->eventTag, phba->fc_eventTag,
 
 896                                 la->granted_AL_PA, la->UlnkSpeed,
 
 898                 lpfc_mbx_process_link_up(phba, la);
 
 900                 phba->fc_stat.LinkDown++;
 
 901                 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
 
 902                                 "%d:1305 Link Down Event x%x received "
 
 903                                 "Data: x%x x%x x%x\n",
 
 904                                 phba->brd_no, la->eventTag, phba->fc_eventTag,
 
 905                                 phba->hba_state, phba->fc_flag);
 
 906                 lpfc_mbx_issue_link_down(phba);
 
 909 lpfc_mbx_cmpl_read_la_free_mbuf:
 
 910         lpfc_mbuf_free(phba, mp->virt, mp->phys);
 
 912         mempool_free(pmb, phba->mbox_mem_pool);
 
 917  * This routine handles processing a REG_LOGIN mailbox
 
 918  * command upon completion. It is setup in the LPFC_MBOXQ
 
 919  * as the completion routine when the command is
 
 920  * handed off to the SLI layer.
 
 923 lpfc_mbx_cmpl_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
 
 925         struct lpfc_sli *psli;
 
 927         struct lpfc_dmabuf *mp;
 
 928         struct lpfc_nodelist *ndlp;
 
 933         ndlp = (struct lpfc_nodelist *) pmb->context2;
 
 934         mp = (struct lpfc_dmabuf *) (pmb->context1);
 
 936         pmb->context1 = NULL;
 
 938         /* Good status, call state machine */
 
 939         lpfc_disc_state_machine(phba, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
 
 940         lpfc_mbuf_free(phba, mp->virt, mp->phys);
 
 942         mempool_free( pmb, phba->mbox_mem_pool);
 
 948  * This routine handles processing a Fabric REG_LOGIN mailbox
 
 949  * command upon completion. It is setup in the LPFC_MBOXQ
 
 950  * as the completion routine when the command is
 
 951  * handed off to the SLI layer.
 
 954 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
 
 956         struct lpfc_sli *psli;
 
 958         struct lpfc_dmabuf *mp;
 
 959         struct lpfc_nodelist *ndlp;
 
 960         struct lpfc_nodelist *ndlp_fdmi;
 
 966         ndlp = (struct lpfc_nodelist *) pmb->context2;
 
 967         mp = (struct lpfc_dmabuf *) (pmb->context1);
 
 970                 lpfc_mbuf_free(phba, mp->virt, mp->phys);
 
 972                 mempool_free( pmb, phba->mbox_mem_pool);
 
 973                 mempool_free( ndlp, phba->nlp_mem_pool);
 
 975                 /* FLOGI failed, so just use loop map to make discovery list */
 
 976                 lpfc_disc_list_loopmap(phba);
 
 978                 /* Start discovery */
 
 979                 lpfc_disc_start(phba);
 
 983         pmb->context1 = NULL;
 
 985         ndlp->nlp_rpi = mb->un.varWords[0];
 
 986         ndlp->nlp_type |= NLP_FABRIC;
 
 987         ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
 
 988         lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
 
 990         if (phba->hba_state == LPFC_FABRIC_CFG_LINK) {
 
 991                 /* This NPort has been assigned an NPort_ID by the fabric as a
 
 992                  * result of the completed fabric login.  Issue a State Change
 
 993                  * Registration (SCR) ELS request to the fabric controller
 
 994                  * (SCR_DID) so that this NPort gets RSCN events from the
 
 997                 lpfc_issue_els_scr(phba, SCR_DID, 0);
 
 999                 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
 
1001                         /* Allocate a new node instance. If the pool is empty,
 
1002                          * start the discovery process and skip the Nameserver
 
1003                          * login process.  This is attempted again later on.
 
1004                          * Otherwise, issue a Port Login (PLOGI) to NameServer.
 
1006                         ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
 
1008                                 lpfc_disc_start(phba);
 
1009                                 lpfc_mbuf_free(phba, mp->virt, mp->phys);
 
1011                                 mempool_free( pmb, phba->mbox_mem_pool);
 
1014                                 lpfc_nlp_init(phba, ndlp, NameServer_DID);
 
1015                                 ndlp->nlp_type |= NLP_FABRIC;
 
1018                 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
 
1019                 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
 
1020                 lpfc_issue_els_plogi(phba, NameServer_DID, 0);
 
1021                 if (phba->cfg_fdmi_on) {
 
1022                         ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
 
1025                                 lpfc_nlp_init(phba, ndlp_fdmi, FDMI_DID);
 
1026                                 ndlp_fdmi->nlp_type |= NLP_FABRIC;
 
1027                                 ndlp_fdmi->nlp_state = NLP_STE_PLOGI_ISSUE;
 
1028                                 lpfc_issue_els_plogi(phba, FDMI_DID, 0);
 
1033         lpfc_mbuf_free(phba, mp->virt, mp->phys);
 
1035         mempool_free( pmb, phba->mbox_mem_pool);
 
1040  * This routine handles processing a NameServer REG_LOGIN mailbox
 
1041  * command upon completion. It is setup in the LPFC_MBOXQ
 
1042  * as the completion routine when the command is
 
1043  * handed off to the SLI layer.
 
1046 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
 
1048         struct lpfc_sli *psli;
 
1050         struct lpfc_dmabuf *mp;
 
1051         struct lpfc_nodelist *ndlp;
 
1056         ndlp = (struct lpfc_nodelist *) pmb->context2;
 
1057         mp = (struct lpfc_dmabuf *) (pmb->context1);
 
1059         if (mb->mbxStatus) {
 
1060                 lpfc_mbuf_free(phba, mp->virt, mp->phys);
 
1062                 mempool_free( pmb, phba->mbox_mem_pool);
 
1063                 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
 
1065                 /* RegLogin failed, so just use loop map to make discovery
 
1067                 lpfc_disc_list_loopmap(phba);
 
1069                 /* Start discovery */
 
1070                 lpfc_disc_start(phba);
 
1074         pmb->context1 = NULL;
 
1076         ndlp->nlp_rpi = mb->un.varWords[0];
 
1077         ndlp->nlp_type |= NLP_FABRIC;
 
1078         ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
 
1079         lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
 
1081         if (phba->hba_state < LPFC_HBA_READY) {
 
1082                 /* Link up discovery requires Fabrib registration. */
 
1083                 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RNN_ID);
 
1084                 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RSNN_NN);
 
1085                 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RFT_ID);
 
1086                 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RFF_ID);
 
1089         phba->fc_ns_retry = 0;
 
1090         /* Good status, issue CT Request to NameServer */
 
1091         if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT)) {
 
1092                 /* Cannot issue NameServer Query, so finish up discovery */
 
1093                 lpfc_disc_start(phba);
 
1096         lpfc_mbuf_free(phba, mp->virt, mp->phys);
 
1098         mempool_free( pmb, phba->mbox_mem_pool);
 
1104 lpfc_register_remote_port(struct lpfc_hba * phba,
 
1105                             struct lpfc_nodelist * ndlp)
 
1107         struct fc_rport *rport;
 
1108         struct lpfc_rport_data *rdata;
 
1109         struct fc_rport_identifiers rport_ids;
 
1111         /* Remote port has reappeared. Re-register w/ FC transport */
 
1112         rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
 
1113         rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
 
1114         rport_ids.port_id = ndlp->nlp_DID;
 
1115         rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
 
1117         ndlp->rport = rport = fc_remote_port_add(phba->host, 0, &rport_ids);
 
1119                 dev_printk(KERN_WARNING, &phba->pcidev->dev,
 
1120                            "Warning: fc_remote_port_add failed\n");
 
1124         /* initialize static port data */
 
1125         rport->maxframe_size = ndlp->nlp_maxframe;
 
1126         rport->supported_classes = ndlp->nlp_class_sup;
 
1127         rdata = rport->dd_data;
 
1128         rdata->pnode = ndlp;
 
1130         if (ndlp->nlp_type & NLP_FCP_TARGET)
 
1131                 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
 
1132         if (ndlp->nlp_type & NLP_FCP_INITIATOR)
 
1133                 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
 
1136         if (rport_ids.roles !=  FC_RPORT_ROLE_UNKNOWN)
 
1137                 fc_remote_port_rolechg(rport, rport_ids.roles);
 
1139         if ((rport->scsi_target_id != -1) &&
 
1140                 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
 
1141                 ndlp->nlp_sid = rport->scsi_target_id;
 
1148 lpfc_unregister_remote_port(struct lpfc_hba * phba,
 
1149                             struct lpfc_nodelist * ndlp)
 
1151         struct fc_rport *rport = ndlp->rport;
 
1152         struct lpfc_rport_data *rdata = rport->dd_data;
 
1154         if (rport->scsi_target_id == -1) {
 
1156                 rdata->pnode = NULL;
 
1159         fc_remote_port_delete(rport);
 
1165 lpfc_nlp_list(struct lpfc_hba * phba, struct lpfc_nodelist * nlp, int list)
 
1167         enum { none, unmapped, mapped } rport_add = none, rport_del = none;
 
1168         struct lpfc_sli      *psli;
 
1171         /* Sanity check to ensure we are not moving to / from the same list */
 
1172         if ((nlp->nlp_flag & NLP_LIST_MASK) == list)
 
1173                 if (list != NLP_NO_LIST)
 
1176         spin_lock_irq(phba->host->host_lock);
 
1177         switch (nlp->nlp_flag & NLP_LIST_MASK) {
 
1178         case NLP_NO_LIST: /* Not on any list */
 
1180         case NLP_UNUSED_LIST:
 
1181                 phba->fc_unused_cnt--;
 
1182                 list_del(&nlp->nlp_listp);
 
1184         case NLP_PLOGI_LIST:
 
1185                 phba->fc_plogi_cnt--;
 
1186                 list_del(&nlp->nlp_listp);
 
1188         case NLP_ADISC_LIST:
 
1189                 phba->fc_adisc_cnt--;
 
1190                 list_del(&nlp->nlp_listp);
 
1192         case NLP_REGLOGIN_LIST:
 
1193                 phba->fc_reglogin_cnt--;
 
1194                 list_del(&nlp->nlp_listp);
 
1197                 phba->fc_prli_cnt--;
 
1198                 list_del(&nlp->nlp_listp);
 
1200         case NLP_UNMAPPED_LIST:
 
1201                 phba->fc_unmap_cnt--;
 
1202                 list_del(&nlp->nlp_listp);
 
1203                 nlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
 
1204                 nlp->nlp_type &= ~NLP_FC_NODE;
 
1205                 phba->nport_event_cnt++;
 
1207                         rport_del = unmapped;
 
1209         case NLP_MAPPED_LIST:
 
1211                 list_del(&nlp->nlp_listp);
 
1212                 phba->nport_event_cnt++;
 
1218                 list_del(&nlp->nlp_listp);
 
1219                 /* Stop delay tmo if taking node off NPR list */
 
1220                 if ((nlp->nlp_flag & NLP_DELAY_TMO) &&
 
1221                    (list != NLP_NPR_LIST)) {
 
1222                         spin_unlock_irq(phba->host->host_lock);
 
1223                         lpfc_cancel_retry_delay_tmo(phba, nlp);
 
1224                         spin_lock_irq(phba->host->host_lock);
 
1229         nlp->nlp_flag &= ~NLP_LIST_MASK;
 
1231         /* Add NPort <did> to <num> list */
 
1232         lpfc_printf_log(phba,
 
1235                         "%d:0904 Add NPort x%x to %d list Data: x%x\n",
 
1237                         nlp->nlp_DID, list, nlp->nlp_flag);
 
1240         case NLP_NO_LIST: /* No list, just remove it */
 
1241                 spin_unlock_irq(phba->host->host_lock);
 
1242                 lpfc_nlp_remove(phba, nlp);
 
1243                 spin_lock_irq(phba->host->host_lock);
 
1244                 /* as node removed - stop further transport calls */
 
1247         case NLP_UNUSED_LIST:
 
1248                 nlp->nlp_flag |= list;
 
1249                 /* Put it at the end of the unused list */
 
1250                 list_add_tail(&nlp->nlp_listp, &phba->fc_unused_list);
 
1251                 phba->fc_unused_cnt++;
 
1253         case NLP_PLOGI_LIST:
 
1254                 nlp->nlp_flag |= list;
 
1255                 /* Put it at the end of the plogi list */
 
1256                 list_add_tail(&nlp->nlp_listp, &phba->fc_plogi_list);
 
1257                 phba->fc_plogi_cnt++;
 
1259         case NLP_ADISC_LIST:
 
1260                 nlp->nlp_flag |= list;
 
1261                 /* Put it at the end of the adisc list */
 
1262                 list_add_tail(&nlp->nlp_listp, &phba->fc_adisc_list);
 
1263                 phba->fc_adisc_cnt++;
 
1265         case NLP_REGLOGIN_LIST:
 
1266                 nlp->nlp_flag |= list;
 
1267                 /* Put it at the end of the reglogin list */
 
1268                 list_add_tail(&nlp->nlp_listp, &phba->fc_reglogin_list);
 
1269                 phba->fc_reglogin_cnt++;
 
1272                 nlp->nlp_flag |= list;
 
1273                 /* Put it at the end of the prli list */
 
1274                 list_add_tail(&nlp->nlp_listp, &phba->fc_prli_list);
 
1275                 phba->fc_prli_cnt++;
 
1277         case NLP_UNMAPPED_LIST:
 
1278                 rport_add = unmapped;
 
1279                 /* ensure all vestiges of "mapped" significance are gone */
 
1280                 nlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
 
1281                 nlp->nlp_flag |= list;
 
1282                 /* Put it at the end of the unmap list */
 
1283                 list_add_tail(&nlp->nlp_listp, &phba->fc_nlpunmap_list);
 
1284                 phba->fc_unmap_cnt++;
 
1285                 phba->nport_event_cnt++;
 
1286                 nlp->nlp_flag &= ~NLP_NODEV_REMOVE;
 
1287                 nlp->nlp_type |= NLP_FC_NODE;
 
1289         case NLP_MAPPED_LIST:
 
1291                 nlp->nlp_flag |= list;
 
1292                 /* Put it at the end of the map list */
 
1293                 list_add_tail(&nlp->nlp_listp, &phba->fc_nlpmap_list);
 
1295                 phba->nport_event_cnt++;
 
1296                 nlp->nlp_flag &= ~NLP_NODEV_REMOVE;
 
1299                 nlp->nlp_flag |= list;
 
1300                 /* Put it at the end of the npr list */
 
1301                 list_add_tail(&nlp->nlp_listp, &phba->fc_npr_list);
 
1304                 nlp->nlp_flag &= ~NLP_RCV_PLOGI;
 
1310         spin_unlock_irq(phba->host->host_lock);
 
1313          * We make all the calls into the transport after we have
 
1314          * moved the node between lists. This so that we don't
 
1315          * release the lock while in-between lists.
 
1318         /* Don't upcall midlayer if we're unloading */
 
1319         if (!(phba->fc_flag & FC_UNLOADING)) {
 
1321                  * We revalidate the rport pointer as the "add" function
 
1322                  * may have removed the remote port.
 
1324                 if ((rport_del != none) && nlp->rport)
 
1325                         lpfc_unregister_remote_port(phba, nlp);
 
1327                 if (rport_add != none) {
 
1329                          * Tell the fc transport about the port, if we haven't
 
1330                          * already. If we have, and it's a scsi entity, be
 
1331                          * sure to unblock any attached scsi devices
 
1333                         if ((!nlp->rport) || (nlp->rport->port_state ==
 
1334                                         FC_PORTSTATE_BLOCKED))
 
1335                                 lpfc_register_remote_port(phba, nlp);
 
1338                          * if we added to Mapped list, but the remote port
 
1339                          * registration failed or assigned a target id outside
 
1340                          * our presentable range - move the node to the
 
1343                         if ((rport_add == mapped) &&
 
1345                              (nlp->rport->scsi_target_id == -1) ||
 
1346                              (nlp->rport->scsi_target_id >= LPFC_MAX_TARGET))) {
 
1347                                 nlp->nlp_state = NLP_STE_UNMAPPED_NODE;
 
1348                                 spin_lock_irq(phba->host->host_lock);
 
1349                                 nlp->nlp_flag |= NLP_TGT_NO_SCSIID;
 
1350                                 spin_unlock_irq(phba->host->host_lock);
 
1351                                 lpfc_nlp_list(phba, nlp, NLP_UNMAPPED_LIST);
 
1359  * Start / ReStart rescue timer for Discovery / RSCN handling
 
1362 lpfc_set_disctmo(struct lpfc_hba * phba)
 
1366         if (phba->hba_state == LPFC_LOCAL_CFG_LINK) {
 
1367                 /* For FAN, timeout should be greater then edtov */
 
1368                 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
 
1370                 /* Normal discovery timeout should be > then ELS/CT timeout
 
1371                  * FC spec states we need 3 * ratov for CT requests
 
1373                 tmo = ((phba->fc_ratov * 3) + 3);
 
1376         mod_timer(&phba->fc_disctmo, jiffies + HZ * tmo);
 
1377         spin_lock_irq(phba->host->host_lock);
 
1378         phba->fc_flag |= FC_DISC_TMO;
 
1379         spin_unlock_irq(phba->host->host_lock);
 
1381         /* Start Discovery Timer state <hba_state> */
 
1382         lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
 
1383                         "%d:0247 Start Discovery Timer state x%x "
 
1384                         "Data: x%x x%lx x%x x%x\n",
 
1386                         phba->hba_state, tmo, (unsigned long)&phba->fc_disctmo,
 
1387                         phba->fc_plogi_cnt, phba->fc_adisc_cnt);
 
1393  * Cancel rescue timer for Discovery / RSCN handling
 
1396 lpfc_can_disctmo(struct lpfc_hba * phba)
 
1398         /* Turn off discovery timer if its running */
 
1399         if (phba->fc_flag & FC_DISC_TMO) {
 
1400                 spin_lock_irq(phba->host->host_lock);
 
1401                 phba->fc_flag &= ~FC_DISC_TMO;
 
1402                 spin_unlock_irq(phba->host->host_lock);
 
1403                 del_timer_sync(&phba->fc_disctmo);
 
1404                 phba->work_hba_events &= ~WORKER_DISC_TMO;
 
1407         /* Cancel Discovery Timer state <hba_state> */
 
1408         lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
 
1409                         "%d:0248 Cancel Discovery Timer state x%x "
 
1410                         "Data: x%x x%x x%x\n",
 
1411                         phba->brd_no, phba->hba_state, phba->fc_flag,
 
1412                         phba->fc_plogi_cnt, phba->fc_adisc_cnt);
 
1418  * Check specified ring for outstanding IOCB on the SLI queue
 
1419  * Return true if iocb matches the specified nport
 
1422 lpfc_check_sli_ndlp(struct lpfc_hba * phba,
 
1423                     struct lpfc_sli_ring * pring,
 
1424                     struct lpfc_iocbq * iocb, struct lpfc_nodelist * ndlp)
 
1426         struct lpfc_sli *psli;
 
1431         if (pring->ringno == LPFC_ELS_RING) {
 
1432                 switch (icmd->ulpCommand) {
 
1433                 case CMD_GEN_REQUEST64_CR:
 
1434                         if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi)
 
1436                 case CMD_ELS_REQUEST64_CR:
 
1437                         if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
 
1439                 case CMD_XMIT_ELS_RSP64_CX:
 
1440                         if (iocb->context1 == (uint8_t *) ndlp)
 
1443         } else if (pring->ringno == psli->extra_ring) {
 
1445         } else if (pring->ringno == psli->fcp_ring) {
 
1446                 /* Skip match check if waiting to relogin to FCP target */
 
1447                 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
 
1448                   (ndlp->nlp_flag & NLP_DELAY_TMO)) {
 
1451                 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
 
1454         } else if (pring->ringno == psli->next_ring) {
 
1461  * Free resources / clean up outstanding I/Os
 
1462  * associated with nlp_rpi in the LPFC_NODELIST entry.
 
1465 lpfc_no_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
 
1467         struct lpfc_sli *psli;
 
1468         struct lpfc_sli_ring *pring;
 
1469         struct lpfc_iocbq *iocb, *next_iocb;
 
1474          * Everything that matches on txcmplq will be returned
 
1475          * by firmware with a no rpi error.
 
1478         rpi = ndlp->nlp_rpi;
 
1480                 /* Now process each ring */
 
1481                 for (i = 0; i < psli->num_rings; i++) {
 
1482                         pring = &psli->ring[i];
 
1484                         spin_lock_irq(phba->host->host_lock);
 
1485                         list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
 
1488                                  * Check to see if iocb matches the nport we are
 
1491                                 if ((lpfc_check_sli_ndlp
 
1492                                      (phba, pring, iocb, ndlp))) {
 
1493                                         /* It matches, so deque and call compl
 
1495                                         list_del(&iocb->list);
 
1497                                         if (iocb->iocb_cmpl) {
 
1500                                                     IOSTAT_LOCAL_REJECT;
 
1501                                                 icmd->un.ulpWord[4] =
 
1503                                                 spin_unlock_irq(phba->host->
 
1505                                                 (iocb->iocb_cmpl) (phba,
 
1507                                                 spin_lock_irq(phba->host->
 
1510                                                 lpfc_sli_release_iocbq(phba,
 
1514                         spin_unlock_irq(phba->host->host_lock);
 
1522  * Free rpi associated with LPFC_NODELIST entry.
 
1523  * This routine is called from lpfc_freenode(), when we are removing
 
1524  * a LPFC_NODELIST entry. It is also called if the driver initiates a
 
1525  * LOGO that completes successfully, and we are waiting to PLOGI back
 
1526  * to the remote NPort. In addition, it is called after we receive
 
1527  * and unsolicated ELS cmd, send back a rsp, the rsp completes and
 
1528  * we are waiting to PLOGI back to the remote NPort.
 
1531 lpfc_unreg_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
 
1536         if (ndlp->nlp_rpi) {
 
1537                 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
 
1538                         lpfc_unreg_login(phba, ndlp->nlp_rpi, mbox);
 
1539                         mbox->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
 
1540                         rc = lpfc_sli_issue_mbox
 
1541                                     (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
 
1542                         if (rc == MBX_NOT_FINISHED)
 
1543                                 mempool_free( mbox, phba->mbox_mem_pool);
 
1545                 lpfc_no_rpi(phba, ndlp);
 
1553  * Free resources associated with LPFC_NODELIST entry
 
1554  * so it can be freed.
 
1557 lpfc_freenode(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
 
1560         LPFC_MBOXQ_t       *nextmb;
 
1561         struct lpfc_dmabuf *mp;
 
1563         /* Cleanup node for NPort <nlp_DID> */
 
1564         lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
 
1565                         "%d:0900 Cleanup node for NPort x%x "
 
1566                         "Data: x%x x%x x%x\n",
 
1567                         phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
 
1568                         ndlp->nlp_state, ndlp->nlp_rpi);
 
1570         lpfc_nlp_list(phba, ndlp, NLP_JUST_DQ);
 
1573          * if unloading the driver - just leave the remote port in place.
 
1574          * The driver unload will force the attached devices to detach
 
1575          * and flush cache's w/o generating flush errors.
 
1577         if ((ndlp->rport) && !(phba->fc_flag & FC_UNLOADING)) {
 
1578                 lpfc_unregister_remote_port(phba, ndlp);
 
1579                 ndlp->nlp_sid = NLP_NO_SID;
 
1582         /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
 
1583         if ((mb = phba->sli.mbox_active)) {
 
1584                 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
 
1585                    (ndlp == (struct lpfc_nodelist *) mb->context2)) {
 
1586                         mb->context2 = NULL;
 
1587                         mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
 
1591         spin_lock_irq(phba->host->host_lock);
 
1592         list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
 
1593                 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
 
1594                    (ndlp == (struct lpfc_nodelist *) mb->context2)) {
 
1595                         mp = (struct lpfc_dmabuf *) (mb->context1);
 
1597                                 lpfc_mbuf_free(phba, mp->virt, mp->phys);
 
1600                         list_del(&mb->list);
 
1601                         mempool_free(mb, phba->mbox_mem_pool);
 
1604         spin_unlock_irq(phba->host->host_lock);
 
1606         lpfc_els_abort(phba,ndlp,0);
 
1607         spin_lock_irq(phba->host->host_lock);
 
1608         ndlp->nlp_flag &= ~NLP_DELAY_TMO;
 
1609         spin_unlock_irq(phba->host->host_lock);
 
1611         ndlp->nlp_last_elscmd = 0;
 
1612         del_timer_sync(&ndlp->nlp_delayfunc);
 
1614         if (!list_empty(&ndlp->els_retry_evt.evt_listp))
 
1615                 list_del_init(&ndlp->els_retry_evt.evt_listp);
 
1617         lpfc_unreg_rpi(phba, ndlp);
 
1623  * Check to see if we can free the nlp back to the freelist.
 
1624  * If we are in the middle of using the nlp in the discovery state
 
1625  * machine, defer the free till we reach the end of the state machine.
 
1628 lpfc_nlp_remove(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
 
1631         if (ndlp->nlp_flag & NLP_DELAY_TMO) {
 
1632                 lpfc_cancel_retry_delay_tmo(phba, ndlp);
 
1635         if (ndlp->nlp_disc_refcnt) {
 
1636                 spin_lock_irq(phba->host->host_lock);
 
1637                 ndlp->nlp_flag |= NLP_DELAY_REMOVE;
 
1638                 spin_unlock_irq(phba->host->host_lock);
 
1640                 lpfc_freenode(phba, ndlp);
 
1641                 mempool_free( ndlp, phba->nlp_mem_pool);
 
1647 lpfc_matchdid(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, uint32_t did)
 
1653         if (did == Bcast_DID)
 
1656         if (ndlp->nlp_DID == 0) {
 
1660         /* First check for Direct match */
 
1661         if (ndlp->nlp_DID == did)
 
1664         /* Next check for area/domain identically equals 0 match */
 
1665         mydid.un.word = phba->fc_myDID;
 
1666         if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
 
1670         matchdid.un.word = did;
 
1671         ndlpdid.un.word = ndlp->nlp_DID;
 
1672         if (matchdid.un.b.id == ndlpdid.un.b.id) {
 
1673                 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
 
1674                     (mydid.un.b.area == matchdid.un.b.area)) {
 
1675                         if ((ndlpdid.un.b.domain == 0) &&
 
1676                             (ndlpdid.un.b.area == 0)) {
 
1677                                 if (ndlpdid.un.b.id)
 
1683                 matchdid.un.word = ndlp->nlp_DID;
 
1684                 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
 
1685                     (mydid.un.b.area == ndlpdid.un.b.area)) {
 
1686                         if ((matchdid.un.b.domain == 0) &&
 
1687                             (matchdid.un.b.area == 0)) {
 
1688                                 if (matchdid.un.b.id)
 
1696 /* Search for a nodelist entry on a specific list */
 
1697 struct lpfc_nodelist *
 
1698 lpfc_findnode_did(struct lpfc_hba * phba, uint32_t order, uint32_t did)
 
1700         struct lpfc_nodelist *ndlp;
 
1701         struct list_head *lists[]={&phba->fc_nlpunmap_list,
 
1702                                    &phba->fc_nlpmap_list,
 
1703                                    &phba->fc_plogi_list,
 
1704                                    &phba->fc_adisc_list,
 
1705                                    &phba->fc_reglogin_list,
 
1706                                    &phba->fc_prli_list,
 
1708                                    &phba->fc_unused_list};
 
1709         uint32_t search[]={NLP_SEARCH_UNMAPPED,
 
1713                            NLP_SEARCH_REGLOGIN,
 
1720         spin_lock_irq(phba->host->host_lock);
 
1721         for (i = 0; i < ARRAY_SIZE(lists); i++ ) {
 
1722                 if (!(order & search[i]))
 
1724                 list_for_each_entry(ndlp, lists[i], nlp_listp) {
 
1725                         if (lpfc_matchdid(phba, ndlp, did)) {
 
1726                                 data1 = (((uint32_t) ndlp->nlp_state << 24) |
 
1727                                          ((uint32_t) ndlp->nlp_xri << 16) |
 
1728                                          ((uint32_t) ndlp->nlp_type << 8) |
 
1729                                          ((uint32_t) ndlp->nlp_rpi & 0xff));
 
1730                                 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
 
1731                                                 "%d:0929 FIND node DID "
 
1732                                                 " Data: x%p x%x x%x x%x\n",
 
1734                                                 ndlp, ndlp->nlp_DID,
 
1735                                                 ndlp->nlp_flag, data1);
 
1736                                 spin_unlock_irq(phba->host->host_lock);
 
1741         spin_unlock_irq(phba->host->host_lock);
 
1743         /* FIND node did <did> NOT FOUND */
 
1744         lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
 
1745                         "%d:0932 FIND node did x%x NOT FOUND Data: x%x\n",
 
1746                         phba->brd_no, did, order);
 
1750 struct lpfc_nodelist *
 
1751 lpfc_setup_disc_node(struct lpfc_hba * phba, uint32_t did)
 
1753         struct lpfc_nodelist *ndlp;
 
1756         ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did);
 
1758                 if ((phba->fc_flag & FC_RSCN_MODE) &&
 
1759                    ((lpfc_rscn_payload_check(phba, did) == 0)))
 
1761                 ndlp = (struct lpfc_nodelist *)
 
1762                      mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
 
1765                 lpfc_nlp_init(phba, ndlp, did);
 
1766                 ndlp->nlp_state = NLP_STE_NPR_NODE;
 
1767                 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
 
1768                 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
 
1771         if (phba->fc_flag & FC_RSCN_MODE) {
 
1772                 if (lpfc_rscn_payload_check(phba, did)) {
 
1773                         ndlp->nlp_flag |= NLP_NPR_2B_DISC;
 
1775                         /* Since this node is marked for discovery,
 
1776                          * delay timeout is not needed.
 
1778                         if (ndlp->nlp_flag & NLP_DELAY_TMO)
 
1779                                 lpfc_cancel_retry_delay_tmo(phba, ndlp);
 
1783                 flg = ndlp->nlp_flag & NLP_LIST_MASK;
 
1784                 if ((flg == NLP_ADISC_LIST) || (flg == NLP_PLOGI_LIST))
 
1786                 ndlp->nlp_state = NLP_STE_NPR_NODE;
 
1787                 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
 
1788                 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
 
1793 /* Build a list of nodes to discover based on the loopmap */
 
1795 lpfc_disc_list_loopmap(struct lpfc_hba * phba)
 
1798         uint32_t alpa, index;
 
1800         if (phba->hba_state <= LPFC_LINK_DOWN) {
 
1803         if (phba->fc_topology != TOPOLOGY_LOOP) {
 
1807         /* Check for loop map present or not */
 
1808         if (phba->alpa_map[0]) {
 
1809                 for (j = 1; j <= phba->alpa_map[0]; j++) {
 
1810                         alpa = phba->alpa_map[j];
 
1812                         if (((phba->fc_myDID & 0xff) == alpa) || (alpa == 0)) {
 
1815                         lpfc_setup_disc_node(phba, alpa);
 
1818                 /* No alpamap, so try all alpa's */
 
1819                 for (j = 0; j < FC_MAXLOOP; j++) {
 
1820                         /* If cfg_scan_down is set, start from highest
 
1821                          * ALPA (0xef) to lowest (0x1).
 
1823                         if (phba->cfg_scan_down)
 
1826                                 index = FC_MAXLOOP - j - 1;
 
1827                         alpa = lpfcAlpaArray[index];
 
1828                         if ((phba->fc_myDID & 0xff) == alpa) {
 
1832                         lpfc_setup_disc_node(phba, alpa);
 
1838 /* Start Link up / RSCN discovery on NPR list */
 
1840 lpfc_disc_start(struct lpfc_hba * phba)
 
1842         struct lpfc_sli *psli;
 
1844         struct lpfc_nodelist *ndlp, *next_ndlp;
 
1845         uint32_t did_changed, num_sent;
 
1846         uint32_t clear_la_pending;
 
1851         if (phba->hba_state <= LPFC_LINK_DOWN) {
 
1854         if (phba->hba_state == LPFC_CLEAR_LA)
 
1855                 clear_la_pending = 1;
 
1857                 clear_la_pending = 0;
 
1859         if (phba->hba_state < LPFC_HBA_READY) {
 
1860                 phba->hba_state = LPFC_DISC_AUTH;
 
1862         lpfc_set_disctmo(phba);
 
1864         if (phba->fc_prevDID == phba->fc_myDID) {
 
1869         phba->fc_prevDID = phba->fc_myDID;
 
1870         phba->num_disc_nodes = 0;
 
1872         /* Start Discovery state <hba_state> */
 
1873         lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
 
1874                         "%d:0202 Start Discovery hba state x%x "
 
1875                         "Data: x%x x%x x%x\n",
 
1876                         phba->brd_no, phba->hba_state, phba->fc_flag,
 
1877                         phba->fc_plogi_cnt, phba->fc_adisc_cnt);
 
1879         /* If our did changed, we MUST do PLOGI */
 
1880         list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
 
1882                 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
 
1884                                 spin_lock_irq(phba->host->host_lock);
 
1885                                 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
 
1886                                 spin_unlock_irq(phba->host->host_lock);
 
1891         /* First do ADISCs - if any */
 
1892         num_sent = lpfc_els_disc_adisc(phba);
 
1897         if ((phba->hba_state < LPFC_HBA_READY) && (!clear_la_pending)) {
 
1898                 /* If we get here, there is nothing to ADISC */
 
1899                 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
 
1900                         phba->hba_state = LPFC_CLEAR_LA;
 
1901                         lpfc_clear_la(phba, mbox);
 
1902                         mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
 
1903                         rc = lpfc_sli_issue_mbox(phba, mbox,
 
1904                                                  (MBX_NOWAIT | MBX_STOP_IOCB));
 
1905                         if (rc == MBX_NOT_FINISHED) {
 
1906                                 mempool_free( mbox, phba->mbox_mem_pool);
 
1907                                 lpfc_disc_flush_list(phba);
 
1908                                 psli->ring[(psli->extra_ring)].flag &=
 
1909                                         ~LPFC_STOP_IOCB_EVENT;
 
1910                                 psli->ring[(psli->fcp_ring)].flag &=
 
1911                                         ~LPFC_STOP_IOCB_EVENT;
 
1912                                 psli->ring[(psli->next_ring)].flag &=
 
1913                                         ~LPFC_STOP_IOCB_EVENT;
 
1914                                 phba->hba_state = LPFC_HBA_READY;
 
1918                 /* Next do PLOGIs - if any */
 
1919                 num_sent = lpfc_els_disc_plogi(phba);
 
1924                 if (phba->fc_flag & FC_RSCN_MODE) {
 
1925                         /* Check to see if more RSCNs came in while we
 
1926                          * were processing this one.
 
1928                         if ((phba->fc_rscn_id_cnt == 0) &&
 
1929                             (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
 
1930                                 spin_lock_irq(phba->host->host_lock);
 
1931                                 phba->fc_flag &= ~FC_RSCN_MODE;
 
1932                                 spin_unlock_irq(phba->host->host_lock);
 
1934                                 lpfc_els_handle_rscn(phba);
 
1941  *  Ignore completion for all IOCBs on tx and txcmpl queue for ELS
 
1942  *  ring the match the sppecified nodelist.
 
1945 lpfc_free_tx(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
 
1947         struct lpfc_sli *psli;
 
1949         struct lpfc_iocbq    *iocb, *next_iocb;
 
1950         struct lpfc_sli_ring *pring;
 
1951         struct lpfc_dmabuf   *mp;
 
1954         pring = &psli->ring[LPFC_ELS_RING];
 
1956         /* Error matching iocb on txq or txcmplq
 
1957          * First check the txq.
 
1959         list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
 
1960                 if (iocb->context1 != ndlp) {
 
1964                 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
 
1965                     (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
 
1967                         list_del(&iocb->list);
 
1969                         lpfc_els_free_iocb(phba, iocb);
 
1973         /* Next check the txcmplq */
 
1974         list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
 
1975                 if (iocb->context1 != ndlp) {
 
1979                 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
 
1980                     (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
 
1982                         iocb->iocb_cmpl = NULL;
 
1983                         /* context2 = cmd, context2->next = rsp, context3 =
 
1985                         if (iocb->context2) {
 
1986                                 /* Free the response IOCB before handling the
 
1989                                 mp = (struct lpfc_dmabuf *) (iocb->context2);
 
1990                                 mp = list_get_first(&mp->list,
 
1994                                         /* Delay before releasing rsp buffer to
 
1995                                          * give UNREG mbox a chance to take
 
1999                                                 &phba->freebufList);
 
2001                                 lpfc_mbuf_free(phba,
 
2002                                                ((struct lpfc_dmabuf *)
 
2003                                                 iocb->context2)->virt,
 
2004                                                ((struct lpfc_dmabuf *)
 
2005                                                 iocb->context2)->phys);
 
2006                                 kfree(iocb->context2);
 
2009                         if (iocb->context3) {
 
2010                                 lpfc_mbuf_free(phba,
 
2011                                                ((struct lpfc_dmabuf *)
 
2012                                                 iocb->context3)->virt,
 
2013                                                ((struct lpfc_dmabuf *)
 
2014                                                 iocb->context3)->phys);
 
2015                                 kfree(iocb->context3);
 
2024 lpfc_disc_flush_list(struct lpfc_hba * phba)
 
2026         struct lpfc_nodelist *ndlp, *next_ndlp;
 
2028         if (phba->fc_plogi_cnt) {
 
2029                 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
 
2031                         lpfc_free_tx(phba, ndlp);
 
2032                         lpfc_nlp_remove(phba, ndlp);
 
2035         if (phba->fc_adisc_cnt) {
 
2036                 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
 
2038                         lpfc_free_tx(phba, ndlp);
 
2039                         lpfc_nlp_remove(phba, ndlp);
 
2045 /*****************************************************************************/
 
2047  * NAME:     lpfc_disc_timeout
 
2049  * FUNCTION: Fibre Channel driver discovery timeout routine.
 
2051  * EXECUTION ENVIRONMENT: interrupt only
 
2059 /*****************************************************************************/
 
2061 lpfc_disc_timeout(unsigned long ptr)
 
2063         struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
 
2064         unsigned long flags = 0;
 
2066         if (unlikely(!phba))
 
2069         spin_lock_irqsave(phba->host->host_lock, flags);
 
2070         if (!(phba->work_hba_events & WORKER_DISC_TMO)) {
 
2071                 phba->work_hba_events |= WORKER_DISC_TMO;
 
2072                 if (phba->work_wait)
 
2073                         wake_up(phba->work_wait);
 
2075         spin_unlock_irqrestore(phba->host->host_lock, flags);
 
2080 lpfc_disc_timeout_handler(struct lpfc_hba *phba)
 
2082         struct lpfc_sli *psli;
 
2083         struct lpfc_nodelist *ndlp, *next_ndlp;
 
2084         LPFC_MBOXQ_t *clearlambox, *initlinkmbox;
 
2085         int rc, clrlaerr = 0;
 
2087         if (unlikely(!phba))
 
2090         if (!(phba->fc_flag & FC_DISC_TMO))
 
2095         spin_lock_irq(phba->host->host_lock);
 
2096         phba->fc_flag &= ~FC_DISC_TMO;
 
2097         spin_unlock_irq(phba->host->host_lock);
 
2099         switch (phba->hba_state) {
 
2101         case LPFC_LOCAL_CFG_LINK:
 
2102         /* hba_state is identically LPFC_LOCAL_CFG_LINK while waiting for FAN */
 
2104                 lpfc_printf_log(phba,
 
2107                                  "%d:0221 FAN timeout\n",
 
2110                 /* Start discovery by sending FLOGI, clean up old rpis */
 
2111                 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
 
2113                         if (ndlp->nlp_type & NLP_FABRIC) {
 
2114                                 /* Clean up the ndlp on Fabric connections */
 
2115                                 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
 
2116                         } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
 
2117                                 /* Fail outstanding IO now since device
 
2118                                  * is marked for PLOGI.
 
2120                                 lpfc_unreg_rpi(phba, ndlp);
 
2123                 phba->hba_state = LPFC_FLOGI;
 
2124                 lpfc_set_disctmo(phba);
 
2125                 lpfc_initial_flogi(phba);
 
2129         /* hba_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
 
2130                 /* Initial FLOGI timeout */
 
2131                 lpfc_printf_log(phba,
 
2134                                  "%d:0222 Initial FLOGI timeout\n",
 
2137                 /* Assume no Fabric and go on with discovery.
 
2138                  * Check for outstanding ELS FLOGI to abort.
 
2141                 /* FLOGI failed, so just use loop map to make discovery list */
 
2142                 lpfc_disc_list_loopmap(phba);
 
2144                 /* Start discovery */
 
2145                 lpfc_disc_start(phba);
 
2148         case LPFC_FABRIC_CFG_LINK:
 
2149         /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
 
2151                 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
 
2152                                 "%d:0223 Timeout while waiting for NameServer "
 
2153                                 "login\n", phba->brd_no);
 
2155                 /* Next look for NameServer ndlp */
 
2156                 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
 
2158                         lpfc_nlp_remove(phba, ndlp);
 
2159                 /* Start discovery */
 
2160                 lpfc_disc_start(phba);
 
2164         /* Check for wait for NameServer Rsp timeout */
 
2165                 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
 
2166                                 "%d:0224 NameServer Query timeout "
 
2169                                 phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
 
2171                 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED,
 
2174                         if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) {
 
2175                                 /* Try it one more time */
 
2176                                 rc = lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT);
 
2180                         phba->fc_ns_retry = 0;
 
2183                 /* Nothing to authenticate, so CLEAR_LA right now */
 
2184                 clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
 
2187                         lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
 
2188                                         "%d:0226 Device Discovery "
 
2189                                         "completion error\n",
 
2191                         phba->hba_state = LPFC_HBA_ERROR;
 
2195                 phba->hba_state = LPFC_CLEAR_LA;
 
2196                 lpfc_clear_la(phba, clearlambox);
 
2197                 clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
 
2198                 rc = lpfc_sli_issue_mbox(phba, clearlambox,
 
2199                                          (MBX_NOWAIT | MBX_STOP_IOCB));
 
2200                 if (rc == MBX_NOT_FINISHED) {
 
2201                         mempool_free(clearlambox, phba->mbox_mem_pool);
 
2206                 /* Setup and issue mailbox INITIALIZE LINK command */
 
2207                 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
 
2208                 if (!initlinkmbox) {
 
2209                         lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
 
2210                                         "%d:0206 Device Discovery "
 
2211                                         "completion error\n",
 
2213                         phba->hba_state = LPFC_HBA_ERROR;
 
2217                 lpfc_linkdown(phba);
 
2218                 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
 
2219                                phba->cfg_link_speed);
 
2220                 initlinkmbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
 
2221                 rc = lpfc_sli_issue_mbox(phba, initlinkmbox,
 
2222                                          (MBX_NOWAIT | MBX_STOP_IOCB));
 
2223                 if (rc == MBX_NOT_FINISHED)
 
2224                         mempool_free(initlinkmbox, phba->mbox_mem_pool);
 
2228         case LPFC_DISC_AUTH:
 
2229         /* Node Authentication timeout */
 
2230                 lpfc_printf_log(phba,
 
2233                                  "%d:0227 Node Authentication timeout\n",
 
2235                 lpfc_disc_flush_list(phba);
 
2236                 clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
 
2239                         lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
 
2240                                         "%d:0207 Device Discovery "
 
2241                                         "completion error\n",
 
2243                         phba->hba_state = LPFC_HBA_ERROR;
 
2246                 phba->hba_state = LPFC_CLEAR_LA;
 
2247                 lpfc_clear_la(phba, clearlambox);
 
2248                 clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
 
2249                 rc = lpfc_sli_issue_mbox(phba, clearlambox,
 
2250                                          (MBX_NOWAIT | MBX_STOP_IOCB));
 
2251                 if (rc == MBX_NOT_FINISHED) {
 
2252                         mempool_free(clearlambox, phba->mbox_mem_pool);
 
2258         /* CLEAR LA timeout */
 
2259                 lpfc_printf_log(phba,
 
2262                                  "%d:0228 CLEAR LA timeout\n",
 
2267         case LPFC_HBA_READY:
 
2268                 if (phba->fc_flag & FC_RSCN_MODE) {
 
2269                         lpfc_printf_log(phba,
 
2272                                         "%d:0231 RSCN timeout Data: x%x x%x\n",
 
2274                                         phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
 
2276                         /* Cleanup any outstanding ELS commands */
 
2277                         lpfc_els_flush_cmd(phba);
 
2279                         lpfc_els_flush_rscn(phba);
 
2280                         lpfc_disc_flush_list(phba);
 
2286                 lpfc_disc_flush_list(phba);
 
2287                 psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
 
2288                 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
 
2289                 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
 
2290                 phba->hba_state = LPFC_HBA_READY;
 
2297  * This routine handles processing a NameServer REG_LOGIN mailbox
 
2298  * command upon completion. It is setup in the LPFC_MBOXQ
 
2299  * as the completion routine when the command is
 
2300  * handed off to the SLI layer.
 
2303 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
 
2305         struct lpfc_sli *psli;
 
2307         struct lpfc_dmabuf *mp;
 
2308         struct lpfc_nodelist *ndlp;
 
2313         ndlp = (struct lpfc_nodelist *) pmb->context2;
 
2314         mp = (struct lpfc_dmabuf *) (pmb->context1);
 
2316         pmb->context1 = NULL;
 
2318         ndlp->nlp_rpi = mb->un.varWords[0];
 
2319         ndlp->nlp_type |= NLP_FABRIC;
 
2320         ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
 
2321         lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
 
2323         /* Start issuing Fabric-Device Management Interface (FDMI)
 
2324          * command to 0xfffffa (FDMI well known port)
 
2326         if (phba->cfg_fdmi_on == 1) {
 
2327                 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
 
2330                  * Delay issuing FDMI command if fdmi-on=2
 
2331                  * (supporting RPA/hostnmae)
 
2333                 mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
 
2336         lpfc_mbuf_free(phba, mp->virt, mp->phys);
 
2338         mempool_free( pmb, phba->mbox_mem_pool);
 
2344  * This routine looks up the ndlp  lists
 
2345  * for the given RPI. If rpi found
 
2346  * it return the node list pointer
 
2349 struct lpfc_nodelist *
 
2350 lpfc_findnode_rpi(struct lpfc_hba * phba, uint16_t rpi)
 
2352         struct lpfc_nodelist *ndlp;
 
2353         struct list_head * lists[]={&phba->fc_nlpunmap_list,
 
2354                                     &phba->fc_nlpmap_list,
 
2355                                     &phba->fc_plogi_list,
 
2356                                     &phba->fc_adisc_list,
 
2357                                     &phba->fc_reglogin_list};
 
2360         spin_lock_irq(phba->host->host_lock);
 
2361         for (i = 0; i < ARRAY_SIZE(lists); i++ )
 
2362                 list_for_each_entry(ndlp, lists[i], nlp_listp)
 
2363                         if (ndlp->nlp_rpi == rpi) {
 
2364                                 spin_unlock_irq(phba->host->host_lock);
 
2367         spin_unlock_irq(phba->host->host_lock);
 
2372  * This routine looks up the ndlp  lists
 
2373  * for the given WWPN. If WWPN found
 
2374  * it return the node list pointer
 
2377 struct lpfc_nodelist *
 
2378 lpfc_findnode_wwpn(struct lpfc_hba * phba, uint32_t order,
 
2379                    struct lpfc_name * wwpn)
 
2381         struct lpfc_nodelist *ndlp;
 
2382         struct list_head * lists[]={&phba->fc_nlpunmap_list,
 
2383                                     &phba->fc_nlpmap_list,
 
2385                                     &phba->fc_plogi_list,
 
2386                                     &phba->fc_adisc_list,
 
2387                                     &phba->fc_reglogin_list,
 
2388                                     &phba->fc_prli_list};
 
2389         uint32_t search[]={NLP_SEARCH_UNMAPPED,
 
2394                            NLP_SEARCH_REGLOGIN,
 
2398         spin_lock_irq(phba->host->host_lock);
 
2399         for (i = 0; i < ARRAY_SIZE(lists); i++ ) {
 
2400                 if (!(order & search[i]))
 
2402                 list_for_each_entry(ndlp, lists[i], nlp_listp) {
 
2403                         if (memcmp(&ndlp->nlp_portname, wwpn,
 
2404                                    sizeof(struct lpfc_name)) == 0) {
 
2405                                 spin_unlock_irq(phba->host->host_lock);
 
2410         spin_unlock_irq(phba->host->host_lock);
 
2415 lpfc_nlp_init(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
 
2418         memset(ndlp, 0, sizeof (struct lpfc_nodelist));
 
2419         INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
 
2420         init_timer(&ndlp->nlp_delayfunc);
 
2421         ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
 
2422         ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
 
2423         ndlp->nlp_DID = did;
 
2424         ndlp->nlp_phba = phba;
 
2425         ndlp->nlp_sid = NLP_NO_SID;