|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1 | /******************************************************************* | 
|  | 2 | * This file is part of the Emulex Linux Device Driver for         * | 
| James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 3 | * Fibre Channel Host Bus Adapters.                                * | 
| James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 4 | * Copyright (C) 2004-2011 Emulex.  All rights reserved.           * | 
| James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 5 | * EMULEX and SLI are trademarks of Emulex.                        * | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6 | * www.emulex.com                                                  * | 
| James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig              * | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8 | *                                                                 * | 
|  | 9 | * This program is free software; you can redistribute it and/or   * | 
| James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 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.                                     * | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 20 | *******************************************************************/ | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 21 | /* See Fibre Channel protocol T11 FC-LS for details */ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 22 | #include <linux/blkdev.h> | 
|  | 23 | #include <linux/pci.h> | 
| Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 24 | #include <linux/slab.h> | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 25 | #include <linux/interrupt.h> | 
|  | 26 |  | 
| James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 27 | #include <scsi/scsi.h> | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 28 | #include <scsi/scsi_device.h> | 
|  | 29 | #include <scsi/scsi_host.h> | 
|  | 30 | #include <scsi/scsi_transport_fc.h> | 
|  | 31 |  | 
| James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 32 | #include "lpfc_hw4.h" | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 33 | #include "lpfc_hw.h" | 
|  | 34 | #include "lpfc_sli.h" | 
| James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 35 | #include "lpfc_sli4.h" | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 36 | #include "lpfc_nl.h" | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 37 | #include "lpfc_disc.h" | 
|  | 38 | #include "lpfc_scsi.h" | 
|  | 39 | #include "lpfc.h" | 
|  | 40 | #include "lpfc_logmsg.h" | 
|  | 41 | #include "lpfc_crtn.h" | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 42 | #include "lpfc_vport.h" | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 43 | #include "lpfc_debugfs.h" | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 44 |  | 
|  | 45 | static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *, | 
|  | 46 | struct lpfc_iocbq *); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 47 | static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *, | 
|  | 48 | struct lpfc_iocbq *); | 
| Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 49 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport); | 
|  | 50 | static int lpfc_issue_els_fdisc(struct lpfc_vport *vport, | 
|  | 51 | struct lpfc_nodelist *ndlp, uint8_t retry); | 
|  | 52 | static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba, | 
|  | 53 | struct lpfc_iocbq *iocb); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 54 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 55 | static int lpfc_max_els_tries = 3; | 
|  | 56 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 57 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 58 | * lpfc_els_chk_latt - Check host link attention event for a vport | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 59 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 60 | * | 
|  | 61 | * This routine checks whether there is an outstanding host link | 
|  | 62 | * attention event during the discovery process with the @vport. It is done | 
|  | 63 | * by reading the HBA's Host Attention (HA) register. If there is any host | 
|  | 64 | * link attention events during this @vport's discovery process, the @vport | 
|  | 65 | * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall | 
|  | 66 | * be issued if the link state is not already in host link cleared state, | 
|  | 67 | * and a return code shall indicate whether the host link attention event | 
|  | 68 | * had happened. | 
|  | 69 | * | 
|  | 70 | * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport | 
|  | 71 | * state in LPFC_VPORT_READY, the request for checking host link attention | 
|  | 72 | * event will be ignored and a return code shall indicate no host link | 
|  | 73 | * attention event had happened. | 
|  | 74 | * | 
|  | 75 | * Return codes | 
|  | 76 | *   0 - no host link attention event happened | 
|  | 77 | *   1 - host link attention event happened | 
|  | 78 | **/ | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 79 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 80 | lpfc_els_chk_latt(struct lpfc_vport *vport) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 81 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 82 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | 83 | struct lpfc_hba  *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 84 | uint32_t ha_copy; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 85 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 86 | if (vport->port_state >= LPFC_VPORT_READY || | 
| James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 87 | phba->link_state == LPFC_LINK_DOWN || | 
|  | 88 | phba->sli_rev > LPFC_SLI_REV3) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 89 | return 0; | 
|  | 90 |  | 
|  | 91 | /* Read the HBA Host Attention Register */ | 
| James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 92 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) | 
|  | 93 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 94 |  | 
|  | 95 | if (!(ha_copy & HA_LATT)) | 
|  | 96 | return 0; | 
|  | 97 |  | 
|  | 98 | /* Pending Link Event during Discovery */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 99 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, | 
|  | 100 | "0237 Pending Link Event during " | 
|  | 101 | "Discovery: State x%x\n", | 
|  | 102 | phba->pport->port_state); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 103 |  | 
|  | 104 | /* CLEAR_LA should re-enable link attention events and | 
| Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 105 | * we should then immediately take a LATT event. The | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 106 | * LATT processing should call lpfc_linkdown() which | 
|  | 107 | * will cleanup any left over in-progress discovery | 
|  | 108 | * events. | 
|  | 109 | */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 110 | spin_lock_irq(shost->host_lock); | 
|  | 111 | vport->fc_flag |= FC_ABORT_DISCOVERY; | 
|  | 112 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 113 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 114 | if (phba->link_state != LPFC_CLEAR_LA) | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 115 | lpfc_issue_clear_la(phba, vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 116 |  | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 117 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 118 | } | 
|  | 119 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 120 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 121 | * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 122 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 123 | * @expectRsp: flag indicating whether response is expected. | 
|  | 124 | * @cmdSize: size of the ELS command. | 
|  | 125 | * @retry: number of retries to the command IOCB when it fails. | 
|  | 126 | * @ndlp: pointer to a node-list data structure. | 
|  | 127 | * @did: destination identifier. | 
|  | 128 | * @elscmd: the ELS command code. | 
|  | 129 | * | 
|  | 130 | * This routine is used for allocating a lpfc-IOCB data structure from | 
|  | 131 | * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters | 
|  | 132 | * passed into the routine for discovery state machine to issue an Extended | 
|  | 133 | * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation | 
|  | 134 | * and preparation routine that is used by all the discovery state machine | 
|  | 135 | * routines and the ELS command-specific fields will be later set up by | 
|  | 136 | * the individual discovery machine routines after calling this routine | 
|  | 137 | * allocating and preparing a generic IOCB data structure. It fills in the | 
|  | 138 | * Buffer Descriptor Entries (BDEs), allocates buffers for both command | 
|  | 139 | * payload and response payload (if expected). The reference count on the | 
|  | 140 | * ndlp is incremented by 1 and the reference to the ndlp is put into | 
|  | 141 | * context1 of the IOCB data structure for this IOCB to hold the ndlp | 
|  | 142 | * reference for the command's callback function to access later. | 
|  | 143 | * | 
|  | 144 | * Return code | 
|  | 145 | *   Pointer to the newly allocated/prepared els iocb data structure | 
|  | 146 | *   NULL - when els iocb data structure allocation/preparation failed | 
|  | 147 | **/ | 
| James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 148 | struct lpfc_iocbq * | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 149 | lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp, | 
|  | 150 | uint16_t cmdSize, uint8_t retry, | 
|  | 151 | struct lpfc_nodelist *ndlp, uint32_t did, | 
|  | 152 | uint32_t elscmd) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 153 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 154 | struct lpfc_hba  *phba = vport->phba; | 
| James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 155 | struct lpfc_iocbq *elsiocb; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 156 | struct lpfc_dmabuf *pcmd, *prsp, *pbuflist; | 
|  | 157 | struct ulp_bde64 *bpl; | 
|  | 158 | IOCB_t *icmd; | 
|  | 159 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 160 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 161 | if (!lpfc_is_link_up(phba)) | 
|  | 162 | return NULL; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 163 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 164 | /* Allocate buffer for  command iocb */ | 
| James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 165 | elsiocb = lpfc_sli_get_iocbq(phba); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 166 |  | 
|  | 167 | if (elsiocb == NULL) | 
|  | 168 | return NULL; | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 169 |  | 
| James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 170 | /* | 
|  | 171 | * If this command is for fabric controller and HBA running | 
|  | 172 | * in FIP mode send FLOGI, FDISC and LOGO as FIP frames. | 
|  | 173 | */ | 
|  | 174 | if ((did == Fabric_DID) && | 
| James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 175 | (phba->hba_flag & HBA_FIP_SUPPORT) && | 
| James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 176 | ((elscmd == ELS_CMD_FLOGI) || | 
|  | 177 | (elscmd == ELS_CMD_FDISC) || | 
|  | 178 | (elscmd == ELS_CMD_LOGO))) | 
| James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 179 | switch (elscmd) { | 
|  | 180 | case ELS_CMD_FLOGI: | 
| James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 181 | elsiocb->iocb_flag |= | 
|  | 182 | ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT) | 
| James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 183 | & LPFC_FIP_ELS_ID_MASK); | 
|  | 184 | break; | 
|  | 185 | case ELS_CMD_FDISC: | 
| James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 186 | elsiocb->iocb_flag |= | 
|  | 187 | ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT) | 
| James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 188 | & LPFC_FIP_ELS_ID_MASK); | 
|  | 189 | break; | 
|  | 190 | case ELS_CMD_LOGO: | 
| James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 191 | elsiocb->iocb_flag |= | 
|  | 192 | ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT) | 
| James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 193 | & LPFC_FIP_ELS_ID_MASK); | 
|  | 194 | break; | 
|  | 195 | } | 
| James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 196 | else | 
| James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 197 | elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK; | 
| James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 198 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 199 | icmd = &elsiocb->iocb; | 
|  | 200 |  | 
|  | 201 | /* fill in BDEs for command */ | 
|  | 202 | /* Allocate buffer for command payload */ | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 203 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | 
|  | 204 | if (pcmd) | 
|  | 205 | pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys); | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 206 | if (!pcmd || !pcmd->virt) | 
|  | 207 | goto els_iocb_free_pcmb_exit; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 208 |  | 
|  | 209 | INIT_LIST_HEAD(&pcmd->list); | 
|  | 210 |  | 
|  | 211 | /* Allocate buffer for response payload */ | 
|  | 212 | if (expectRsp) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 213 | prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 214 | if (prsp) | 
|  | 215 | prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, | 
|  | 216 | &prsp->phys); | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 217 | if (!prsp || !prsp->virt) | 
|  | 218 | goto els_iocb_free_prsp_exit; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 219 | INIT_LIST_HEAD(&prsp->list); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 220 | } else | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 221 | prsp = NULL; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 222 |  | 
|  | 223 | /* Allocate buffer for Buffer ptr list */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 224 | pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 225 | if (pbuflist) | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 226 | pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI, | 
|  | 227 | &pbuflist->phys); | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 228 | if (!pbuflist || !pbuflist->virt) | 
|  | 229 | goto els_iocb_free_pbuf_exit; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 230 |  | 
|  | 231 | INIT_LIST_HEAD(&pbuflist->list); | 
|  | 232 |  | 
|  | 233 | icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); | 
|  | 234 | icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys); | 
| James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 235 | icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 236 | icmd->un.elsreq64.remoteID = did;	/* DID */ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 237 | if (expectRsp) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 238 | icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 239 | icmd->ulpCommand = CMD_ELS_REQUEST64_CR; | 
| James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 240 | icmd->ulpTimeout = phba->fc_ratov * 2; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 241 | } else { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 242 | icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 243 | icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX; | 
|  | 244 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 245 | icmd->ulpBdeCount = 1; | 
|  | 246 | icmd->ulpLe = 1; | 
|  | 247 | icmd->ulpClass = CLASS3; | 
|  | 248 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 249 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { | 
|  | 250 | icmd->un.elsreq64.myID = vport->fc_myDID; | 
|  | 251 |  | 
|  | 252 | /* For ELS_REQUEST64_CR, use the VPI by default */ | 
| James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 253 | icmd->ulpContext = phba->vpi_ids[vport->vpi]; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 254 | icmd->ulpCt_h = 0; | 
| James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 255 | /* The CT field must be 0=INVALID_RPI for the ECHO cmd */ | 
|  | 256 | if (elscmd == ELS_CMD_ECHO) | 
|  | 257 | icmd->ulpCt_l = 0; /* context = invalid RPI */ | 
|  | 258 | else | 
|  | 259 | icmd->ulpCt_l = 1; /* context = VPI */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 260 | } | 
|  | 261 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 262 | bpl = (struct ulp_bde64 *) pbuflist->virt; | 
|  | 263 | bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys)); | 
|  | 264 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys)); | 
|  | 265 | bpl->tus.f.bdeSize = cmdSize; | 
|  | 266 | bpl->tus.f.bdeFlags = 0; | 
|  | 267 | bpl->tus.w = le32_to_cpu(bpl->tus.w); | 
|  | 268 |  | 
|  | 269 | if (expectRsp) { | 
|  | 270 | bpl++; | 
|  | 271 | bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys)); | 
|  | 272 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys)); | 
|  | 273 | bpl->tus.f.bdeSize = FCELSSIZE; | 
| James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 274 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 275 | bpl->tus.w = le32_to_cpu(bpl->tus.w); | 
|  | 276 | } | 
|  | 277 |  | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 278 | /* prevent preparing iocb with NULL ndlp reference */ | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 279 | elsiocb->context1 = lpfc_nlp_get(ndlp); | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 280 | if (!elsiocb->context1) | 
|  | 281 | goto els_iocb_free_pbuf_exit; | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 282 | elsiocb->context2 = pcmd; | 
|  | 283 | elsiocb->context3 = pbuflist; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 284 | elsiocb->retry = retry; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 285 | elsiocb->vport = vport; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 286 | elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT; | 
|  | 287 |  | 
|  | 288 | if (prsp) { | 
|  | 289 | list_add(&prsp->list, &pcmd->list); | 
|  | 290 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 291 | if (expectRsp) { | 
|  | 292 | /* Xmit ELS command <elsCmd> to remote NPORT <did> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 293 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 294 | "0116 Xmit ELS command x%x to remote " | 
|  | 295 | "NPORT x%x I/O tag: x%x, port state: x%x\n", | 
|  | 296 | elscmd, did, elsiocb->iotag, | 
|  | 297 | vport->port_state); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 298 | } else { | 
|  | 299 | /* Xmit ELS response <elsCmd> to remote NPORT <did> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 300 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 301 | "0117 Xmit ELS response x%x to remote " | 
|  | 302 | "NPORT x%x I/O tag: x%x, size: x%x\n", | 
|  | 303 | elscmd, ndlp->nlp_DID, elsiocb->iotag, | 
|  | 304 | cmdSize); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 305 | } | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 306 | return elsiocb; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 307 |  | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 308 | els_iocb_free_pbuf_exit: | 
| James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 309 | if (expectRsp) | 
|  | 310 | lpfc_mbuf_free(phba, prsp->virt, prsp->phys); | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 311 | kfree(pbuflist); | 
|  | 312 |  | 
|  | 313 | els_iocb_free_prsp_exit: | 
|  | 314 | lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); | 
|  | 315 | kfree(prsp); | 
|  | 316 |  | 
|  | 317 | els_iocb_free_pcmb_exit: | 
|  | 318 | kfree(pcmd); | 
|  | 319 | lpfc_sli_release_iocbq(phba, elsiocb); | 
|  | 320 | return NULL; | 
|  | 321 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 322 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 323 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 324 | * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 325 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 326 | * | 
|  | 327 | * This routine issues a fabric registration login for a @vport. An | 
|  | 328 | * active ndlp node with Fabric_DID must already exist for this @vport. | 
|  | 329 | * The routine invokes two mailbox commands to carry out fabric registration | 
|  | 330 | * login through the HBA firmware: the first mailbox command requests the | 
|  | 331 | * HBA to perform link configuration for the @vport; and the second mailbox | 
|  | 332 | * command requests the HBA to perform the actual fabric registration login | 
|  | 333 | * with the @vport. | 
|  | 334 | * | 
|  | 335 | * Return code | 
|  | 336 | *   0 - successfully issued fabric registration login for @vport | 
|  | 337 | *   -ENXIO -- failed to issue fabric registration login for @vport | 
|  | 338 | **/ | 
| James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 339 | int | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 340 | lpfc_issue_fabric_reglogin(struct lpfc_vport *vport) | 
|  | 341 | { | 
|  | 342 | struct lpfc_hba  *phba = vport->phba; | 
|  | 343 | LPFC_MBOXQ_t *mbox; | 
|  | 344 | struct lpfc_dmabuf *mp; | 
|  | 345 | struct lpfc_nodelist *ndlp; | 
|  | 346 | struct serv_parm *sp; | 
|  | 347 | int rc; | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 348 | int err = 0; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 349 |  | 
|  | 350 | sp = &phba->fc_fabparam; | 
|  | 351 | ndlp = lpfc_findnode_did(vport, Fabric_DID); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 352 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 353 | err = 1; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 354 | goto fail; | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 355 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 356 |  | 
|  | 357 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 358 | if (!mbox) { | 
|  | 359 | err = 2; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 360 | goto fail; | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 361 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 362 |  | 
|  | 363 | vport->port_state = LPFC_FABRIC_CFG_LINK; | 
|  | 364 | lpfc_config_link(phba, mbox); | 
|  | 365 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | 
|  | 366 | mbox->vport = vport; | 
|  | 367 |  | 
| James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 368 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 369 | if (rc == MBX_NOT_FINISHED) { | 
|  | 370 | err = 3; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 371 | goto fail_free_mbox; | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 372 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 373 |  | 
|  | 374 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 375 | if (!mbox) { | 
|  | 376 | err = 4; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 377 | goto fail; | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 378 | } | 
| James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 379 | rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, | 
|  | 380 | ndlp->nlp_rpi); | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 381 | if (rc) { | 
|  | 382 | err = 5; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 383 | goto fail_free_mbox; | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 384 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 385 |  | 
|  | 386 | mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login; | 
|  | 387 | mbox->vport = vport; | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 388 | /* increment the reference count on ndlp to hold reference | 
|  | 389 | * for the callback routine. | 
|  | 390 | */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 391 | mbox->context2 = lpfc_nlp_get(ndlp); | 
|  | 392 |  | 
| James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 393 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 394 | if (rc == MBX_NOT_FINISHED) { | 
|  | 395 | err = 6; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 396 | goto fail_issue_reg_login; | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 397 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 398 |  | 
|  | 399 | return 0; | 
|  | 400 |  | 
|  | 401 | fail_issue_reg_login: | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 402 | /* decrement the reference count on ndlp just incremented | 
|  | 403 | * for the failed mbox command. | 
|  | 404 | */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 405 | lpfc_nlp_put(ndlp); | 
|  | 406 | mp = (struct lpfc_dmabuf *) mbox->context1; | 
|  | 407 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | 
|  | 408 | kfree(mp); | 
|  | 409 | fail_free_mbox: | 
|  | 410 | mempool_free(mbox, phba->mbox_mem_pool); | 
|  | 411 |  | 
|  | 412 | fail: | 
|  | 413 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 414 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 415 | "0249 Cannot issue Register Fabric login: Err %d\n", err); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 416 | return -ENXIO; | 
|  | 417 | } | 
|  | 418 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 419 | /** | 
| James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 420 | * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login | 
|  | 421 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 422 | * | 
|  | 423 | * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for | 
|  | 424 | * the @vport. This mailbox command is necessary for FCoE only. | 
|  | 425 | * | 
|  | 426 | * Return code | 
|  | 427 | *   0 - successfully issued REG_VFI for @vport | 
|  | 428 | *   A failure code otherwise. | 
|  | 429 | **/ | 
|  | 430 | static int | 
|  | 431 | lpfc_issue_reg_vfi(struct lpfc_vport *vport) | 
|  | 432 | { | 
|  | 433 | struct lpfc_hba  *phba = vport->phba; | 
|  | 434 | LPFC_MBOXQ_t *mboxq; | 
|  | 435 | struct lpfc_nodelist *ndlp; | 
|  | 436 | struct serv_parm *sp; | 
|  | 437 | struct lpfc_dmabuf *dmabuf; | 
|  | 438 | int rc = 0; | 
|  | 439 |  | 
|  | 440 | sp = &phba->fc_fabparam; | 
|  | 441 | ndlp = lpfc_findnode_did(vport, Fabric_DID); | 
|  | 442 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { | 
|  | 443 | rc = -ENODEV; | 
|  | 444 | goto fail; | 
|  | 445 | } | 
|  | 446 |  | 
|  | 447 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | 
|  | 448 | if (!dmabuf) { | 
|  | 449 | rc = -ENOMEM; | 
|  | 450 | goto fail; | 
|  | 451 | } | 
|  | 452 | dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys); | 
|  | 453 | if (!dmabuf->virt) { | 
|  | 454 | rc = -ENOMEM; | 
|  | 455 | goto fail_free_dmabuf; | 
|  | 456 | } | 
| James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 457 |  | 
| James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 458 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | 
|  | 459 | if (!mboxq) { | 
|  | 460 | rc = -ENOMEM; | 
|  | 461 | goto fail_free_coherent; | 
|  | 462 | } | 
|  | 463 | vport->port_state = LPFC_FABRIC_CFG_LINK; | 
|  | 464 | memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam)); | 
|  | 465 | lpfc_reg_vfi(mboxq, vport, dmabuf->phys); | 
|  | 466 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi; | 
|  | 467 | mboxq->vport = vport; | 
|  | 468 | mboxq->context1 = dmabuf; | 
|  | 469 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | 
|  | 470 | if (rc == MBX_NOT_FINISHED) { | 
|  | 471 | rc = -ENXIO; | 
|  | 472 | goto fail_free_mbox; | 
|  | 473 | } | 
|  | 474 | return 0; | 
|  | 475 |  | 
|  | 476 | fail_free_mbox: | 
|  | 477 | mempool_free(mboxq, phba->mbox_mem_pool); | 
|  | 478 | fail_free_coherent: | 
|  | 479 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); | 
|  | 480 | fail_free_dmabuf: | 
|  | 481 | kfree(dmabuf); | 
|  | 482 | fail: | 
|  | 483 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | 
|  | 484 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 485 | "0289 Issue Register VFI failed: Err %d\n", rc); | 
|  | 486 | return rc; | 
|  | 487 | } | 
|  | 488 |  | 
|  | 489 | /** | 
| James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 490 | * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean. | 
|  | 491 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 492 | * @sp: pointer to service parameter data structure. | 
|  | 493 | * | 
|  | 494 | * This routine is called from FLOGI/FDISC completion handler functions. | 
|  | 495 | * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric | 
|  | 496 | * node nodename is changed in the completion service parameter else return | 
|  | 497 | * 0. This function also set flag in the vport data structure to delay | 
|  | 498 | * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit | 
|  | 499 | * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric | 
|  | 500 | * node nodename is changed in the completion service parameter. | 
|  | 501 | * | 
|  | 502 | * Return code | 
|  | 503 | *   0 - FCID and Fabric Nodename and Fabric portname is not changed. | 
|  | 504 | *   1 - FCID or Fabric Nodename or Fabric portname is changed. | 
|  | 505 | * | 
|  | 506 | **/ | 
|  | 507 | static uint8_t | 
|  | 508 | lpfc_check_clean_addr_bit(struct lpfc_vport *vport, | 
|  | 509 | struct serv_parm *sp) | 
|  | 510 | { | 
|  | 511 | uint8_t fabric_param_changed = 0; | 
|  | 512 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | 513 |  | 
|  | 514 | if ((vport->fc_prevDID != vport->fc_myDID) || | 
|  | 515 | memcmp(&vport->fabric_portname, &sp->portName, | 
|  | 516 | sizeof(struct lpfc_name)) || | 
|  | 517 | memcmp(&vport->fabric_nodename, &sp->nodeName, | 
|  | 518 | sizeof(struct lpfc_name))) | 
|  | 519 | fabric_param_changed = 1; | 
|  | 520 |  | 
|  | 521 | /* | 
|  | 522 | * Word 1 Bit 31 in common service parameter is overloaded. | 
|  | 523 | * Word 1 Bit 31 in FLOGI request is multiple NPort request | 
|  | 524 | * Word 1 Bit 31 in FLOGI response is clean address bit | 
|  | 525 | * | 
|  | 526 | * If fabric parameter is changed and clean address bit is | 
|  | 527 | * cleared delay nport discovery if | 
|  | 528 | * - vport->fc_prevDID != 0 (not initial discovery) OR | 
|  | 529 | * - lpfc_delay_discovery module parameter is set. | 
|  | 530 | */ | 
|  | 531 | if (fabric_param_changed && !sp->cmn.clean_address_bit && | 
|  | 532 | (vport->fc_prevDID || lpfc_delay_discovery)) { | 
|  | 533 | spin_lock_irq(shost->host_lock); | 
|  | 534 | vport->fc_flag |= FC_DISC_DELAYED; | 
|  | 535 | spin_unlock_irq(shost->host_lock); | 
|  | 536 | } | 
|  | 537 |  | 
|  | 538 | return fabric_param_changed; | 
|  | 539 | } | 
|  | 540 |  | 
|  | 541 |  | 
|  | 542 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 543 | * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 544 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 545 | * @ndlp: pointer to a node-list data structure. | 
|  | 546 | * @sp: pointer to service parameter data structure. | 
|  | 547 | * @irsp: pointer to the IOCB within the lpfc response IOCB. | 
|  | 548 | * | 
|  | 549 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback | 
|  | 550 | * function to handle the completion of a Fabric Login (FLOGI) into a fabric | 
|  | 551 | * port in a fabric topology. It properly sets up the parameters to the @ndlp | 
|  | 552 | * from the IOCB response. It also check the newly assigned N_Port ID to the | 
|  | 553 | * @vport against the previously assigned N_Port ID. If it is different from | 
|  | 554 | * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine | 
|  | 555 | * is invoked on all the remaining nodes with the @vport to unregister the | 
|  | 556 | * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin() | 
|  | 557 | * is invoked to register login to the fabric. | 
|  | 558 | * | 
|  | 559 | * Return code | 
|  | 560 | *   0 - Success (currently, always return 0) | 
|  | 561 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 562 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 563 | lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, | 
|  | 564 | struct serv_parm *sp, IOCB_t *irsp) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 565 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 566 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | 567 | struct lpfc_hba  *phba = vport->phba; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 568 | struct lpfc_nodelist *np; | 
|  | 569 | struct lpfc_nodelist *next_np; | 
| James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 570 | uint8_t fabric_param_changed; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 571 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 572 | spin_lock_irq(shost->host_lock); | 
|  | 573 | vport->fc_flag |= FC_FABRIC; | 
|  | 574 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 575 |  | 
|  | 576 | phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov); | 
|  | 577 | if (sp->cmn.edtovResolution)	/* E_D_TOV ticks are in nanoseconds */ | 
|  | 578 | phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000; | 
|  | 579 |  | 
| James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 580 | phba->fc_edtovResol = sp->cmn.edtovResolution; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 581 | phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; | 
|  | 582 |  | 
| James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 583 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 584 | spin_lock_irq(shost->host_lock); | 
|  | 585 | vport->fc_flag |= FC_PUBLIC_LOOP; | 
|  | 586 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 587 | } | 
|  | 588 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 589 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 590 | memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 591 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 592 | ndlp->nlp_class_sup = 0; | 
|  | 593 | if (sp->cls1.classValid) | 
|  | 594 | ndlp->nlp_class_sup |= FC_COS_CLASS1; | 
|  | 595 | if (sp->cls2.classValid) | 
|  | 596 | ndlp->nlp_class_sup |= FC_COS_CLASS2; | 
|  | 597 | if (sp->cls3.classValid) | 
|  | 598 | ndlp->nlp_class_sup |= FC_COS_CLASS3; | 
|  | 599 | if (sp->cls4.classValid) | 
|  | 600 | ndlp->nlp_class_sup |= FC_COS_CLASS4; | 
|  | 601 | ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | | 
|  | 602 | sp->cmn.bbRcvSizeLsb; | 
| James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 603 |  | 
|  | 604 | fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp); | 
|  | 605 | memcpy(&vport->fabric_portname, &sp->portName, | 
|  | 606 | sizeof(struct lpfc_name)); | 
|  | 607 | memcpy(&vport->fabric_nodename, &sp->nodeName, | 
|  | 608 | sizeof(struct lpfc_name)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 609 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); | 
|  | 610 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 611 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { | 
|  | 612 | if (sp->cmn.response_multiple_NPort) { | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 613 | lpfc_printf_vlog(vport, KERN_WARNING, | 
|  | 614 | LOG_ELS | LOG_VPORT, | 
|  | 615 | "1816 FLOGI NPIV supported, " | 
|  | 616 | "response data 0x%x\n", | 
|  | 617 | sp->cmn.response_multiple_NPort); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 618 | phba->link_flag |= LS_NPIV_FAB_SUPPORTED; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 619 | } else { | 
|  | 620 | /* Because we asked f/w for NPIV it still expects us | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 621 | to call reg_vnpid atleast for the physcial host */ | 
|  | 622 | lpfc_printf_vlog(vport, KERN_WARNING, | 
|  | 623 | LOG_ELS | LOG_VPORT, | 
|  | 624 | "1817 Fabric does not support NPIV " | 
|  | 625 | "- configuring single port mode.\n"); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 626 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; | 
|  | 627 | } | 
|  | 628 | } | 
|  | 629 |  | 
| James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 630 | if (fabric_param_changed && | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 631 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { | 
|  | 632 |  | 
|  | 633 | /* If our NportID changed, we need to ensure all | 
|  | 634 | * remaining NPORTs get unreg_login'ed. | 
|  | 635 | */ | 
|  | 636 | list_for_each_entry_safe(np, next_np, | 
|  | 637 | &vport->fc_nodes, nlp_listp) { | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 638 | if (!NLP_CHK_NODE_ACT(np)) | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 639 | continue; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 640 | if ((np->nlp_state != NLP_STE_NPR_NODE) || | 
|  | 641 | !(np->nlp_flag & NLP_NPR_ADISC)) | 
|  | 642 | continue; | 
|  | 643 | spin_lock_irq(shost->host_lock); | 
|  | 644 | np->nlp_flag &= ~NLP_NPR_ADISC; | 
|  | 645 | spin_unlock_irq(shost->host_lock); | 
|  | 646 | lpfc_unreg_rpi(vport, np); | 
|  | 647 | } | 
| James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 648 | lpfc_cleanup_pending_mbox(vport); | 
| James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 649 |  | 
| James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 650 | if (phba->sli_rev == LPFC_SLI_REV4) { | 
| James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 651 | lpfc_sli4_unreg_all_rpis(vport); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 652 | lpfc_mbx_unreg_vpi(vport); | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 653 | spin_lock_irq(shost->host_lock); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 654 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; | 
| James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 655 | /* | 
|  | 656 | * If VPI is unreged, driver need to do INIT_VPI | 
|  | 657 | * before re-registering | 
|  | 658 | */ | 
| James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 659 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; | 
|  | 660 | spin_unlock_irq(shost->host_lock); | 
|  | 661 | } | 
| James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 662 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && | 
|  | 663 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { | 
|  | 664 | /* | 
|  | 665 | * Driver needs to re-reg VPI in order for f/w | 
|  | 666 | * to update the MAC address. | 
|  | 667 | */ | 
| James Smart | 9589b06 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 668 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); | 
| James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 669 | lpfc_register_new_vport(phba, vport, ndlp); | 
|  | 670 | return 0; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 671 | } | 
|  | 672 |  | 
| James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 673 | if (phba->sli_rev < LPFC_SLI_REV4) { | 
|  | 674 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE); | 
|  | 675 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED && | 
|  | 676 | vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) | 
|  | 677 | lpfc_register_new_vport(phba, vport, ndlp); | 
|  | 678 | else | 
|  | 679 | lpfc_issue_fabric_reglogin(vport); | 
|  | 680 | } else { | 
|  | 681 | ndlp->nlp_type |= NLP_FABRIC; | 
|  | 682 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); | 
| James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 683 | if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) && | 
|  | 684 | (vport->vpi_state & LPFC_VPI_REGISTERED)) { | 
| James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 685 | lpfc_start_fdiscs(phba); | 
|  | 686 | lpfc_do_scr_ns_plogi(phba, vport); | 
| James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 687 | } else if (vport->fc_flag & FC_VFI_REGISTERED) | 
| James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 688 | lpfc_issue_init_vpi(vport); | 
| James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 689 | else | 
| James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 690 | lpfc_issue_reg_vfi(vport); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 691 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 692 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 693 | } | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 694 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 695 | * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 696 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 697 | * @ndlp: pointer to a node-list data structure. | 
|  | 698 | * @sp: pointer to service parameter data structure. | 
|  | 699 | * | 
|  | 700 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback | 
|  | 701 | * function to handle the completion of a Fabric Login (FLOGI) into an N_Port | 
|  | 702 | * in a point-to-point topology. First, the @vport's N_Port Name is compared | 
|  | 703 | * with the received N_Port Name: if the @vport's N_Port Name is greater than | 
|  | 704 | * the received N_Port Name lexicographically, this node shall assign local | 
|  | 705 | * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and | 
|  | 706 | * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise, | 
|  | 707 | * this node shall just wait for the remote node to issue PLOGI and assign | 
|  | 708 | * N_Port IDs. | 
|  | 709 | * | 
|  | 710 | * Return code | 
|  | 711 | *   0 - Success | 
|  | 712 | *   -ENXIO - Fail | 
|  | 713 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 714 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 715 | lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, | 
|  | 716 | struct serv_parm *sp) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 717 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 718 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | 719 | struct lpfc_hba  *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 720 | LPFC_MBOXQ_t *mbox; | 
|  | 721 | int rc; | 
|  | 722 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 723 | spin_lock_irq(shost->host_lock); | 
|  | 724 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); | 
|  | 725 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 726 |  | 
|  | 727 | phba->fc_edtov = FF_DEF_EDTOV; | 
|  | 728 | phba->fc_ratov = FF_DEF_RATOV; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 729 | rc = memcmp(&vport->fc_portname, &sp->portName, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 730 | sizeof(vport->fc_portname)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 731 | if (rc >= 0) { | 
|  | 732 | /* This side will initiate the PLOGI */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 733 | spin_lock_irq(shost->host_lock); | 
|  | 734 | vport->fc_flag |= FC_PT2PT_PLOGI; | 
|  | 735 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 736 |  | 
|  | 737 | /* | 
|  | 738 | * N_Port ID cannot be 0, set our to LocalID the other | 
|  | 739 | * side will be RemoteID. | 
|  | 740 | */ | 
|  | 741 |  | 
|  | 742 | /* not equal */ | 
|  | 743 | if (rc) | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 744 | vport->fc_myDID = PT2PT_LocalID; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 745 |  | 
|  | 746 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | 
|  | 747 | if (!mbox) | 
|  | 748 | goto fail; | 
|  | 749 |  | 
|  | 750 | lpfc_config_link(phba, mbox); | 
|  | 751 |  | 
|  | 752 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 753 | mbox->vport = vport; | 
| James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 754 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 755 | if (rc == MBX_NOT_FINISHED) { | 
|  | 756 | mempool_free(mbox, phba->mbox_mem_pool); | 
|  | 757 | goto fail; | 
|  | 758 | } | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 759 | /* Decrement ndlp reference count indicating that ndlp can be | 
|  | 760 | * safely released when other references to it are done. | 
|  | 761 | */ | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 762 | lpfc_nlp_put(ndlp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 763 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 764 | ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 765 | if (!ndlp) { | 
|  | 766 | /* | 
|  | 767 | * Cannot find existing Fabric ndlp, so allocate a | 
|  | 768 | * new one | 
|  | 769 | */ | 
|  | 770 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | 
|  | 771 | if (!ndlp) | 
|  | 772 | goto fail; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 773 | lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 774 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | 
|  | 775 | ndlp = lpfc_enable_node(vport, ndlp, | 
|  | 776 | NLP_STE_UNUSED_NODE); | 
|  | 777 | if(!ndlp) | 
|  | 778 | goto fail; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 779 | } | 
|  | 780 |  | 
|  | 781 | memcpy(&ndlp->nlp_portname, &sp->portName, | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 782 | sizeof(struct lpfc_name)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 783 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 784 | sizeof(struct lpfc_name)); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 785 | /* Set state will put ndlp onto node list if not already done */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 786 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); | 
|  | 787 | spin_lock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 788 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 789 | spin_unlock_irq(shost->host_lock); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 790 | } else | 
|  | 791 | /* This side will wait for the PLOGI, decrement ndlp reference | 
|  | 792 | * count indicating that ndlp can be released when other | 
|  | 793 | * references to it are done. | 
|  | 794 | */ | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 795 | lpfc_nlp_put(ndlp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 796 |  | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 797 | /* If we are pt2pt with another NPort, force NPIV off! */ | 
|  | 798 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; | 
|  | 799 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 800 | spin_lock_irq(shost->host_lock); | 
|  | 801 | vport->fc_flag |= FC_PT2PT; | 
|  | 802 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 803 |  | 
|  | 804 | /* Start discovery - this should just do CLEAR_LA */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 805 | lpfc_disc_start(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 806 | return 0; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 807 | fail: | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 808 | return -ENXIO; | 
|  | 809 | } | 
|  | 810 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 811 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 812 | * lpfc_cmpl_els_flogi - Completion callback function for flogi | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 813 | * @phba: pointer to lpfc hba data structure. | 
|  | 814 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 815 | * @rspiocb: pointer to lpfc response iocb data structure. | 
|  | 816 | * | 
|  | 817 | * This routine is the top-level completion callback function for issuing | 
|  | 818 | * a Fabric Login (FLOGI) command. If the response IOCB reported error, | 
|  | 819 | * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If | 
|  | 820 | * retry has been made (either immediately or delayed with lpfc_els_retry() | 
|  | 821 | * returning 1), the command IOCB will be released and function returned. | 
|  | 822 | * If the retry attempt has been given up (possibly reach the maximum | 
|  | 823 | * number of retries), one additional decrement of ndlp reference shall be | 
|  | 824 | * invoked before going out after releasing the command IOCB. This will | 
|  | 825 | * actually release the remote node (Note, lpfc_els_free_iocb() will also | 
|  | 826 | * invoke one decrement of ndlp reference count). If no error reported in | 
|  | 827 | * the IOCB status, the command Port ID field is used to determine whether | 
|  | 828 | * this is a point-to-point topology or a fabric topology: if the Port ID | 
|  | 829 | * field is assigned, it is a fabric topology; otherwise, it is a | 
|  | 830 | * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or | 
|  | 831 | * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the | 
|  | 832 | * specific topology completion conditions. | 
|  | 833 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 834 | static void | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 835 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | 
|  | 836 | struct lpfc_iocbq *rspiocb) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 837 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 838 | struct lpfc_vport *vport = cmdiocb->vport; | 
|  | 839 | struct Scsi_Host  *shost = lpfc_shost_from_vport(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 840 | IOCB_t *irsp = &rspiocb->iocb; | 
|  | 841 | struct lpfc_nodelist *ndlp = cmdiocb->context1; | 
|  | 842 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; | 
|  | 843 | struct serv_parm *sp; | 
| James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 844 | uint16_t fcf_index; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 845 | int rc; | 
|  | 846 |  | 
|  | 847 | /* Check to see if link went down during discovery */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 848 | if (lpfc_els_chk_latt(vport)) { | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 849 | /* One additional decrement on node reference count to | 
|  | 850 | * trigger the release of the node | 
|  | 851 | */ | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 852 | lpfc_nlp_put(ndlp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 853 | goto out; | 
|  | 854 | } | 
|  | 855 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 856 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 857 | "FLOGI cmpl:      status:x%x/x%x state:x%x", | 
|  | 858 | irsp->ulpStatus, irsp->un.ulpWord[4], | 
|  | 859 | vport->port_state); | 
|  | 860 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 861 | if (irsp->ulpStatus) { | 
| James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 862 | /* | 
| James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 863 | * In case of FIP mode, perform roundrobin FCF failover | 
| James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 864 | * due to new FCF discovery | 
|  | 865 | */ | 
|  | 866 | if ((phba->hba_flag & HBA_FIP_SUPPORT) && | 
| James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 867 | (phba->fcf.fcf_flag & FCF_DISCOVERY) && | 
| James Smart | 9589b06 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 868 | !((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && | 
|  | 869 | (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED))) { | 
| James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 870 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, | 
| James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 871 | "2611 FLOGI failed on FCF (x%x), " | 
|  | 872 | "status:x%x/x%x, tmo:x%x, perform " | 
|  | 873 | "roundrobin FCF failover\n", | 
| James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 874 | phba->fcf.current_rec.fcf_indx, | 
|  | 875 | irsp->ulpStatus, irsp->un.ulpWord[4], | 
|  | 876 | irsp->ulpTimeout); | 
| James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 877 | lpfc_sli4_set_fcf_flogi_fail(phba, | 
|  | 878 | phba->fcf.current_rec.fcf_indx); | 
| James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 879 | fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); | 
| James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 880 | rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index); | 
|  | 881 | if (rc) | 
|  | 882 | goto out; | 
| James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 883 | } | 
|  | 884 |  | 
| James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 885 | /* FLOGI failure */ | 
|  | 886 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 887 | "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n", | 
|  | 888 | irsp->ulpStatus, irsp->un.ulpWord[4], | 
|  | 889 | irsp->ulpTimeout); | 
|  | 890 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 891 | /* Check for retry */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 892 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 893 | goto out; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 894 |  | 
| James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 895 | /* FLOGI failure */ | 
|  | 896 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 897 | "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n", | 
|  | 898 | irsp->ulpStatus, irsp->un.ulpWord[4], | 
|  | 899 | irsp->ulpTimeout); | 
|  | 900 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 901 | /* FLOGI failed, so there is no fabric */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 902 | spin_lock_irq(shost->host_lock); | 
|  | 903 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); | 
|  | 904 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 905 |  | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 906 | /* If private loop, then allow max outstanding els to be | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 907 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no | 
|  | 908 | * alpa map would take too long otherwise. | 
|  | 909 | */ | 
|  | 910 | if (phba->alpa_map[0] == 0) { | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 911 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; | 
| James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 912 | if ((phba->sli_rev == LPFC_SLI_REV4) && | 
|  | 913 | (!(vport->fc_flag & FC_VFI_REGISTERED) || | 
|  | 914 | (vport->fc_prevDID != vport->fc_myDID))) { | 
|  | 915 | if (vport->fc_flag & FC_VFI_REGISTERED) | 
|  | 916 | lpfc_sli4_unreg_all_rpis(vport); | 
|  | 917 | lpfc_issue_reg_vfi(vport); | 
|  | 918 | lpfc_nlp_put(ndlp); | 
|  | 919 | goto out; | 
|  | 920 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 921 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 922 | goto flogifail; | 
|  | 923 | } | 
| James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 924 | spin_lock_irq(shost->host_lock); | 
|  | 925 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; | 
| James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 926 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; | 
| James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 927 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 928 |  | 
|  | 929 | /* | 
|  | 930 | * The FLogI succeeded.  Sync the data for the CPU before | 
|  | 931 | * accessing it. | 
|  | 932 | */ | 
|  | 933 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); | 
|  | 934 |  | 
|  | 935 | sp = prsp->virt + sizeof(uint32_t); | 
|  | 936 |  | 
|  | 937 | /* FLOGI completes successfully */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 938 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
| André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 939 | "0101 FLOGI completes successfully " | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 940 | "Data: x%x x%x x%x x%x\n", | 
|  | 941 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, | 
|  | 942 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 943 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 944 | if (vport->port_state == LPFC_FLOGI) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 945 | /* | 
|  | 946 | * If Common Service Parameters indicate Nport | 
|  | 947 | * we are point to point, if Fport we are Fabric. | 
|  | 948 | */ | 
|  | 949 | if (sp->cmn.fPort) | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 950 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); | 
| James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 951 | else if (!(phba->hba_flag & HBA_FCOE_MODE)) | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 952 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); | 
| James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 953 | else { | 
|  | 954 | lpfc_printf_vlog(vport, KERN_ERR, | 
|  | 955 | LOG_FIP | LOG_ELS, | 
|  | 956 | "2831 FLOGI response with cleared Fabric " | 
|  | 957 | "bit fcf_index 0x%x " | 
|  | 958 | "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x " | 
|  | 959 | "Fabric Name " | 
|  | 960 | "%02x%02x%02x%02x%02x%02x%02x%02x\n", | 
|  | 961 | phba->fcf.current_rec.fcf_indx, | 
|  | 962 | phba->fcf.current_rec.switch_name[0], | 
|  | 963 | phba->fcf.current_rec.switch_name[1], | 
|  | 964 | phba->fcf.current_rec.switch_name[2], | 
|  | 965 | phba->fcf.current_rec.switch_name[3], | 
|  | 966 | phba->fcf.current_rec.switch_name[4], | 
|  | 967 | phba->fcf.current_rec.switch_name[5], | 
|  | 968 | phba->fcf.current_rec.switch_name[6], | 
|  | 969 | phba->fcf.current_rec.switch_name[7], | 
|  | 970 | phba->fcf.current_rec.fabric_name[0], | 
|  | 971 | phba->fcf.current_rec.fabric_name[1], | 
|  | 972 | phba->fcf.current_rec.fabric_name[2], | 
|  | 973 | phba->fcf.current_rec.fabric_name[3], | 
|  | 974 | phba->fcf.current_rec.fabric_name[4], | 
|  | 975 | phba->fcf.current_rec.fabric_name[5], | 
|  | 976 | phba->fcf.current_rec.fabric_name[6], | 
|  | 977 | phba->fcf.current_rec.fabric_name[7]); | 
|  | 978 | lpfc_nlp_put(ndlp); | 
|  | 979 | spin_lock_irq(&phba->hbalock); | 
|  | 980 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; | 
| James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 981 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); | 
| James Smart | dbb6b3a | 2010-06-08 18:31:37 -0400 | [diff] [blame] | 982 | spin_unlock_irq(&phba->hbalock); | 
|  | 983 | goto out; | 
|  | 984 | } | 
| James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 985 | if (!rc) { | 
|  | 986 | /* Mark the FCF discovery process done */ | 
| James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 987 | if (phba->hba_flag & HBA_FIP_SUPPORT) | 
|  | 988 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP | | 
|  | 989 | LOG_ELS, | 
| James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 990 | "2769 FLOGI to FCF (x%x) " | 
|  | 991 | "completed successfully\n", | 
| James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 992 | phba->fcf.current_rec.fcf_indx); | 
| James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 993 | spin_lock_irq(&phba->hbalock); | 
|  | 994 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; | 
| James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 995 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); | 
| James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 996 | spin_unlock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 997 | goto out; | 
| James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 998 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 999 | } | 
|  | 1000 |  | 
|  | 1001 | flogifail: | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1002 | lpfc_nlp_put(ndlp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1003 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1004 | if (!lpfc_error_lost_link(irsp)) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1005 | /* FLOGI failed, so just use loop map to make discovery list */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1006 | lpfc_disc_list_loopmap(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1007 |  | 
|  | 1008 | /* Start discovery */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1009 | lpfc_disc_start(vport); | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1010 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || | 
|  | 1011 | ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) && | 
|  | 1012 | (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) && | 
|  | 1013 | (phba->link_state != LPFC_CLEAR_LA)) { | 
|  | 1014 | /* If FLOGI failed enable link interrupt. */ | 
|  | 1015 | lpfc_issue_clear_la(phba, vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1016 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1017 | out: | 
|  | 1018 | lpfc_els_free_iocb(phba, cmdiocb); | 
|  | 1019 | } | 
|  | 1020 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1021 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1022 | * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1023 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 1024 | * @ndlp: pointer to a node-list data structure. | 
|  | 1025 | * @retry: number of retries to the command IOCB. | 
|  | 1026 | * | 
|  | 1027 | * This routine issues a Fabric Login (FLOGI) Request ELS command | 
|  | 1028 | * for a @vport. The initiator service parameters are put into the payload | 
|  | 1029 | * of the FLOGI Request IOCB and the top-level callback function pointer | 
|  | 1030 | * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback | 
|  | 1031 | * function field. The lpfc_issue_fabric_iocb routine is invoked to send | 
|  | 1032 | * out FLOGI ELS command with one outstanding fabric IOCB at a time. | 
|  | 1033 | * | 
|  | 1034 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | 
|  | 1035 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | 
|  | 1036 | * will be stored into the context1 field of the IOCB for the completion | 
|  | 1037 | * callback function to the FLOGI ELS command. | 
|  | 1038 | * | 
|  | 1039 | * Return code | 
|  | 1040 | *   0 - successfully issued flogi iocb for @vport | 
|  | 1041 | *   1 - failed to issue flogi iocb for @vport | 
|  | 1042 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1043 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1044 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1045 | uint8_t retry) | 
|  | 1046 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1047 | struct lpfc_hba  *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1048 | struct serv_parm *sp; | 
|  | 1049 | IOCB_t *icmd; | 
|  | 1050 | struct lpfc_iocbq *elsiocb; | 
|  | 1051 | struct lpfc_sli_ring *pring; | 
|  | 1052 | uint8_t *pcmd; | 
|  | 1053 | uint16_t cmdsize; | 
|  | 1054 | uint32_t tmo; | 
|  | 1055 | int rc; | 
|  | 1056 |  | 
|  | 1057 | pring = &phba->sli.ring[LPFC_ELS_RING]; | 
|  | 1058 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1059 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1060 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, | 
|  | 1061 | ndlp->nlp_DID, ELS_CMD_FLOGI); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1062 |  | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1063 | if (!elsiocb) | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1064 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1065 |  | 
|  | 1066 | icmd = &elsiocb->iocb; | 
|  | 1067 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 1068 |  | 
|  | 1069 | /* For FLOGI request, remainder of payload is service parameters */ | 
|  | 1070 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1071 | pcmd += sizeof(uint32_t); | 
|  | 1072 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1073 | sp = (struct serv_parm *) pcmd; | 
|  | 1074 |  | 
|  | 1075 | /* Setup CSPs accordingly for Fabric */ | 
|  | 1076 | sp->cmn.e_d_tov = 0; | 
|  | 1077 | sp->cmn.w2.r_a_tov = 0; | 
|  | 1078 | sp->cls1.classValid = 0; | 
|  | 1079 | sp->cls2.seqDelivery = 1; | 
|  | 1080 | sp->cls3.seqDelivery = 1; | 
|  | 1081 | if (sp->cmn.fcphLow < FC_PH3) | 
|  | 1082 | sp->cmn.fcphLow = FC_PH3; | 
|  | 1083 | if (sp->cmn.fcphHigh < FC_PH3) | 
|  | 1084 | sp->cmn.fcphHigh = FC_PH3; | 
|  | 1085 |  | 
| James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 1086 | if  (phba->sli_rev == LPFC_SLI_REV4) { | 
|  | 1087 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == | 
|  | 1088 | LPFC_SLI_INTF_IF_TYPE_0) { | 
|  | 1089 | elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1); | 
|  | 1090 | elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1); | 
|  | 1091 | /* FLOGI needs to be 3 for WQE FCFI */ | 
|  | 1092 | /* Set the fcfi to the fcfi we registered with */ | 
|  | 1093 | elsiocb->iocb.ulpContext = phba->fcf.fcfi; | 
|  | 1094 | } | 
| James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 1095 | } else { | 
|  | 1096 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { | 
|  | 1097 | sp->cmn.request_multiple_Nport = 1; | 
|  | 1098 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ | 
|  | 1099 | icmd->ulpCt_h = 1; | 
|  | 1100 | icmd->ulpCt_l = 0; | 
|  | 1101 | } else | 
|  | 1102 | sp->cmn.request_multiple_Nport = 0; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1103 | } | 
|  | 1104 |  | 
| James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1105 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) { | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1106 | icmd->un.elsreq64.myID = 0; | 
|  | 1107 | icmd->un.elsreq64.fl = 1; | 
|  | 1108 | } | 
|  | 1109 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1110 | tmo = phba->fc_ratov; | 
|  | 1111 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1112 | lpfc_set_disctmo(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1113 | phba->fc_ratov = tmo; | 
|  | 1114 |  | 
|  | 1115 | phba->fc_stat.elsXmitFLOGI++; | 
|  | 1116 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1117 |  | 
|  | 1118 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 1119 | "Issue FLOGI:     opt:x%x", | 
|  | 1120 | phba->sli3_options, 0, 0); | 
|  | 1121 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1122 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1123 | if (rc == IOCB_ERROR) { | 
|  | 1124 | lpfc_els_free_iocb(phba, elsiocb); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1125 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1126 | } | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1127 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1128 | } | 
|  | 1129 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1130 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1131 | * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1132 | * @phba: pointer to lpfc hba data structure. | 
|  | 1133 | * | 
|  | 1134 | * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs | 
|  | 1135 | * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq | 
|  | 1136 | * list and issues an abort IOCB commond on each outstanding IOCB that | 
|  | 1137 | * contains a active Fabric_DID ndlp. Note that this function is to issue | 
|  | 1138 | * the abort IOCB command on all the outstanding IOCBs, thus when this | 
|  | 1139 | * function returns, it does not guarantee all the IOCBs are actually aborted. | 
|  | 1140 | * | 
|  | 1141 | * Return code | 
| Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 1142 | *   0 - Successfully issued abort iocb on all outstanding flogis (Always 0) | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1143 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1144 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1145 | lpfc_els_abort_flogi(struct lpfc_hba *phba) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1146 | { | 
|  | 1147 | struct lpfc_sli_ring *pring; | 
|  | 1148 | struct lpfc_iocbq *iocb, *next_iocb; | 
|  | 1149 | struct lpfc_nodelist *ndlp; | 
|  | 1150 | IOCB_t *icmd; | 
|  | 1151 |  | 
|  | 1152 | /* Abort outstanding I/O on NPort <nlp_DID> */ | 
|  | 1153 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1154 | "0201 Abort outstanding I/O on NPort x%x\n", | 
|  | 1155 | Fabric_DID); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1156 |  | 
|  | 1157 | pring = &phba->sli.ring[LPFC_ELS_RING]; | 
|  | 1158 |  | 
|  | 1159 | /* | 
|  | 1160 | * Check the txcmplq for an iocb that matches the nport the driver is | 
|  | 1161 | * searching for. | 
|  | 1162 | */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1163 | spin_lock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1164 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { | 
|  | 1165 | icmd = &iocb->iocb; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1166 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR && | 
|  | 1167 | icmd->un.elsreq64.bdl.ulpIoTag32) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1168 | ndlp = (struct lpfc_nodelist *)(iocb->context1); | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1169 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && | 
|  | 1170 | (ndlp->nlp_DID == Fabric_DID)) | 
| James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 1171 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1172 | } | 
|  | 1173 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1174 | spin_unlock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1175 |  | 
|  | 1176 | return 0; | 
|  | 1177 | } | 
|  | 1178 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1179 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1180 | * lpfc_initial_flogi - Issue an initial fabric login for a vport | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1181 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 1182 | * | 
|  | 1183 | * This routine issues an initial Fabric Login (FLOGI) for the @vport | 
|  | 1184 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from | 
|  | 1185 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and | 
|  | 1186 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, | 
|  | 1187 | * it will just be enabled and made active. The lpfc_issue_els_flogi() routine | 
|  | 1188 | * is then invoked with the @vport and the ndlp to perform the FLOGI for the | 
|  | 1189 | * @vport. | 
|  | 1190 | * | 
|  | 1191 | * Return code | 
|  | 1192 | *   0 - failed to issue initial flogi for @vport | 
|  | 1193 | *   1 - successfully issued initial flogi for @vport | 
|  | 1194 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1195 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1196 | lpfc_initial_flogi(struct lpfc_vport *vport) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1197 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1198 | struct lpfc_hba *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1199 | struct lpfc_nodelist *ndlp; | 
|  | 1200 |  | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1201 | vport->port_state = LPFC_FLOGI; | 
|  | 1202 | lpfc_set_disctmo(vport); | 
|  | 1203 |  | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1204 | /* First look for the Fabric ndlp */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1205 | ndlp = lpfc_findnode_did(vport, Fabric_DID); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1206 | if (!ndlp) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1207 | /* Cannot find existing Fabric ndlp, so allocate a new one */ | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1208 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | 
|  | 1209 | if (!ndlp) | 
|  | 1210 | return 0; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1211 | lpfc_nlp_init(vport, ndlp, Fabric_DID); | 
| James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 1212 | /* Set the node type */ | 
|  | 1213 | ndlp->nlp_type |= NLP_FABRIC; | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1214 | /* Put ndlp onto node list */ | 
|  | 1215 | lpfc_enqueue_node(vport, ndlp); | 
|  | 1216 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | 
|  | 1217 | /* re-setup ndlp without removing from node list */ | 
|  | 1218 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | 
|  | 1219 | if (!ndlp) | 
|  | 1220 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1221 | } | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1222 |  | 
| James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1223 | if (lpfc_issue_els_flogi(vport, ndlp, 0)) { | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1224 | /* This decrement of reference count to node shall kick off | 
|  | 1225 | * the release of the node. | 
|  | 1226 | */ | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1227 | lpfc_nlp_put(ndlp); | 
| James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1228 | return 0; | 
|  | 1229 | } | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1230 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1231 | } | 
|  | 1232 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1233 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1234 | * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1235 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 1236 | * | 
|  | 1237 | * This routine issues an initial Fabric Discover (FDISC) for the @vport | 
|  | 1238 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from | 
|  | 1239 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and | 
|  | 1240 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, | 
|  | 1241 | * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine | 
|  | 1242 | * is then invoked with the @vport and the ndlp to perform the FDISC for the | 
|  | 1243 | * @vport. | 
|  | 1244 | * | 
|  | 1245 | * Return code | 
|  | 1246 | *   0 - failed to issue initial fdisc for @vport | 
|  | 1247 | *   1 - successfully issued initial fdisc for @vport | 
|  | 1248 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1249 | int | 
|  | 1250 | lpfc_initial_fdisc(struct lpfc_vport *vport) | 
|  | 1251 | { | 
|  | 1252 | struct lpfc_hba *phba = vport->phba; | 
|  | 1253 | struct lpfc_nodelist *ndlp; | 
|  | 1254 |  | 
|  | 1255 | /* First look for the Fabric ndlp */ | 
|  | 1256 | ndlp = lpfc_findnode_did(vport, Fabric_DID); | 
|  | 1257 | if (!ndlp) { | 
|  | 1258 | /* Cannot find existing Fabric ndlp, so allocate a new one */ | 
|  | 1259 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | 
|  | 1260 | if (!ndlp) | 
|  | 1261 | return 0; | 
|  | 1262 | lpfc_nlp_init(vport, ndlp, Fabric_DID); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1263 | /* Put ndlp onto node list */ | 
|  | 1264 | lpfc_enqueue_node(vport, ndlp); | 
|  | 1265 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | 
|  | 1266 | /* re-setup ndlp without removing from node list */ | 
|  | 1267 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | 
|  | 1268 | if (!ndlp) | 
|  | 1269 | return 0; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1270 | } | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1271 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1272 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1273 | /* decrement node reference count to trigger the release of | 
|  | 1274 | * the node. | 
|  | 1275 | */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1276 | lpfc_nlp_put(ndlp); | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1277 | return 0; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1278 | } | 
|  | 1279 | return 1; | 
|  | 1280 | } | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1281 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1282 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1283 | * lpfc_more_plogi - Check and issue remaining plogis for a vport | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1284 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 1285 | * | 
|  | 1286 | * This routine checks whether there are more remaining Port Logins | 
|  | 1287 | * (PLOGI) to be issued for the @vport. If so, it will invoke the routine | 
|  | 1288 | * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes | 
|  | 1289 | * to issue ELS PLOGIs up to the configured discover threads with the | 
|  | 1290 | * @vport (@vport->cfg_discovery_threads). The function also decrement | 
|  | 1291 | * the @vport's num_disc_node by 1 if it is not already 0. | 
|  | 1292 | **/ | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1293 | void | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1294 | lpfc_more_plogi(struct lpfc_vport *vport) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1295 | { | 
|  | 1296 | int sentplogi; | 
|  | 1297 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1298 | if (vport->num_disc_nodes) | 
|  | 1299 | vport->num_disc_nodes--; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1300 |  | 
|  | 1301 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1302 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, | 
|  | 1303 | "0232 Continue discovery with %d PLOGIs to go " | 
|  | 1304 | "Data: x%x x%x x%x\n", | 
|  | 1305 | vport->num_disc_nodes, vport->fc_plogi_cnt, | 
|  | 1306 | vport->fc_flag, vport->port_state); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1307 | /* Check to see if there are more PLOGIs to be sent */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1308 | if (vport->fc_flag & FC_NLP_MORE) | 
|  | 1309 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ | 
|  | 1310 | sentplogi = lpfc_els_disc_plogi(vport); | 
|  | 1311 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1312 | return; | 
|  | 1313 | } | 
|  | 1314 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1315 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1316 | * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1317 | * @phba: pointer to lpfc hba data structure. | 
|  | 1318 | * @prsp: pointer to response IOCB payload. | 
|  | 1319 | * @ndlp: pointer to a node-list data structure. | 
|  | 1320 | * | 
|  | 1321 | * This routine checks and indicates whether the WWPN of an N_Port, retrieved | 
|  | 1322 | * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt. | 
|  | 1323 | * The following cases are considered N_Port confirmed: | 
|  | 1324 | * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches | 
|  | 1325 | * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but | 
|  | 1326 | * it does not have WWPN assigned either. If the WWPN is confirmed, the | 
|  | 1327 | * pointer to the @ndlp will be returned. If the WWPN is not confirmed: | 
|  | 1328 | * 1) if there is a node on vport list other than the @ndlp with the same | 
|  | 1329 | * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked | 
|  | 1330 | * on that node to release the RPI associated with the node; 2) if there is | 
|  | 1331 | * no node found on vport list with the same WWPN of the N_Port PLOGI logged | 
|  | 1332 | * into, a new node shall be allocated (or activated). In either case, the | 
|  | 1333 | * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall | 
|  | 1334 | * be released and the new_ndlp shall be put on to the vport node list and | 
|  | 1335 | * its pointer returned as the confirmed node. | 
|  | 1336 | * | 
|  | 1337 | * Note that before the @ndlp got "released", the keepDID from not-matching | 
|  | 1338 | * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID | 
|  | 1339 | * of the @ndlp. This is because the release of @ndlp is actually to put it | 
|  | 1340 | * into an inactive state on the vport node list and the vport node list | 
|  | 1341 | * management algorithm does not allow two node with a same DID. | 
|  | 1342 | * | 
|  | 1343 | * Return code | 
|  | 1344 | *   pointer to the PLOGI N_Port @ndlp | 
|  | 1345 | **/ | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1346 | static struct lpfc_nodelist * | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1347 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1348 | struct lpfc_nodelist *ndlp) | 
|  | 1349 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1350 | struct lpfc_vport    *vport = ndlp->vport; | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1351 | struct lpfc_nodelist *new_ndlp; | 
| James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1352 | struct lpfc_rport_data *rdata; | 
|  | 1353 | struct fc_rport *rport; | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1354 | struct serv_parm *sp; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1355 | uint8_t  name[sizeof(struct lpfc_name)]; | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1356 | uint32_t rc, keepDID = 0; | 
| James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1357 | int  put_node; | 
|  | 1358 | int  put_rport; | 
| James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1359 | struct lpfc_node_rrqs rrq; | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1360 |  | 
| James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 1361 | /* Fabric nodes can have the same WWPN so we don't bother searching | 
|  | 1362 | * by WWPN.  Just return the ndlp that was given to us. | 
|  | 1363 | */ | 
|  | 1364 | if (ndlp->nlp_type & NLP_FABRIC) | 
|  | 1365 | return ndlp; | 
|  | 1366 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1367 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); | 
| James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1368 | memset(name, 0, sizeof(struct lpfc_name)); | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1369 |  | 
| James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1370 | /* Now we find out if the NPort we are logging into, matches the WWPN | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1371 | * we have for that ndlp. If not, we have some work to do. | 
|  | 1372 | */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1373 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1374 |  | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1375 | if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp)) | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1376 | return ndlp; | 
| James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1377 | memset(&rrq.xri_bitmap, 0, sizeof(new_ndlp->active_rrqs.xri_bitmap)); | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1378 |  | 
|  | 1379 | if (!new_ndlp) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1380 | rc = memcmp(&ndlp->nlp_portname, name, | 
|  | 1381 | sizeof(struct lpfc_name)); | 
| James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1382 | if (!rc) | 
|  | 1383 | return ndlp; | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1384 | new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC); | 
|  | 1385 | if (!new_ndlp) | 
|  | 1386 | return ndlp; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1387 | lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1388 | } else if (!NLP_CHK_NODE_ACT(new_ndlp)) { | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1389 | rc = memcmp(&ndlp->nlp_portname, name, | 
|  | 1390 | sizeof(struct lpfc_name)); | 
|  | 1391 | if (!rc) | 
|  | 1392 | return ndlp; | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1393 | new_ndlp = lpfc_enable_node(vport, new_ndlp, | 
|  | 1394 | NLP_STE_UNUSED_NODE); | 
|  | 1395 | if (!new_ndlp) | 
|  | 1396 | return ndlp; | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1397 | keepDID = new_ndlp->nlp_DID; | 
| James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1398 | if (phba->sli_rev == LPFC_SLI_REV4) | 
|  | 1399 | memcpy(&rrq.xri_bitmap, | 
|  | 1400 | &new_ndlp->active_rrqs.xri_bitmap, | 
|  | 1401 | sizeof(new_ndlp->active_rrqs.xri_bitmap)); | 
|  | 1402 | } else { | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1403 | keepDID = new_ndlp->nlp_DID; | 
| James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1404 | if (phba->sli_rev == LPFC_SLI_REV4) | 
|  | 1405 | memcpy(&rrq.xri_bitmap, | 
|  | 1406 | &new_ndlp->active_rrqs.xri_bitmap, | 
|  | 1407 | sizeof(new_ndlp->active_rrqs.xri_bitmap)); | 
|  | 1408 | } | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1409 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1410 | lpfc_unreg_rpi(vport, new_ndlp); | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1411 | new_ndlp->nlp_DID = ndlp->nlp_DID; | 
| James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1412 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; | 
| James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1413 | if (phba->sli_rev == LPFC_SLI_REV4) | 
|  | 1414 | memcpy(new_ndlp->active_rrqs.xri_bitmap, | 
|  | 1415 | &ndlp->active_rrqs.xri_bitmap, | 
|  | 1416 | sizeof(ndlp->active_rrqs.xri_bitmap)); | 
| James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1417 |  | 
|  | 1418 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) | 
|  | 1419 | new_ndlp->nlp_flag |= NLP_NPR_2B_DISC; | 
|  | 1420 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; | 
|  | 1421 |  | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1422 | /* Set state will put new_ndlp on to node list if not already done */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1423 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1424 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1425 | /* Move this back to NPR state */ | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1426 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { | 
|  | 1427 | /* The new_ndlp is replacing ndlp totally, so we need | 
|  | 1428 | * to put ndlp on UNUSED list and try to free it. | 
|  | 1429 | */ | 
| James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1430 |  | 
|  | 1431 | /* Fix up the rport accordingly */ | 
|  | 1432 | rport =  ndlp->rport; | 
|  | 1433 | if (rport) { | 
|  | 1434 | rdata = rport->dd_data; | 
|  | 1435 | if (rdata->pnode == ndlp) { | 
|  | 1436 | lpfc_nlp_put(ndlp); | 
|  | 1437 | ndlp->rport = NULL; | 
|  | 1438 | rdata->pnode = lpfc_nlp_get(new_ndlp); | 
|  | 1439 | new_ndlp->rport = rport; | 
|  | 1440 | } | 
|  | 1441 | new_ndlp->nlp_type = ndlp->nlp_type; | 
|  | 1442 | } | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1443 | /* We shall actually free the ndlp with both nlp_DID and | 
|  | 1444 | * nlp_portname fields equals 0 to avoid any ndlp on the | 
|  | 1445 | * nodelist never to be used. | 
|  | 1446 | */ | 
|  | 1447 | if (ndlp->nlp_DID == 0) { | 
|  | 1448 | spin_lock_irq(&phba->ndlp_lock); | 
|  | 1449 | NLP_SET_FREE_REQ(ndlp); | 
|  | 1450 | spin_unlock_irq(&phba->ndlp_lock); | 
|  | 1451 | } | 
| James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1452 |  | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1453 | /* Two ndlps cannot have the same did on the nodelist */ | 
|  | 1454 | ndlp->nlp_DID = keepDID; | 
| James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1455 | if (phba->sli_rev == LPFC_SLI_REV4) | 
|  | 1456 | memcpy(&ndlp->active_rrqs.xri_bitmap, | 
|  | 1457 | &rrq.xri_bitmap, | 
|  | 1458 | sizeof(ndlp->active_rrqs.xri_bitmap)); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1459 | lpfc_drop_node(vport, ndlp); | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1460 | } | 
| James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1461 | else { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1462 | lpfc_unreg_rpi(vport, ndlp); | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1463 | /* Two ndlps cannot have the same did */ | 
|  | 1464 | ndlp->nlp_DID = keepDID; | 
| James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1465 | if (phba->sli_rev == LPFC_SLI_REV4) | 
|  | 1466 | memcpy(&ndlp->active_rrqs.xri_bitmap, | 
|  | 1467 | &rrq.xri_bitmap, | 
|  | 1468 | sizeof(ndlp->active_rrqs.xri_bitmap)); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1469 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); | 
| James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 1470 | /* Since we are swapping the ndlp passed in with the new one | 
|  | 1471 | * and the did has already been swapped, copy over the | 
|  | 1472 | * state and names. | 
|  | 1473 | */ | 
|  | 1474 | memcpy(&new_ndlp->nlp_portname, &ndlp->nlp_portname, | 
|  | 1475 | sizeof(struct lpfc_name)); | 
|  | 1476 | memcpy(&new_ndlp->nlp_nodename, &ndlp->nlp_nodename, | 
|  | 1477 | sizeof(struct lpfc_name)); | 
|  | 1478 | new_ndlp->nlp_state = ndlp->nlp_state; | 
|  | 1479 | /* Fix up the rport accordingly */ | 
|  | 1480 | rport = ndlp->rport; | 
|  | 1481 | if (rport) { | 
|  | 1482 | rdata = rport->dd_data; | 
|  | 1483 | put_node = rdata->pnode != NULL; | 
|  | 1484 | put_rport = ndlp->rport != NULL; | 
|  | 1485 | rdata->pnode = NULL; | 
|  | 1486 | ndlp->rport = NULL; | 
|  | 1487 | if (put_node) | 
|  | 1488 | lpfc_nlp_put(ndlp); | 
|  | 1489 | if (put_rport) | 
|  | 1490 | put_device(&rport->dev); | 
|  | 1491 | } | 
| James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1492 | } | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1493 | return new_ndlp; | 
|  | 1494 | } | 
|  | 1495 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1496 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1497 | * lpfc_end_rscn - Check and handle more rscn for a vport | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1498 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 1499 | * | 
|  | 1500 | * This routine checks whether more Registration State Change | 
|  | 1501 | * Notifications (RSCNs) came in while the discovery state machine was in | 
|  | 1502 | * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be | 
|  | 1503 | * invoked to handle the additional RSCNs for the @vport. Otherwise, the | 
|  | 1504 | * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of | 
|  | 1505 | * handling the RSCNs. | 
|  | 1506 | **/ | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1507 | void | 
|  | 1508 | lpfc_end_rscn(struct lpfc_vport *vport) | 
|  | 1509 | { | 
|  | 1510 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | 1511 |  | 
|  | 1512 | if (vport->fc_flag & FC_RSCN_MODE) { | 
|  | 1513 | /* | 
|  | 1514 | * Check to see if more RSCNs came in while we were | 
|  | 1515 | * processing this one. | 
|  | 1516 | */ | 
|  | 1517 | if (vport->fc_rscn_id_cnt || | 
|  | 1518 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) | 
|  | 1519 | lpfc_els_handle_rscn(vport); | 
|  | 1520 | else { | 
|  | 1521 | spin_lock_irq(shost->host_lock); | 
|  | 1522 | vport->fc_flag &= ~FC_RSCN_MODE; | 
|  | 1523 | spin_unlock_irq(shost->host_lock); | 
|  | 1524 | } | 
|  | 1525 | } | 
|  | 1526 | } | 
|  | 1527 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1528 | /** | 
| James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1529 | * lpfc_cmpl_els_rrq - Completion handled for els RRQs. | 
|  | 1530 | * @phba: pointer to lpfc hba data structure. | 
|  | 1531 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 1532 | * @rspiocb: pointer to lpfc response iocb data structure. | 
|  | 1533 | * | 
|  | 1534 | * This routine will call the clear rrq function to free the rrq and | 
|  | 1535 | * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not | 
|  | 1536 | * exist then the clear_rrq is still called because the rrq needs to | 
|  | 1537 | * be freed. | 
|  | 1538 | **/ | 
|  | 1539 |  | 
|  | 1540 | static void | 
|  | 1541 | lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | 
|  | 1542 | struct lpfc_iocbq *rspiocb) | 
|  | 1543 | { | 
|  | 1544 | struct lpfc_vport *vport = cmdiocb->vport; | 
|  | 1545 | IOCB_t *irsp; | 
|  | 1546 | struct lpfc_nodelist *ndlp; | 
|  | 1547 | struct lpfc_node_rrq *rrq; | 
|  | 1548 |  | 
|  | 1549 | /* we pass cmdiocb to state machine which needs rspiocb as well */ | 
|  | 1550 | rrq = cmdiocb->context_un.rrq; | 
|  | 1551 | cmdiocb->context_un.rsp_iocb = rspiocb; | 
|  | 1552 |  | 
|  | 1553 | irsp = &rspiocb->iocb; | 
|  | 1554 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 1555 | "RRQ cmpl:      status:x%x/x%x did:x%x", | 
|  | 1556 | irsp->ulpStatus, irsp->un.ulpWord[4], | 
|  | 1557 | irsp->un.elsreq64.remoteID); | 
|  | 1558 |  | 
|  | 1559 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); | 
|  | 1560 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) { | 
|  | 1561 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 1562 | "2882 RRQ completes to NPort x%x " | 
|  | 1563 | "with no ndlp. Data: x%x x%x x%x\n", | 
|  | 1564 | irsp->un.elsreq64.remoteID, | 
|  | 1565 | irsp->ulpStatus, irsp->un.ulpWord[4], | 
|  | 1566 | irsp->ulpIoTag); | 
|  | 1567 | goto out; | 
|  | 1568 | } | 
|  | 1569 |  | 
|  | 1570 | /* rrq completes to NPort <nlp_DID> */ | 
|  | 1571 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 1572 | "2880 RRQ completes to NPort x%x " | 
|  | 1573 | "Data: x%x x%x x%x x%x x%x\n", | 
|  | 1574 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], | 
|  | 1575 | irsp->ulpTimeout, rrq->xritag, rrq->rxid); | 
|  | 1576 |  | 
|  | 1577 | if (irsp->ulpStatus) { | 
|  | 1578 | /* Check for retry */ | 
|  | 1579 | /* RRQ failed Don't print the vport to vport rjts */ | 
|  | 1580 | if (irsp->ulpStatus != IOSTAT_LS_RJT || | 
|  | 1581 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && | 
|  | 1582 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || | 
|  | 1583 | (phba)->pport->cfg_log_verbose & LOG_ELS) | 
|  | 1584 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 1585 | "2881 RRQ failure DID:%06X Status:x%x/x%x\n", | 
|  | 1586 | ndlp->nlp_DID, irsp->ulpStatus, | 
|  | 1587 | irsp->un.ulpWord[4]); | 
|  | 1588 | } | 
|  | 1589 | out: | 
|  | 1590 | if (rrq) | 
|  | 1591 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); | 
|  | 1592 | lpfc_els_free_iocb(phba, cmdiocb); | 
|  | 1593 | return; | 
|  | 1594 | } | 
|  | 1595 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1596 | * lpfc_cmpl_els_plogi - Completion callback function for plogi | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1597 | * @phba: pointer to lpfc hba data structure. | 
|  | 1598 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 1599 | * @rspiocb: pointer to lpfc response iocb data structure. | 
|  | 1600 | * | 
|  | 1601 | * This routine is the completion callback function for issuing the Port | 
|  | 1602 | * Login (PLOGI) command. For PLOGI completion, there must be an active | 
|  | 1603 | * ndlp on the vport node list that matches the remote node ID from the | 
| Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1604 | * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1605 | * ignored and command IOCB released. The PLOGI response IOCB status is | 
|  | 1606 | * checked for error conditons. If there is error status reported, PLOGI | 
|  | 1607 | * retry shall be attempted by invoking the lpfc_els_retry() routine. | 
|  | 1608 | * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on | 
|  | 1609 | * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine | 
|  | 1610 | * (DSM) is set for this PLOGI completion. Finally, it checks whether | 
|  | 1611 | * there are additional N_Port nodes with the vport that need to perform | 
|  | 1612 | * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition | 
|  | 1613 | * PLOGIs. | 
|  | 1614 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1615 | static void | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1616 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | 
|  | 1617 | struct lpfc_iocbq *rspiocb) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1618 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1619 | struct lpfc_vport *vport = cmdiocb->vport; | 
|  | 1620 | struct Scsi_Host  *shost = lpfc_shost_from_vport(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1621 | IOCB_t *irsp; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1622 | struct lpfc_nodelist *ndlp; | 
| James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1623 | struct lpfc_dmabuf *prsp; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1624 | int disc, rc, did, type; | 
|  | 1625 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1626 | /* we pass cmdiocb to state machine which needs rspiocb as well */ | 
|  | 1627 | cmdiocb->context_un.rsp_iocb = rspiocb; | 
|  | 1628 |  | 
|  | 1629 | irsp = &rspiocb->iocb; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1630 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 1631 | "PLOGI cmpl:      status:x%x/x%x did:x%x", | 
|  | 1632 | irsp->ulpStatus, irsp->un.ulpWord[4], | 
|  | 1633 | irsp->un.elsreq64.remoteID); | 
|  | 1634 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1635 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1636 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1637 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 1638 | "0136 PLOGI completes to NPort x%x " | 
|  | 1639 | "with no ndlp. Data: x%x x%x x%x\n", | 
|  | 1640 | irsp->un.elsreq64.remoteID, | 
|  | 1641 | irsp->ulpStatus, irsp->un.ulpWord[4], | 
|  | 1642 | irsp->ulpIoTag); | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1643 | goto out; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1644 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1645 |  | 
|  | 1646 | /* Since ndlp can be freed in the disc state machine, note if this node | 
|  | 1647 | * is being used during discovery. | 
|  | 1648 | */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1649 | spin_lock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1650 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1651 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1652 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1653 | rc   = 0; | 
|  | 1654 |  | 
|  | 1655 | /* PLOGI completes to NPort <nlp_DID> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1656 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 1657 | "0102 PLOGI completes to NPort x%x " | 
|  | 1658 | "Data: x%x x%x x%x x%x x%x\n", | 
|  | 1659 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], | 
|  | 1660 | irsp->ulpTimeout, disc, vport->num_disc_nodes); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1661 | /* Check to see if link went down during discovery */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1662 | if (lpfc_els_chk_latt(vport)) { | 
|  | 1663 | spin_lock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1664 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1665 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1666 | goto out; | 
|  | 1667 | } | 
|  | 1668 |  | 
|  | 1669 | /* ndlp could be freed in DSM, save these values now */ | 
|  | 1670 | type = ndlp->nlp_type; | 
|  | 1671 | did = ndlp->nlp_DID; | 
|  | 1672 |  | 
|  | 1673 | if (irsp->ulpStatus) { | 
|  | 1674 | /* Check for retry */ | 
|  | 1675 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { | 
|  | 1676 | /* ELS command is being retried */ | 
|  | 1677 | if (disc) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1678 | spin_lock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1679 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1680 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1681 | } | 
|  | 1682 | goto out; | 
|  | 1683 | } | 
| James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1684 | /* PLOGI failed Don't print the vport to vport rjts */ | 
|  | 1685 | if (irsp->ulpStatus != IOSTAT_LS_RJT || | 
|  | 1686 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && | 
|  | 1687 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || | 
|  | 1688 | (phba)->pport->cfg_log_verbose & LOG_ELS) | 
|  | 1689 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
| James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1690 | "2753 PLOGI failure DID:%06X Status:x%x/x%x\n", | 
|  | 1691 | ndlp->nlp_DID, irsp->ulpStatus, | 
|  | 1692 | irsp->un.ulpWord[4]); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1693 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1694 | if (lpfc_error_lost_link(irsp)) | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1695 | rc = NLP_STE_FREED_NODE; | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1696 | else | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1697 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1698 | NLP_EVT_CMPL_PLOGI); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1699 | } else { | 
|  | 1700 | /* Good status, call state machine */ | 
| James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1701 | prsp = list_entry(((struct lpfc_dmabuf *) | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1702 | cmdiocb->context2)->list.next, | 
|  | 1703 | struct lpfc_dmabuf, list); | 
|  | 1704 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1705 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1706 | NLP_EVT_CMPL_PLOGI); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1707 | } | 
|  | 1708 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1709 | if (disc && vport->num_disc_nodes) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1710 | /* Check to see if there are more PLOGIs to be sent */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1711 | lpfc_more_plogi(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1712 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1713 | if (vport->num_disc_nodes == 0) { | 
|  | 1714 | spin_lock_irq(shost->host_lock); | 
|  | 1715 | vport->fc_flag &= ~FC_NDISC_ACTIVE; | 
|  | 1716 | spin_unlock_irq(shost->host_lock); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1717 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1718 | lpfc_can_disctmo(vport); | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1719 | lpfc_end_rscn(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1720 | } | 
|  | 1721 | } | 
|  | 1722 |  | 
|  | 1723 | out: | 
|  | 1724 | lpfc_els_free_iocb(phba, cmdiocb); | 
|  | 1725 | return; | 
|  | 1726 | } | 
|  | 1727 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1728 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1729 | * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1730 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 1731 | * @did: destination port identifier. | 
|  | 1732 | * @retry: number of retries to the command IOCB. | 
|  | 1733 | * | 
|  | 1734 | * This routine issues a Port Login (PLOGI) command to a remote N_Port | 
|  | 1735 | * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, | 
|  | 1736 | * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. | 
|  | 1737 | * This routine constructs the proper feilds of the PLOGI IOCB and invokes | 
|  | 1738 | * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. | 
|  | 1739 | * | 
|  | 1740 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | 
|  | 1741 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | 
|  | 1742 | * will be stored into the context1 field of the IOCB for the completion | 
|  | 1743 | * callback function to the PLOGI ELS command. | 
|  | 1744 | * | 
|  | 1745 | * Return code | 
|  | 1746 | *   0 - Successfully issued a plogi for @vport | 
|  | 1747 | *   1 - failed to issue a plogi for @vport | 
|  | 1748 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1749 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1750 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1751 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1752 | struct lpfc_hba  *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1753 | struct serv_parm *sp; | 
|  | 1754 | IOCB_t *icmd; | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1755 | struct lpfc_nodelist *ndlp; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1756 | struct lpfc_iocbq *elsiocb; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1757 | struct lpfc_sli *psli; | 
|  | 1758 | uint8_t *pcmd; | 
|  | 1759 | uint16_t cmdsize; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1760 | int ret; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1761 |  | 
|  | 1762 | psli = &phba->sli; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1763 |  | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1764 | ndlp = lpfc_findnode_did(vport, did); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1765 | if (ndlp && !NLP_CHK_NODE_ACT(ndlp)) | 
|  | 1766 | ndlp = NULL; | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1767 |  | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1768 | /* If ndlp is not NULL, we will bump the reference count on it */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1769 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1770 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1771 | ELS_CMD_PLOGI); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1772 | if (!elsiocb) | 
|  | 1773 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1774 |  | 
|  | 1775 | icmd = &elsiocb->iocb; | 
|  | 1776 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 1777 |  | 
|  | 1778 | /* For PLOGI request, remainder of payload is service parameters */ | 
|  | 1779 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1780 | pcmd += sizeof(uint32_t); | 
|  | 1781 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1782 | sp = (struct serv_parm *) pcmd; | 
|  | 1783 |  | 
| James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 1784 | /* | 
|  | 1785 | * If we are a N-port connected to a Fabric, fix-up paramm's so logins | 
|  | 1786 | * to device on remote loops work. | 
|  | 1787 | */ | 
|  | 1788 | if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP)) | 
|  | 1789 | sp->cmn.altBbCredit = 1; | 
|  | 1790 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1791 | if (sp->cmn.fcphLow < FC_PH_4_3) | 
|  | 1792 | sp->cmn.fcphLow = FC_PH_4_3; | 
|  | 1793 |  | 
|  | 1794 | if (sp->cmn.fcphHigh < FC_PH3) | 
|  | 1795 | sp->cmn.fcphHigh = FC_PH3; | 
|  | 1796 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1797 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 1798 | "Issue PLOGI:     did:x%x", | 
|  | 1799 | did, 0, 0); | 
|  | 1800 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1801 | phba->fc_stat.elsXmitPLOGI++; | 
|  | 1802 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; | 
| James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1803 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1804 |  | 
|  | 1805 | if (ret == IOCB_ERROR) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1806 | lpfc_els_free_iocb(phba, elsiocb); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1807 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1808 | } | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1809 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1810 | } | 
|  | 1811 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1812 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1813 | * lpfc_cmpl_els_prli - Completion callback function for prli | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1814 | * @phba: pointer to lpfc hba data structure. | 
|  | 1815 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 1816 | * @rspiocb: pointer to lpfc response iocb data structure. | 
|  | 1817 | * | 
|  | 1818 | * This routine is the completion callback function for a Process Login | 
|  | 1819 | * (PRLI) ELS command. The PRLI response IOCB status is checked for error | 
|  | 1820 | * status. If there is error status reported, PRLI retry shall be attempted | 
|  | 1821 | * by invoking the lpfc_els_retry() routine. Otherwise, the state | 
|  | 1822 | * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this | 
|  | 1823 | * ndlp to mark the PRLI completion. | 
|  | 1824 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1825 | static void | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1826 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | 
|  | 1827 | struct lpfc_iocbq *rspiocb) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1828 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1829 | struct lpfc_vport *vport = cmdiocb->vport; | 
|  | 1830 | struct Scsi_Host  *shost = lpfc_shost_from_vport(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1831 | IOCB_t *irsp; | 
|  | 1832 | struct lpfc_sli *psli; | 
|  | 1833 | struct lpfc_nodelist *ndlp; | 
|  | 1834 |  | 
|  | 1835 | psli = &phba->sli; | 
|  | 1836 | /* we pass cmdiocb to state machine which needs rspiocb as well */ | 
|  | 1837 | cmdiocb->context_un.rsp_iocb = rspiocb; | 
|  | 1838 |  | 
|  | 1839 | irsp = &(rspiocb->iocb); | 
|  | 1840 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1841 | spin_lock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1842 | ndlp->nlp_flag &= ~NLP_PRLI_SND; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1843 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1844 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1845 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 1846 | "PRLI cmpl:       status:x%x/x%x did:x%x", | 
|  | 1847 | irsp->ulpStatus, irsp->un.ulpWord[4], | 
|  | 1848 | ndlp->nlp_DID); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1849 | /* PRLI completes to NPort <nlp_DID> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1850 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 1851 | "0103 PRLI completes to NPort x%x " | 
|  | 1852 | "Data: x%x x%x x%x x%x\n", | 
|  | 1853 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], | 
|  | 1854 | irsp->ulpTimeout, vport->num_disc_nodes); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1855 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1856 | vport->fc_prli_sent--; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1857 | /* Check to see if link went down during discovery */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1858 | if (lpfc_els_chk_latt(vport)) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1859 | goto out; | 
|  | 1860 |  | 
|  | 1861 | if (irsp->ulpStatus) { | 
|  | 1862 | /* Check for retry */ | 
|  | 1863 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { | 
|  | 1864 | /* ELS command is being retried */ | 
|  | 1865 | goto out; | 
|  | 1866 | } | 
|  | 1867 | /* PRLI failed */ | 
| James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1868 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 1869 | "2754 PRLI failure DID:%06X Status:x%x/x%x\n", | 
|  | 1870 | ndlp->nlp_DID, irsp->ulpStatus, | 
|  | 1871 | irsp->un.ulpWord[4]); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1872 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1873 | if (lpfc_error_lost_link(irsp)) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1874 | goto out; | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1875 | else | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1876 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1877 | NLP_EVT_CMPL_PRLI); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1878 | } else | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1879 | /* Good status, call state machine */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1880 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1881 | NLP_EVT_CMPL_PRLI); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1882 | out: | 
|  | 1883 | lpfc_els_free_iocb(phba, cmdiocb); | 
|  | 1884 | return; | 
|  | 1885 | } | 
|  | 1886 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1887 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1888 | * lpfc_issue_els_prli - Issue a prli iocb command for a vport | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1889 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 1890 | * @ndlp: pointer to a node-list data structure. | 
|  | 1891 | * @retry: number of retries to the command IOCB. | 
|  | 1892 | * | 
|  | 1893 | * This routine issues a Process Login (PRLI) ELS command for the | 
|  | 1894 | * @vport. The PRLI service parameters are set up in the payload of the | 
|  | 1895 | * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine | 
|  | 1896 | * is put to the IOCB completion callback func field before invoking the | 
|  | 1897 | * routine lpfc_sli_issue_iocb() to send out PRLI command. | 
|  | 1898 | * | 
|  | 1899 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | 
|  | 1900 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | 
|  | 1901 | * will be stored into the context1 field of the IOCB for the completion | 
|  | 1902 | * callback function to the PRLI ELS command. | 
|  | 1903 | * | 
|  | 1904 | * Return code | 
|  | 1905 | *   0 - successfully issued prli iocb command for @vport | 
|  | 1906 | *   1 - failed to issue prli iocb command for @vport | 
|  | 1907 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1908 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1909 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1910 | uint8_t retry) | 
|  | 1911 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1912 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | 1913 | struct lpfc_hba *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1914 | PRLI *npr; | 
|  | 1915 | IOCB_t *icmd; | 
|  | 1916 | struct lpfc_iocbq *elsiocb; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1917 | uint8_t *pcmd; | 
|  | 1918 | uint16_t cmdsize; | 
|  | 1919 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1920 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1921 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, | 
|  | 1922 | ndlp->nlp_DID, ELS_CMD_PRLI); | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1923 | if (!elsiocb) | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1924 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1925 |  | 
|  | 1926 | icmd = &elsiocb->iocb; | 
|  | 1927 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 1928 |  | 
|  | 1929 | /* For PRLI request, remainder of payload is service parameters */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1930 | memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t))); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1931 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLI; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1932 | pcmd += sizeof(uint32_t); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1933 |  | 
|  | 1934 | /* For PRLI, remainder of payload is PRLI parameter page */ | 
|  | 1935 | npr = (PRLI *) pcmd; | 
|  | 1936 | /* | 
|  | 1937 | * If our firmware version is 3.20 or later, | 
|  | 1938 | * set the following bits for FC-TAPE support. | 
|  | 1939 | */ | 
|  | 1940 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { | 
|  | 1941 | npr->ConfmComplAllowed = 1; | 
|  | 1942 | npr->Retry = 1; | 
|  | 1943 | npr->TaskRetryIdReq = 1; | 
|  | 1944 | } | 
|  | 1945 | npr->estabImagePair = 1; | 
|  | 1946 | npr->readXferRdyDis = 1; | 
|  | 1947 |  | 
|  | 1948 | /* For FCP support */ | 
|  | 1949 | npr->prliType = PRLI_FCP_TYPE; | 
|  | 1950 | npr->initiatorFunc = 1; | 
|  | 1951 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1952 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 1953 | "Issue PRLI:      did:x%x", | 
|  | 1954 | ndlp->nlp_DID, 0, 0); | 
|  | 1955 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1956 | phba->fc_stat.elsXmitPRLI++; | 
|  | 1957 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1958 | spin_lock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1959 | ndlp->nlp_flag |= NLP_PRLI_SND; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1960 | spin_unlock_irq(shost->host_lock); | 
| James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1961 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == | 
|  | 1962 | IOCB_ERROR) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1963 | spin_lock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1964 | ndlp->nlp_flag &= ~NLP_PRLI_SND; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1965 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1966 | lpfc_els_free_iocb(phba, elsiocb); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1967 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1968 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1969 | vport->fc_prli_sent++; | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1970 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1971 | } | 
|  | 1972 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1973 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1974 | * lpfc_rscn_disc - Perform rscn discovery for a vport | 
| James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1975 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 1976 | * | 
|  | 1977 | * This routine performs Registration State Change Notification (RSCN) | 
|  | 1978 | * discovery for a @vport. If the @vport's node port recovery count is not | 
|  | 1979 | * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all | 
|  | 1980 | * the nodes that need recovery. If none of the PLOGI were needed through | 
|  | 1981 | * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be | 
|  | 1982 | * invoked to check and handle possible more RSCN came in during the period | 
|  | 1983 | * of processing the current ones. | 
|  | 1984 | **/ | 
|  | 1985 | static void | 
|  | 1986 | lpfc_rscn_disc(struct lpfc_vport *vport) | 
|  | 1987 | { | 
|  | 1988 | lpfc_can_disctmo(vport); | 
|  | 1989 |  | 
|  | 1990 | /* RSCN discovery */ | 
|  | 1991 | /* go thru NPR nodes and issue ELS PLOGIs */ | 
|  | 1992 | if (vport->fc_npr_cnt) | 
|  | 1993 | if (lpfc_els_disc_plogi(vport)) | 
|  | 1994 | return; | 
|  | 1995 |  | 
|  | 1996 | lpfc_end_rscn(vport); | 
|  | 1997 | } | 
|  | 1998 |  | 
|  | 1999 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2000 | * lpfc_adisc_done - Complete the adisc phase of discovery | 
| James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2001 | * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs. | 
|  | 2002 | * | 
|  | 2003 | * This function is called when the final ADISC is completed during discovery. | 
|  | 2004 | * This function handles clearing link attention or issuing reg_vpi depending | 
|  | 2005 | * on whether npiv is enabled. This function also kicks off the PLOGI phase of | 
|  | 2006 | * discovery. | 
|  | 2007 | * This function is called with no locks held. | 
|  | 2008 | **/ | 
|  | 2009 | static void | 
|  | 2010 | lpfc_adisc_done(struct lpfc_vport *vport) | 
|  | 2011 | { | 
|  | 2012 | struct Scsi_Host   *shost = lpfc_shost_from_vport(vport); | 
|  | 2013 | struct lpfc_hba   *phba = vport->phba; | 
|  | 2014 |  | 
|  | 2015 | /* | 
|  | 2016 | * For NPIV, cmpl_reg_vpi will set port_state to READY, | 
|  | 2017 | * and continue discovery. | 
|  | 2018 | */ | 
|  | 2019 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && | 
| James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 2020 | !(vport->fc_flag & FC_RSCN_MODE) && | 
|  | 2021 | (phba->sli_rev < LPFC_SLI_REV4)) { | 
| James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2022 | lpfc_issue_reg_vpi(phba, vport); | 
|  | 2023 | return; | 
|  | 2024 | } | 
|  | 2025 | /* | 
|  | 2026 | * For SLI2, we need to set port_state to READY | 
|  | 2027 | * and continue discovery. | 
|  | 2028 | */ | 
|  | 2029 | if (vport->port_state < LPFC_VPORT_READY) { | 
|  | 2030 | /* If we get here, there is nothing to ADISC */ | 
|  | 2031 | if (vport->port_type == LPFC_PHYSICAL_PORT) | 
|  | 2032 | lpfc_issue_clear_la(phba, vport); | 
|  | 2033 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { | 
|  | 2034 | vport->num_disc_nodes = 0; | 
|  | 2035 | /* go thru NPR list, issue ELS PLOGIs */ | 
|  | 2036 | if (vport->fc_npr_cnt) | 
|  | 2037 | lpfc_els_disc_plogi(vport); | 
|  | 2038 | if (!vport->num_disc_nodes) { | 
|  | 2039 | spin_lock_irq(shost->host_lock); | 
|  | 2040 | vport->fc_flag &= ~FC_NDISC_ACTIVE; | 
|  | 2041 | spin_unlock_irq(shost->host_lock); | 
|  | 2042 | lpfc_can_disctmo(vport); | 
|  | 2043 | lpfc_end_rscn(vport); | 
|  | 2044 | } | 
|  | 2045 | } | 
|  | 2046 | vport->port_state = LPFC_VPORT_READY; | 
|  | 2047 | } else | 
|  | 2048 | lpfc_rscn_disc(vport); | 
|  | 2049 | } | 
|  | 2050 |  | 
|  | 2051 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2052 | * lpfc_more_adisc - Issue more adisc as needed | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2053 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 2054 | * | 
|  | 2055 | * This routine determines whether there are more ndlps on a @vport | 
|  | 2056 | * node list need to have Address Discover (ADISC) issued. If so, it will | 
|  | 2057 | * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's | 
|  | 2058 | * remaining nodes which need to have ADISC sent. | 
|  | 2059 | **/ | 
| James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2060 | void | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2061 | lpfc_more_adisc(struct lpfc_vport *vport) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2062 | { | 
|  | 2063 | int sentadisc; | 
|  | 2064 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2065 | if (vport->num_disc_nodes) | 
|  | 2066 | vport->num_disc_nodes--; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2067 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2068 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, | 
|  | 2069 | "0210 Continue discovery with %d ADISCs to go " | 
|  | 2070 | "Data: x%x x%x x%x\n", | 
|  | 2071 | vport->num_disc_nodes, vport->fc_adisc_cnt, | 
|  | 2072 | vport->fc_flag, vport->port_state); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2073 | /* Check to see if there are more ADISCs to be sent */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2074 | if (vport->fc_flag & FC_NLP_MORE) { | 
|  | 2075 | lpfc_set_disctmo(vport); | 
|  | 2076 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ | 
|  | 2077 | sentadisc = lpfc_els_disc_adisc(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2078 | } | 
| James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2079 | if (!vport->num_disc_nodes) | 
|  | 2080 | lpfc_adisc_done(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2081 | return; | 
|  | 2082 | } | 
|  | 2083 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2084 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2085 | * lpfc_cmpl_els_adisc - Completion callback function for adisc | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2086 | * @phba: pointer to lpfc hba data structure. | 
|  | 2087 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 2088 | * @rspiocb: pointer to lpfc response iocb data structure. | 
|  | 2089 | * | 
|  | 2090 | * This routine is the completion function for issuing the Address Discover | 
|  | 2091 | * (ADISC) command. It first checks to see whether link went down during | 
|  | 2092 | * the discovery process. If so, the node will be marked as node port | 
|  | 2093 | * recovery for issuing discover IOCB by the link attention handler and | 
|  | 2094 | * exit. Otherwise, the response status is checked. If error was reported | 
|  | 2095 | * in the response status, the ADISC command shall be retried by invoking | 
|  | 2096 | * the lpfc_els_retry() routine. Otherwise, if no error was reported in | 
|  | 2097 | * the response status, the state machine is invoked to set transition | 
|  | 2098 | * with respect to NLP_EVT_CMPL_ADISC event. | 
|  | 2099 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2100 | static void | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2101 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | 
|  | 2102 | struct lpfc_iocbq *rspiocb) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2103 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2104 | struct lpfc_vport *vport = cmdiocb->vport; | 
|  | 2105 | struct Scsi_Host  *shost = lpfc_shost_from_vport(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2106 | IOCB_t *irsp; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2107 | struct lpfc_nodelist *ndlp; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2108 | int  disc; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2109 |  | 
|  | 2110 | /* we pass cmdiocb to state machine which needs rspiocb as well */ | 
|  | 2111 | cmdiocb->context_un.rsp_iocb = rspiocb; | 
|  | 2112 |  | 
|  | 2113 | irsp = &(rspiocb->iocb); | 
|  | 2114 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2115 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2116 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 2117 | "ADISC cmpl:      status:x%x/x%x did:x%x", | 
|  | 2118 | irsp->ulpStatus, irsp->un.ulpWord[4], | 
|  | 2119 | ndlp->nlp_DID); | 
|  | 2120 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2121 | /* Since ndlp can be freed in the disc state machine, note if this node | 
|  | 2122 | * is being used during discovery. | 
|  | 2123 | */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2124 | spin_lock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2125 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2126 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2127 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2128 | /* ADISC completes to NPort <nlp_DID> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2129 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 2130 | "0104 ADISC completes to NPort x%x " | 
|  | 2131 | "Data: x%x x%x x%x x%x x%x\n", | 
|  | 2132 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], | 
|  | 2133 | irsp->ulpTimeout, disc, vport->num_disc_nodes); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2134 | /* Check to see if link went down during discovery */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2135 | if (lpfc_els_chk_latt(vport)) { | 
|  | 2136 | spin_lock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2137 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2138 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2139 | goto out; | 
|  | 2140 | } | 
|  | 2141 |  | 
|  | 2142 | if (irsp->ulpStatus) { | 
|  | 2143 | /* Check for retry */ | 
|  | 2144 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { | 
|  | 2145 | /* ELS command is being retried */ | 
|  | 2146 | if (disc) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2147 | spin_lock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2148 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2149 | spin_unlock_irq(shost->host_lock); | 
|  | 2150 | lpfc_set_disctmo(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2151 | } | 
|  | 2152 | goto out; | 
|  | 2153 | } | 
|  | 2154 | /* ADISC failed */ | 
| James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2155 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 2156 | "2755 ADISC failure DID:%06X Status:x%x/x%x\n", | 
|  | 2157 | ndlp->nlp_DID, irsp->ulpStatus, | 
|  | 2158 | irsp->un.ulpWord[4]); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2159 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2160 | if (!lpfc_error_lost_link(irsp)) | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2161 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2162 | NLP_EVT_CMPL_ADISC); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2163 | } else | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2164 | /* Good status, call state machine */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2165 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2166 | NLP_EVT_CMPL_ADISC); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2167 |  | 
| James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2168 | /* Check to see if there are more ADISCs to be sent */ | 
|  | 2169 | if (disc && vport->num_disc_nodes) | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2170 | lpfc_more_adisc(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2171 | out: | 
|  | 2172 | lpfc_els_free_iocb(phba, cmdiocb); | 
|  | 2173 | return; | 
|  | 2174 | } | 
|  | 2175 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2176 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2177 | * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2178 | * @vport: pointer to a virtual N_Port data structure. | 
|  | 2179 | * @ndlp: pointer to a node-list data structure. | 
|  | 2180 | * @retry: number of retries to the command IOCB. | 
|  | 2181 | * | 
|  | 2182 | * This routine issues an Address Discover (ADISC) for an @ndlp on a | 
|  | 2183 | * @vport. It prepares the payload of the ADISC ELS command, updates the | 
|  | 2184 | * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine | 
|  | 2185 | * to issue the ADISC ELS command. | 
|  | 2186 | * | 
|  | 2187 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | 
|  | 2188 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | 
|  | 2189 | * will be stored into the context1 field of the IOCB for the completion | 
|  | 2190 | * callback function to the ADISC ELS command. | 
|  | 2191 | * | 
|  | 2192 | * Return code | 
|  | 2193 | *   0 - successfully issued adisc | 
|  | 2194 | *   1 - failed to issue adisc | 
|  | 2195 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2196 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2197 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2198 | uint8_t retry) | 
|  | 2199 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2200 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | 2201 | struct lpfc_hba  *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2202 | ADISC *ap; | 
|  | 2203 | IOCB_t *icmd; | 
|  | 2204 | struct lpfc_iocbq *elsiocb; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2205 | uint8_t *pcmd; | 
|  | 2206 | uint16_t cmdsize; | 
|  | 2207 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2208 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2209 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, | 
|  | 2210 | ndlp->nlp_DID, ELS_CMD_ADISC); | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2211 | if (!elsiocb) | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2212 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2213 |  | 
|  | 2214 | icmd = &elsiocb->iocb; | 
|  | 2215 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 2216 |  | 
|  | 2217 | /* For ADISC request, remainder of payload is service parameters */ | 
|  | 2218 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2219 | pcmd += sizeof(uint32_t); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2220 |  | 
|  | 2221 | /* Fill in ADISC payload */ | 
|  | 2222 | ap = (ADISC *) pcmd; | 
|  | 2223 | ap->hardAL_PA = phba->fc_pref_ALPA; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2224 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); | 
|  | 2225 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2226 | ap->DID = be32_to_cpu(vport->fc_myDID); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2227 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2228 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 2229 | "Issue ADISC:     did:x%x", | 
|  | 2230 | ndlp->nlp_DID, 0, 0); | 
|  | 2231 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2232 | phba->fc_stat.elsXmitADISC++; | 
|  | 2233 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2234 | spin_lock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2235 | ndlp->nlp_flag |= NLP_ADISC_SND; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2236 | spin_unlock_irq(shost->host_lock); | 
| James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2237 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == | 
|  | 2238 | IOCB_ERROR) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2239 | spin_lock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2240 | ndlp->nlp_flag &= ~NLP_ADISC_SND; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2241 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2242 | lpfc_els_free_iocb(phba, elsiocb); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2243 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2244 | } | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2245 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2246 | } | 
|  | 2247 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2248 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2249 | * lpfc_cmpl_els_logo - Completion callback function for logo | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2250 | * @phba: pointer to lpfc hba data structure. | 
|  | 2251 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 2252 | * @rspiocb: pointer to lpfc response iocb data structure. | 
|  | 2253 | * | 
|  | 2254 | * This routine is the completion function for issuing the ELS Logout (LOGO) | 
|  | 2255 | * command. If no error status was reported from the LOGO response, the | 
|  | 2256 | * state machine of the associated ndlp shall be invoked for transition with | 
|  | 2257 | * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported, | 
|  | 2258 | * the lpfc_els_retry() routine will be invoked to retry the LOGO command. | 
|  | 2259 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2260 | static void | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2261 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | 
|  | 2262 | struct lpfc_iocbq *rspiocb) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2263 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2264 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; | 
|  | 2265 | struct lpfc_vport *vport = ndlp->vport; | 
|  | 2266 | struct Scsi_Host  *shost = lpfc_shost_from_vport(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2267 | IOCB_t *irsp; | 
|  | 2268 | struct lpfc_sli *psli; | 
| James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2269 | struct lpfcMboxq *mbox; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2270 |  | 
|  | 2271 | psli = &phba->sli; | 
|  | 2272 | /* we pass cmdiocb to state machine which needs rspiocb as well */ | 
|  | 2273 | cmdiocb->context_un.rsp_iocb = rspiocb; | 
|  | 2274 |  | 
|  | 2275 | irsp = &(rspiocb->iocb); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2276 | spin_lock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2277 | ndlp->nlp_flag &= ~NLP_LOGO_SND; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2278 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2279 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2280 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 2281 | "LOGO cmpl:       status:x%x/x%x did:x%x", | 
|  | 2282 | irsp->ulpStatus, irsp->un.ulpWord[4], | 
|  | 2283 | ndlp->nlp_DID); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2284 | /* LOGO completes to NPort <nlp_DID> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2285 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 2286 | "0105 LOGO completes to NPort x%x " | 
|  | 2287 | "Data: x%x x%x x%x x%x\n", | 
|  | 2288 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], | 
|  | 2289 | irsp->ulpTimeout, vport->num_disc_nodes); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2290 | /* Check to see if link went down during discovery */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2291 | if (lpfc_els_chk_latt(vport)) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2292 | goto out; | 
|  | 2293 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2294 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { | 
|  | 2295 | /* NLP_EVT_DEVICE_RM should unregister the RPI | 
|  | 2296 | * which should abort all outstanding IOs. | 
|  | 2297 | */ | 
|  | 2298 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, | 
|  | 2299 | NLP_EVT_DEVICE_RM); | 
|  | 2300 | goto out; | 
|  | 2301 | } | 
|  | 2302 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2303 | if (irsp->ulpStatus) { | 
|  | 2304 | /* Check for retry */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2305 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2306 | /* ELS command is being retried */ | 
|  | 2307 | goto out; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2308 | /* LOGO failed */ | 
| James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2309 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 2310 | "2756 LOGO failure DID:%06X Status:x%x/x%x\n", | 
|  | 2311 | ndlp->nlp_DID, irsp->ulpStatus, | 
|  | 2312 | irsp->un.ulpWord[4]); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2313 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2314 | if (lpfc_error_lost_link(irsp)) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2315 | goto out; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2316 | else | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2317 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2318 | NLP_EVT_CMPL_LOGO); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2319 | } else | 
| Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2320 | /* Good status, call state machine. | 
|  | 2321 | * This will unregister the rpi if needed. | 
|  | 2322 | */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2323 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2324 | NLP_EVT_CMPL_LOGO); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2325 | out: | 
|  | 2326 | lpfc_els_free_iocb(phba, cmdiocb); | 
| James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2327 | /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */ | 
|  | 2328 | if ((vport->fc_flag & FC_PT2PT) && | 
|  | 2329 | !(vport->fc_flag & FC_PT2PT_PLOGI)) { | 
|  | 2330 | phba->pport->fc_myDID = 0; | 
|  | 2331 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | 
|  | 2332 | if (mbox) { | 
|  | 2333 | lpfc_config_link(phba, mbox); | 
|  | 2334 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | 
|  | 2335 | mbox->vport = vport; | 
|  | 2336 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) == | 
|  | 2337 | MBX_NOT_FINISHED) { | 
|  | 2338 | mempool_free(mbox, phba->mbox_mem_pool); | 
|  | 2339 | } | 
|  | 2340 | } | 
|  | 2341 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2342 | return; | 
|  | 2343 | } | 
|  | 2344 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2345 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2346 | * lpfc_issue_els_logo - Issue a logo to an node on a vport | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2347 | * @vport: pointer to a virtual N_Port data structure. | 
|  | 2348 | * @ndlp: pointer to a node-list data structure. | 
|  | 2349 | * @retry: number of retries to the command IOCB. | 
|  | 2350 | * | 
|  | 2351 | * This routine constructs and issues an ELS Logout (LOGO) iocb command | 
|  | 2352 | * to a remote node, referred by an @ndlp on a @vport. It constructs the | 
|  | 2353 | * payload of the IOCB, properly sets up the @ndlp state, and invokes the | 
|  | 2354 | * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. | 
|  | 2355 | * | 
|  | 2356 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | 
|  | 2357 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | 
|  | 2358 | * will be stored into the context1 field of the IOCB for the completion | 
|  | 2359 | * callback function to the LOGO ELS command. | 
|  | 2360 | * | 
|  | 2361 | * Return code | 
|  | 2362 | *   0 - successfully issued logo | 
|  | 2363 | *   1 - failed to issue logo | 
|  | 2364 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2365 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2366 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2367 | uint8_t retry) | 
|  | 2368 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2369 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | 2370 | struct lpfc_hba  *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2371 | IOCB_t *icmd; | 
|  | 2372 | struct lpfc_iocbq *elsiocb; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2373 | uint8_t *pcmd; | 
|  | 2374 | uint16_t cmdsize; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2375 | int rc; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2376 |  | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2377 | spin_lock_irq(shost->host_lock); | 
|  | 2378 | if (ndlp->nlp_flag & NLP_LOGO_SND) { | 
|  | 2379 | spin_unlock_irq(shost->host_lock); | 
|  | 2380 | return 0; | 
|  | 2381 | } | 
|  | 2382 | spin_unlock_irq(shost->host_lock); | 
|  | 2383 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2384 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2385 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, | 
|  | 2386 | ndlp->nlp_DID, ELS_CMD_LOGO); | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2387 | if (!elsiocb) | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2388 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2389 |  | 
|  | 2390 | icmd = &elsiocb->iocb; | 
|  | 2391 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 2392 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2393 | pcmd += sizeof(uint32_t); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2394 |  | 
|  | 2395 | /* Fill in LOGO payload */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2396 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2397 | pcmd += sizeof(uint32_t); | 
|  | 2398 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2399 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2400 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 2401 | "Issue LOGO:      did:x%x", | 
|  | 2402 | ndlp->nlp_DID, 0, 0); | 
|  | 2403 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2404 | phba->fc_stat.elsXmitLOGO++; | 
|  | 2405 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2406 | spin_lock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2407 | ndlp->nlp_flag |= NLP_LOGO_SND; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2408 | spin_unlock_irq(shost->host_lock); | 
| James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2409 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2410 |  | 
|  | 2411 | if (rc == IOCB_ERROR) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2412 | spin_lock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2413 | ndlp->nlp_flag &= ~NLP_LOGO_SND; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2414 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2415 | lpfc_els_free_iocb(phba, elsiocb); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2416 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2417 | } | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2418 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2419 | } | 
|  | 2420 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2421 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2422 | * lpfc_cmpl_els_cmd - Completion callback function for generic els command | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2423 | * @phba: pointer to lpfc hba data structure. | 
|  | 2424 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 2425 | * @rspiocb: pointer to lpfc response iocb data structure. | 
|  | 2426 | * | 
|  | 2427 | * This routine is a generic completion callback function for ELS commands. | 
|  | 2428 | * Specifically, it is the callback function which does not need to perform | 
|  | 2429 | * any command specific operations. It is currently used by the ELS command | 
|  | 2430 | * issuing routines for the ELS State Change  Request (SCR), | 
|  | 2431 | * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution | 
|  | 2432 | * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than | 
|  | 2433 | * certain debug loggings, this callback function simply invokes the | 
|  | 2434 | * lpfc_els_chk_latt() routine to check whether link went down during the | 
|  | 2435 | * discovery process. | 
|  | 2436 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2437 | static void | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2438 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | 
|  | 2439 | struct lpfc_iocbq *rspiocb) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2440 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2441 | struct lpfc_vport *vport = cmdiocb->vport; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2442 | IOCB_t *irsp; | 
|  | 2443 |  | 
|  | 2444 | irsp = &rspiocb->iocb; | 
|  | 2445 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2446 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 2447 | "ELS cmd cmpl:    status:x%x/x%x did:x%x", | 
|  | 2448 | irsp->ulpStatus, irsp->un.ulpWord[4], | 
|  | 2449 | irsp->un.elsreq64.remoteID); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2450 | /* ELS cmd tag <ulpIoTag> completes */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2451 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 2452 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", | 
|  | 2453 | irsp->ulpIoTag, irsp->ulpStatus, | 
|  | 2454 | irsp->un.ulpWord[4], irsp->ulpTimeout); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2455 | /* Check to see if link went down during discovery */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2456 | lpfc_els_chk_latt(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2457 | lpfc_els_free_iocb(phba, cmdiocb); | 
|  | 2458 | return; | 
|  | 2459 | } | 
|  | 2460 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2461 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2462 | * lpfc_issue_els_scr - Issue a scr to an node on a vport | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2463 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 2464 | * @nportid: N_Port identifier to the remote node. | 
|  | 2465 | * @retry: number of retries to the command IOCB. | 
|  | 2466 | * | 
|  | 2467 | * This routine issues a State Change Request (SCR) to a fabric node | 
|  | 2468 | * on a @vport. The remote node @nportid is passed into the function. It | 
|  | 2469 | * first search the @vport node list to find the matching ndlp. If no such | 
|  | 2470 | * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An | 
|  | 2471 | * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() | 
|  | 2472 | * routine is invoked to send the SCR IOCB. | 
|  | 2473 | * | 
|  | 2474 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | 
|  | 2475 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | 
|  | 2476 | * will be stored into the context1 field of the IOCB for the completion | 
|  | 2477 | * callback function to the SCR ELS command. | 
|  | 2478 | * | 
|  | 2479 | * Return code | 
|  | 2480 | *   0 - Successfully issued scr command | 
|  | 2481 | *   1 - Failed to issue scr command | 
|  | 2482 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2483 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2484 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2485 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2486 | struct lpfc_hba  *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2487 | IOCB_t *icmd; | 
|  | 2488 | struct lpfc_iocbq *elsiocb; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2489 | struct lpfc_sli *psli; | 
|  | 2490 | uint8_t *pcmd; | 
|  | 2491 | uint16_t cmdsize; | 
|  | 2492 | struct lpfc_nodelist *ndlp; | 
|  | 2493 |  | 
|  | 2494 | psli = &phba->sli; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2495 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2496 |  | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2497 | ndlp = lpfc_findnode_did(vport, nportid); | 
|  | 2498 | if (!ndlp) { | 
|  | 2499 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | 
|  | 2500 | if (!ndlp) | 
|  | 2501 | return 1; | 
|  | 2502 | lpfc_nlp_init(vport, ndlp, nportid); | 
|  | 2503 | lpfc_enqueue_node(vport, ndlp); | 
|  | 2504 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | 
|  | 2505 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | 
|  | 2506 | if (!ndlp) | 
|  | 2507 | return 1; | 
|  | 2508 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2509 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2510 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, | 
|  | 2511 | ndlp->nlp_DID, ELS_CMD_SCR); | 
|  | 2512 |  | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2513 | if (!elsiocb) { | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2514 | /* This will trigger the release of the node just | 
|  | 2515 | * allocated | 
|  | 2516 | */ | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2517 | lpfc_nlp_put(ndlp); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2518 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2519 | } | 
|  | 2520 |  | 
|  | 2521 | icmd = &elsiocb->iocb; | 
|  | 2522 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 2523 |  | 
|  | 2524 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2525 | pcmd += sizeof(uint32_t); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2526 |  | 
|  | 2527 | /* For SCR, remainder of payload is SCR parameter page */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2528 | memset(pcmd, 0, sizeof(SCR)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2529 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; | 
|  | 2530 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2531 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 2532 | "Issue SCR:       did:x%x", | 
|  | 2533 | ndlp->nlp_DID, 0, 0); | 
|  | 2534 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2535 | phba->fc_stat.elsXmitSCR++; | 
|  | 2536 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; | 
| James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2537 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == | 
|  | 2538 | IOCB_ERROR) { | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2539 | /* The additional lpfc_nlp_put will cause the following | 
|  | 2540 | * lpfc_els_free_iocb routine to trigger the rlease of | 
|  | 2541 | * the node. | 
|  | 2542 | */ | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2543 | lpfc_nlp_put(ndlp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2544 | lpfc_els_free_iocb(phba, elsiocb); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2545 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2546 | } | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2547 | /* This will cause the callback-function lpfc_cmpl_els_cmd to | 
|  | 2548 | * trigger the release of node. | 
|  | 2549 | */ | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2550 | lpfc_nlp_put(ndlp); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2551 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2552 | } | 
|  | 2553 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2554 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2555 | * lpfc_issue_els_farpr - Issue a farp to an node on a vport | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2556 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 2557 | * @nportid: N_Port identifier to the remote node. | 
|  | 2558 | * @retry: number of retries to the command IOCB. | 
|  | 2559 | * | 
|  | 2560 | * This routine issues a Fibre Channel Address Resolution Response | 
|  | 2561 | * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) | 
|  | 2562 | * is passed into the function. It first search the @vport node list to find | 
|  | 2563 | * the matching ndlp. If no such ndlp is found, a new ndlp shall be created | 
|  | 2564 | * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the | 
|  | 2565 | * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. | 
|  | 2566 | * | 
|  | 2567 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | 
|  | 2568 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | 
|  | 2569 | * will be stored into the context1 field of the IOCB for the completion | 
|  | 2570 | * callback function to the PARPR ELS command. | 
|  | 2571 | * | 
|  | 2572 | * Return code | 
|  | 2573 | *   0 - Successfully issued farpr command | 
|  | 2574 | *   1 - Failed to issue farpr command | 
|  | 2575 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2576 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2577 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2578 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2579 | struct lpfc_hba  *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2580 | IOCB_t *icmd; | 
|  | 2581 | struct lpfc_iocbq *elsiocb; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2582 | struct lpfc_sli *psli; | 
|  | 2583 | FARP *fp; | 
|  | 2584 | uint8_t *pcmd; | 
|  | 2585 | uint32_t *lp; | 
|  | 2586 | uint16_t cmdsize; | 
|  | 2587 | struct lpfc_nodelist *ondlp; | 
|  | 2588 | struct lpfc_nodelist *ndlp; | 
|  | 2589 |  | 
|  | 2590 | psli = &phba->sli; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2591 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2592 |  | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2593 | ndlp = lpfc_findnode_did(vport, nportid); | 
|  | 2594 | if (!ndlp) { | 
|  | 2595 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | 
|  | 2596 | if (!ndlp) | 
|  | 2597 | return 1; | 
|  | 2598 | lpfc_nlp_init(vport, ndlp, nportid); | 
|  | 2599 | lpfc_enqueue_node(vport, ndlp); | 
|  | 2600 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | 
|  | 2601 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | 
|  | 2602 | if (!ndlp) | 
|  | 2603 | return 1; | 
|  | 2604 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2605 |  | 
|  | 2606 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, | 
|  | 2607 | ndlp->nlp_DID, ELS_CMD_RNID); | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2608 | if (!elsiocb) { | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2609 | /* This will trigger the release of the node just | 
|  | 2610 | * allocated | 
|  | 2611 | */ | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2612 | lpfc_nlp_put(ndlp); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2613 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2614 | } | 
|  | 2615 |  | 
|  | 2616 | icmd = &elsiocb->iocb; | 
|  | 2617 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 2618 |  | 
|  | 2619 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2620 | pcmd += sizeof(uint32_t); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2621 |  | 
|  | 2622 | /* Fill in FARPR payload */ | 
|  | 2623 | fp = (FARP *) (pcmd); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2624 | memset(fp, 0, sizeof(FARP)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2625 | lp = (uint32_t *) pcmd; | 
|  | 2626 | *lp++ = be32_to_cpu(nportid); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2627 | *lp++ = be32_to_cpu(vport->fc_myDID); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2628 | fp->Rflags = 0; | 
|  | 2629 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); | 
|  | 2630 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2631 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); | 
|  | 2632 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2633 | ondlp = lpfc_findnode_did(vport, nportid); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2634 | if (ondlp && NLP_CHK_NODE_ACT(ondlp)) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2635 | memcpy(&fp->OportName, &ondlp->nlp_portname, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2636 | sizeof(struct lpfc_name)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2637 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2638 | sizeof(struct lpfc_name)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2639 | } | 
|  | 2640 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2641 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 2642 | "Issue FARPR:     did:x%x", | 
|  | 2643 | ndlp->nlp_DID, 0, 0); | 
|  | 2644 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2645 | phba->fc_stat.elsXmitFARPR++; | 
|  | 2646 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; | 
| James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2647 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == | 
|  | 2648 | IOCB_ERROR) { | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2649 | /* The additional lpfc_nlp_put will cause the following | 
|  | 2650 | * lpfc_els_free_iocb routine to trigger the release of | 
|  | 2651 | * the node. | 
|  | 2652 | */ | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2653 | lpfc_nlp_put(ndlp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2654 | lpfc_els_free_iocb(phba, elsiocb); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2655 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2656 | } | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2657 | /* This will cause the callback-function lpfc_cmpl_els_cmd to | 
|  | 2658 | * trigger the release of the node. | 
|  | 2659 | */ | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2660 | lpfc_nlp_put(ndlp); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2661 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2662 | } | 
|  | 2663 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2664 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2665 | * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2666 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 2667 | * @nlp: pointer to a node-list data structure. | 
|  | 2668 | * | 
|  | 2669 | * This routine cancels the timer with a delayed IOCB-command retry for | 
|  | 2670 | * a @vport's @ndlp. It stops the timer for the delayed function retrial and | 
|  | 2671 | * removes the ELS retry event if it presents. In addition, if the | 
|  | 2672 | * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB | 
|  | 2673 | * commands are sent for the @vport's nodes that require issuing discovery | 
|  | 2674 | * ADISC. | 
|  | 2675 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2676 | void | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2677 | lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp) | 
| James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2678 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2679 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2680 | struct lpfc_work_evt *evtp; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2681 |  | 
| James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2682 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) | 
|  | 2683 | return; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2684 | spin_lock_irq(shost->host_lock); | 
| James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2685 | nlp->nlp_flag &= ~NLP_DELAY_TMO; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2686 | spin_unlock_irq(shost->host_lock); | 
| James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2687 | del_timer_sync(&nlp->nlp_delayfunc); | 
|  | 2688 | nlp->nlp_last_elscmd = 0; | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2689 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { | 
| James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2690 | list_del_init(&nlp->els_retry_evt.evt_listp); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2691 | /* Decrement nlp reference count held for the delayed retry */ | 
|  | 2692 | evtp = &nlp->els_retry_evt; | 
|  | 2693 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); | 
|  | 2694 | } | 
| James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2695 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2696 | spin_lock_irq(shost->host_lock); | 
| James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2697 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2698 | spin_unlock_irq(shost->host_lock); | 
|  | 2699 | if (vport->num_disc_nodes) { | 
| James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2700 | if (vport->port_state < LPFC_VPORT_READY) { | 
|  | 2701 | /* Check if there are more ADISCs to be sent */ | 
|  | 2702 | lpfc_more_adisc(vport); | 
| James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2703 | } else { | 
|  | 2704 | /* Check if there are more PLOGIs to be sent */ | 
|  | 2705 | lpfc_more_plogi(vport); | 
| James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2706 | if (vport->num_disc_nodes == 0) { | 
|  | 2707 | spin_lock_irq(shost->host_lock); | 
|  | 2708 | vport->fc_flag &= ~FC_NDISC_ACTIVE; | 
|  | 2709 | spin_unlock_irq(shost->host_lock); | 
|  | 2710 | lpfc_can_disctmo(vport); | 
|  | 2711 | lpfc_end_rscn(vport); | 
|  | 2712 | } | 
| James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2713 | } | 
|  | 2714 | } | 
|  | 2715 | } | 
|  | 2716 | return; | 
|  | 2717 | } | 
|  | 2718 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2719 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2720 | * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2721 | * @ptr: holder for the pointer to the timer function associated data (ndlp). | 
|  | 2722 | * | 
|  | 2723 | * This routine is invoked by the ndlp delayed-function timer to check | 
|  | 2724 | * whether there is any pending ELS retry event(s) with the node. If not, it | 
|  | 2725 | * simply returns. Otherwise, if there is at least one ELS delayed event, it | 
|  | 2726 | * adds the delayed events to the HBA work list and invokes the | 
|  | 2727 | * lpfc_worker_wake_up() routine to wake up worker thread to process the | 
|  | 2728 | * event. Note that lpfc_nlp_get() is called before posting the event to | 
|  | 2729 | * the work list to hold reference count of ndlp so that it guarantees the | 
|  | 2730 | * reference to ndlp will still be available when the worker thread gets | 
|  | 2731 | * to the event associated with the ndlp. | 
|  | 2732 | **/ | 
| James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2733 | void | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2734 | lpfc_els_retry_delay(unsigned long ptr) | 
|  | 2735 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2736 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr; | 
|  | 2737 | struct lpfc_vport *vport = ndlp->vport; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2738 | struct lpfc_hba   *phba = vport->phba; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2739 | unsigned long flags; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2740 | struct lpfc_work_evt  *evtp = &ndlp->els_retry_evt; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2741 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2742 | spin_lock_irqsave(&phba->hbalock, flags); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2743 | if (!list_empty(&evtp->evt_listp)) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2744 | spin_unlock_irqrestore(&phba->hbalock, flags); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2745 | return; | 
|  | 2746 | } | 
|  | 2747 |  | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2748 | /* We need to hold the node by incrementing the reference | 
|  | 2749 | * count until the queued work is done | 
|  | 2750 | */ | 
|  | 2751 | evtp->evt_arg1  = lpfc_nlp_get(ndlp); | 
| James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2752 | if (evtp->evt_arg1) { | 
|  | 2753 | evtp->evt = LPFC_EVT_ELS_RETRY; | 
|  | 2754 | list_add_tail(&evtp->evt_listp, &phba->work_list); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2755 | lpfc_worker_wake_up(phba); | 
| James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2756 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2757 | spin_unlock_irqrestore(&phba->hbalock, flags); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2758 | return; | 
|  | 2759 | } | 
|  | 2760 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2761 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2762 | * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2763 | * @ndlp: pointer to a node-list data structure. | 
|  | 2764 | * | 
|  | 2765 | * This routine is the worker-thread handler for processing the @ndlp delayed | 
|  | 2766 | * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves | 
|  | 2767 | * the last ELS command from the associated ndlp and invokes the proper ELS | 
|  | 2768 | * function according to the delayed ELS command to retry the command. | 
|  | 2769 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2770 | void | 
|  | 2771 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) | 
|  | 2772 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2773 | struct lpfc_vport *vport = ndlp->vport; | 
|  | 2774 | struct Scsi_Host  *shost = lpfc_shost_from_vport(vport); | 
|  | 2775 | uint32_t cmd, did, retry; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2776 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2777 | spin_lock_irq(shost->host_lock); | 
| Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2778 | did = ndlp->nlp_DID; | 
|  | 2779 | cmd = ndlp->nlp_last_elscmd; | 
|  | 2780 | ndlp->nlp_last_elscmd = 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2781 |  | 
|  | 2782 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2783 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2784 | return; | 
|  | 2785 | } | 
|  | 2786 |  | 
|  | 2787 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2788 | spin_unlock_irq(shost->host_lock); | 
| James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 2789 | /* | 
|  | 2790 | * If a discovery event readded nlp_delayfunc after timer | 
|  | 2791 | * firing and before processing the timer, cancel the | 
|  | 2792 | * nlp_delayfunc. | 
|  | 2793 | */ | 
|  | 2794 | del_timer_sync(&ndlp->nlp_delayfunc); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2795 | retry = ndlp->nlp_retry; | 
| James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 2796 | ndlp->nlp_retry = 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2797 |  | 
|  | 2798 | switch (cmd) { | 
|  | 2799 | case ELS_CMD_FLOGI: | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2800 | lpfc_issue_els_flogi(vport, ndlp, retry); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2801 | break; | 
|  | 2802 | case ELS_CMD_PLOGI: | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2803 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { | 
| Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2804 | ndlp->nlp_prev_state = ndlp->nlp_state; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2805 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); | 
| Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2806 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2807 | break; | 
|  | 2808 | case ELS_CMD_ADISC: | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2809 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { | 
| Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2810 | ndlp->nlp_prev_state = ndlp->nlp_state; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2811 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); | 
| Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2812 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2813 | break; | 
|  | 2814 | case ELS_CMD_PRLI: | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2815 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { | 
| Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2816 | ndlp->nlp_prev_state = ndlp->nlp_state; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2817 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); | 
| Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2818 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2819 | break; | 
|  | 2820 | case ELS_CMD_LOGO: | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2821 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { | 
| Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2822 | ndlp->nlp_prev_state = ndlp->nlp_state; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2823 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); | 
| Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2824 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2825 | break; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2826 | case ELS_CMD_FDISC: | 
| James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 2827 | if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)) | 
|  | 2828 | lpfc_issue_els_fdisc(vport, ndlp, retry); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2829 | break; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2830 | } | 
|  | 2831 | return; | 
|  | 2832 | } | 
|  | 2833 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2834 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2835 | * lpfc_els_retry - Make retry decision on an els command iocb | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2836 | * @phba: pointer to lpfc hba data structure. | 
|  | 2837 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 2838 | * @rspiocb: pointer to lpfc response iocb data structure. | 
|  | 2839 | * | 
|  | 2840 | * This routine makes a retry decision on an ELS command IOCB, which has | 
|  | 2841 | * failed. The following ELS IOCBs use this function for retrying the command | 
|  | 2842 | * when previously issued command responsed with error status: FLOGI, PLOGI, | 
|  | 2843 | * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the | 
|  | 2844 | * returned error status, it makes the decision whether a retry shall be | 
|  | 2845 | * issued for the command, and whether a retry shall be made immediately or | 
|  | 2846 | * delayed. In the former case, the corresponding ELS command issuing-function | 
|  | 2847 | * is called to retry the command. In the later case, the ELS command shall | 
|  | 2848 | * be posted to the ndlp delayed event and delayed function timer set to the | 
|  | 2849 | * ndlp for the delayed command issusing. | 
|  | 2850 | * | 
|  | 2851 | * Return code | 
|  | 2852 | *   0 - No retry of els command is made | 
|  | 2853 | *   1 - Immediate or delayed retry of els command is made | 
|  | 2854 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2855 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2856 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | 
|  | 2857 | struct lpfc_iocbq *rspiocb) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2858 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2859 | struct lpfc_vport *vport = cmdiocb->vport; | 
|  | 2860 | struct Scsi_Host  *shost = lpfc_shost_from_vport(vport); | 
|  | 2861 | IOCB_t *irsp = &rspiocb->iocb; | 
|  | 2862 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; | 
|  | 2863 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2864 | uint32_t *elscmd; | 
|  | 2865 | struct ls_rjt stat; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2866 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2867 | int logerr = 0; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2868 | uint32_t cmd = 0; | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2869 | uint32_t did; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2870 |  | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2871 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2872 | /* Note: context2 may be 0 for internal driver abort | 
|  | 2873 | * of delays ELS command. | 
|  | 2874 | */ | 
|  | 2875 |  | 
|  | 2876 | if (pcmd && pcmd->virt) { | 
|  | 2877 | elscmd = (uint32_t *) (pcmd->virt); | 
|  | 2878 | cmd = *elscmd++; | 
|  | 2879 | } | 
|  | 2880 |  | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2881 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2882 | did = ndlp->nlp_DID; | 
|  | 2883 | else { | 
|  | 2884 | /* We should only hit this case for retrying PLOGI */ | 
|  | 2885 | did = irsp->un.elsreq64.remoteID; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2886 | ndlp = lpfc_findnode_did(vport, did); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2887 | if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp)) | 
|  | 2888 | && (cmd != ELS_CMD_PLOGI)) | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2889 | return 1; | 
|  | 2890 | } | 
|  | 2891 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2892 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 2893 | "Retry ELS:       wd7:x%x wd4:x%x did:x%x", | 
|  | 2894 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); | 
|  | 2895 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2896 | switch (irsp->ulpStatus) { | 
|  | 2897 | case IOSTAT_FCP_RSP_ERROR: | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2898 | break; | 
| James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2899 | case IOSTAT_REMOTE_STOP: | 
|  | 2900 | if (phba->sli_rev == LPFC_SLI_REV4) { | 
|  | 2901 | /* This IO was aborted by the target, we don't | 
|  | 2902 | * know the rxid and because we did not send the | 
|  | 2903 | * ABTS we cannot generate and RRQ. | 
|  | 2904 | */ | 
|  | 2905 | lpfc_set_rrq_active(phba, ndlp, | 
|  | 2906 | cmdiocb->sli4_xritag, 0, 0); | 
|  | 2907 | } | 
|  | 2908 | break; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2909 | case IOSTAT_LOCAL_REJECT: | 
|  | 2910 | switch ((irsp->un.ulpWord[4] & 0xff)) { | 
|  | 2911 | case IOERR_LOOP_OPEN_FAILURE: | 
| James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2912 | if (cmd == ELS_CMD_FLOGI) { | 
|  | 2913 | if (PCI_DEVICE_ID_HORNET == | 
|  | 2914 | phba->pcidev->device) { | 
| James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2915 | phba->fc_topology = LPFC_TOPOLOGY_LOOP; | 
| James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2916 | phba->pport->fc_myDID = 0; | 
|  | 2917 | phba->alpa_map[0] = 0; | 
|  | 2918 | phba->alpa_map[1] = 0; | 
|  | 2919 | } | 
|  | 2920 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2921 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2922 | delay = 1000; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2923 | retry = 1; | 
|  | 2924 | break; | 
|  | 2925 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2926 | case IOERR_ILLEGAL_COMMAND: | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2927 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 2928 | "0124 Retry illegal cmd x%x " | 
|  | 2929 | "retry:x%x delay:x%x\n", | 
|  | 2930 | cmd, cmdiocb->retry, delay); | 
|  | 2931 | retry = 1; | 
|  | 2932 | /* All command's retry policy */ | 
|  | 2933 | maxretry = 8; | 
|  | 2934 | if (cmdiocb->retry > 2) | 
|  | 2935 | delay = 1000; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2936 | break; | 
|  | 2937 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2938 | case IOERR_NO_RESOURCES: | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2939 | logerr = 1; /* HBA out of resources */ | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2940 | retry = 1; | 
|  | 2941 | if (cmdiocb->retry > 100) | 
|  | 2942 | delay = 100; | 
|  | 2943 | maxretry = 250; | 
|  | 2944 | break; | 
|  | 2945 |  | 
|  | 2946 | case IOERR_ILLEGAL_FRAME: | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2947 | delay = 100; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2948 | retry = 1; | 
|  | 2949 | break; | 
|  | 2950 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2951 | case IOERR_SEQUENCE_TIMEOUT: | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2952 | case IOERR_INVALID_RPI: | 
|  | 2953 | retry = 1; | 
|  | 2954 | break; | 
|  | 2955 | } | 
|  | 2956 | break; | 
|  | 2957 |  | 
|  | 2958 | case IOSTAT_NPORT_RJT: | 
|  | 2959 | case IOSTAT_FABRIC_RJT: | 
|  | 2960 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { | 
|  | 2961 | retry = 1; | 
|  | 2962 | break; | 
|  | 2963 | } | 
|  | 2964 | break; | 
|  | 2965 |  | 
|  | 2966 | case IOSTAT_NPORT_BSY: | 
|  | 2967 | case IOSTAT_FABRIC_BSY: | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2968 | logerr = 1; /* Fabric / Remote NPort out of resources */ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2969 | retry = 1; | 
|  | 2970 | break; | 
|  | 2971 |  | 
|  | 2972 | case IOSTAT_LS_RJT: | 
|  | 2973 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); | 
|  | 2974 | /* Added for Vendor specifc support | 
|  | 2975 | * Just keep retrying for these Rsn / Exp codes | 
|  | 2976 | */ | 
|  | 2977 | switch (stat.un.b.lsRjtRsnCode) { | 
|  | 2978 | case LSRJT_UNABLE_TPC: | 
|  | 2979 | if (stat.un.b.lsRjtRsnCodeExp == | 
|  | 2980 | LSEXP_CMD_IN_PROGRESS) { | 
|  | 2981 | if (cmd == ELS_CMD_PLOGI) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2982 | delay = 1000; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2983 | maxretry = 48; | 
|  | 2984 | } | 
|  | 2985 | retry = 1; | 
|  | 2986 | break; | 
|  | 2987 | } | 
| James Smart | ffc9549 | 2010-06-07 15:23:17 -0400 | [diff] [blame] | 2988 | if (stat.un.b.lsRjtRsnCodeExp == | 
|  | 2989 | LSEXP_CANT_GIVE_DATA) { | 
|  | 2990 | if (cmd == ELS_CMD_PLOGI) { | 
|  | 2991 | delay = 1000; | 
|  | 2992 | maxretry = 48; | 
|  | 2993 | } | 
|  | 2994 | retry = 1; | 
|  | 2995 | break; | 
|  | 2996 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2997 | if (cmd == ELS_CMD_PLOGI) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2998 | delay = 1000; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2999 | maxretry = lpfc_max_els_tries + 1; | 
|  | 3000 | retry = 1; | 
|  | 3001 | break; | 
|  | 3002 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3003 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && | 
|  | 3004 | (cmd == ELS_CMD_FDISC) && | 
|  | 3005 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3006 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 3007 | "0125 FDISC Failed (x%x). " | 
|  | 3008 | "Fabric out of resources\n", | 
|  | 3009 | stat.un.lsRjtError); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3010 | lpfc_vport_set_state(vport, | 
|  | 3011 | FC_VPORT_NO_FABRIC_RSCS); | 
|  | 3012 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3013 | break; | 
|  | 3014 |  | 
|  | 3015 | case LSRJT_LOGICAL_BSY: | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3016 | if ((cmd == ELS_CMD_PLOGI) || | 
|  | 3017 | (cmd == ELS_CMD_PRLI)) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3018 | delay = 1000; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3019 | maxretry = 48; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3020 | } else if (cmd == ELS_CMD_FDISC) { | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3021 | /* FDISC retry policy */ | 
|  | 3022 | maxretry = 48; | 
|  | 3023 | if (cmdiocb->retry >= 32) | 
|  | 3024 | delay = 1000; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3025 | } | 
|  | 3026 | retry = 1; | 
|  | 3027 | break; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3028 |  | 
|  | 3029 | case LSRJT_LOGICAL_ERR: | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3030 | /* There are some cases where switches return this | 
|  | 3031 | * error when they are not ready and should be returning | 
|  | 3032 | * Logical Busy. We should delay every time. | 
|  | 3033 | */ | 
|  | 3034 | if (cmd == ELS_CMD_FDISC && | 
|  | 3035 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { | 
|  | 3036 | maxretry = 3; | 
|  | 3037 | delay = 1000; | 
|  | 3038 | retry = 1; | 
|  | 3039 | break; | 
|  | 3040 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3041 | case LSRJT_PROTOCOL_ERR: | 
|  | 3042 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && | 
|  | 3043 | (cmd == ELS_CMD_FDISC) && | 
|  | 3044 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || | 
|  | 3045 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) | 
|  | 3046 | ) { | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3047 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3048 | "0122 FDISC Failed (x%x). " | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3049 | "Fabric Detected Bad WWN\n", | 
|  | 3050 | stat.un.lsRjtError); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3051 | lpfc_vport_set_state(vport, | 
|  | 3052 | FC_VPORT_FABRIC_REJ_WWN); | 
|  | 3053 | } | 
|  | 3054 | break; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3055 | } | 
|  | 3056 | break; | 
|  | 3057 |  | 
|  | 3058 | case IOSTAT_INTERMED_RSP: | 
|  | 3059 | case IOSTAT_BA_RJT: | 
|  | 3060 | break; | 
|  | 3061 |  | 
|  | 3062 | default: | 
|  | 3063 | break; | 
|  | 3064 | } | 
|  | 3065 |  | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3066 | if (did == FDMI_DID) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3067 | retry = 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3068 |  | 
| James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3069 | if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) && | 
| James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3070 | (phba->fc_topology != LPFC_TOPOLOGY_LOOP) && | 
| James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 3071 | !lpfc_error_lost_link(irsp)) { | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3072 | /* FLOGI retry policy */ | 
|  | 3073 | retry = 1; | 
| James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 3074 | /* retry forever */ | 
|  | 3075 | maxretry = 0; | 
|  | 3076 | if (cmdiocb->retry >= 100) | 
|  | 3077 | delay = 5000; | 
|  | 3078 | else if (cmdiocb->retry >= 32) | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3079 | delay = 1000; | 
|  | 3080 | } | 
|  | 3081 |  | 
| James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 3082 | cmdiocb->retry++; | 
|  | 3083 | if (maxretry && (cmdiocb->retry >= maxretry)) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3084 | phba->fc_stat.elsRetryExceeded++; | 
|  | 3085 | retry = 0; | 
|  | 3086 | } | 
|  | 3087 |  | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3088 | if ((vport->load_flag & FC_UNLOADING) != 0) | 
|  | 3089 | retry = 0; | 
|  | 3090 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3091 | if (retry) { | 
| James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3092 | if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) { | 
|  | 3093 | /* Stop retrying PLOGI and FDISC if in FCF discovery */ | 
|  | 3094 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { | 
|  | 3095 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 3096 | "2849 Stop retry ELS command " | 
|  | 3097 | "x%x to remote NPORT x%x, " | 
|  | 3098 | "Data: x%x x%x\n", cmd, did, | 
|  | 3099 | cmdiocb->retry, delay); | 
|  | 3100 | return 0; | 
|  | 3101 | } | 
|  | 3102 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3103 |  | 
|  | 3104 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3105 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 3106 | "0107 Retry ELS command x%x to remote " | 
|  | 3107 | "NPORT x%x Data: x%x x%x\n", | 
|  | 3108 | cmd, did, cmdiocb->retry, delay); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3109 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3110 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && | 
|  | 3111 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || | 
|  | 3112 | ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) { | 
|  | 3113 | /* Don't reset timer for no resources */ | 
|  | 3114 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3115 | /* If discovery / RSCN timer is running, reset it */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3116 | if (timer_pending(&vport->fc_disctmo) || | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3117 | (vport->fc_flag & FC_RSCN_MODE)) | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3118 | lpfc_set_disctmo(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3119 | } | 
|  | 3120 |  | 
|  | 3121 | phba->fc_stat.elsXmitRetry++; | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3122 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3123 | phba->fc_stat.elsDelayRetry++; | 
|  | 3124 | ndlp->nlp_retry = cmdiocb->retry; | 
|  | 3125 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3126 | /* delay is specified in milliseconds */ | 
|  | 3127 | mod_timer(&ndlp->nlp_delayfunc, | 
|  | 3128 | jiffies + msecs_to_jiffies(delay)); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3129 | spin_lock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3130 | ndlp->nlp_flag |= NLP_DELAY_TMO; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3131 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3132 |  | 
| Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3133 | ndlp->nlp_prev_state = ndlp->nlp_state; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3134 | if (cmd == ELS_CMD_PRLI) | 
|  | 3135 | lpfc_nlp_set_state(vport, ndlp, | 
|  | 3136 | NLP_STE_REG_LOGIN_ISSUE); | 
|  | 3137 | else | 
|  | 3138 | lpfc_nlp_set_state(vport, ndlp, | 
|  | 3139 | NLP_STE_NPR_NODE); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3140 | ndlp->nlp_last_elscmd = cmd; | 
|  | 3141 |  | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3142 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3143 | } | 
|  | 3144 | switch (cmd) { | 
|  | 3145 | case ELS_CMD_FLOGI: | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3146 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3147 | return 1; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3148 | case ELS_CMD_FDISC: | 
|  | 3149 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); | 
|  | 3150 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3151 | case ELS_CMD_PLOGI: | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3152 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3153 | ndlp->nlp_prev_state = ndlp->nlp_state; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3154 | lpfc_nlp_set_state(vport, ndlp, | 
| James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3155 | NLP_STE_PLOGI_ISSUE); | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3156 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3157 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3158 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3159 | case ELS_CMD_ADISC: | 
| Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3160 | ndlp->nlp_prev_state = ndlp->nlp_state; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3161 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); | 
|  | 3162 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3163 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3164 | case ELS_CMD_PRLI: | 
| Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3165 | ndlp->nlp_prev_state = ndlp->nlp_state; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3166 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); | 
|  | 3167 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3168 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3169 | case ELS_CMD_LOGO: | 
| Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3170 | ndlp->nlp_prev_state = ndlp->nlp_state; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3171 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); | 
|  | 3172 | lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3173 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3174 | } | 
|  | 3175 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3176 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3177 | if (logerr) { | 
|  | 3178 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 3179 | "0137 No retry ELS command x%x to remote " | 
|  | 3180 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", | 
|  | 3181 | cmd, did, irsp->ulpStatus, | 
|  | 3182 | irsp->un.ulpWord[4]); | 
|  | 3183 | } | 
|  | 3184 | else { | 
|  | 3185 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
| James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3186 | "0108 No retry ELS command x%x to remote " | 
|  | 3187 | "NPORT x%x Retried:%d Error:x%x/%x\n", | 
|  | 3188 | cmd, did, cmdiocb->retry, irsp->ulpStatus, | 
|  | 3189 | irsp->un.ulpWord[4]); | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3190 | } | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3191 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3192 | } | 
|  | 3193 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3194 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3195 | * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3196 | * @phba: pointer to lpfc hba data structure. | 
|  | 3197 | * @buf_ptr1: pointer to the lpfc DMA buffer data structure. | 
|  | 3198 | * | 
|  | 3199 | * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) | 
|  | 3200 | * associated with a command IOCB back to the lpfc DMA buffer pool. It first | 
|  | 3201 | * checks to see whether there is a lpfc DMA buffer associated with the | 
|  | 3202 | * response of the command IOCB. If so, it will be released before releasing | 
|  | 3203 | * the lpfc DMA buffer associated with the IOCB itself. | 
|  | 3204 | * | 
|  | 3205 | * Return code | 
|  | 3206 | *   0 - Successfully released lpfc DMA buffer (currently, always return 0) | 
|  | 3207 | **/ | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3208 | static int | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3209 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) | 
|  | 3210 | { | 
|  | 3211 | struct lpfc_dmabuf *buf_ptr; | 
|  | 3212 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3213 | /* Free the response before processing the command. */ | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3214 | if (!list_empty(&buf_ptr1->list)) { | 
|  | 3215 | list_remove_head(&buf_ptr1->list, buf_ptr, | 
|  | 3216 | struct lpfc_dmabuf, | 
|  | 3217 | list); | 
|  | 3218 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | 
|  | 3219 | kfree(buf_ptr); | 
|  | 3220 | } | 
|  | 3221 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); | 
|  | 3222 | kfree(buf_ptr1); | 
|  | 3223 | return 0; | 
|  | 3224 | } | 
|  | 3225 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3226 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3227 | * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3228 | * @phba: pointer to lpfc hba data structure. | 
|  | 3229 | * @buf_ptr: pointer to the lpfc dma buffer data structure. | 
|  | 3230 | * | 
|  | 3231 | * This routine releases the lpfc Direct Memory Access (DMA) buffer | 
|  | 3232 | * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer | 
|  | 3233 | * pool. | 
|  | 3234 | * | 
|  | 3235 | * Return code | 
|  | 3236 | *   0 - Successfully released lpfc DMA buffer (currently, always return 0) | 
|  | 3237 | **/ | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3238 | static int | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3239 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) | 
|  | 3240 | { | 
|  | 3241 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | 
|  | 3242 | kfree(buf_ptr); | 
|  | 3243 | return 0; | 
|  | 3244 | } | 
|  | 3245 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3246 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3247 | * lpfc_els_free_iocb - Free a command iocb and its associated resources | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3248 | * @phba: pointer to lpfc hba data structure. | 
|  | 3249 | * @elsiocb: pointer to lpfc els command iocb data structure. | 
|  | 3250 | * | 
|  | 3251 | * This routine frees a command IOCB and its associated resources. The | 
|  | 3252 | * command IOCB data structure contains the reference to various associated | 
|  | 3253 | * resources, these fields must be set to NULL if the associated reference | 
|  | 3254 | * not present: | 
|  | 3255 | *   context1 - reference to ndlp | 
|  | 3256 | *   context2 - reference to cmd | 
|  | 3257 | *   context2->next - reference to rsp | 
|  | 3258 | *   context3 - reference to bpl | 
|  | 3259 | * | 
|  | 3260 | * It first properly decrements the reference count held on ndlp for the | 
|  | 3261 | * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not | 
|  | 3262 | * set, it invokes the lpfc_els_free_data() routine to release the Direct | 
|  | 3263 | * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it | 
|  | 3264 | * adds the DMA buffer the @phba data structure for the delayed release. | 
|  | 3265 | * If reference to the Buffer Pointer List (BPL) is present, the | 
|  | 3266 | * lpfc_els_free_bpl() routine is invoked to release the DMA memory | 
|  | 3267 | * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is | 
|  | 3268 | * invoked to release the IOCB data structure back to @phba IOCBQ list. | 
|  | 3269 | * | 
|  | 3270 | * Return code | 
|  | 3271 | *   0 - Success (currently, always return 0) | 
|  | 3272 | **/ | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3273 | int | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3274 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3275 | { | 
|  | 3276 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; | 
| James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3277 | struct lpfc_nodelist *ndlp; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3278 |  | 
| James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3279 | ndlp = (struct lpfc_nodelist *)elsiocb->context1; | 
|  | 3280 | if (ndlp) { | 
|  | 3281 | if (ndlp->nlp_flag & NLP_DEFER_RM) { | 
|  | 3282 | lpfc_nlp_put(ndlp); | 
|  | 3283 |  | 
|  | 3284 | /* If the ndlp is not being used by another discovery | 
|  | 3285 | * thread, free it. | 
|  | 3286 | */ | 
|  | 3287 | if (!lpfc_nlp_not_used(ndlp)) { | 
|  | 3288 | /* If ndlp is being used by another discovery | 
|  | 3289 | * thread, just clear NLP_DEFER_RM | 
|  | 3290 | */ | 
|  | 3291 | ndlp->nlp_flag &= ~NLP_DEFER_RM; | 
|  | 3292 | } | 
|  | 3293 | } | 
|  | 3294 | else | 
|  | 3295 | lpfc_nlp_put(ndlp); | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3296 | elsiocb->context1 = NULL; | 
|  | 3297 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3298 | /* context2  = cmd,  context2->next = rsp, context3 = bpl */ | 
|  | 3299 | if (elsiocb->context2) { | 
| James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3300 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { | 
|  | 3301 | /* Firmware could still be in progress of DMAing | 
|  | 3302 | * payload, so don't free data buffer till after | 
|  | 3303 | * a hbeat. | 
|  | 3304 | */ | 
|  | 3305 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; | 
|  | 3306 | buf_ptr = elsiocb->context2; | 
|  | 3307 | elsiocb->context2 = NULL; | 
|  | 3308 | if (buf_ptr) { | 
|  | 3309 | buf_ptr1 = NULL; | 
|  | 3310 | spin_lock_irq(&phba->hbalock); | 
|  | 3311 | if (!list_empty(&buf_ptr->list)) { | 
|  | 3312 | list_remove_head(&buf_ptr->list, | 
|  | 3313 | buf_ptr1, struct lpfc_dmabuf, | 
|  | 3314 | list); | 
|  | 3315 | INIT_LIST_HEAD(&buf_ptr1->list); | 
|  | 3316 | list_add_tail(&buf_ptr1->list, | 
|  | 3317 | &phba->elsbuf); | 
|  | 3318 | phba->elsbuf_cnt++; | 
|  | 3319 | } | 
|  | 3320 | INIT_LIST_HEAD(&buf_ptr->list); | 
|  | 3321 | list_add_tail(&buf_ptr->list, &phba->elsbuf); | 
|  | 3322 | phba->elsbuf_cnt++; | 
|  | 3323 | spin_unlock_irq(&phba->hbalock); | 
|  | 3324 | } | 
|  | 3325 | } else { | 
|  | 3326 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; | 
|  | 3327 | lpfc_els_free_data(phba, buf_ptr1); | 
|  | 3328 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3329 | } | 
|  | 3330 |  | 
|  | 3331 | if (elsiocb->context3) { | 
|  | 3332 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3333 | lpfc_els_free_bpl(phba, buf_ptr); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3334 | } | 
| James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3335 | lpfc_sli_release_iocbq(phba, elsiocb); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3336 | return 0; | 
|  | 3337 | } | 
|  | 3338 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3339 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3340 | * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3341 | * @phba: pointer to lpfc hba data structure. | 
|  | 3342 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 3343 | * @rspiocb: pointer to lpfc response iocb data structure. | 
|  | 3344 | * | 
|  | 3345 | * This routine is the completion callback function to the Logout (LOGO) | 
|  | 3346 | * Accept (ACC) Response ELS command. This routine is invoked to indicate | 
|  | 3347 | * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to | 
|  | 3348 | * release the ndlp if it has the last reference remaining (reference count | 
|  | 3349 | * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1 | 
|  | 3350 | * field to NULL to inform the following lpfc_els_free_iocb() routine no | 
|  | 3351 | * ndlp reference count needs to be decremented. Otherwise, the ndlp | 
|  | 3352 | * reference use-count shall be decremented by the lpfc_els_free_iocb() | 
|  | 3353 | * routine. Finally, the lpfc_els_free_iocb() is invoked to release the | 
|  | 3354 | * IOCB data structure. | 
|  | 3355 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3356 | static void | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3357 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | 
|  | 3358 | struct lpfc_iocbq *rspiocb) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3359 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3360 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; | 
|  | 3361 | struct lpfc_vport *vport = cmdiocb->vport; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3362 | IOCB_t *irsp; | 
|  | 3363 |  | 
|  | 3364 | irsp = &rspiocb->iocb; | 
|  | 3365 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, | 
|  | 3366 | "ACC LOGO cmpl:   status:x%x/x%x did:x%x", | 
|  | 3367 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3368 | /* ACC to LOGO completes to NPort <nlp_DID> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3369 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 3370 | "0109 ACC to LOGO completes to NPort x%x " | 
|  | 3371 | "Data: x%x x%x x%x\n", | 
|  | 3372 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | 
|  | 3373 | ndlp->nlp_rpi); | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3374 |  | 
|  | 3375 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { | 
|  | 3376 | /* NPort Recovery mode or node is just allocated */ | 
|  | 3377 | if (!lpfc_nlp_not_used(ndlp)) { | 
|  | 3378 | /* If the ndlp is being used by another discovery | 
|  | 3379 | * thread, just unregister the RPI. | 
|  | 3380 | */ | 
|  | 3381 | lpfc_unreg_rpi(vport, ndlp); | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3382 | } else { | 
|  | 3383 | /* Indicate the node has already released, should | 
|  | 3384 | * not reference to it from within lpfc_els_free_iocb. | 
|  | 3385 | */ | 
|  | 3386 | cmdiocb->context1 = NULL; | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3387 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3388 | } | 
| James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3389 |  | 
|  | 3390 | /* | 
|  | 3391 | * The driver received a LOGO from the rport and has ACK'd it. | 
|  | 3392 | * At this point, the driver is done so release the IOCB and | 
|  | 3393 | * remove the ndlp reference. | 
|  | 3394 | */ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3395 | lpfc_els_free_iocb(phba, cmdiocb); | 
| James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 3396 | lpfc_nlp_put(ndlp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3397 | return; | 
|  | 3398 | } | 
|  | 3399 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3400 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3401 | * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3402 | * @phba: pointer to lpfc hba data structure. | 
|  | 3403 | * @pmb: pointer to the driver internal queue element for mailbox command. | 
|  | 3404 | * | 
|  | 3405 | * This routine is the completion callback function for unregister default | 
|  | 3406 | * RPI (Remote Port Index) mailbox command to the @phba. It simply releases | 
|  | 3407 | * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and | 
|  | 3408 | * decrements the ndlp reference count held for this completion callback | 
|  | 3409 | * function. After that, it invokes the lpfc_nlp_not_used() to check | 
|  | 3410 | * whether there is only one reference left on the ndlp. If so, it will | 
|  | 3411 | * perform one more decrement and trigger the release of the ndlp. | 
|  | 3412 | **/ | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3413 | void | 
|  | 3414 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) | 
|  | 3415 | { | 
|  | 3416 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); | 
|  | 3417 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; | 
|  | 3418 |  | 
|  | 3419 | pmb->context1 = NULL; | 
| James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3420 | pmb->context2 = NULL; | 
|  | 3421 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3422 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | 
|  | 3423 | kfree(mp); | 
|  | 3424 | mempool_free(pmb, phba->mbox_mem_pool); | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3425 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { | 
| James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3426 | lpfc_nlp_put(ndlp); | 
| James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3427 | /* This is the end of the default RPI cleanup logic for this | 
|  | 3428 | * ndlp. If no other discovery threads are using this ndlp. | 
|  | 3429 | * we should free all resources associated with it. | 
|  | 3430 | */ | 
|  | 3431 | lpfc_nlp_not_used(ndlp); | 
|  | 3432 | } | 
| James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3433 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3434 | return; | 
|  | 3435 | } | 
|  | 3436 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3437 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3438 | * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3439 | * @phba: pointer to lpfc hba data structure. | 
|  | 3440 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 3441 | * @rspiocb: pointer to lpfc response iocb data structure. | 
|  | 3442 | * | 
|  | 3443 | * This routine is the completion callback function for ELS Response IOCB | 
|  | 3444 | * command. In normal case, this callback function just properly sets the | 
|  | 3445 | * nlp_flag bitmap in the ndlp data structure, if the mbox command reference | 
|  | 3446 | * field in the command IOCB is not NULL, the referred mailbox command will | 
|  | 3447 | * be send out, and then invokes the lpfc_els_free_iocb() routine to release | 
|  | 3448 | * the IOCB. Under error conditions, such as when a LS_RJT is returned or a | 
|  | 3449 | * link down event occurred during the discovery, the lpfc_nlp_not_used() | 
|  | 3450 | * routine shall be invoked trying to release the ndlp if no other threads | 
|  | 3451 | * are currently referring it. | 
|  | 3452 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3453 | static void | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3454 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3455 | struct lpfc_iocbq *rspiocb) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3456 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3457 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; | 
|  | 3458 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; | 
|  | 3459 | struct Scsi_Host  *shost = vport ? lpfc_shost_from_vport(vport) : NULL; | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3460 | IOCB_t  *irsp; | 
|  | 3461 | uint8_t *pcmd; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3462 | LPFC_MBOXQ_t *mbox = NULL; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3463 | struct lpfc_dmabuf *mp = NULL; | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3464 | uint32_t ls_rjt = 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3465 |  | 
| James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 3466 | irsp = &rspiocb->iocb; | 
|  | 3467 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3468 | if (cmdiocb->context_un.mbox) | 
|  | 3469 | mbox = cmdiocb->context_un.mbox; | 
|  | 3470 |  | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3471 | /* First determine if this is a LS_RJT cmpl. Note, this callback | 
|  | 3472 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. | 
|  | 3473 | */ | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3474 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3475 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && | 
|  | 3476 | (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3477 | /* A LS_RJT associated with Default RPI cleanup has its own | 
| Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 3478 | * separate code path. | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3479 | */ | 
|  | 3480 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) | 
|  | 3481 | ls_rjt = 1; | 
|  | 3482 | } | 
|  | 3483 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3484 | /* Check to see if link went down during discovery */ | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3485 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3486 | if (mbox) { | 
| James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3487 | mp = (struct lpfc_dmabuf *) mbox->context1; | 
|  | 3488 | if (mp) { | 
|  | 3489 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | 
|  | 3490 | kfree(mp); | 
|  | 3491 | } | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3492 | mempool_free(mbox, phba->mbox_mem_pool); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3493 | } | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3494 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && | 
|  | 3495 | (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3496 | if (lpfc_nlp_not_used(ndlp)) { | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3497 | ndlp = NULL; | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3498 | /* Indicate the node has already released, | 
|  | 3499 | * should not reference to it from within | 
|  | 3500 | * the routine lpfc_els_free_iocb. | 
|  | 3501 | */ | 
|  | 3502 | cmdiocb->context1 = NULL; | 
|  | 3503 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3504 | goto out; | 
|  | 3505 | } | 
|  | 3506 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3507 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3508 | "ELS rsp cmpl:    status:x%x/x%x did:x%x", | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3509 | irsp->ulpStatus, irsp->un.ulpWord[4], | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3510 | cmdiocb->iocb.un.elsreq64.remoteID); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3511 | /* ELS response tag <ulpIoTag> completes */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3512 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 3513 | "0110 ELS response tag x%x completes " | 
|  | 3514 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", | 
|  | 3515 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, | 
|  | 3516 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, | 
|  | 3517 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | 
|  | 3518 | ndlp->nlp_rpi); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3519 | if (mbox) { | 
|  | 3520 | if ((rspiocb->iocb.ulpStatus == 0) | 
|  | 3521 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3522 | lpfc_unreg_rpi(vport, ndlp); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3523 | /* Increment reference count to ndlp to hold the | 
|  | 3524 | * reference to ndlp for the callback function. | 
|  | 3525 | */ | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3526 | mbox->context2 = lpfc_nlp_get(ndlp); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3527 | mbox->vport = vport; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3528 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { | 
|  | 3529 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; | 
|  | 3530 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; | 
|  | 3531 | } | 
|  | 3532 | else { | 
|  | 3533 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; | 
|  | 3534 | ndlp->nlp_prev_state = ndlp->nlp_state; | 
|  | 3535 | lpfc_nlp_set_state(vport, ndlp, | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3536 | NLP_STE_REG_LOGIN_ISSUE); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3537 | } | 
| James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3538 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3539 | != MBX_NOT_FINISHED) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3540 | goto out; | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3541 | else | 
|  | 3542 | /* Decrement the ndlp reference count we | 
|  | 3543 | * set for this failed mailbox command. | 
|  | 3544 | */ | 
|  | 3545 | lpfc_nlp_put(ndlp); | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3546 |  | 
|  | 3547 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ | 
|  | 3548 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 3549 | "0138 ELS rsp: Cannot issue reg_login for x%x " | 
|  | 3550 | "Data: x%x x%x x%x\n", | 
|  | 3551 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | 
|  | 3552 | ndlp->nlp_rpi); | 
|  | 3553 |  | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3554 | if (lpfc_nlp_not_used(ndlp)) { | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3555 | ndlp = NULL; | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3556 | /* Indicate node has already been released, | 
|  | 3557 | * should not reference to it from within | 
|  | 3558 | * the routine lpfc_els_free_iocb. | 
|  | 3559 | */ | 
|  | 3560 | cmdiocb->context1 = NULL; | 
|  | 3561 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3562 | } else { | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3563 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ | 
|  | 3564 | if (!lpfc_error_lost_link(irsp) && | 
|  | 3565 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3566 | if (lpfc_nlp_not_used(ndlp)) { | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3567 | ndlp = NULL; | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3568 | /* Indicate node has already been | 
|  | 3569 | * released, should not reference | 
|  | 3570 | * to it from within the routine | 
|  | 3571 | * lpfc_els_free_iocb. | 
|  | 3572 | */ | 
|  | 3573 | cmdiocb->context1 = NULL; | 
|  | 3574 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3575 | } | 
|  | 3576 | } | 
| James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3577 | mp = (struct lpfc_dmabuf *) mbox->context1; | 
|  | 3578 | if (mp) { | 
|  | 3579 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | 
|  | 3580 | kfree(mp); | 
|  | 3581 | } | 
|  | 3582 | mempool_free(mbox, phba->mbox_mem_pool); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3583 | } | 
|  | 3584 | out: | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3585 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3586 | spin_lock_irq(shost->host_lock); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3587 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3588 | spin_unlock_irq(shost->host_lock); | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3589 |  | 
|  | 3590 | /* If the node is not being used by another discovery thread, | 
|  | 3591 | * and we are sending a reject, we are done with it. | 
|  | 3592 | * Release driver reference count here and free associated | 
|  | 3593 | * resources. | 
|  | 3594 | */ | 
|  | 3595 | if (ls_rjt) | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3596 | if (lpfc_nlp_not_used(ndlp)) | 
|  | 3597 | /* Indicate node has already been released, | 
|  | 3598 | * should not reference to it from within | 
|  | 3599 | * the routine lpfc_els_free_iocb. | 
|  | 3600 | */ | 
|  | 3601 | cmdiocb->context1 = NULL; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3602 | } | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3603 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3604 | lpfc_els_free_iocb(phba, cmdiocb); | 
|  | 3605 | return; | 
|  | 3606 | } | 
|  | 3607 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3608 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3609 | * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3610 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 3611 | * @flag: the els command code to be accepted. | 
|  | 3612 | * @oldiocb: pointer to the original lpfc command iocb data structure. | 
|  | 3613 | * @ndlp: pointer to a node-list data structure. | 
|  | 3614 | * @mbox: pointer to the driver internal queue element for mailbox command. | 
|  | 3615 | * | 
|  | 3616 | * This routine prepares and issues an Accept (ACC) response IOCB | 
|  | 3617 | * command. It uses the @flag to properly set up the IOCB field for the | 
|  | 3618 | * specific ACC response command to be issued and invokes the | 
|  | 3619 | * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a | 
|  | 3620 | * @mbox pointer is passed in, it will be put into the context_un.mbox | 
|  | 3621 | * field of the IOCB for the completion callback function to issue the | 
|  | 3622 | * mailbox command to the HBA later when callback is invoked. | 
|  | 3623 | * | 
|  | 3624 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | 
|  | 3625 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | 
|  | 3626 | * will be stored into the context1 field of the IOCB for the completion | 
|  | 3627 | * callback function to the corresponding response ELS IOCB command. | 
|  | 3628 | * | 
|  | 3629 | * Return code | 
|  | 3630 | *   0 - Successfully issued acc response | 
|  | 3631 | *   1 - Failed to issue acc response | 
|  | 3632 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3633 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3634 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, | 
|  | 3635 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3636 | LPFC_MBOXQ_t *mbox) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3637 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3638 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | 3639 | struct lpfc_hba  *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3640 | IOCB_t *icmd; | 
|  | 3641 | IOCB_t *oldcmd; | 
|  | 3642 | struct lpfc_iocbq *elsiocb; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3643 | struct lpfc_sli *psli; | 
|  | 3644 | uint8_t *pcmd; | 
|  | 3645 | uint16_t cmdsize; | 
|  | 3646 | int rc; | 
| James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3647 | ELS_PKT *els_pkt_ptr; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3648 |  | 
|  | 3649 | psli = &phba->sli; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3650 | oldcmd = &oldiocb->iocb; | 
|  | 3651 |  | 
|  | 3652 | switch (flag) { | 
|  | 3653 | case ELS_CMD_ACC: | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3654 | cmdsize = sizeof(uint32_t); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3655 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, | 
|  | 3656 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3657 | if (!elsiocb) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3658 | spin_lock_irq(shost->host_lock); | 
| Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3659 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3660 | spin_unlock_irq(shost->host_lock); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3661 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3662 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3663 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3664 | icmd = &elsiocb->iocb; | 
| James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3665 | icmd->ulpContext = oldcmd->ulpContext;	/* Xri / rx_id */ | 
|  | 3666 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3667 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 3668 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3669 | pcmd += sizeof(uint32_t); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3670 |  | 
|  | 3671 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, | 
|  | 3672 | "Issue ACC:       did:x%x flg:x%x", | 
|  | 3673 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3674 | break; | 
|  | 3675 | case ELS_CMD_PLOGI: | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3676 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3677 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, | 
|  | 3678 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3679 | if (!elsiocb) | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3680 | return 1; | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3681 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3682 | icmd = &elsiocb->iocb; | 
| James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3683 | icmd->ulpContext = oldcmd->ulpContext;	/* Xri / rx_id */ | 
|  | 3684 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3685 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 3686 |  | 
|  | 3687 | if (mbox) | 
|  | 3688 | elsiocb->context_un.mbox = mbox; | 
|  | 3689 |  | 
|  | 3690 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3691 | pcmd += sizeof(uint32_t); | 
|  | 3692 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3693 |  | 
|  | 3694 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, | 
|  | 3695 | "Issue ACC PLOGI: did:x%x flg:x%x", | 
|  | 3696 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3697 | break; | 
| James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3698 | case ELS_CMD_PRLO: | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3699 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3700 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, | 
| James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3701 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); | 
|  | 3702 | if (!elsiocb) | 
|  | 3703 | return 1; | 
|  | 3704 |  | 
|  | 3705 | icmd = &elsiocb->iocb; | 
| James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3706 | icmd->ulpContext = oldcmd->ulpContext;	/* Xri / rx_id */ | 
|  | 3707 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; | 
| James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3708 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 3709 |  | 
|  | 3710 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3711 | sizeof(uint32_t) + sizeof(PRLO)); | 
| James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3712 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; | 
|  | 3713 | els_pkt_ptr = (ELS_PKT *) pcmd; | 
|  | 3714 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3715 |  | 
|  | 3716 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, | 
|  | 3717 | "Issue ACC PRLO:  did:x%x flg:x%x", | 
|  | 3718 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | 
| James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3719 | break; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3720 | default: | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3721 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3722 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3723 | /* Xmit ELS ACC response tag <ulpIoTag> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3724 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 3725 | "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " | 
|  | 3726 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n", | 
|  | 3727 | elsiocb->iotag, elsiocb->iocb.ulpContext, | 
|  | 3728 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | 
|  | 3729 | ndlp->nlp_rpi); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3730 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3731 | spin_lock_irq(shost->host_lock); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3732 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3733 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3734 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; | 
|  | 3735 | } else { | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3736 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3737 | } | 
|  | 3738 |  | 
|  | 3739 | phba->fc_stat.elsXmitACC++; | 
| James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3740 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3741 | if (rc == IOCB_ERROR) { | 
|  | 3742 | lpfc_els_free_iocb(phba, elsiocb); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3743 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3744 | } | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3745 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3746 | } | 
|  | 3747 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3748 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3749 | * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3750 | * @vport: pointer to a virtual N_Port data structure. | 
|  | 3751 | * @rejectError: | 
|  | 3752 | * @oldiocb: pointer to the original lpfc command iocb data structure. | 
|  | 3753 | * @ndlp: pointer to a node-list data structure. | 
|  | 3754 | * @mbox: pointer to the driver internal queue element for mailbox command. | 
|  | 3755 | * | 
|  | 3756 | * This routine prepares and issue an Reject (RJT) response IOCB | 
|  | 3757 | * command. If a @mbox pointer is passed in, it will be put into the | 
|  | 3758 | * context_un.mbox field of the IOCB for the completion callback function | 
|  | 3759 | * to issue to the HBA later. | 
|  | 3760 | * | 
|  | 3761 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | 
|  | 3762 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | 
|  | 3763 | * will be stored into the context1 field of the IOCB for the completion | 
|  | 3764 | * callback function to the reject response ELS IOCB command. | 
|  | 3765 | * | 
|  | 3766 | * Return code | 
|  | 3767 | *   0 - Successfully issued reject response | 
|  | 3768 | *   1 - Failed to issue reject response | 
|  | 3769 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3770 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3771 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3772 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, | 
|  | 3773 | LPFC_MBOXQ_t *mbox) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3774 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3775 | struct lpfc_hba  *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3776 | IOCB_t *icmd; | 
|  | 3777 | IOCB_t *oldcmd; | 
|  | 3778 | struct lpfc_iocbq *elsiocb; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3779 | struct lpfc_sli *psli; | 
|  | 3780 | uint8_t *pcmd; | 
|  | 3781 | uint16_t cmdsize; | 
|  | 3782 | int rc; | 
|  | 3783 |  | 
|  | 3784 | psli = &phba->sli; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3785 | cmdsize = 2 * sizeof(uint32_t); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3786 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, | 
|  | 3787 | ndlp->nlp_DID, ELS_CMD_LS_RJT); | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3788 | if (!elsiocb) | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3789 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3790 |  | 
|  | 3791 | icmd = &elsiocb->iocb; | 
|  | 3792 | oldcmd = &oldiocb->iocb; | 
| James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3793 | icmd->ulpContext = oldcmd->ulpContext;	/* Xri / rx_id */ | 
|  | 3794 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3795 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 3796 |  | 
|  | 3797 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3798 | pcmd += sizeof(uint32_t); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3799 | *((uint32_t *) (pcmd)) = rejectError; | 
|  | 3800 |  | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3801 | if (mbox) | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3802 | elsiocb->context_un.mbox = mbox; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3803 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3804 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3805 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 3806 | "0129 Xmit ELS RJT x%x response tag x%x " | 
|  | 3807 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " | 
|  | 3808 | "rpi x%x\n", | 
|  | 3809 | rejectError, elsiocb->iotag, | 
|  | 3810 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, | 
|  | 3811 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3812 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, | 
|  | 3813 | "Issue LS_RJT:    did:x%x flg:x%x err:x%x", | 
|  | 3814 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); | 
|  | 3815 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3816 | phba->fc_stat.elsXmitLSRJT++; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3817 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; | 
| James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3818 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3819 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3820 | if (rc == IOCB_ERROR) { | 
|  | 3821 | lpfc_els_free_iocb(phba, elsiocb); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3822 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3823 | } | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3824 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3825 | } | 
|  | 3826 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3827 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3828 | * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3829 | * @vport: pointer to a virtual N_Port data structure. | 
|  | 3830 | * @oldiocb: pointer to the original lpfc command iocb data structure. | 
|  | 3831 | * @ndlp: pointer to a node-list data structure. | 
|  | 3832 | * | 
|  | 3833 | * This routine prepares and issues an Accept (ACC) response to Address | 
|  | 3834 | * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB | 
|  | 3835 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. | 
|  | 3836 | * | 
|  | 3837 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | 
|  | 3838 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | 
|  | 3839 | * will be stored into the context1 field of the IOCB for the completion | 
|  | 3840 | * callback function to the ADISC Accept response ELS IOCB command. | 
|  | 3841 | * | 
|  | 3842 | * Return code | 
|  | 3843 | *   0 - Successfully issued acc adisc response | 
|  | 3844 | *   1 - Failed to issue adisc acc response | 
|  | 3845 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3846 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3847 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, | 
|  | 3848 | struct lpfc_nodelist *ndlp) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3849 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3850 | struct lpfc_hba  *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3851 | ADISC *ap; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3852 | IOCB_t *icmd, *oldcmd; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3853 | struct lpfc_iocbq *elsiocb; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3854 | uint8_t *pcmd; | 
|  | 3855 | uint16_t cmdsize; | 
|  | 3856 | int rc; | 
|  | 3857 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3858 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3859 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, | 
|  | 3860 | ndlp->nlp_DID, ELS_CMD_ACC); | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3861 | if (!elsiocb) | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3862 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3863 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3864 | icmd = &elsiocb->iocb; | 
|  | 3865 | oldcmd = &oldiocb->iocb; | 
| James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3866 | icmd->ulpContext = oldcmd->ulpContext;	/* Xri / rx_id */ | 
|  | 3867 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; | 
| James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3868 |  | 
|  | 3869 | /* Xmit ADISC ACC response tag <ulpIoTag> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3870 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 3871 | "0130 Xmit ADISC ACC response iotag x%x xri: " | 
|  | 3872 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", | 
|  | 3873 | elsiocb->iotag, elsiocb->iocb.ulpContext, | 
|  | 3874 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | 
|  | 3875 | ndlp->nlp_rpi); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3876 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 3877 |  | 
|  | 3878 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3879 | pcmd += sizeof(uint32_t); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3880 |  | 
|  | 3881 | ap = (ADISC *) (pcmd); | 
|  | 3882 | ap->hardAL_PA = phba->fc_pref_ALPA; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3883 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); | 
|  | 3884 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3885 | ap->DID = be32_to_cpu(vport->fc_myDID); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3886 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3887 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, | 
|  | 3888 | "Issue ACC ADISC: did:x%x flg:x%x", | 
|  | 3889 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | 
|  | 3890 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3891 | phba->fc_stat.elsXmitACC++; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3892 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; | 
| James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3893 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3894 | if (rc == IOCB_ERROR) { | 
|  | 3895 | lpfc_els_free_iocb(phba, elsiocb); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3896 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3897 | } | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3898 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3899 | } | 
|  | 3900 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3901 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3902 | * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3903 | * @vport: pointer to a virtual N_Port data structure. | 
|  | 3904 | * @oldiocb: pointer to the original lpfc command iocb data structure. | 
|  | 3905 | * @ndlp: pointer to a node-list data structure. | 
|  | 3906 | * | 
|  | 3907 | * This routine prepares and issues an Accept (ACC) response to Process | 
|  | 3908 | * Login (PRLI) ELS command. It simply prepares the payload of the IOCB | 
|  | 3909 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. | 
|  | 3910 | * | 
|  | 3911 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | 
|  | 3912 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | 
|  | 3913 | * will be stored into the context1 field of the IOCB for the completion | 
|  | 3914 | * callback function to the PRLI Accept response ELS IOCB command. | 
|  | 3915 | * | 
|  | 3916 | * Return code | 
|  | 3917 | *   0 - Successfully issued acc prli response | 
|  | 3918 | *   1 - Failed to issue acc prli response | 
|  | 3919 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3920 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3921 | lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, | 
| James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3922 | struct lpfc_nodelist *ndlp) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3923 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3924 | struct lpfc_hba  *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3925 | PRLI *npr; | 
|  | 3926 | lpfc_vpd_t *vpd; | 
|  | 3927 | IOCB_t *icmd; | 
|  | 3928 | IOCB_t *oldcmd; | 
|  | 3929 | struct lpfc_iocbq *elsiocb; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3930 | struct lpfc_sli *psli; | 
|  | 3931 | uint8_t *pcmd; | 
|  | 3932 | uint16_t cmdsize; | 
|  | 3933 | int rc; | 
|  | 3934 |  | 
|  | 3935 | psli = &phba->sli; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3936 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3937 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3938 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3939 | ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK))); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3940 | if (!elsiocb) | 
|  | 3941 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3942 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3943 | icmd = &elsiocb->iocb; | 
|  | 3944 | oldcmd = &oldiocb->iocb; | 
| James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3945 | icmd->ulpContext = oldcmd->ulpContext;	/* Xri / rx_id */ | 
|  | 3946 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; | 
|  | 3947 |  | 
| James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3948 | /* Xmit PRLI ACC response tag <ulpIoTag> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3949 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 3950 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " | 
|  | 3951 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", | 
|  | 3952 | elsiocb->iotag, elsiocb->iocb.ulpContext, | 
|  | 3953 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | 
|  | 3954 | ndlp->nlp_rpi); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3955 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 3956 |  | 
|  | 3957 | *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3958 | pcmd += sizeof(uint32_t); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3959 |  | 
|  | 3960 | /* For PRLI, remainder of payload is PRLI parameter page */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3961 | memset(pcmd, 0, sizeof(PRLI)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3962 |  | 
|  | 3963 | npr = (PRLI *) pcmd; | 
|  | 3964 | vpd = &phba->vpd; | 
|  | 3965 | /* | 
| James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3966 | * If the remote port is a target and our firmware version is 3.20 or | 
|  | 3967 | * later, set the following bits for FC-TAPE support. | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3968 | */ | 
| James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3969 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && | 
|  | 3970 | (vpd->rev.feaLevelHigh >= 0x02)) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3971 | npr->ConfmComplAllowed = 1; | 
|  | 3972 | npr->Retry = 1; | 
|  | 3973 | npr->TaskRetryIdReq = 1; | 
|  | 3974 | } | 
|  | 3975 |  | 
|  | 3976 | npr->acceptRspCode = PRLI_REQ_EXECUTED; | 
|  | 3977 | npr->estabImagePair = 1; | 
|  | 3978 | npr->readXferRdyDis = 1; | 
|  | 3979 | npr->ConfmComplAllowed = 1; | 
|  | 3980 |  | 
|  | 3981 | npr->prliType = PRLI_FCP_TYPE; | 
|  | 3982 | npr->initiatorFunc = 1; | 
|  | 3983 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3984 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, | 
|  | 3985 | "Issue ACC PRLI:  did:x%x flg:x%x", | 
|  | 3986 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | 
|  | 3987 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3988 | phba->fc_stat.elsXmitACC++; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3989 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3990 |  | 
| James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3991 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3992 | if (rc == IOCB_ERROR) { | 
|  | 3993 | lpfc_els_free_iocb(phba, elsiocb); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3994 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3995 | } | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3996 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3997 | } | 
|  | 3998 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3999 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4000 | * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4001 | * @vport: pointer to a virtual N_Port data structure. | 
|  | 4002 | * @format: rnid command format. | 
|  | 4003 | * @oldiocb: pointer to the original lpfc command iocb data structure. | 
|  | 4004 | * @ndlp: pointer to a node-list data structure. | 
|  | 4005 | * | 
|  | 4006 | * This routine issues a Request Node Identification Data (RNID) Accept | 
|  | 4007 | * (ACC) response. It constructs the RNID ACC response command according to | 
|  | 4008 | * the proper @format and then calls the lpfc_sli_issue_iocb() routine to | 
|  | 4009 | * issue the response. Note that this command does not need to hold the ndlp | 
|  | 4010 | * reference count for the callback. So, the ndlp reference count taken by | 
|  | 4011 | * the lpfc_prep_els_iocb() routine is put back and the context1 field of | 
|  | 4012 | * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that | 
|  | 4013 | * there is no ndlp reference available. | 
|  | 4014 | * | 
|  | 4015 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | 
|  | 4016 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | 
|  | 4017 | * will be stored into the context1 field of the IOCB for the completion | 
|  | 4018 | * callback function. However, for the RNID Accept Response ELS command, | 
|  | 4019 | * this is undone later by this routine after the IOCB is allocated. | 
|  | 4020 | * | 
|  | 4021 | * Return code | 
|  | 4022 | *   0 - Successfully issued acc rnid response | 
|  | 4023 | *   1 - Failed to issue acc rnid response | 
|  | 4024 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4025 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4026 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4027 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4028 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4029 | struct lpfc_hba  *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4030 | RNID *rn; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4031 | IOCB_t *icmd, *oldcmd; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4032 | struct lpfc_iocbq *elsiocb; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4033 | struct lpfc_sli *psli; | 
|  | 4034 | uint8_t *pcmd; | 
|  | 4035 | uint16_t cmdsize; | 
|  | 4036 | int rc; | 
|  | 4037 |  | 
|  | 4038 | psli = &phba->sli; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4039 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) | 
|  | 4040 | + (2 * sizeof(struct lpfc_name)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4041 | if (format) | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4042 | cmdsize += sizeof(RNID_TOP_DISC); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4043 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4044 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, | 
|  | 4045 | ndlp->nlp_DID, ELS_CMD_ACC); | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4046 | if (!elsiocb) | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4047 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4048 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4049 | icmd = &elsiocb->iocb; | 
|  | 4050 | oldcmd = &oldiocb->iocb; | 
| James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4051 | icmd->ulpContext = oldcmd->ulpContext;	/* Xri / rx_id */ | 
|  | 4052 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; | 
|  | 4053 |  | 
| James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4054 | /* Xmit RNID ACC response tag <ulpIoTag> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4055 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 4056 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", | 
|  | 4057 | elsiocb->iotag, elsiocb->iocb.ulpContext); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4058 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4059 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4060 | pcmd += sizeof(uint32_t); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4061 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4062 | memset(pcmd, 0, sizeof(RNID)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4063 | rn = (RNID *) (pcmd); | 
|  | 4064 | rn->Format = format; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4065 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); | 
|  | 4066 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); | 
|  | 4067 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4068 | switch (format) { | 
|  | 4069 | case 0: | 
|  | 4070 | rn->SpecificLen = 0; | 
|  | 4071 | break; | 
|  | 4072 | case RNID_TOPOLOGY_DISC: | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4073 | rn->SpecificLen = sizeof(RNID_TOP_DISC); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4074 | memcpy(&rn->un.topologyDisc.portName, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4075 | &vport->fc_portname, sizeof(struct lpfc_name)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4076 | rn->un.topologyDisc.unitType = RNID_HBA; | 
|  | 4077 | rn->un.topologyDisc.physPort = 0; | 
|  | 4078 | rn->un.topologyDisc.attachedNodes = 0; | 
|  | 4079 | break; | 
|  | 4080 | default: | 
|  | 4081 | rn->CommonLen = 0; | 
|  | 4082 | rn->SpecificLen = 0; | 
|  | 4083 | break; | 
|  | 4084 | } | 
|  | 4085 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4086 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, | 
|  | 4087 | "Issue ACC RNID:  did:x%x flg:x%x", | 
|  | 4088 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | 
|  | 4089 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4090 | phba->fc_stat.elsXmitACC++; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4091 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4092 |  | 
| James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4093 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4094 | if (rc == IOCB_ERROR) { | 
|  | 4095 | lpfc_els_free_iocb(phba, elsiocb); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4096 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4097 | } | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4098 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4099 | } | 
|  | 4100 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4101 | /** | 
| James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4102 | * lpfc_els_clear_rrq - Clear the rq that this rrq describes. | 
|  | 4103 | * @vport: pointer to a virtual N_Port data structure. | 
|  | 4104 | * @iocb: pointer to the lpfc command iocb data structure. | 
|  | 4105 | * @ndlp: pointer to a node-list data structure. | 
|  | 4106 | * | 
|  | 4107 | * Return | 
|  | 4108 | **/ | 
|  | 4109 | static void | 
|  | 4110 | lpfc_els_clear_rrq(struct lpfc_vport *vport, | 
|  | 4111 | struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp) | 
|  | 4112 | { | 
|  | 4113 | struct lpfc_hba  *phba = vport->phba; | 
|  | 4114 | uint8_t *pcmd; | 
|  | 4115 | struct RRQ *rrq; | 
|  | 4116 | uint16_t rxid; | 
| James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4117 | uint16_t xri; | 
| James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4118 | struct lpfc_node_rrq *prrq; | 
|  | 4119 |  | 
|  | 4120 |  | 
|  | 4121 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt); | 
|  | 4122 | pcmd += sizeof(uint32_t); | 
|  | 4123 | rrq = (struct RRQ *)pcmd; | 
| James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4124 | rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg); | 
| James Smart | 9589b06 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 4125 | rxid = bf_get(rrq_rxid, rrq); | 
| James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4126 |  | 
|  | 4127 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 4128 | "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x" | 
|  | 4129 | " x%x x%x\n", | 
| James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4130 | be32_to_cpu(bf_get(rrq_did, rrq)), | 
| James Smart | 9589b06 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 4131 | bf_get(rrq_oxid, rrq), | 
| James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4132 | rxid, | 
|  | 4133 | iocb->iotag, iocb->iocb.ulpContext); | 
|  | 4134 |  | 
|  | 4135 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, | 
|  | 4136 | "Clear RRQ:  did:x%x flg:x%x exchg:x%.08x", | 
|  | 4137 | ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg); | 
| James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4138 | if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq))) | 
| James Smart | 9589b06 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 4139 | xri = bf_get(rrq_oxid, rrq); | 
| James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4140 | else | 
|  | 4141 | xri = rxid; | 
|  | 4142 | prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID); | 
| James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4143 | if (prrq) | 
| James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 4144 | lpfc_clr_rrq_active(phba, xri, prrq); | 
| James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4145 | return; | 
|  | 4146 | } | 
|  | 4147 |  | 
|  | 4148 | /** | 
| James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4149 | * lpfc_els_rsp_echo_acc - Issue echo acc response | 
|  | 4150 | * @vport: pointer to a virtual N_Port data structure. | 
|  | 4151 | * @data: pointer to echo data to return in the accept. | 
|  | 4152 | * @oldiocb: pointer to the original lpfc command iocb data structure. | 
|  | 4153 | * @ndlp: pointer to a node-list data structure. | 
|  | 4154 | * | 
|  | 4155 | * Return code | 
|  | 4156 | *   0 - Successfully issued acc echo response | 
|  | 4157 | *   1 - Failed to issue acc echo response | 
|  | 4158 | **/ | 
|  | 4159 | static int | 
|  | 4160 | lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data, | 
|  | 4161 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) | 
|  | 4162 | { | 
|  | 4163 | struct lpfc_hba  *phba = vport->phba; | 
|  | 4164 | struct lpfc_iocbq *elsiocb; | 
|  | 4165 | struct lpfc_sli *psli; | 
|  | 4166 | uint8_t *pcmd; | 
|  | 4167 | uint16_t cmdsize; | 
|  | 4168 | int rc; | 
|  | 4169 |  | 
|  | 4170 | psli = &phba->sli; | 
|  | 4171 | cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len; | 
|  | 4172 |  | 
| James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 4173 | /* The accumulated length can exceed the BPL_SIZE.  For | 
|  | 4174 | * now, use this as the limit | 
|  | 4175 | */ | 
|  | 4176 | if (cmdsize > LPFC_BPL_SIZE) | 
|  | 4177 | cmdsize = LPFC_BPL_SIZE; | 
| James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4178 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, | 
|  | 4179 | ndlp->nlp_DID, ELS_CMD_ACC); | 
|  | 4180 | if (!elsiocb) | 
|  | 4181 | return 1; | 
|  | 4182 |  | 
| James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 4183 | elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext;  /* Xri / rx_id */ | 
|  | 4184 | elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id; | 
|  | 4185 |  | 
| James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4186 | /* Xmit ECHO ACC response tag <ulpIoTag> */ | 
|  | 4187 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 4188 | "2876 Xmit ECHO ACC response tag x%x xri x%x\n", | 
|  | 4189 | elsiocb->iotag, elsiocb->iocb.ulpContext); | 
|  | 4190 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 4191 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | 
|  | 4192 | pcmd += sizeof(uint32_t); | 
|  | 4193 | memcpy(pcmd, data, cmdsize - sizeof(uint32_t)); | 
|  | 4194 |  | 
|  | 4195 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, | 
|  | 4196 | "Issue ACC ECHO:  did:x%x flg:x%x", | 
|  | 4197 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | 
|  | 4198 |  | 
|  | 4199 | phba->fc_stat.elsXmitACC++; | 
|  | 4200 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; | 
| James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4201 |  | 
|  | 4202 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); | 
|  | 4203 | if (rc == IOCB_ERROR) { | 
|  | 4204 | lpfc_els_free_iocb(phba, elsiocb); | 
|  | 4205 | return 1; | 
|  | 4206 | } | 
|  | 4207 | return 0; | 
|  | 4208 | } | 
|  | 4209 |  | 
|  | 4210 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4211 | * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4212 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 4213 | * | 
|  | 4214 | * This routine issues Address Discover (ADISC) ELS commands to those | 
|  | 4215 | * N_Ports which are in node port recovery state and ADISC has not been issued | 
|  | 4216 | * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the | 
|  | 4217 | * lpfc_issue_els_adisc() routine, the per @vport number of discover count | 
|  | 4218 | * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a | 
|  | 4219 | * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will | 
|  | 4220 | * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC | 
|  | 4221 | * IOCBs quit for later pick up. On the other hand, after walking through | 
|  | 4222 | * all the ndlps with the @vport and there is none ADISC IOCB issued, the | 
|  | 4223 | * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is | 
|  | 4224 | * no more ADISC need to be sent. | 
|  | 4225 | * | 
|  | 4226 | * Return code | 
|  | 4227 | *    The number of N_Ports with adisc issued. | 
|  | 4228 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4229 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4230 | lpfc_els_disc_adisc(struct lpfc_vport *vport) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4231 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4232 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4233 | struct lpfc_nodelist *ndlp, *next_ndlp; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4234 | int sentadisc = 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4235 |  | 
| James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4236 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4237 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4238 | if (!NLP_CHK_NODE_ACT(ndlp)) | 
|  | 4239 | continue; | 
| James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4240 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && | 
|  | 4241 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && | 
|  | 4242 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4243 | spin_lock_irq(shost->host_lock); | 
| James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4244 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4245 | spin_unlock_irq(shost->host_lock); | 
| James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4246 | ndlp->nlp_prev_state = ndlp->nlp_state; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4247 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); | 
|  | 4248 | lpfc_issue_els_adisc(vport, ndlp, 0); | 
| James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4249 | sentadisc++; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4250 | vport->num_disc_nodes++; | 
|  | 4251 | if (vport->num_disc_nodes >= | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4252 | vport->cfg_discovery_threads) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4253 | spin_lock_irq(shost->host_lock); | 
|  | 4254 | vport->fc_flag |= FC_NLP_MORE; | 
|  | 4255 | spin_unlock_irq(shost->host_lock); | 
| James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4256 | break; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4257 | } | 
|  | 4258 | } | 
|  | 4259 | } | 
|  | 4260 | if (sentadisc == 0) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4261 | spin_lock_irq(shost->host_lock); | 
|  | 4262 | vport->fc_flag &= ~FC_NLP_MORE; | 
|  | 4263 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4264 | } | 
| Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4265 | return sentadisc; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4266 | } | 
|  | 4267 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4268 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4269 | * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4270 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 4271 | * | 
|  | 4272 | * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports | 
|  | 4273 | * which are in node port recovery state, with a @vport. Each time an ELS | 
|  | 4274 | * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, | 
|  | 4275 | * the per @vport number of discover count (num_disc_nodes) shall be | 
|  | 4276 | * incremented. If the num_disc_nodes reaches a pre-configured threshold | 
|  | 4277 | * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE | 
|  | 4278 | * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for | 
|  | 4279 | * later pick up. On the other hand, after walking through all the ndlps with | 
|  | 4280 | * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag | 
|  | 4281 | * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC | 
|  | 4282 | * PLOGI need to be sent. | 
|  | 4283 | * | 
|  | 4284 | * Return code | 
|  | 4285 | *   The number of N_Ports with plogi issued. | 
|  | 4286 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4287 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4288 | lpfc_els_disc_plogi(struct lpfc_vport *vport) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4289 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4290 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4291 | struct lpfc_nodelist *ndlp, *next_ndlp; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4292 | int sentplogi = 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4293 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4294 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ | 
|  | 4295 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4296 | if (!NLP_CHK_NODE_ACT(ndlp)) | 
|  | 4297 | continue; | 
| James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4298 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && | 
|  | 4299 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && | 
|  | 4300 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && | 
|  | 4301 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { | 
|  | 4302 | ndlp->nlp_prev_state = ndlp->nlp_state; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4303 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); | 
|  | 4304 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); | 
| James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4305 | sentplogi++; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4306 | vport->num_disc_nodes++; | 
|  | 4307 | if (vport->num_disc_nodes >= | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4308 | vport->cfg_discovery_threads) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4309 | spin_lock_irq(shost->host_lock); | 
|  | 4310 | vport->fc_flag |= FC_NLP_MORE; | 
|  | 4311 | spin_unlock_irq(shost->host_lock); | 
| James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4312 | break; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4313 | } | 
|  | 4314 | } | 
|  | 4315 | } | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4316 | if (sentplogi) { | 
|  | 4317 | lpfc_set_disctmo(vport); | 
|  | 4318 | } | 
|  | 4319 | else { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4320 | spin_lock_irq(shost->host_lock); | 
|  | 4321 | vport->fc_flag &= ~FC_NLP_MORE; | 
|  | 4322 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4323 | } | 
| Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4324 | return sentplogi; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4325 | } | 
|  | 4326 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4327 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4328 | * lpfc_els_flush_rscn - Clean up any rscn activities with a vport | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4329 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 4330 | * | 
|  | 4331 | * This routine cleans up any Registration State Change Notification | 
|  | 4332 | * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the | 
|  | 4333 | * @vport together with the host_lock is used to prevent multiple thread | 
|  | 4334 | * trying to access the RSCN array on a same @vport at the same time. | 
|  | 4335 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4336 | void | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4337 | lpfc_els_flush_rscn(struct lpfc_vport *vport) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4338 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4339 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | 4340 | struct lpfc_hba  *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4341 | int i; | 
|  | 4342 |  | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4343 | spin_lock_irq(shost->host_lock); | 
|  | 4344 | if (vport->fc_rscn_flush) { | 
|  | 4345 | /* Another thread is walking fc_rscn_id_list on this vport */ | 
|  | 4346 | spin_unlock_irq(shost->host_lock); | 
|  | 4347 | return; | 
|  | 4348 | } | 
|  | 4349 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ | 
|  | 4350 | vport->fc_rscn_flush = 1; | 
|  | 4351 | spin_unlock_irq(shost->host_lock); | 
|  | 4352 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4353 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4354 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4355 | vport->fc_rscn_id_list[i] = NULL; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4356 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4357 | spin_lock_irq(shost->host_lock); | 
|  | 4358 | vport->fc_rscn_id_cnt = 0; | 
|  | 4359 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); | 
|  | 4360 | spin_unlock_irq(shost->host_lock); | 
|  | 4361 | lpfc_can_disctmo(vport); | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4362 | /* Indicate we are done walking this fc_rscn_id_list */ | 
|  | 4363 | vport->fc_rscn_flush = 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4364 | } | 
|  | 4365 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4366 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4367 | * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4368 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 4369 | * @did: remote destination port identifier. | 
|  | 4370 | * | 
|  | 4371 | * This routine checks whether there is any pending Registration State | 
|  | 4372 | * Configuration Notification (RSCN) to a @did on @vport. | 
|  | 4373 | * | 
|  | 4374 | * Return code | 
|  | 4375 | *   None zero - The @did matched with a pending rscn | 
|  | 4376 | *   0 - not able to match @did with a pending rscn | 
|  | 4377 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4378 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4379 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4380 | { | 
|  | 4381 | D_ID ns_did; | 
|  | 4382 | D_ID rscn_did; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4383 | uint32_t *lp; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4384 | uint32_t payload_len, i; | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4385 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4386 |  | 
|  | 4387 | ns_did.un.word = did; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4388 |  | 
|  | 4389 | /* Never match fabric nodes for RSCNs */ | 
|  | 4390 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4391 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4392 |  | 
|  | 4393 | /* If we are doing a FULL RSCN rediscovery, match everything */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4394 | if (vport->fc_flag & FC_RSCN_DISCOVERY) | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4395 | return did; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4396 |  | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4397 | spin_lock_irq(shost->host_lock); | 
|  | 4398 | if (vport->fc_rscn_flush) { | 
|  | 4399 | /* Another thread is walking fc_rscn_id_list on this vport */ | 
|  | 4400 | spin_unlock_irq(shost->host_lock); | 
|  | 4401 | return 0; | 
|  | 4402 | } | 
|  | 4403 | /* Indicate we are walking fc_rscn_id_list on this vport */ | 
|  | 4404 | vport->fc_rscn_flush = 1; | 
|  | 4405 | spin_unlock_irq(shost->host_lock); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4406 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4407 | lp = vport->fc_rscn_id_list[i]->virt; | 
|  | 4408 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); | 
|  | 4409 | payload_len -= sizeof(uint32_t);	/* take off word 0 */ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4410 | while (payload_len) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4411 | rscn_did.un.word = be32_to_cpu(*lp++); | 
|  | 4412 | payload_len -= sizeof(uint32_t); | 
| James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4413 | switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) { | 
|  | 4414 | case RSCN_ADDRESS_FORMAT_PORT: | 
| James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 4415 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) | 
|  | 4416 | && (ns_did.un.b.area == rscn_did.un.b.area) | 
|  | 4417 | && (ns_did.un.b.id == rscn_did.un.b.id)) | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4418 | goto return_did_out; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4419 | break; | 
| James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4420 | case RSCN_ADDRESS_FORMAT_AREA: | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4421 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) | 
|  | 4422 | && (ns_did.un.b.area == rscn_did.un.b.area)) | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4423 | goto return_did_out; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4424 | break; | 
| James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4425 | case RSCN_ADDRESS_FORMAT_DOMAIN: | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4426 | if (ns_did.un.b.domain == rscn_did.un.b.domain) | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4427 | goto return_did_out; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4428 | break; | 
| James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4429 | case RSCN_ADDRESS_FORMAT_FABRIC: | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4430 | goto return_did_out; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4431 | } | 
|  | 4432 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4433 | } | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4434 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ | 
|  | 4435 | vport->fc_rscn_flush = 0; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4436 | return 0; | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4437 | return_did_out: | 
|  | 4438 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ | 
|  | 4439 | vport->fc_rscn_flush = 0; | 
|  | 4440 | return did; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4441 | } | 
|  | 4442 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4443 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4444 | * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4445 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 4446 | * | 
|  | 4447 | * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the | 
|  | 4448 | * state machine for a @vport's nodes that are with pending RSCN (Registration | 
|  | 4449 | * State Change Notification). | 
|  | 4450 | * | 
|  | 4451 | * Return code | 
|  | 4452 | *   0 - Successful (currently alway return 0) | 
|  | 4453 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4454 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4455 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4456 | { | 
| James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4457 | struct lpfc_nodelist *ndlp = NULL; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4458 |  | 
| James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4459 | /* Move all affected nodes by pending RSCNs to NPR state. */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4460 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4461 | if (!NLP_CHK_NODE_ACT(ndlp) || | 
| James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4462 | (ndlp->nlp_state == NLP_STE_UNUSED_NODE) || | 
|  | 4463 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4464 | continue; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4465 | lpfc_disc_state_machine(vport, ndlp, NULL, | 
| James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4466 | NLP_EVT_DEVICE_RECOVERY); | 
|  | 4467 | lpfc_cancel_retry_delay_tmo(vport, ndlp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4468 | } | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4469 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4470 | } | 
|  | 4471 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4472 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4473 | * lpfc_send_rscn_event - Send an RSCN event to management application | 
| James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4474 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 4475 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 4476 | * | 
|  | 4477 | * lpfc_send_rscn_event sends an RSCN netlink event to management | 
|  | 4478 | * applications. | 
|  | 4479 | */ | 
|  | 4480 | static void | 
|  | 4481 | lpfc_send_rscn_event(struct lpfc_vport *vport, | 
|  | 4482 | struct lpfc_iocbq *cmdiocb) | 
|  | 4483 | { | 
|  | 4484 | struct lpfc_dmabuf *pcmd; | 
|  | 4485 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | 4486 | uint32_t *payload_ptr; | 
|  | 4487 | uint32_t payload_len; | 
|  | 4488 | struct lpfc_rscn_event_header *rscn_event_data; | 
|  | 4489 |  | 
|  | 4490 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | 
|  | 4491 | payload_ptr = (uint32_t *) pcmd->virt; | 
|  | 4492 | payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK); | 
|  | 4493 |  | 
|  | 4494 | rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) + | 
|  | 4495 | payload_len, GFP_KERNEL); | 
|  | 4496 | if (!rscn_event_data) { | 
|  | 4497 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 4498 | "0147 Failed to allocate memory for RSCN event\n"); | 
|  | 4499 | return; | 
|  | 4500 | } | 
|  | 4501 | rscn_event_data->event_type = FC_REG_RSCN_EVENT; | 
|  | 4502 | rscn_event_data->payload_length = payload_len; | 
|  | 4503 | memcpy(rscn_event_data->rscn_payload, payload_ptr, | 
|  | 4504 | payload_len); | 
|  | 4505 |  | 
|  | 4506 | fc_host_post_vendor_event(shost, | 
|  | 4507 | fc_get_event_number(), | 
|  | 4508 | sizeof(struct lpfc_els_event_header) + payload_len, | 
|  | 4509 | (char *)rscn_event_data, | 
|  | 4510 | LPFC_NL_VENDOR_ID); | 
|  | 4511 |  | 
|  | 4512 | kfree(rscn_event_data); | 
|  | 4513 | } | 
|  | 4514 |  | 
|  | 4515 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4516 | * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4517 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 4518 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 4519 | * @ndlp: pointer to a node-list data structure. | 
|  | 4520 | * | 
|  | 4521 | * This routine processes an unsolicited RSCN (Registration State Change | 
|  | 4522 | * Notification) IOCB. First, the payload of the unsolicited RSCN is walked | 
|  | 4523 | * to invoke fc_host_post_event() routine to the FC transport layer. If the | 
|  | 4524 | * discover state machine is about to begin discovery, it just accepts the | 
|  | 4525 | * RSCN and the discovery process will satisfy the RSCN. If this RSCN only | 
|  | 4526 | * contains N_Port IDs for other vports on this HBA, it just accepts the | 
|  | 4527 | * RSCN and ignore processing it. If the state machine is in the recovery | 
|  | 4528 | * state, the fc_rscn_id_list of this @vport is walked and the | 
|  | 4529 | * lpfc_rscn_recovery_check() routine is invoked to send recovery event for | 
|  | 4530 | * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() | 
|  | 4531 | * routine is invoked to handle the RSCN event. | 
|  | 4532 | * | 
|  | 4533 | * Return code | 
|  | 4534 | *   0 - Just sent the acc response | 
|  | 4535 | *   1 - Sent the acc response and waited for name server completion | 
|  | 4536 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4537 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4538 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4539 | struct lpfc_nodelist *ndlp) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4540 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4541 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | 4542 | struct lpfc_hba  *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4543 | struct lpfc_dmabuf *pcmd; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4544 | uint32_t *lp, *datap; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4545 | IOCB_t *icmd; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4546 | uint32_t payload_len, length, nportid, *cmd; | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4547 | int rscn_cnt; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4548 | int rscn_id = 0, hba_id = 0; | 
| James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4549 | int i; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4550 |  | 
|  | 4551 | icmd = &cmdiocb->iocb; | 
|  | 4552 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | 
|  | 4553 | lp = (uint32_t *) pcmd->virt; | 
|  | 4554 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4555 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); | 
|  | 4556 | payload_len -= sizeof(uint32_t);	/* take off word 0 */ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4557 | /* RSCN received */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4558 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, | 
|  | 4559 | "0214 RSCN received Data: x%x x%x x%x x%x\n", | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4560 | vport->fc_flag, payload_len, *lp, | 
|  | 4561 | vport->fc_rscn_id_cnt); | 
| James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 4562 |  | 
|  | 4563 | /* Send an RSCN event to the management application */ | 
|  | 4564 | lpfc_send_rscn_event(vport, cmdiocb); | 
|  | 4565 |  | 
| James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4566 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4567 | fc_host_post_event(shost, fc_get_event_number(), | 
| James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 4568 | FCH_EVT_RSCN, lp[i]); | 
|  | 4569 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4570 | /* If we are about to begin discovery, just ACC the RSCN. | 
|  | 4571 | * Discovery processing will satisfy it. | 
|  | 4572 | */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4573 | if (vport->port_state <= LPFC_NS_QRY) { | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4574 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 4575 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", | 
|  | 4576 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); | 
|  | 4577 |  | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4578 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4579 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4580 | } | 
|  | 4581 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4582 | /* If this RSCN just contains NPortIDs for other vports on this HBA, | 
|  | 4583 | * just ACC and ignore it. | 
|  | 4584 | */ | 
|  | 4585 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4586 | !(vport->cfg_peer_port_login)) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4587 | i = payload_len; | 
|  | 4588 | datap = lp; | 
|  | 4589 | while (i > 0) { | 
|  | 4590 | nportid = *datap++; | 
|  | 4591 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); | 
|  | 4592 | i -= sizeof(uint32_t); | 
|  | 4593 | rscn_id++; | 
| James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 4594 | if (lpfc_find_vport_by_did(phba, nportid)) | 
|  | 4595 | hba_id++; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4596 | } | 
|  | 4597 | if (rscn_id == hba_id) { | 
|  | 4598 | /* ALL NPortIDs in RSCN are on HBA */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4599 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4600 | "0219 Ignore RSCN " | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4601 | "Data: x%x x%x x%x x%x\n", | 
|  | 4602 | vport->fc_flag, payload_len, | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4603 | *lp, vport->fc_rscn_id_cnt); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4604 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 4605 | "RCV RSCN vport:  did:x%x/ste:x%x flg:x%x", | 
|  | 4606 | ndlp->nlp_DID, vport->port_state, | 
|  | 4607 | ndlp->nlp_flag); | 
|  | 4608 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4609 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4610 | ndlp, NULL); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4611 | return 0; | 
|  | 4612 | } | 
|  | 4613 | } | 
|  | 4614 |  | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4615 | spin_lock_irq(shost->host_lock); | 
|  | 4616 | if (vport->fc_rscn_flush) { | 
|  | 4617 | /* Another thread is walking fc_rscn_id_list on this vport */ | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4618 | vport->fc_flag |= FC_RSCN_DISCOVERY; | 
| James Smart | 9795724 | 2009-12-21 17:03:15 -0500 | [diff] [blame] | 4619 | spin_unlock_irq(shost->host_lock); | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4620 | /* Send back ACC */ | 
|  | 4621 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4622 | return 0; | 
|  | 4623 | } | 
|  | 4624 | /* Indicate we are walking fc_rscn_id_list on this vport */ | 
|  | 4625 | vport->fc_rscn_flush = 1; | 
|  | 4626 | spin_unlock_irq(shost->host_lock); | 
| André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4627 | /* Get the array count after successfully have the token */ | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4628 | rscn_cnt = vport->fc_rscn_id_cnt; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4629 | /* If we are already processing an RSCN, save the received | 
|  | 4630 | * RSCN payload buffer, cmdiocb->context2 to process later. | 
|  | 4631 | */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4632 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4633 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 4634 | "RCV RSCN defer:  did:x%x/ste:x%x flg:x%x", | 
|  | 4635 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); | 
|  | 4636 |  | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4637 | spin_lock_irq(shost->host_lock); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4638 | vport->fc_flag |= FC_RSCN_DEFERRED; | 
|  | 4639 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4640 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4641 | vport->fc_flag |= FC_RSCN_MODE; | 
|  | 4642 | spin_unlock_irq(shost->host_lock); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4643 | if (rscn_cnt) { | 
|  | 4644 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; | 
|  | 4645 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); | 
|  | 4646 | } | 
|  | 4647 | if ((rscn_cnt) && | 
|  | 4648 | (payload_len + length <= LPFC_BPL_SIZE)) { | 
|  | 4649 | *cmd &= ELS_CMD_MASK; | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4650 | *cmd |= cpu_to_be32(payload_len + length); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4651 | memcpy(((uint8_t *)cmd) + length, lp, | 
|  | 4652 | payload_len); | 
|  | 4653 | } else { | 
|  | 4654 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; | 
|  | 4655 | vport->fc_rscn_id_cnt++; | 
|  | 4656 | /* If we zero, cmdiocb->context2, the calling | 
|  | 4657 | * routine will not try to free it. | 
|  | 4658 | */ | 
|  | 4659 | cmdiocb->context2 = NULL; | 
|  | 4660 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4661 | /* Deferred RSCN */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4662 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, | 
|  | 4663 | "0235 Deferred RSCN " | 
|  | 4664 | "Data: x%x x%x x%x\n", | 
|  | 4665 | vport->fc_rscn_id_cnt, vport->fc_flag, | 
|  | 4666 | vport->port_state); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4667 | } else { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4668 | vport->fc_flag |= FC_RSCN_DISCOVERY; | 
|  | 4669 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4670 | /* ReDiscovery RSCN */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4671 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, | 
|  | 4672 | "0234 ReDiscovery RSCN " | 
|  | 4673 | "Data: x%x x%x x%x\n", | 
|  | 4674 | vport->fc_rscn_id_cnt, vport->fc_flag, | 
|  | 4675 | vport->port_state); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4676 | } | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4677 | /* Indicate we are done walking fc_rscn_id_list on this vport */ | 
|  | 4678 | vport->fc_rscn_flush = 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4679 | /* Send back ACC */ | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4680 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4681 | /* send RECOVERY event for ALL nodes that match RSCN payload */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4682 | lpfc_rscn_recovery_check(vport); | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4683 | spin_lock_irq(shost->host_lock); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4684 | vport->fc_flag &= ~FC_RSCN_DEFERRED; | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4685 | spin_unlock_irq(shost->host_lock); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4686 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4687 | } | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4688 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 4689 | "RCV RSCN:        did:x%x/ste:x%x flg:x%x", | 
|  | 4690 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); | 
|  | 4691 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4692 | spin_lock_irq(shost->host_lock); | 
|  | 4693 | vport->fc_flag |= FC_RSCN_MODE; | 
|  | 4694 | spin_unlock_irq(shost->host_lock); | 
|  | 4695 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4696 | /* Indicate we are done walking fc_rscn_id_list on this vport */ | 
|  | 4697 | vport->fc_rscn_flush = 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4698 | /* | 
|  | 4699 | * If we zero, cmdiocb->context2, the calling routine will | 
|  | 4700 | * not try to free it. | 
|  | 4701 | */ | 
|  | 4702 | cmdiocb->context2 = NULL; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4703 | lpfc_set_disctmo(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4704 | /* Send back ACC */ | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4705 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4706 | /* send RECOVERY event for ALL nodes that match RSCN payload */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4707 | lpfc_rscn_recovery_check(vport); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4708 | return lpfc_els_handle_rscn(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4709 | } | 
|  | 4710 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4711 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4712 | * lpfc_els_handle_rscn - Handle rscn for a vport | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4713 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 4714 | * | 
|  | 4715 | * This routine handles the Registration State Configuration Notification | 
|  | 4716 | * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall | 
|  | 4717 | * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, | 
|  | 4718 | * if the ndlp to NameServer exists, a Common Transport (CT) command to the | 
|  | 4719 | * NameServer shall be issued. If CT command to the NameServer fails to be | 
|  | 4720 | * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any | 
|  | 4721 | * RSCN activities with the @vport. | 
|  | 4722 | * | 
|  | 4723 | * Return code | 
|  | 4724 | *   0 - Cleaned up rscn on the @vport | 
|  | 4725 | *   1 - Wait for plogi to name server before proceed | 
|  | 4726 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4727 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4728 | lpfc_els_handle_rscn(struct lpfc_vport *vport) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4729 | { | 
|  | 4730 | struct lpfc_nodelist *ndlp; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4731 | struct lpfc_hba *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4732 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4733 | /* Ignore RSCN if the port is being torn down. */ | 
|  | 4734 | if (vport->load_flag & FC_UNLOADING) { | 
|  | 4735 | lpfc_els_flush_rscn(vport); | 
|  | 4736 | return 0; | 
|  | 4737 | } | 
|  | 4738 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4739 | /* Start timer for RSCN processing */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4740 | lpfc_set_disctmo(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4741 |  | 
|  | 4742 | /* RSCN processed */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4743 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, | 
|  | 4744 | "0215 RSCN processed Data: x%x x%x x%x x%x\n", | 
|  | 4745 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, | 
|  | 4746 | vport->port_state); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4747 |  | 
|  | 4748 | /* To process RSCN, first compare RSCN data with NameServer */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4749 | vport->fc_ns_retry = 0; | 
| James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4750 | vport->num_disc_nodes = 0; | 
|  | 4751 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4752 | ndlp = lpfc_findnode_did(vport, NameServer_DID); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4753 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) | 
|  | 4754 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4755 | /* Good ndlp, issue CT Request to NameServer */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4756 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4757 | /* Wait for NameServer query cmpl before we can | 
|  | 4758 | continue */ | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4759 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4760 | } else { | 
|  | 4761 | /* If login to NameServer does not exist, issue one */ | 
|  | 4762 | /* Good status, issue PLOGI to NameServer */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4763 | ndlp = lpfc_findnode_did(vport, NameServer_DID); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4764 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4765 | /* Wait for NameServer login cmpl before we can | 
|  | 4766 | continue */ | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4767 | return 1; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4768 |  | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4769 | if (ndlp) { | 
|  | 4770 | ndlp = lpfc_enable_node(vport, ndlp, | 
|  | 4771 | NLP_STE_PLOGI_ISSUE); | 
|  | 4772 | if (!ndlp) { | 
|  | 4773 | lpfc_els_flush_rscn(vport); | 
|  | 4774 | return 0; | 
|  | 4775 | } | 
|  | 4776 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4777 | } else { | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4778 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | 
|  | 4779 | if (!ndlp) { | 
|  | 4780 | lpfc_els_flush_rscn(vport); | 
|  | 4781 | return 0; | 
|  | 4782 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4783 | lpfc_nlp_init(vport, ndlp, NameServer_DID); | 
| Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4784 | ndlp->nlp_prev_state = ndlp->nlp_state; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4785 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4786 | } | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4787 | ndlp->nlp_type |= NLP_FABRIC; | 
|  | 4788 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); | 
|  | 4789 | /* Wait for NameServer login cmpl before we can | 
|  | 4790 | * continue | 
|  | 4791 | */ | 
|  | 4792 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4793 | } | 
|  | 4794 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4795 | lpfc_els_flush_rscn(vport); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4796 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4797 | } | 
|  | 4798 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4799 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4800 | * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4801 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 4802 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 4803 | * @ndlp: pointer to a node-list data structure. | 
|  | 4804 | * | 
|  | 4805 | * This routine processes Fabric Login (FLOGI) IOCB received as an ELS | 
|  | 4806 | * unsolicited event. An unsolicited FLOGI can be received in a point-to- | 
|  | 4807 | * point topology. As an unsolicited FLOGI should not be received in a loop | 
|  | 4808 | * mode, any unsolicited FLOGI received in loop mode shall be ignored. The | 
|  | 4809 | * lpfc_check_sparm() routine is invoked to check the parameters in the | 
|  | 4810 | * unsolicited FLOGI. If parameters validation failed, the routine | 
|  | 4811 | * lpfc_els_rsp_reject() shall be called with reject reason code set to | 
|  | 4812 | * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the | 
|  | 4813 | * FLOGI shall be compared with the Port WWN of the @vport to determine who | 
|  | 4814 | * will initiate PLOGI. The higher lexicographical value party shall has | 
|  | 4815 | * higher priority (as the winning port) and will initiate PLOGI and | 
|  | 4816 | * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result | 
|  | 4817 | * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI | 
|  | 4818 | * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. | 
|  | 4819 | * | 
|  | 4820 | * Return code | 
|  | 4821 | *   0 - Successfully processed the unsolicited flogi | 
|  | 4822 | *   1 - Failed to process the unsolicited flogi | 
|  | 4823 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4824 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4825 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4826 | struct lpfc_nodelist *ndlp) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4827 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4828 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | 4829 | struct lpfc_hba  *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4830 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | 
|  | 4831 | uint32_t *lp = (uint32_t *) pcmd->virt; | 
|  | 4832 | IOCB_t *icmd = &cmdiocb->iocb; | 
|  | 4833 | struct serv_parm *sp; | 
|  | 4834 | LPFC_MBOXQ_t *mbox; | 
|  | 4835 | struct ls_rjt stat; | 
|  | 4836 | uint32_t cmd, did; | 
|  | 4837 | int rc; | 
|  | 4838 |  | 
|  | 4839 | cmd = *lp++; | 
|  | 4840 | sp = (struct serv_parm *) lp; | 
|  | 4841 |  | 
|  | 4842 | /* FLOGI received */ | 
|  | 4843 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4844 | lpfc_set_disctmo(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4845 |  | 
| James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4846 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4847 | /* We should never receive a FLOGI in loop mode, ignore it */ | 
|  | 4848 | did = icmd->un.elsreq64.remoteID; | 
|  | 4849 |  | 
|  | 4850 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in | 
|  | 4851 | Loop Mode */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4852 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 4853 | "0113 An FLOGI ELS command x%x was " | 
|  | 4854 | "received from DID x%x in Loop Mode\n", | 
|  | 4855 | cmd, did); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4856 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4857 | } | 
|  | 4858 |  | 
|  | 4859 | did = Fabric_DID; | 
|  | 4860 |  | 
| James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 4861 | if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4862 | /* For a FLOGI we accept, then if our portname is greater | 
|  | 4863 | * then the remote portname we initiate Nport login. | 
|  | 4864 | */ | 
|  | 4865 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4866 | rc = memcmp(&vport->fc_portname, &sp->portName, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4867 | sizeof(struct lpfc_name)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4868 |  | 
|  | 4869 | if (!rc) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4870 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | 
|  | 4871 | if (!mbox) | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4872 | return 1; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4873 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4874 | lpfc_linkdown(phba); | 
|  | 4875 | lpfc_init_link(phba, mbox, | 
|  | 4876 | phba->cfg_topology, | 
|  | 4877 | phba->cfg_link_speed); | 
| James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4878 | mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4879 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4880 | mbox->vport = vport; | 
| James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4881 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); | 
| James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4882 | lpfc_set_loopback_flag(phba); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4883 | if (rc == MBX_NOT_FINISHED) { | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4884 | mempool_free(mbox, phba->mbox_mem_pool); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4885 | } | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4886 | return 1; | 
| Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4887 | } else if (rc > 0) {	/* greater than */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4888 | spin_lock_irq(shost->host_lock); | 
|  | 4889 | vport->fc_flag |= FC_PT2PT_PLOGI; | 
|  | 4890 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4891 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4892 | spin_lock_irq(shost->host_lock); | 
|  | 4893 | vport->fc_flag |= FC_PT2PT; | 
|  | 4894 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); | 
|  | 4895 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4896 | } else { | 
|  | 4897 | /* Reject this request because invalid parameters */ | 
|  | 4898 | stat.un.b.lsRjtRsvd0 = 0; | 
|  | 4899 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | 
|  | 4900 | stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; | 
|  | 4901 | stat.un.b.vendorUnique = 0; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4902 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, | 
|  | 4903 | NULL); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4904 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4905 | } | 
|  | 4906 |  | 
|  | 4907 | /* Send back ACC */ | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4908 | lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4909 |  | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4910 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4911 | } | 
|  | 4912 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4913 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4914 | * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4915 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 4916 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 4917 | * @ndlp: pointer to a node-list data structure. | 
|  | 4918 | * | 
|  | 4919 | * This routine processes Request Node Identification Data (RNID) IOCB | 
|  | 4920 | * received as an ELS unsolicited event. Only when the RNID specified format | 
|  | 4921 | * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) | 
|  | 4922 | * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to | 
|  | 4923 | * Accept (ACC) the RNID ELS command. All the other RNID formats are | 
|  | 4924 | * rejected by invoking the lpfc_els_rsp_reject() routine. | 
|  | 4925 | * | 
|  | 4926 | * Return code | 
|  | 4927 | *   0 - Successfully processed rnid iocb (currently always return 0) | 
|  | 4928 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4929 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4930 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, | 
|  | 4931 | struct lpfc_nodelist *ndlp) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4932 | { | 
|  | 4933 | struct lpfc_dmabuf *pcmd; | 
|  | 4934 | uint32_t *lp; | 
|  | 4935 | IOCB_t *icmd; | 
|  | 4936 | RNID *rn; | 
|  | 4937 | struct ls_rjt stat; | 
|  | 4938 | uint32_t cmd, did; | 
|  | 4939 |  | 
|  | 4940 | icmd = &cmdiocb->iocb; | 
|  | 4941 | did = icmd->un.elsreq64.remoteID; | 
|  | 4942 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | 
|  | 4943 | lp = (uint32_t *) pcmd->virt; | 
|  | 4944 |  | 
|  | 4945 | cmd = *lp++; | 
|  | 4946 | rn = (RNID *) lp; | 
|  | 4947 |  | 
|  | 4948 | /* RNID received */ | 
|  | 4949 |  | 
|  | 4950 | switch (rn->Format) { | 
|  | 4951 | case 0: | 
|  | 4952 | case RNID_TOPOLOGY_DISC: | 
|  | 4953 | /* Send back ACC */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4954 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4955 | break; | 
|  | 4956 | default: | 
|  | 4957 | /* Reject this request because format not supported */ | 
|  | 4958 | stat.un.b.lsRjtRsvd0 = 0; | 
|  | 4959 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | 
|  | 4960 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; | 
|  | 4961 | stat.un.b.vendorUnique = 0; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4962 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, | 
|  | 4963 | NULL); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4964 | } | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4965 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4966 | } | 
|  | 4967 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4968 | /** | 
| James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 4969 | * lpfc_els_rcv_echo - Process an unsolicited echo iocb | 
|  | 4970 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 4971 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 4972 | * @ndlp: pointer to a node-list data structure. | 
|  | 4973 | * | 
|  | 4974 | * Return code | 
|  | 4975 | *   0 - Successfully processed echo iocb (currently always return 0) | 
|  | 4976 | **/ | 
|  | 4977 | static int | 
|  | 4978 | lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, | 
|  | 4979 | struct lpfc_nodelist *ndlp) | 
|  | 4980 | { | 
|  | 4981 | uint8_t *pcmd; | 
|  | 4982 |  | 
|  | 4983 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); | 
|  | 4984 |  | 
|  | 4985 | /* skip over first word of echo command to find echo data */ | 
|  | 4986 | pcmd += sizeof(uint32_t); | 
|  | 4987 |  | 
|  | 4988 | lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp); | 
|  | 4989 | return 0; | 
|  | 4990 | } | 
|  | 4991 |  | 
|  | 4992 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4993 | * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4994 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 4995 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 4996 | * @ndlp: pointer to a node-list data structure. | 
|  | 4997 | * | 
|  | 4998 | * This routine processes a Link Incident Report Registration(LIRR) IOCB | 
|  | 4999 | * received as an ELS unsolicited event. Currently, this function just invokes | 
|  | 5000 | * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. | 
|  | 5001 | * | 
|  | 5002 | * Return code | 
|  | 5003 | *   0 - Successfully processed lirr iocb (currently always return 0) | 
|  | 5004 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5005 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5006 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, | 
|  | 5007 | struct lpfc_nodelist *ndlp) | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5008 | { | 
|  | 5009 | struct ls_rjt stat; | 
|  | 5010 |  | 
|  | 5011 | /* For now, unconditionally reject this command */ | 
|  | 5012 | stat.un.b.lsRjtRsvd0 = 0; | 
|  | 5013 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | 
|  | 5014 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; | 
|  | 5015 | stat.un.b.vendorUnique = 0; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5016 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5017 | return 0; | 
|  | 5018 | } | 
|  | 5019 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5020 | /** | 
| James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 5021 | * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb | 
|  | 5022 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 5023 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 5024 | * @ndlp: pointer to a node-list data structure. | 
|  | 5025 | * | 
|  | 5026 | * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB | 
|  | 5027 | * received as an ELS unsolicited event. A request to RRQ shall only | 
|  | 5028 | * be accepted if the Originator Nx_Port N_Port_ID or the Responder | 
|  | 5029 | * Nx_Port N_Port_ID of the target Exchange is the same as the | 
|  | 5030 | * N_Port_ID of the Nx_Port that makes the request. If the RRQ is | 
|  | 5031 | * not accepted, an LS_RJT with reason code "Unable to perform | 
|  | 5032 | * command request" and reason code explanation "Invalid Originator | 
|  | 5033 | * S_ID" shall be returned. For now, we just unconditionally accept | 
|  | 5034 | * RRQ from the target. | 
|  | 5035 | **/ | 
|  | 5036 | static void | 
|  | 5037 | lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, | 
|  | 5038 | struct lpfc_nodelist *ndlp) | 
|  | 5039 | { | 
|  | 5040 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); | 
| James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 5041 | if (vport->phba->sli_rev == LPFC_SLI_REV4) | 
|  | 5042 | lpfc_els_clear_rrq(vport, cmdiocb, ndlp); | 
| James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 5043 | } | 
|  | 5044 |  | 
|  | 5045 | /** | 
| James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5046 | * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd | 
|  | 5047 | * @phba: pointer to lpfc hba data structure. | 
|  | 5048 | * @pmb: pointer to the driver internal queue element for mailbox command. | 
|  | 5049 | * | 
|  | 5050 | * This routine is the completion callback function for the MBX_READ_LNK_STAT | 
|  | 5051 | * mailbox command. This callback function is to actually send the Accept | 
|  | 5052 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It | 
|  | 5053 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT | 
|  | 5054 | * mailbox command, constructs the RPS response with the link statistics | 
|  | 5055 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC | 
|  | 5056 | * response to the RPS. | 
|  | 5057 | * | 
|  | 5058 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | 
|  | 5059 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | 
|  | 5060 | * will be stored into the context1 field of the IOCB for the completion | 
|  | 5061 | * callback function to the RPS Accept Response ELS IOCB command. | 
|  | 5062 | * | 
|  | 5063 | **/ | 
|  | 5064 | static void | 
|  | 5065 | lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) | 
|  | 5066 | { | 
|  | 5067 | MAILBOX_t *mb; | 
|  | 5068 | IOCB_t *icmd; | 
|  | 5069 | struct RLS_RSP *rls_rsp; | 
|  | 5070 | uint8_t *pcmd; | 
|  | 5071 | struct lpfc_iocbq *elsiocb; | 
|  | 5072 | struct lpfc_nodelist *ndlp; | 
| James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5073 | uint16_t oxid; | 
|  | 5074 | uint16_t rxid; | 
| James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5075 | uint32_t cmdsize; | 
|  | 5076 |  | 
|  | 5077 | mb = &pmb->u.mb; | 
|  | 5078 |  | 
|  | 5079 | ndlp = (struct lpfc_nodelist *) pmb->context2; | 
| James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5080 | rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff); | 
|  | 5081 | oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff); | 
| James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5082 | pmb->context1 = NULL; | 
|  | 5083 | pmb->context2 = NULL; | 
|  | 5084 |  | 
|  | 5085 | if (mb->mbxStatus) { | 
|  | 5086 | mempool_free(pmb, phba->mbox_mem_pool); | 
|  | 5087 | return; | 
|  | 5088 | } | 
|  | 5089 |  | 
|  | 5090 | cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t); | 
|  | 5091 | mempool_free(pmb, phba->mbox_mem_pool); | 
|  | 5092 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, | 
|  | 5093 | lpfc_max_els_tries, ndlp, | 
|  | 5094 | ndlp->nlp_DID, ELS_CMD_ACC); | 
|  | 5095 |  | 
|  | 5096 | /* Decrement the ndlp reference count from previous mbox command */ | 
|  | 5097 | lpfc_nlp_put(ndlp); | 
|  | 5098 |  | 
|  | 5099 | if (!elsiocb) | 
|  | 5100 | return; | 
|  | 5101 |  | 
|  | 5102 | icmd = &elsiocb->iocb; | 
| James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5103 | icmd->ulpContext = rxid; | 
|  | 5104 | icmd->unsli3.rcvsli3.ox_id = oxid; | 
| James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5105 |  | 
|  | 5106 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 5107 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | 
|  | 5108 | pcmd += sizeof(uint32_t); /* Skip past command */ | 
|  | 5109 | rls_rsp = (struct RLS_RSP *)pcmd; | 
|  | 5110 |  | 
|  | 5111 | rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); | 
|  | 5112 | rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); | 
|  | 5113 | rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); | 
|  | 5114 | rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); | 
|  | 5115 | rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); | 
|  | 5116 | rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); | 
|  | 5117 |  | 
|  | 5118 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ | 
|  | 5119 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, | 
|  | 5120 | "2874 Xmit ELS RLS ACC response tag x%x xri x%x, " | 
|  | 5121 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", | 
|  | 5122 | elsiocb->iotag, elsiocb->iocb.ulpContext, | 
|  | 5123 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | 
|  | 5124 | ndlp->nlp_rpi); | 
|  | 5125 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; | 
|  | 5126 | phba->fc_stat.elsXmitACC++; | 
|  | 5127 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) | 
|  | 5128 | lpfc_els_free_iocb(phba, elsiocb); | 
|  | 5129 | } | 
|  | 5130 |  | 
|  | 5131 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5132 | * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5133 | * @phba: pointer to lpfc hba data structure. | 
|  | 5134 | * @pmb: pointer to the driver internal queue element for mailbox command. | 
|  | 5135 | * | 
|  | 5136 | * This routine is the completion callback function for the MBX_READ_LNK_STAT | 
|  | 5137 | * mailbox command. This callback function is to actually send the Accept | 
|  | 5138 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It | 
|  | 5139 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT | 
|  | 5140 | * mailbox command, constructs the RPS response with the link statistics | 
|  | 5141 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC | 
|  | 5142 | * response to the RPS. | 
|  | 5143 | * | 
|  | 5144 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | 
|  | 5145 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | 
|  | 5146 | * will be stored into the context1 field of the IOCB for the completion | 
|  | 5147 | * callback function to the RPS Accept Response ELS IOCB command. | 
|  | 5148 | * | 
|  | 5149 | **/ | 
| Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 5150 | static void | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5151 | lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5152 | { | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5153 | MAILBOX_t *mb; | 
|  | 5154 | IOCB_t *icmd; | 
|  | 5155 | RPS_RSP *rps_rsp; | 
|  | 5156 | uint8_t *pcmd; | 
|  | 5157 | struct lpfc_iocbq *elsiocb; | 
|  | 5158 | struct lpfc_nodelist *ndlp; | 
| James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5159 | uint16_t status; | 
|  | 5160 | uint16_t oxid; | 
|  | 5161 | uint16_t rxid; | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5162 | uint32_t cmdsize; | 
|  | 5163 |  | 
| James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5164 | mb = &pmb->u.mb; | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5165 |  | 
|  | 5166 | ndlp = (struct lpfc_nodelist *) pmb->context2; | 
| James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5167 | rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff); | 
|  | 5168 | oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff); | 
| Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 5169 | pmb->context1 = NULL; | 
|  | 5170 | pmb->context2 = NULL; | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5171 |  | 
|  | 5172 | if (mb->mbxStatus) { | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5173 | mempool_free(pmb, phba->mbox_mem_pool); | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5174 | return; | 
|  | 5175 | } | 
|  | 5176 |  | 
|  | 5177 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5178 | mempool_free(pmb, phba->mbox_mem_pool); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5179 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, | 
|  | 5180 | lpfc_max_els_tries, ndlp, | 
|  | 5181 | ndlp->nlp_DID, ELS_CMD_ACC); | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5182 |  | 
|  | 5183 | /* Decrement the ndlp reference count from previous mbox command */ | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5184 | lpfc_nlp_put(ndlp); | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5185 |  | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5186 | if (!elsiocb) | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5187 | return; | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5188 |  | 
|  | 5189 | icmd = &elsiocb->iocb; | 
| James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5190 | icmd->ulpContext = rxid; | 
|  | 5191 | icmd->unsli3.rcvsli3.ox_id = oxid; | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5192 |  | 
|  | 5193 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 5194 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5195 | pcmd += sizeof(uint32_t); /* Skip past command */ | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5196 | rps_rsp = (RPS_RSP *)pcmd; | 
|  | 5197 |  | 
| James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5198 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5199 | status = 0x10; | 
|  | 5200 | else | 
|  | 5201 | status = 0x8; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5202 | if (phba->pport->fc_flag & FC_FABRIC) | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5203 | status |= 0x4; | 
|  | 5204 |  | 
|  | 5205 | rps_rsp->rsvd1 = 0; | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5206 | rps_rsp->portStatus = cpu_to_be16(status); | 
|  | 5207 | rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); | 
|  | 5208 | rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); | 
|  | 5209 | rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); | 
|  | 5210 | rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); | 
|  | 5211 | rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); | 
|  | 5212 | rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5213 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5214 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, | 
|  | 5215 | "0118 Xmit ELS RPS ACC response tag x%x xri x%x, " | 
|  | 5216 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", | 
|  | 5217 | elsiocb->iotag, elsiocb->iocb.ulpContext, | 
|  | 5218 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | 
|  | 5219 | ndlp->nlp_rpi); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5220 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5221 | phba->fc_stat.elsXmitACC++; | 
| James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5222 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5223 | lpfc_els_free_iocb(phba, elsiocb); | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5224 | return; | 
|  | 5225 | } | 
|  | 5226 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5227 | /** | 
| James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5228 | * lpfc_els_rcv_rls - Process an unsolicited rls iocb | 
|  | 5229 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 5230 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 5231 | * @ndlp: pointer to a node-list data structure. | 
|  | 5232 | * | 
|  | 5233 | * This routine processes Read Port Status (RPL) IOCB received as an | 
|  | 5234 | * ELS unsolicited event. It first checks the remote port state. If the | 
|  | 5235 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE | 
|  | 5236 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject | 
|  | 5237 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command | 
|  | 5238 | * for reading the HBA link statistics. It is for the callback function, | 
|  | 5239 | * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command | 
|  | 5240 | * to actually sending out RPL Accept (ACC) response. | 
|  | 5241 | * | 
|  | 5242 | * Return codes | 
|  | 5243 | *   0 - Successfully processed rls iocb (currently always return 0) | 
|  | 5244 | **/ | 
|  | 5245 | static int | 
|  | 5246 | lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, | 
|  | 5247 | struct lpfc_nodelist *ndlp) | 
|  | 5248 | { | 
|  | 5249 | struct lpfc_hba *phba = vport->phba; | 
|  | 5250 | LPFC_MBOXQ_t *mbox; | 
|  | 5251 | struct lpfc_dmabuf *pcmd; | 
|  | 5252 | struct ls_rjt stat; | 
|  | 5253 |  | 
|  | 5254 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && | 
|  | 5255 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) | 
|  | 5256 | /* reject the unsolicited RPS request and done with it */ | 
|  | 5257 | goto reject_out; | 
|  | 5258 |  | 
|  | 5259 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | 
|  | 5260 |  | 
|  | 5261 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); | 
|  | 5262 | if (mbox) { | 
|  | 5263 | lpfc_read_lnk_stat(phba, mbox); | 
| James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5264 | mbox->context1 = (void *)((unsigned long) | 
|  | 5265 | ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) | | 
|  | 5266 | cmdiocb->iocb.ulpContext)); /* rx_id */ | 
| James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5267 | mbox->context2 = lpfc_nlp_get(ndlp); | 
|  | 5268 | mbox->vport = vport; | 
|  | 5269 | mbox->mbox_cmpl = lpfc_els_rsp_rls_acc; | 
|  | 5270 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) | 
|  | 5271 | != MBX_NOT_FINISHED) | 
|  | 5272 | /* Mbox completion will send ELS Response */ | 
|  | 5273 | return 0; | 
|  | 5274 | /* Decrement reference count used for the failed mbox | 
|  | 5275 | * command. | 
|  | 5276 | */ | 
|  | 5277 | lpfc_nlp_put(ndlp); | 
|  | 5278 | mempool_free(mbox, phba->mbox_mem_pool); | 
|  | 5279 | } | 
|  | 5280 | reject_out: | 
|  | 5281 | /* issue rejection response */ | 
|  | 5282 | stat.un.b.lsRjtRsvd0 = 0; | 
|  | 5283 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | 
|  | 5284 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; | 
|  | 5285 | stat.un.b.vendorUnique = 0; | 
|  | 5286 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); | 
|  | 5287 | return 0; | 
|  | 5288 | } | 
|  | 5289 |  | 
|  | 5290 | /** | 
|  | 5291 | * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb | 
|  | 5292 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 5293 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 5294 | * @ndlp: pointer to a node-list data structure. | 
|  | 5295 | * | 
|  | 5296 | * This routine processes Read Timout Value (RTV) IOCB received as an | 
|  | 5297 | * ELS unsolicited event. It first checks the remote port state. If the | 
|  | 5298 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE | 
|  | 5299 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject | 
|  | 5300 | * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout | 
|  | 5301 | * Value (RTV) unsolicited IOCB event. | 
|  | 5302 | * | 
|  | 5303 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | 
|  | 5304 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | 
|  | 5305 | * will be stored into the context1 field of the IOCB for the completion | 
|  | 5306 | * callback function to the RPS Accept Response ELS IOCB command. | 
|  | 5307 | * | 
|  | 5308 | * Return codes | 
|  | 5309 | *   0 - Successfully processed rtv iocb (currently always return 0) | 
|  | 5310 | **/ | 
|  | 5311 | static int | 
|  | 5312 | lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, | 
|  | 5313 | struct lpfc_nodelist *ndlp) | 
|  | 5314 | { | 
|  | 5315 | struct lpfc_hba *phba = vport->phba; | 
|  | 5316 | struct ls_rjt stat; | 
|  | 5317 | struct RTV_RSP *rtv_rsp; | 
|  | 5318 | uint8_t *pcmd; | 
|  | 5319 | struct lpfc_iocbq *elsiocb; | 
|  | 5320 | uint32_t cmdsize; | 
|  | 5321 |  | 
|  | 5322 |  | 
|  | 5323 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && | 
|  | 5324 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) | 
|  | 5325 | /* reject the unsolicited RPS request and done with it */ | 
|  | 5326 | goto reject_out; | 
|  | 5327 |  | 
|  | 5328 | cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t); | 
|  | 5329 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, | 
|  | 5330 | lpfc_max_els_tries, ndlp, | 
|  | 5331 | ndlp->nlp_DID, ELS_CMD_ACC); | 
|  | 5332 |  | 
|  | 5333 | if (!elsiocb) | 
|  | 5334 | return 1; | 
|  | 5335 |  | 
|  | 5336 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 5337 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | 
|  | 5338 | pcmd += sizeof(uint32_t); /* Skip past command */ | 
|  | 5339 |  | 
|  | 5340 | /* use the command's xri in the response */ | 
| James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5341 | elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext;  /* Xri / rx_id */ | 
|  | 5342 | elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id; | 
| James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 5343 |  | 
|  | 5344 | rtv_rsp = (struct RTV_RSP *)pcmd; | 
|  | 5345 |  | 
|  | 5346 | /* populate RTV payload */ | 
|  | 5347 | rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */ | 
|  | 5348 | rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov); | 
|  | 5349 | bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0); | 
|  | 5350 | bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */ | 
|  | 5351 | rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov); | 
|  | 5352 |  | 
|  | 5353 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ | 
|  | 5354 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, | 
|  | 5355 | "2875 Xmit ELS RTV ACC response tag x%x xri x%x, " | 
|  | 5356 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, " | 
|  | 5357 | "Data: x%x x%x x%x\n", | 
|  | 5358 | elsiocb->iotag, elsiocb->iocb.ulpContext, | 
|  | 5359 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | 
|  | 5360 | ndlp->nlp_rpi, | 
|  | 5361 | rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov); | 
|  | 5362 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; | 
|  | 5363 | phba->fc_stat.elsXmitACC++; | 
|  | 5364 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) | 
|  | 5365 | lpfc_els_free_iocb(phba, elsiocb); | 
|  | 5366 | return 0; | 
|  | 5367 |  | 
|  | 5368 | reject_out: | 
|  | 5369 | /* issue rejection response */ | 
|  | 5370 | stat.un.b.lsRjtRsvd0 = 0; | 
|  | 5371 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | 
|  | 5372 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; | 
|  | 5373 | stat.un.b.vendorUnique = 0; | 
|  | 5374 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); | 
|  | 5375 | return 0; | 
|  | 5376 | } | 
|  | 5377 |  | 
|  | 5378 | /* lpfc_els_rcv_rps - Process an unsolicited rps iocb | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5379 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 5380 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 5381 | * @ndlp: pointer to a node-list data structure. | 
|  | 5382 | * | 
|  | 5383 | * This routine processes Read Port Status (RPS) IOCB received as an | 
|  | 5384 | * ELS unsolicited event. It first checks the remote port state. If the | 
|  | 5385 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE | 
|  | 5386 | * state, it invokes the lpfc_els_rsp_reject() routine to send the reject | 
|  | 5387 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command | 
|  | 5388 | * for reading the HBA link statistics. It is for the callback function, | 
|  | 5389 | * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command | 
|  | 5390 | * to actually sending out RPS Accept (ACC) response. | 
|  | 5391 | * | 
|  | 5392 | * Return codes | 
|  | 5393 | *   0 - Successfully processed rps iocb (currently always return 0) | 
|  | 5394 | **/ | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5395 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5396 | lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, | 
|  | 5397 | struct lpfc_nodelist *ndlp) | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5398 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5399 | struct lpfc_hba *phba = vport->phba; | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5400 | uint32_t *lp; | 
|  | 5401 | uint8_t flag; | 
|  | 5402 | LPFC_MBOXQ_t *mbox; | 
|  | 5403 | struct lpfc_dmabuf *pcmd; | 
|  | 5404 | RPS *rps; | 
|  | 5405 | struct ls_rjt stat; | 
|  | 5406 |  | 
| Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5407 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && | 
| James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5408 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) | 
|  | 5409 | /* reject the unsolicited RPS request and done with it */ | 
|  | 5410 | goto reject_out; | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5411 |  | 
|  | 5412 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | 
|  | 5413 | lp = (uint32_t *) pcmd->virt; | 
|  | 5414 | flag = (be32_to_cpu(*lp++) & 0xf); | 
|  | 5415 | rps = (RPS *) lp; | 
|  | 5416 |  | 
|  | 5417 | if ((flag == 0) || | 
|  | 5418 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5419 | ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5420 | sizeof(struct lpfc_name)) == 0))) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5421 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5422 | printk("Fix me....\n"); | 
|  | 5423 | dump_stack(); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5424 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); | 
|  | 5425 | if (mbox) { | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5426 | lpfc_read_lnk_stat(phba, mbox); | 
| James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5427 | mbox->context1 = (void *)((unsigned long) | 
|  | 5428 | ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) | | 
|  | 5429 | cmdiocb->iocb.ulpContext)); /* rx_id */ | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5430 | mbox->context2 = lpfc_nlp_get(ndlp); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5431 | mbox->vport = vport; | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5432 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5433 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) | 
| James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5434 | != MBX_NOT_FINISHED) | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5435 | /* Mbox completion will send ELS Response */ | 
|  | 5436 | return 0; | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5437 | /* Decrement reference count used for the failed mbox | 
|  | 5438 | * command. | 
|  | 5439 | */ | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5440 | lpfc_nlp_put(ndlp); | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5441 | mempool_free(mbox, phba->mbox_mem_pool); | 
|  | 5442 | } | 
|  | 5443 | } | 
| James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5444 |  | 
|  | 5445 | reject_out: | 
|  | 5446 | /* issue rejection response */ | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5447 | stat.un.b.lsRjtRsvd0 = 0; | 
|  | 5448 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | 
|  | 5449 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; | 
|  | 5450 | stat.un.b.vendorUnique = 0; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5451 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5452 | return 0; | 
|  | 5453 | } | 
|  | 5454 |  | 
| James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 5455 | /* lpfc_issue_els_rrq - Process an unsolicited rps iocb | 
|  | 5456 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 5457 | * @ndlp: pointer to a node-list data structure. | 
|  | 5458 | * @did: DID of the target. | 
|  | 5459 | * @rrq: Pointer to the rrq struct. | 
|  | 5460 | * | 
|  | 5461 | * Build a ELS RRQ command and send it to the target. If the issue_iocb is | 
|  | 5462 | * Successful the the completion handler will clear the RRQ. | 
|  | 5463 | * | 
|  | 5464 | * Return codes | 
|  | 5465 | *   0 - Successfully sent rrq els iocb. | 
|  | 5466 | *   1 - Failed to send rrq els iocb. | 
|  | 5467 | **/ | 
|  | 5468 | static int | 
|  | 5469 | lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, | 
|  | 5470 | uint32_t did, struct lpfc_node_rrq *rrq) | 
|  | 5471 | { | 
|  | 5472 | struct lpfc_hba  *phba = vport->phba; | 
|  | 5473 | struct RRQ *els_rrq; | 
|  | 5474 | IOCB_t *icmd; | 
|  | 5475 | struct lpfc_iocbq *elsiocb; | 
|  | 5476 | uint8_t *pcmd; | 
|  | 5477 | uint16_t cmdsize; | 
|  | 5478 | int ret; | 
|  | 5479 |  | 
|  | 5480 |  | 
|  | 5481 | if (ndlp != rrq->ndlp) | 
|  | 5482 | ndlp = rrq->ndlp; | 
|  | 5483 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) | 
|  | 5484 | return 1; | 
|  | 5485 |  | 
|  | 5486 | /* If ndlp is not NULL, we will bump the reference count on it */ | 
|  | 5487 | cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ)); | 
|  | 5488 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did, | 
|  | 5489 | ELS_CMD_RRQ); | 
|  | 5490 | if (!elsiocb) | 
|  | 5491 | return 1; | 
|  | 5492 |  | 
|  | 5493 | icmd = &elsiocb->iocb; | 
|  | 5494 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 5495 |  | 
|  | 5496 | /* For RRQ request, remainder of payload is Exchange IDs */ | 
|  | 5497 | *((uint32_t *) (pcmd)) = ELS_CMD_RRQ; | 
|  | 5498 | pcmd += sizeof(uint32_t); | 
|  | 5499 | els_rrq = (struct RRQ *) pcmd; | 
|  | 5500 |  | 
|  | 5501 | bf_set(rrq_oxid, els_rrq, rrq->xritag); | 
|  | 5502 | bf_set(rrq_rxid, els_rrq, rrq->rxid); | 
|  | 5503 | bf_set(rrq_did, els_rrq, vport->fc_myDID); | 
|  | 5504 | els_rrq->rrq = cpu_to_be32(els_rrq->rrq); | 
|  | 5505 | els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg); | 
|  | 5506 |  | 
|  | 5507 |  | 
|  | 5508 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 5509 | "Issue RRQ:     did:x%x", | 
|  | 5510 | did, rrq->xritag, rrq->rxid); | 
|  | 5511 | elsiocb->context_un.rrq = rrq; | 
|  | 5512 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq; | 
|  | 5513 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); | 
|  | 5514 |  | 
|  | 5515 | if (ret == IOCB_ERROR) { | 
|  | 5516 | lpfc_els_free_iocb(phba, elsiocb); | 
|  | 5517 | return 1; | 
|  | 5518 | } | 
|  | 5519 | return 0; | 
|  | 5520 | } | 
|  | 5521 |  | 
|  | 5522 | /** | 
|  | 5523 | * lpfc_send_rrq - Sends ELS RRQ if needed. | 
|  | 5524 | * @phba: pointer to lpfc hba data structure. | 
|  | 5525 | * @rrq: pointer to the active rrq. | 
|  | 5526 | * | 
|  | 5527 | * This routine will call the lpfc_issue_els_rrq if the rrq is | 
|  | 5528 | * still active for the xri. If this function returns a failure then | 
|  | 5529 | * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq. | 
|  | 5530 | * | 
|  | 5531 | * Returns 0 Success. | 
|  | 5532 | *         1 Failure. | 
|  | 5533 | **/ | 
|  | 5534 | int | 
|  | 5535 | lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq) | 
|  | 5536 | { | 
|  | 5537 | struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport, | 
|  | 5538 | rrq->nlp_DID); | 
|  | 5539 | if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag)) | 
|  | 5540 | return lpfc_issue_els_rrq(rrq->vport, ndlp, | 
|  | 5541 | rrq->nlp_DID, rrq); | 
|  | 5542 | else | 
|  | 5543 | return 1; | 
|  | 5544 | } | 
|  | 5545 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5546 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5547 | * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5548 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 5549 | * @cmdsize: size of the ELS command. | 
|  | 5550 | * @oldiocb: pointer to the original lpfc command iocb data structure. | 
|  | 5551 | * @ndlp: pointer to a node-list data structure. | 
|  | 5552 | * | 
|  | 5553 | * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. | 
|  | 5554 | * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. | 
|  | 5555 | * | 
|  | 5556 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | 
|  | 5557 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | 
|  | 5558 | * will be stored into the context1 field of the IOCB for the completion | 
|  | 5559 | * callback function to the RPL Accept Response ELS command. | 
|  | 5560 | * | 
|  | 5561 | * Return code | 
|  | 5562 | *   0 - Successfully issued ACC RPL ELS command | 
|  | 5563 | *   1 - Failed to issue ACC RPL ELS command | 
|  | 5564 | **/ | 
| Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 5565 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5566 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, | 
|  | 5567 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5568 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5569 | struct lpfc_hba *phba = vport->phba; | 
|  | 5570 | IOCB_t *icmd, *oldcmd; | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5571 | RPL_RSP rpl_rsp; | 
|  | 5572 | struct lpfc_iocbq *elsiocb; | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5573 | uint8_t *pcmd; | 
|  | 5574 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5575 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, | 
|  | 5576 | ndlp->nlp_DID, ELS_CMD_ACC); | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5577 |  | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5578 | if (!elsiocb) | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5579 | return 1; | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 5580 |  | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5581 | icmd = &elsiocb->iocb; | 
|  | 5582 | oldcmd = &oldiocb->iocb; | 
| James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 5583 | icmd->ulpContext = oldcmd->ulpContext;	/* Xri / rx_id */ | 
|  | 5584 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5585 |  | 
|  | 5586 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 5587 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5588 | pcmd += sizeof(uint16_t); | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5589 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); | 
|  | 5590 | pcmd += sizeof(uint16_t); | 
|  | 5591 |  | 
|  | 5592 | /* Setup the RPL ACC payload */ | 
|  | 5593 | rpl_rsp.listLen = be32_to_cpu(1); | 
|  | 5594 | rpl_rsp.index = 0; | 
|  | 5595 | rpl_rsp.port_num_blk.portNum = 0; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5596 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); | 
|  | 5597 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5598 | sizeof(struct lpfc_name)); | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5599 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5600 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5601 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 5602 | "0120 Xmit ELS RPL ACC response tag x%x " | 
|  | 5603 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " | 
|  | 5604 | "rpi x%x\n", | 
|  | 5605 | elsiocb->iotag, elsiocb->iocb.ulpContext, | 
|  | 5606 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | 
|  | 5607 | ndlp->nlp_rpi); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5608 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5609 | phba->fc_stat.elsXmitACC++; | 
| James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5610 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == | 
|  | 5611 | IOCB_ERROR) { | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5612 | lpfc_els_free_iocb(phba, elsiocb); | 
|  | 5613 | return 1; | 
|  | 5614 | } | 
|  | 5615 | return 0; | 
|  | 5616 | } | 
|  | 5617 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5618 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5619 | * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5620 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 5621 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 5622 | * @ndlp: pointer to a node-list data structure. | 
|  | 5623 | * | 
|  | 5624 | * This routine processes Read Port List (RPL) IOCB received as an ELS | 
|  | 5625 | * unsolicited event. It first checks the remote port state. If the remote | 
|  | 5626 | * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it | 
|  | 5627 | * invokes the lpfc_els_rsp_reject() routine to send reject response. | 
|  | 5628 | * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine | 
|  | 5629 | * to accept the RPL. | 
|  | 5630 | * | 
|  | 5631 | * Return code | 
|  | 5632 | *   0 - Successfully processed rpl iocb (currently always return 0) | 
|  | 5633 | **/ | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5634 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5635 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, | 
|  | 5636 | struct lpfc_nodelist *ndlp) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5637 | { | 
|  | 5638 | struct lpfc_dmabuf *pcmd; | 
|  | 5639 | uint32_t *lp; | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5640 | uint32_t maxsize; | 
|  | 5641 | uint16_t cmdsize; | 
|  | 5642 | RPL *rpl; | 
|  | 5643 | struct ls_rjt stat; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5644 |  | 
| Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5645 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && | 
|  | 5646 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { | 
| James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5647 | /* issue rejection response */ | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5648 | stat.un.b.lsRjtRsvd0 = 0; | 
|  | 5649 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | 
|  | 5650 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; | 
|  | 5651 | stat.un.b.vendorUnique = 0; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5652 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, | 
|  | 5653 | NULL); | 
| James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 5654 | /* rejected the unsolicited RPL request and done with it */ | 
|  | 5655 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5656 | } | 
|  | 5657 |  | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5658 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | 
|  | 5659 | lp = (uint32_t *) pcmd->virt; | 
|  | 5660 | rpl = (RPL *) (lp + 1); | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5661 | maxsize = be32_to_cpu(rpl->maxsize); | 
|  | 5662 |  | 
|  | 5663 | /* We support only one port */ | 
|  | 5664 | if ((rpl->index == 0) && | 
|  | 5665 | ((maxsize == 0) || | 
|  | 5666 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { | 
|  | 5667 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); | 
| Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 5668 | } else { | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5669 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); | 
|  | 5670 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5671 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5672 |  | 
|  | 5673 | return 0; | 
|  | 5674 | } | 
|  | 5675 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5676 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5677 | * lpfc_els_rcv_farp - Process an unsolicited farp request els command | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5678 | * @vport: pointer to a virtual N_Port data structure. | 
|  | 5679 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 5680 | * @ndlp: pointer to a node-list data structure. | 
|  | 5681 | * | 
|  | 5682 | * This routine processes Fibre Channel Address Resolution Protocol | 
|  | 5683 | * (FARP) Request IOCB received as an ELS unsolicited event. Currently, | 
|  | 5684 | * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, | 
|  | 5685 | * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the | 
|  | 5686 | * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the | 
|  | 5687 | * remote PortName is compared against the FC PortName stored in the @vport | 
|  | 5688 | * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is | 
|  | 5689 | * compared against the FC NodeName stored in the @vport data structure. | 
|  | 5690 | * If any of these matches and the FARP_REQUEST_FARPR flag is set in the | 
|  | 5691 | * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is | 
|  | 5692 | * invoked to send out FARP Response to the remote node. Before sending the | 
|  | 5693 | * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP | 
|  | 5694 | * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() | 
|  | 5695 | * routine is invoked to log into the remote port first. | 
|  | 5696 | * | 
|  | 5697 | * Return code | 
|  | 5698 | *   0 - Either the FARP Match Mode not supported or successfully processed | 
|  | 5699 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5700 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5701 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, | 
|  | 5702 | struct lpfc_nodelist *ndlp) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5703 | { | 
|  | 5704 | struct lpfc_dmabuf *pcmd; | 
|  | 5705 | uint32_t *lp; | 
|  | 5706 | IOCB_t *icmd; | 
|  | 5707 | FARP *fp; | 
|  | 5708 | uint32_t cmd, cnt, did; | 
|  | 5709 |  | 
|  | 5710 | icmd = &cmdiocb->iocb; | 
|  | 5711 | did = icmd->un.elsreq64.remoteID; | 
|  | 5712 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | 
|  | 5713 | lp = (uint32_t *) pcmd->virt; | 
|  | 5714 |  | 
|  | 5715 | cmd = *lp++; | 
|  | 5716 | fp = (FARP *) lp; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5717 | /* FARP-REQ received from DID <did> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5718 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 5719 | "0601 FARP-REQ received from DID x%x\n", did); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5720 | /* We will only support match on WWPN or WWNN */ | 
|  | 5721 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5722 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5723 | } | 
|  | 5724 |  | 
|  | 5725 | cnt = 0; | 
|  | 5726 | /* If this FARP command is searching for my portname */ | 
|  | 5727 | if (fp->Mflags & FARP_MATCH_PORT) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5728 | if (memcmp(&fp->RportName, &vport->fc_portname, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5729 | sizeof(struct lpfc_name)) == 0) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5730 | cnt = 1; | 
|  | 5731 | } | 
|  | 5732 |  | 
|  | 5733 | /* If this FARP command is searching for my nodename */ | 
|  | 5734 | if (fp->Mflags & FARP_MATCH_NODE) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5735 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5736 | sizeof(struct lpfc_name)) == 0) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5737 | cnt = 1; | 
|  | 5738 | } | 
|  | 5739 |  | 
|  | 5740 | if (cnt) { | 
|  | 5741 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || | 
|  | 5742 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { | 
|  | 5743 | /* Log back into the node before sending the FARP. */ | 
|  | 5744 | if (fp->Rflags & FARP_REQUEST_PLOGI) { | 
| Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5745 | ndlp->nlp_prev_state = ndlp->nlp_state; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5746 | lpfc_nlp_set_state(vport, ndlp, | 
| James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 5747 | NLP_STE_PLOGI_ISSUE); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5748 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5749 | } | 
|  | 5750 |  | 
|  | 5751 | /* Send a FARP response to that node */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5752 | if (fp->Rflags & FARP_REQUEST_FARPR) | 
|  | 5753 | lpfc_issue_els_farpr(vport, did, 0); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5754 | } | 
|  | 5755 | } | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5756 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5757 | } | 
|  | 5758 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5759 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5760 | * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5761 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 5762 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 5763 | * @ndlp: pointer to a node-list data structure. | 
|  | 5764 | * | 
|  | 5765 | * This routine processes Fibre Channel Address Resolution Protocol | 
|  | 5766 | * Response (FARPR) IOCB received as an ELS unsolicited event. It simply | 
|  | 5767 | * invokes the lpfc_els_rsp_acc() routine to the remote node to accept | 
|  | 5768 | * the FARP response request. | 
|  | 5769 | * | 
|  | 5770 | * Return code | 
|  | 5771 | *   0 - Successfully processed FARPR IOCB (currently always return 0) | 
|  | 5772 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5773 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5774 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, | 
|  | 5775 | struct lpfc_nodelist  *ndlp) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5776 | { | 
|  | 5777 | struct lpfc_dmabuf *pcmd; | 
|  | 5778 | uint32_t *lp; | 
|  | 5779 | IOCB_t *icmd; | 
|  | 5780 | uint32_t cmd, did; | 
|  | 5781 |  | 
|  | 5782 | icmd = &cmdiocb->iocb; | 
|  | 5783 | did = icmd->un.elsreq64.remoteID; | 
|  | 5784 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | 
|  | 5785 | lp = (uint32_t *) pcmd->virt; | 
|  | 5786 |  | 
|  | 5787 | cmd = *lp++; | 
|  | 5788 | /* FARP-RSP received from DID <did> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5789 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 5790 | "0600 FARP-RSP received from DID x%x\n", did); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5791 | /* ACCEPT the Farp resp request */ | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5792 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5793 |  | 
|  | 5794 | return 0; | 
|  | 5795 | } | 
|  | 5796 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5797 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5798 | * lpfc_els_rcv_fan - Process an unsolicited fan iocb command | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5799 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 5800 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 5801 | * @fan_ndlp: pointer to a node-list data structure. | 
|  | 5802 | * | 
|  | 5803 | * This routine processes a Fabric Address Notification (FAN) IOCB | 
|  | 5804 | * command received as an ELS unsolicited event. The FAN ELS command will | 
|  | 5805 | * only be processed on a physical port (i.e., the @vport represents the | 
|  | 5806 | * physical port). The fabric NodeName and PortName from the FAN IOCB are | 
|  | 5807 | * compared against those in the phba data structure. If any of those is | 
|  | 5808 | * different, the lpfc_initial_flogi() routine is invoked to initialize | 
|  | 5809 | * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, | 
|  | 5810 | * if both of those are identical, the lpfc_issue_fabric_reglogin() routine | 
|  | 5811 | * is invoked to register login to the fabric. | 
|  | 5812 | * | 
|  | 5813 | * Return code | 
|  | 5814 | *   0 - Successfully processed fan iocb (currently always return 0). | 
|  | 5815 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5816 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5817 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, | 
|  | 5818 | struct lpfc_nodelist *fan_ndlp) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5819 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5820 | struct lpfc_hba *phba = vport->phba; | 
| James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5821 | uint32_t *lp; | 
|  | 5822 | FAN *fp; | 
| Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5823 |  | 
| James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5824 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); | 
|  | 5825 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; | 
|  | 5826 | fp = (FAN *) ++lp; | 
| Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5827 | /* FAN received; Fan does not have a reply sequence */ | 
| James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5828 | if ((vport == phba->pport) && | 
|  | 5829 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { | 
| Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5830 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, | 
| James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5831 | sizeof(struct lpfc_name))) || | 
| Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 5832 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, | 
| James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5833 | sizeof(struct lpfc_name)))) { | 
|  | 5834 | /* This port has switched fabrics. FLOGI is required */ | 
| James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5835 | lpfc_issue_init_vfi(vport); | 
| James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 5836 | } else { | 
|  | 5837 | /* FAN verified - skip FLOGI */ | 
|  | 5838 | vport->fc_myDID = vport->fc_prevDID; | 
| James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 5839 | if (phba->sli_rev < LPFC_SLI_REV4) | 
|  | 5840 | lpfc_issue_fabric_reglogin(vport); | 
|  | 5841 | else | 
|  | 5842 | lpfc_issue_reg_vfi(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5843 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5844 | } | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5845 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5846 | } | 
|  | 5847 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5848 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5849 | * lpfc_els_timeout - Handler funciton to the els timer | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5850 | * @ptr: holder for the timer function associated data. | 
|  | 5851 | * | 
|  | 5852 | * This routine is invoked by the ELS timer after timeout. It posts the ELS | 
|  | 5853 | * timer timeout event by setting the WORKER_ELS_TMO bit to the work port | 
|  | 5854 | * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake | 
|  | 5855 | * up the worker thread. It is for the worker thread to invoke the routine | 
|  | 5856 | * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. | 
|  | 5857 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5858 | void | 
|  | 5859 | lpfc_els_timeout(unsigned long ptr) | 
|  | 5860 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5861 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; | 
|  | 5862 | struct lpfc_hba   *phba = vport->phba; | 
| James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5863 | uint32_t tmo_posted; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5864 | unsigned long iflag; | 
|  | 5865 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5866 | spin_lock_irqsave(&vport->work_port_lock, iflag); | 
| James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5867 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; | 
|  | 5868 | if (!tmo_posted) | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5869 | vport->work_port_events |= WORKER_ELS_TMO; | 
| James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5870 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5871 |  | 
| James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 5872 | if (!tmo_posted) | 
|  | 5873 | lpfc_worker_wake_up(phba); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5874 | return; | 
|  | 5875 | } | 
|  | 5876 |  | 
| James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5877 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5878 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5879 | * lpfc_els_timeout_handler - Process an els timeout event | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5880 | * @vport: pointer to a virtual N_Port data structure. | 
|  | 5881 | * | 
|  | 5882 | * This routine is the actual handler function that processes an ELS timeout | 
|  | 5883 | * event. It walks the ELS ring to get and abort all the IOCBs (except the | 
|  | 5884 | * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by | 
|  | 5885 | * invoking the lpfc_sli_issue_abort_iotag() routine. | 
|  | 5886 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5887 | void | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5888 | lpfc_els_timeout_handler(struct lpfc_vport *vport) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5889 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5890 | struct lpfc_hba  *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5891 | struct lpfc_sli_ring *pring; | 
|  | 5892 | struct lpfc_iocbq *tmp_iocb, *piocb; | 
|  | 5893 | IOCB_t *cmd = NULL; | 
|  | 5894 | struct lpfc_dmabuf *pcmd; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5895 | uint32_t els_command = 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5896 | uint32_t timeout; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5897 | uint32_t remote_ID = 0xffffffff; | 
| James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5898 | LIST_HEAD(txcmplq_completions); | 
|  | 5899 | LIST_HEAD(abort_list); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5900 |  | 
| James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5901 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5902 | timeout = (uint32_t)(phba->fc_ratov << 1); | 
|  | 5903 |  | 
|  | 5904 | pring = &phba->sli.ring[LPFC_ELS_RING]; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5905 |  | 
| James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5906 | spin_lock_irq(&phba->hbalock); | 
|  | 5907 | list_splice_init(&pring->txcmplq, &txcmplq_completions); | 
|  | 5908 | spin_unlock_irq(&phba->hbalock); | 
|  | 5909 |  | 
|  | 5910 | list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5911 | cmd = &piocb->iocb; | 
|  | 5912 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5913 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || | 
|  | 5914 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || | 
|  | 5915 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5916 | continue; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5917 |  | 
|  | 5918 | if (piocb->vport != vport) | 
|  | 5919 | continue; | 
|  | 5920 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5921 | pcmd = (struct lpfc_dmabuf *) piocb->context2; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5922 | if (pcmd) | 
|  | 5923 | els_command = *(uint32_t *) (pcmd->virt); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5924 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5925 | if (els_command == ELS_CMD_FARP || | 
|  | 5926 | els_command == ELS_CMD_FARPR || | 
|  | 5927 | els_command == ELS_CMD_FDISC) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5928 | continue; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5929 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5930 | if (piocb->drvrTimeout > 0) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5931 | if (piocb->drvrTimeout >= timeout) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5932 | piocb->drvrTimeout -= timeout; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5933 | else | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5934 | piocb->drvrTimeout = 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5935 | continue; | 
|  | 5936 | } | 
|  | 5937 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5938 | remote_ID = 0xffffffff; | 
|  | 5939 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5940 | remote_ID = cmd->un.elsreq64.remoteID; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5941 | else { | 
|  | 5942 | struct lpfc_nodelist *ndlp; | 
|  | 5943 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5944 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5945 | remote_ID = ndlp->nlp_DID; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5946 | } | 
| James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5947 | list_add_tail(&piocb->dlist, &abort_list); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5948 | } | 
| James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5949 | spin_lock_irq(&phba->hbalock); | 
|  | 5950 | list_splice(&txcmplq_completions, &pring->txcmplq); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5951 | spin_unlock_irq(&phba->hbalock); | 
| James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 5952 |  | 
| James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 5953 | list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { | 
|  | 5954 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 5955 | "0127 ELS timeout Data: x%x x%x x%x " | 
|  | 5956 | "x%x\n", els_command, | 
|  | 5957 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); | 
|  | 5958 | spin_lock_irq(&phba->hbalock); | 
|  | 5959 | list_del_init(&piocb->dlist); | 
|  | 5960 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); | 
|  | 5961 | spin_unlock_irq(&phba->hbalock); | 
|  | 5962 | } | 
|  | 5963 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5964 | if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) | 
|  | 5965 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5966 | } | 
|  | 5967 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5968 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5969 | * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5970 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 5971 | * | 
|  | 5972 | * This routine is used to clean up all the outstanding ELS commands on a | 
|  | 5973 | * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() | 
|  | 5974 | * routine. After that, it walks the ELS transmit queue to remove all the | 
|  | 5975 | * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For | 
|  | 5976 | * the IOCBs with a non-NULL completion callback function, the callback | 
|  | 5977 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and | 
|  | 5978 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion | 
|  | 5979 | * callback function, the IOCB will simply be released. Finally, it walks | 
|  | 5980 | * the ELS transmit completion queue to issue an abort IOCB to any transmit | 
|  | 5981 | * completion queue IOCB that is associated with the @vport and is not | 
|  | 5982 | * an IOCB from libdfc (i.e., the management plane IOCBs that are not | 
|  | 5983 | * part of the discovery state machine) out to HBA by invoking the | 
|  | 5984 | * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the | 
|  | 5985 | * abort IOCB to any transmit completion queueed IOCB, it does not guarantee | 
|  | 5986 | * the IOCBs are aborted when this function returns. | 
|  | 5987 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5988 | void | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5989 | lpfc_els_flush_cmd(struct lpfc_vport *vport) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5990 | { | 
| James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5991 | LIST_HEAD(completions); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5992 | struct lpfc_hba  *phba = vport->phba; | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5993 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5994 | struct lpfc_iocbq *tmp_iocb, *piocb; | 
|  | 5995 | IOCB_t *cmd = NULL; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5996 |  | 
|  | 5997 | lpfc_fabric_abort_vport(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5998 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5999 | spin_lock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6000 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { | 
|  | 6001 | cmd = &piocb->iocb; | 
|  | 6002 |  | 
|  | 6003 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { | 
|  | 6004 | continue; | 
|  | 6005 | } | 
|  | 6006 |  | 
|  | 6007 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6008 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || | 
|  | 6009 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || | 
|  | 6010 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || | 
|  | 6011 | cmd->ulpCommand == CMD_ABORT_XRI_CN) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6012 | continue; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6013 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6014 | if (piocb->vport != vport) | 
|  | 6015 | continue; | 
|  | 6016 |  | 
| James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 6017 | list_move_tail(&piocb->list, &completions); | 
| James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 6018 | pring->txq_cnt--; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6019 | } | 
|  | 6020 |  | 
|  | 6021 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6022 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { | 
|  | 6023 | continue; | 
|  | 6024 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6025 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6026 | if (piocb->vport != vport) | 
|  | 6027 | continue; | 
|  | 6028 |  | 
| James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 6029 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6030 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6031 | spin_unlock_irq(&phba->hbalock); | 
| James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 6032 |  | 
| James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6033 | /* Cancell all the IOCBs from the completions list */ | 
|  | 6034 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | 
|  | 6035 | IOERR_SLI_ABORTED); | 
| James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 6036 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6037 | return; | 
|  | 6038 | } | 
|  | 6039 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6040 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6041 | * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6042 | * @phba: pointer to lpfc hba data structure. | 
|  | 6043 | * | 
|  | 6044 | * This routine is used to clean up all the outstanding ELS commands on a | 
|  | 6045 | * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() | 
|  | 6046 | * routine. After that, it walks the ELS transmit queue to remove all the | 
|  | 6047 | * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For | 
|  | 6048 | * the IOCBs with the completion callback function associated, the callback | 
|  | 6049 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and | 
|  | 6050 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion | 
|  | 6051 | * callback function associated, the IOCB will simply be released. Finally, | 
|  | 6052 | * it walks the ELS transmit completion queue to issue an abort IOCB to any | 
|  | 6053 | * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the | 
|  | 6054 | * management plane IOCBs that are not part of the discovery state machine) | 
|  | 6055 | * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. | 
|  | 6056 | **/ | 
| James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6057 | void | 
|  | 6058 | lpfc_els_flush_all_cmd(struct lpfc_hba  *phba) | 
|  | 6059 | { | 
|  | 6060 | LIST_HEAD(completions); | 
|  | 6061 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | 
|  | 6062 | struct lpfc_iocbq *tmp_iocb, *piocb; | 
|  | 6063 | IOCB_t *cmd = NULL; | 
|  | 6064 |  | 
|  | 6065 | lpfc_fabric_abort_hba(phba); | 
|  | 6066 | spin_lock_irq(&phba->hbalock); | 
|  | 6067 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { | 
|  | 6068 | cmd = &piocb->iocb; | 
|  | 6069 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) | 
|  | 6070 | continue; | 
|  | 6071 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ | 
|  | 6072 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || | 
|  | 6073 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || | 
|  | 6074 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || | 
|  | 6075 | cmd->ulpCommand == CMD_ABORT_XRI_CN) | 
|  | 6076 | continue; | 
|  | 6077 | list_move_tail(&piocb->list, &completions); | 
|  | 6078 | pring->txq_cnt--; | 
|  | 6079 | } | 
|  | 6080 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { | 
|  | 6081 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) | 
|  | 6082 | continue; | 
|  | 6083 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); | 
|  | 6084 | } | 
|  | 6085 | spin_unlock_irq(&phba->hbalock); | 
| James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6086 |  | 
|  | 6087 | /* Cancel all the IOCBs from the completions list */ | 
|  | 6088 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | 
|  | 6089 | IOERR_SLI_ABORTED); | 
|  | 6090 |  | 
| James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6091 | return; | 
|  | 6092 | } | 
|  | 6093 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6094 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6095 | * lpfc_send_els_failure_event - Posts an ELS command failure event | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6096 | * @phba: Pointer to hba context object. | 
|  | 6097 | * @cmdiocbp: Pointer to command iocb which reported error. | 
|  | 6098 | * @rspiocbp: Pointer to response iocb which reported error. | 
|  | 6099 | * | 
|  | 6100 | * This function sends an event when there is an ELS command | 
|  | 6101 | * failure. | 
|  | 6102 | **/ | 
|  | 6103 | void | 
|  | 6104 | lpfc_send_els_failure_event(struct lpfc_hba *phba, | 
|  | 6105 | struct lpfc_iocbq *cmdiocbp, | 
|  | 6106 | struct lpfc_iocbq *rspiocbp) | 
|  | 6107 | { | 
|  | 6108 | struct lpfc_vport *vport = cmdiocbp->vport; | 
|  | 6109 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | 6110 | struct lpfc_lsrjt_event lsrjt_event; | 
|  | 6111 | struct lpfc_fabric_event_header fabric_event; | 
|  | 6112 | struct ls_rjt stat; | 
|  | 6113 | struct lpfc_nodelist *ndlp; | 
|  | 6114 | uint32_t *pcmd; | 
|  | 6115 |  | 
|  | 6116 | ndlp = cmdiocbp->context1; | 
|  | 6117 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) | 
|  | 6118 | return; | 
|  | 6119 |  | 
|  | 6120 | if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) { | 
|  | 6121 | lsrjt_event.header.event_type = FC_REG_ELS_EVENT; | 
|  | 6122 | lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV; | 
|  | 6123 | memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname, | 
|  | 6124 | sizeof(struct lpfc_name)); | 
|  | 6125 | memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename, | 
|  | 6126 | sizeof(struct lpfc_name)); | 
|  | 6127 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) | 
|  | 6128 | cmdiocbp->context2)->virt); | 
| James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 6129 | lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0; | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6130 | stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]); | 
|  | 6131 | lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode; | 
|  | 6132 | lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp; | 
|  | 6133 | fc_host_post_vendor_event(shost, | 
|  | 6134 | fc_get_event_number(), | 
|  | 6135 | sizeof(lsrjt_event), | 
|  | 6136 | (char *)&lsrjt_event, | 
| James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6137 | LPFC_NL_VENDOR_ID); | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6138 | return; | 
|  | 6139 | } | 
|  | 6140 | if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) || | 
|  | 6141 | (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) { | 
|  | 6142 | fabric_event.event_type = FC_REG_FABRIC_EVENT; | 
|  | 6143 | if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) | 
|  | 6144 | fabric_event.subcategory = LPFC_EVENT_PORT_BUSY; | 
|  | 6145 | else | 
|  | 6146 | fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY; | 
|  | 6147 | memcpy(fabric_event.wwpn, &ndlp->nlp_portname, | 
|  | 6148 | sizeof(struct lpfc_name)); | 
|  | 6149 | memcpy(fabric_event.wwnn, &ndlp->nlp_nodename, | 
|  | 6150 | sizeof(struct lpfc_name)); | 
|  | 6151 | fc_host_post_vendor_event(shost, | 
|  | 6152 | fc_get_event_number(), | 
|  | 6153 | sizeof(fabric_event), | 
|  | 6154 | (char *)&fabric_event, | 
| James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6155 | LPFC_NL_VENDOR_ID); | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6156 | return; | 
|  | 6157 | } | 
|  | 6158 |  | 
|  | 6159 | } | 
|  | 6160 |  | 
|  | 6161 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6162 | * lpfc_send_els_event - Posts unsolicited els event | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6163 | * @vport: Pointer to vport object. | 
|  | 6164 | * @ndlp: Pointer FC node object. | 
|  | 6165 | * @cmd: ELS command code. | 
|  | 6166 | * | 
|  | 6167 | * This function posts an event when there is an incoming | 
|  | 6168 | * unsolicited ELS command. | 
|  | 6169 | **/ | 
|  | 6170 | static void | 
|  | 6171 | lpfc_send_els_event(struct lpfc_vport *vport, | 
|  | 6172 | struct lpfc_nodelist *ndlp, | 
| James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6173 | uint32_t *payload) | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6174 | { | 
| James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6175 | struct lpfc_els_event_header *els_data = NULL; | 
|  | 6176 | struct lpfc_logo_event *logo_data = NULL; | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6177 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | 6178 |  | 
| James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6179 | if (*payload == ELS_CMD_LOGO) { | 
|  | 6180 | logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL); | 
|  | 6181 | if (!logo_data) { | 
|  | 6182 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 6183 | "0148 Failed to allocate memory " | 
|  | 6184 | "for LOGO event\n"); | 
|  | 6185 | return; | 
|  | 6186 | } | 
|  | 6187 | els_data = &logo_data->header; | 
|  | 6188 | } else { | 
|  | 6189 | els_data = kmalloc(sizeof(struct lpfc_els_event_header), | 
|  | 6190 | GFP_KERNEL); | 
|  | 6191 | if (!els_data) { | 
|  | 6192 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 6193 | "0149 Failed to allocate memory " | 
|  | 6194 | "for ELS event\n"); | 
|  | 6195 | return; | 
|  | 6196 | } | 
|  | 6197 | } | 
|  | 6198 | els_data->event_type = FC_REG_ELS_EVENT; | 
|  | 6199 | switch (*payload) { | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6200 | case ELS_CMD_PLOGI: | 
| James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6201 | els_data->subcategory = LPFC_EVENT_PLOGI_RCV; | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6202 | break; | 
|  | 6203 | case ELS_CMD_PRLO: | 
| James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6204 | els_data->subcategory = LPFC_EVENT_PRLO_RCV; | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6205 | break; | 
|  | 6206 | case ELS_CMD_ADISC: | 
| James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6207 | els_data->subcategory = LPFC_EVENT_ADISC_RCV; | 
|  | 6208 | break; | 
|  | 6209 | case ELS_CMD_LOGO: | 
|  | 6210 | els_data->subcategory = LPFC_EVENT_LOGO_RCV; | 
|  | 6211 | /* Copy the WWPN in the LOGO payload */ | 
|  | 6212 | memcpy(logo_data->logo_wwpn, &payload[2], | 
|  | 6213 | sizeof(struct lpfc_name)); | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6214 | break; | 
|  | 6215 | default: | 
| Julia Lawall | e916141 | 2009-02-08 22:43:19 +0100 | [diff] [blame] | 6216 | kfree(els_data); | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6217 | return; | 
|  | 6218 | } | 
| James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6219 | memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name)); | 
|  | 6220 | memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name)); | 
|  | 6221 | if (*payload == ELS_CMD_LOGO) { | 
|  | 6222 | fc_host_post_vendor_event(shost, | 
|  | 6223 | fc_get_event_number(), | 
|  | 6224 | sizeof(struct lpfc_logo_event), | 
|  | 6225 | (char *)logo_data, | 
|  | 6226 | LPFC_NL_VENDOR_ID); | 
|  | 6227 | kfree(logo_data); | 
|  | 6228 | } else { | 
|  | 6229 | fc_host_post_vendor_event(shost, | 
|  | 6230 | fc_get_event_number(), | 
|  | 6231 | sizeof(struct lpfc_els_event_header), | 
|  | 6232 | (char *)els_data, | 
|  | 6233 | LPFC_NL_VENDOR_ID); | 
|  | 6234 | kfree(els_data); | 
|  | 6235 | } | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6236 |  | 
|  | 6237 | return; | 
|  | 6238 | } | 
|  | 6239 |  | 
|  | 6240 |  | 
|  | 6241 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6242 | * lpfc_els_unsol_buffer - Process an unsolicited event data buffer | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6243 | * @phba: pointer to lpfc hba data structure. | 
|  | 6244 | * @pring: pointer to a SLI ring. | 
|  | 6245 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 6246 | * @elsiocb: pointer to lpfc els command iocb data structure. | 
|  | 6247 | * | 
|  | 6248 | * This routine is used for processing the IOCB associated with a unsolicited | 
|  | 6249 | * event. It first determines whether there is an existing ndlp that matches | 
|  | 6250 | * the DID from the unsolicited IOCB. If not, it will create a new one with | 
|  | 6251 | * the DID from the unsolicited IOCB. The ELS command from the unsolicited | 
|  | 6252 | * IOCB is then used to invoke the proper routine and to set up proper state | 
|  | 6253 | * of the discovery state machine. | 
|  | 6254 | **/ | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6255 | static void | 
|  | 6256 | lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6257 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6258 | { | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6259 | struct Scsi_Host  *shost; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6260 | struct lpfc_nodelist *ndlp; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6261 | struct ls_rjt stat; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6262 | uint32_t *payload; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6263 | uint32_t cmd, did, newnode, rjt_err = 0; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6264 | IOCB_t *icmd = &elsiocb->iocb; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6265 |  | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6266 | if (!vport || !(elsiocb->context2)) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6267 | goto dropit; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6268 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6269 | newnode = 0; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6270 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; | 
|  | 6271 | cmd = *payload; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6272 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) | 
| James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 6273 | lpfc_post_buffer(phba, pring, 1); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6274 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6275 | did = icmd->un.rcvels.remoteID; | 
|  | 6276 | if (icmd->ulpStatus) { | 
|  | 6277 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 6278 | "RCV Unsol ELS:  status:x%x/x%x did:x%x", | 
|  | 6279 | icmd->ulpStatus, icmd->un.ulpWord[4], did); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6280 | goto dropit; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6281 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6282 |  | 
|  | 6283 | /* Check to see if link went down during discovery */ | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6284 | if (lpfc_els_chk_latt(vport)) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6285 | goto dropit; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6286 |  | 
| James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 6287 | /* Ignore traffic received during vport shutdown. */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6288 | if (vport->load_flag & FC_UNLOADING) | 
|  | 6289 | goto dropit; | 
|  | 6290 |  | 
| James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 6291 | /* If NPort discovery is delayed drop incoming ELS */ | 
|  | 6292 | if ((vport->fc_flag & FC_DISC_DELAYED) && | 
|  | 6293 | (cmd != ELS_CMD_PLOGI)) | 
|  | 6294 | goto dropit; | 
|  | 6295 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6296 | ndlp = lpfc_findnode_did(vport, did); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6297 | if (!ndlp) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6298 | /* Cannot find existing Fabric ndlp, so allocate a new one */ | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 6299 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6300 | if (!ndlp) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6301 | goto dropit; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6302 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6303 | lpfc_nlp_init(vport, ndlp, did); | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6304 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6305 | newnode = 1; | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6306 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6307 | ndlp->nlp_type |= NLP_FABRIC; | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6308 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | 
|  | 6309 | ndlp = lpfc_enable_node(vport, ndlp, | 
|  | 6310 | NLP_STE_UNUSED_NODE); | 
|  | 6311 | if (!ndlp) | 
|  | 6312 | goto dropit; | 
|  | 6313 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); | 
|  | 6314 | newnode = 1; | 
|  | 6315 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) | 
|  | 6316 | ndlp->nlp_type |= NLP_FABRIC; | 
|  | 6317 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { | 
|  | 6318 | /* This is similar to the new node path */ | 
|  | 6319 | ndlp = lpfc_nlp_get(ndlp); | 
|  | 6320 | if (!ndlp) | 
|  | 6321 | goto dropit; | 
|  | 6322 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); | 
|  | 6323 | newnode = 1; | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6324 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6325 |  | 
|  | 6326 | phba->fc_stat.elsRcvFrame++; | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6327 |  | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 6328 | elsiocb->context1 = lpfc_nlp_get(ndlp); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6329 | elsiocb->vport = vport; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6330 |  | 
|  | 6331 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { | 
|  | 6332 | cmd &= ELS_CMD_MASK; | 
|  | 6333 | } | 
|  | 6334 | /* ELS command <elsCmd> received from NPORT <did> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6335 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 6336 | "0112 ELS command x%x received from NPORT x%x " | 
|  | 6337 | "Data: x%x\n", cmd, did, vport->port_state); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6338 | switch (cmd) { | 
|  | 6339 | case ELS_CMD_PLOGI: | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6340 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 6341 | "RCV PLOGI:       did:x%x/ste:x%x flg:x%x", | 
|  | 6342 | did, vport->port_state, ndlp->nlp_flag); | 
|  | 6343 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6344 | phba->fc_stat.elsRcvPLOGI++; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6345 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); | 
|  | 6346 |  | 
| James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6347 | lpfc_send_els_event(vport, ndlp, payload); | 
| James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 6348 |  | 
|  | 6349 | /* If Nport discovery is delayed, reject PLOGIs */ | 
|  | 6350 | if (vport->fc_flag & FC_DISC_DELAYED) { | 
|  | 6351 | rjt_err = LSRJT_UNABLE_TPC; | 
|  | 6352 | break; | 
|  | 6353 | } | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6354 | if (vport->port_state < LPFC_DISC_AUTH) { | 
| James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 6355 | if (!(phba->pport->fc_flag & FC_PT2PT) || | 
|  | 6356 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { | 
|  | 6357 | rjt_err = LSRJT_UNABLE_TPC; | 
|  | 6358 | break; | 
|  | 6359 | } | 
|  | 6360 | /* We get here, and drop thru, if we are PT2PT with | 
|  | 6361 | * another NPort and the other side has initiated | 
|  | 6362 | * the PLOGI before responding to our FLOGI. | 
|  | 6363 | */ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6364 | } | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6365 |  | 
|  | 6366 | shost = lpfc_shost_from_vport(vport); | 
|  | 6367 | spin_lock_irq(shost->host_lock); | 
|  | 6368 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; | 
|  | 6369 | spin_unlock_irq(shost->host_lock); | 
|  | 6370 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6371 | lpfc_disc_state_machine(vport, ndlp, elsiocb, | 
|  | 6372 | NLP_EVT_RCV_PLOGI); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6373 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6374 | break; | 
|  | 6375 | case ELS_CMD_FLOGI: | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6376 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 6377 | "RCV FLOGI:       did:x%x/ste:x%x flg:x%x", | 
|  | 6378 | did, vport->port_state, ndlp->nlp_flag); | 
|  | 6379 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6380 | phba->fc_stat.elsRcvFLOGI++; | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6381 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6382 | if (newnode) | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6383 | lpfc_nlp_put(ndlp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6384 | break; | 
|  | 6385 | case ELS_CMD_LOGO: | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6386 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 6387 | "RCV LOGO:        did:x%x/ste:x%x flg:x%x", | 
|  | 6388 | did, vport->port_state, ndlp->nlp_flag); | 
|  | 6389 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6390 | phba->fc_stat.elsRcvLOGO++; | 
| James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6391 | lpfc_send_els_event(vport, ndlp, payload); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6392 | if (vport->port_state < LPFC_DISC_AUTH) { | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6393 | rjt_err = LSRJT_UNABLE_TPC; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6394 | break; | 
|  | 6395 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6396 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6397 | break; | 
|  | 6398 | case ELS_CMD_PRLO: | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6399 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 6400 | "RCV PRLO:        did:x%x/ste:x%x flg:x%x", | 
|  | 6401 | did, vport->port_state, ndlp->nlp_flag); | 
|  | 6402 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6403 | phba->fc_stat.elsRcvPRLO++; | 
| James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6404 | lpfc_send_els_event(vport, ndlp, payload); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6405 | if (vport->port_state < LPFC_DISC_AUTH) { | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6406 | rjt_err = LSRJT_UNABLE_TPC; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6407 | break; | 
|  | 6408 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6409 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6410 | break; | 
|  | 6411 | case ELS_CMD_RSCN: | 
|  | 6412 | phba->fc_stat.elsRcvRSCN++; | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 6413 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6414 | if (newnode) | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6415 | lpfc_nlp_put(ndlp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6416 | break; | 
|  | 6417 | case ELS_CMD_ADISC: | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6418 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 6419 | "RCV ADISC:       did:x%x/ste:x%x flg:x%x", | 
|  | 6420 | did, vport->port_state, ndlp->nlp_flag); | 
|  | 6421 |  | 
| James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 6422 | lpfc_send_els_event(vport, ndlp, payload); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6423 | phba->fc_stat.elsRcvADISC++; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6424 | if (vport->port_state < LPFC_DISC_AUTH) { | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6425 | rjt_err = LSRJT_UNABLE_TPC; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6426 | break; | 
|  | 6427 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6428 | lpfc_disc_state_machine(vport, ndlp, elsiocb, | 
|  | 6429 | NLP_EVT_RCV_ADISC); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6430 | break; | 
|  | 6431 | case ELS_CMD_PDISC: | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6432 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 6433 | "RCV PDISC:       did:x%x/ste:x%x flg:x%x", | 
|  | 6434 | did, vport->port_state, ndlp->nlp_flag); | 
|  | 6435 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6436 | phba->fc_stat.elsRcvPDISC++; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6437 | if (vport->port_state < LPFC_DISC_AUTH) { | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6438 | rjt_err = LSRJT_UNABLE_TPC; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6439 | break; | 
|  | 6440 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6441 | lpfc_disc_state_machine(vport, ndlp, elsiocb, | 
|  | 6442 | NLP_EVT_RCV_PDISC); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6443 | break; | 
|  | 6444 | case ELS_CMD_FARPR: | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6445 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 6446 | "RCV FARPR:       did:x%x/ste:x%x flg:x%x", | 
|  | 6447 | did, vport->port_state, ndlp->nlp_flag); | 
|  | 6448 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6449 | phba->fc_stat.elsRcvFARPR++; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6450 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6451 | break; | 
|  | 6452 | case ELS_CMD_FARP: | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6453 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 6454 | "RCV FARP:        did:x%x/ste:x%x flg:x%x", | 
|  | 6455 | did, vport->port_state, ndlp->nlp_flag); | 
|  | 6456 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6457 | phba->fc_stat.elsRcvFARP++; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6458 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6459 | break; | 
|  | 6460 | case ELS_CMD_FAN: | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6461 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 6462 | "RCV FAN:         did:x%x/ste:x%x flg:x%x", | 
|  | 6463 | did, vport->port_state, ndlp->nlp_flag); | 
|  | 6464 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6465 | phba->fc_stat.elsRcvFAN++; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6466 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6467 | break; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6468 | case ELS_CMD_PRLI: | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6469 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 6470 | "RCV PRLI:        did:x%x/ste:x%x flg:x%x", | 
|  | 6471 | did, vport->port_state, ndlp->nlp_flag); | 
|  | 6472 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6473 | phba->fc_stat.elsRcvPRLI++; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6474 | if (vport->port_state < LPFC_DISC_AUTH) { | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6475 | rjt_err = LSRJT_UNABLE_TPC; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6476 | break; | 
|  | 6477 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6478 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6479 | break; | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6480 | case ELS_CMD_LIRR: | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6481 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 6482 | "RCV LIRR:        did:x%x/ste:x%x flg:x%x", | 
|  | 6483 | did, vport->port_state, ndlp->nlp_flag); | 
|  | 6484 |  | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6485 | phba->fc_stat.elsRcvLIRR++; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6486 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6487 | if (newnode) | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6488 | lpfc_nlp_put(ndlp); | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6489 | break; | 
| James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6490 | case ELS_CMD_RLS: | 
|  | 6491 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 6492 | "RCV RLS:         did:x%x/ste:x%x flg:x%x", | 
|  | 6493 | did, vport->port_state, ndlp->nlp_flag); | 
|  | 6494 |  | 
|  | 6495 | phba->fc_stat.elsRcvRLS++; | 
|  | 6496 | lpfc_els_rcv_rls(vport, elsiocb, ndlp); | 
|  | 6497 | if (newnode) | 
|  | 6498 | lpfc_nlp_put(ndlp); | 
|  | 6499 | break; | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6500 | case ELS_CMD_RPS: | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6501 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 6502 | "RCV RPS:         did:x%x/ste:x%x flg:x%x", | 
|  | 6503 | did, vport->port_state, ndlp->nlp_flag); | 
|  | 6504 |  | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6505 | phba->fc_stat.elsRcvRPS++; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6506 | lpfc_els_rcv_rps(vport, elsiocb, ndlp); | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6507 | if (newnode) | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6508 | lpfc_nlp_put(ndlp); | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6509 | break; | 
|  | 6510 | case ELS_CMD_RPL: | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6511 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 6512 | "RCV RPL:         did:x%x/ste:x%x flg:x%x", | 
|  | 6513 | did, vport->port_state, ndlp->nlp_flag); | 
|  | 6514 |  | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6515 | phba->fc_stat.elsRcvRPL++; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6516 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6517 | if (newnode) | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6518 | lpfc_nlp_put(ndlp); | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 6519 | break; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6520 | case ELS_CMD_RNID: | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6521 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 6522 | "RCV RNID:        did:x%x/ste:x%x flg:x%x", | 
|  | 6523 | did, vport->port_state, ndlp->nlp_flag); | 
|  | 6524 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6525 | phba->fc_stat.elsRcvRNID++; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6526 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6527 | if (newnode) | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6528 | lpfc_nlp_put(ndlp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6529 | break; | 
| James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6530 | case ELS_CMD_RTV: | 
|  | 6531 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 6532 | "RCV RTV:        did:x%x/ste:x%x flg:x%x", | 
|  | 6533 | did, vport->port_state, ndlp->nlp_flag); | 
|  | 6534 | phba->fc_stat.elsRcvRTV++; | 
|  | 6535 | lpfc_els_rcv_rtv(vport, elsiocb, ndlp); | 
|  | 6536 | if (newnode) | 
|  | 6537 | lpfc_nlp_put(ndlp); | 
|  | 6538 | break; | 
| James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6539 | case ELS_CMD_RRQ: | 
|  | 6540 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 6541 | "RCV RRQ:         did:x%x/ste:x%x flg:x%x", | 
|  | 6542 | did, vport->port_state, ndlp->nlp_flag); | 
|  | 6543 |  | 
|  | 6544 | phba->fc_stat.elsRcvRRQ++; | 
|  | 6545 | lpfc_els_rcv_rrq(vport, elsiocb, ndlp); | 
|  | 6546 | if (newnode) | 
|  | 6547 | lpfc_nlp_put(ndlp); | 
|  | 6548 | break; | 
| James Smart | 12265f6 | 2010-10-22 11:05:53 -0400 | [diff] [blame] | 6549 | case ELS_CMD_ECHO: | 
|  | 6550 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 6551 | "RCV ECHO:        did:x%x/ste:x%x flg:x%x", | 
|  | 6552 | did, vport->port_state, ndlp->nlp_flag); | 
|  | 6553 |  | 
|  | 6554 | phba->fc_stat.elsRcvECHO++; | 
|  | 6555 | lpfc_els_rcv_echo(vport, elsiocb, ndlp); | 
|  | 6556 | if (newnode) | 
|  | 6557 | lpfc_nlp_put(ndlp); | 
|  | 6558 | break; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6559 | default: | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6560 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 6561 | "RCV ELS cmd:     cmd:x%x did:x%x/ste:x%x", | 
|  | 6562 | cmd, did, vport->port_state); | 
|  | 6563 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6564 | /* Unsupported ELS command, reject */ | 
| James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 6565 | rjt_err = LSRJT_CMD_UNSUPPORTED; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6566 |  | 
|  | 6567 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6568 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 6569 | "0115 Unknown ELS command x%x " | 
|  | 6570 | "received from NPORT x%x\n", cmd, did); | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 6571 | if (newnode) | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6572 | lpfc_nlp_put(ndlp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6573 | break; | 
|  | 6574 | } | 
|  | 6575 |  | 
|  | 6576 | /* check if need to LS_RJT received ELS cmd */ | 
|  | 6577 | if (rjt_err) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6578 | memset(&stat, 0, sizeof(stat)); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6579 | stat.un.b.lsRjtRsnCode = rjt_err; | 
| James.Smart@Emulex.Com | 1f679ca | 2005-06-25 10:34:27 -0400 | [diff] [blame] | 6580 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6581 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, | 
|  | 6582 | NULL); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6583 | } | 
|  | 6584 |  | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6585 | lpfc_nlp_put(elsiocb->context1); | 
|  | 6586 | elsiocb->context1 = NULL; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6587 | return; | 
|  | 6588 |  | 
|  | 6589 | dropit: | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6590 | if (vport && !(vport->load_flag & FC_UNLOADING)) | 
| James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6591 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 6592 | "0111 Dropping received ELS cmd " | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6593 | "Data: x%x x%x x%x\n", | 
| James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6594 | icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout); | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6595 | phba->fc_stat.elsRcvDrop++; | 
|  | 6596 | } | 
|  | 6597 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6598 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6599 | * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6600 | * @phba: pointer to lpfc hba data structure. | 
|  | 6601 | * @vpi: host virtual N_Port identifier. | 
|  | 6602 | * | 
|  | 6603 | * This routine finds a vport on a HBA (referred by @phba) through a | 
|  | 6604 | * @vpi. The function walks the HBA's vport list and returns the address | 
|  | 6605 | * of the vport with the matching @vpi. | 
|  | 6606 | * | 
|  | 6607 | * Return code | 
|  | 6608 | *    NULL - No vport with the matching @vpi found | 
|  | 6609 | *    Otherwise - Address to the vport with the matching @vpi. | 
|  | 6610 | **/ | 
| James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 6611 | struct lpfc_vport * | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6612 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) | 
|  | 6613 | { | 
|  | 6614 | struct lpfc_vport *vport; | 
| James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6615 | unsigned long flags; | 
| James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 6616 | int i = 0; | 
| James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6617 |  | 
|  | 6618 | /* The physical ports are always vpi 0 - translate is unnecessary. */ | 
|  | 6619 | if (vpi > 0) { | 
|  | 6620 | /* | 
|  | 6621 | * Translate the physical vpi to the logical vpi.  The | 
|  | 6622 | * vport stores the logical vpi. | 
|  | 6623 | */ | 
|  | 6624 | for (i = 0; i < phba->max_vpi; i++) { | 
|  | 6625 | if (vpi == phba->vpi_ids[i]) | 
|  | 6626 | break; | 
|  | 6627 | } | 
|  | 6628 |  | 
|  | 6629 | if (i >= phba->max_vpi) { | 
|  | 6630 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, | 
|  | 6631 | "2936 Could not find Vport mapped " | 
|  | 6632 | "to vpi %d\n", vpi); | 
|  | 6633 | return NULL; | 
|  | 6634 | } | 
|  | 6635 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6636 |  | 
| James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6637 | spin_lock_irqsave(&phba->hbalock, flags); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6638 | list_for_each_entry(vport, &phba->port_list, listentry) { | 
| James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 6639 | if (vport->vpi == i) { | 
| James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6640 | spin_unlock_irqrestore(&phba->hbalock, flags); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6641 | return vport; | 
| James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6642 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6643 | } | 
| James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 6644 | spin_unlock_irqrestore(&phba->hbalock, flags); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6645 | return NULL; | 
|  | 6646 | } | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6647 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6648 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6649 | * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6650 | * @phba: pointer to lpfc hba data structure. | 
|  | 6651 | * @pring: pointer to a SLI ring. | 
|  | 6652 | * @elsiocb: pointer to lpfc els iocb data structure. | 
|  | 6653 | * | 
|  | 6654 | * This routine is used to process an unsolicited event received from a SLI | 
|  | 6655 | * (Service Level Interface) ring. The actual processing of the data buffer | 
|  | 6656 | * associated with the unsolicited event is done by invoking the routine | 
|  | 6657 | * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the | 
|  | 6658 | * SLI ring on which the unsolicited event was received. | 
|  | 6659 | **/ | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6660 | void | 
|  | 6661 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | 
|  | 6662 | struct lpfc_iocbq *elsiocb) | 
|  | 6663 | { | 
|  | 6664 | struct lpfc_vport *vport = phba->pport; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6665 | IOCB_t *icmd = &elsiocb->iocb; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6666 | dma_addr_t paddr; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6667 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; | 
|  | 6668 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6669 |  | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 6670 | elsiocb->context1 = NULL; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6671 | elsiocb->context2 = NULL; | 
|  | 6672 | elsiocb->context3 = NULL; | 
|  | 6673 |  | 
|  | 6674 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { | 
|  | 6675 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); | 
|  | 6676 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && | 
|  | 6677 | (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) { | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6678 | phba->fc_stat.NoRcvBuf++; | 
|  | 6679 | /* Not enough posted buffers; Try posting more buffers */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6680 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) | 
| James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 6681 | lpfc_post_buffer(phba, pring, 0); | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6682 | return; | 
|  | 6683 | } | 
|  | 6684 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6685 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && | 
|  | 6686 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || | 
|  | 6687 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { | 
|  | 6688 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) | 
|  | 6689 | vport = phba->pport; | 
| James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6690 | else | 
|  | 6691 | vport = lpfc_find_vport_by_vpid(phba, | 
| James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6692 | icmd->unsli3.rcvsli3.vpi); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6693 | } | 
| James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6694 |  | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6695 | /* If there are no BDEs associated | 
|  | 6696 | * with this IOCB, there is nothing to do. | 
|  | 6697 | */ | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6698 | if (icmd->ulpBdeCount == 0) | 
|  | 6699 | return; | 
|  | 6700 |  | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6701 | /* type of ELS cmd is first 32bit word | 
|  | 6702 | * in packet | 
|  | 6703 | */ | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6704 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6705 | elsiocb->context2 = bdeBuf1; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6706 | } else { | 
|  | 6707 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, | 
|  | 6708 | icmd->un.cont64[0].addrLow); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6709 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, | 
|  | 6710 | paddr); | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6711 | } | 
|  | 6712 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6713 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); | 
|  | 6714 | /* | 
|  | 6715 | * The different unsolicited event handlers would tell us | 
|  | 6716 | * if they are done with "mp" by setting context2 to NULL. | 
|  | 6717 | */ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6718 | if (elsiocb->context2) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6719 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); | 
|  | 6720 | elsiocb->context2 = NULL; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6721 | } | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6722 |  | 
|  | 6723 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6724 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6725 | icmd->ulpBdeCount == 2) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6726 | elsiocb->context2 = bdeBuf2; | 
|  | 6727 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6728 | /* free mp if we are done with it */ | 
|  | 6729 | if (elsiocb->context2) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6730 | lpfc_in_buf_free(phba, elsiocb->context2); | 
|  | 6731 | elsiocb->context2 = NULL; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 6732 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6733 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6734 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6735 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6736 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6737 | * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6738 | * @phba: pointer to lpfc hba data structure. | 
|  | 6739 | * @vport: pointer to a virtual N_Port data structure. | 
|  | 6740 | * | 
|  | 6741 | * This routine issues a Port Login (PLOGI) to the Name Server with | 
|  | 6742 | * State Change Request (SCR) for a @vport. This routine will create an | 
|  | 6743 | * ndlp for the Name Server associated to the @vport if such node does | 
|  | 6744 | * not already exist. The PLOGI to Name Server is issued by invoking the | 
|  | 6745 | * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface | 
|  | 6746 | * (FDMI) is configured to the @vport, a FDMI node will be created and | 
|  | 6747 | * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. | 
|  | 6748 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6749 | void | 
|  | 6750 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) | 
|  | 6751 | { | 
|  | 6752 | struct lpfc_nodelist *ndlp, *ndlp_fdmi; | 
| James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 6753 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | 6754 |  | 
|  | 6755 | /* | 
|  | 6756 | * If lpfc_delay_discovery parameter is set and the clean address | 
|  | 6757 | * bit is cleared and fc fabric parameters chenged, delay FC NPort | 
|  | 6758 | * discovery. | 
|  | 6759 | */ | 
|  | 6760 | spin_lock_irq(shost->host_lock); | 
|  | 6761 | if (vport->fc_flag & FC_DISC_DELAYED) { | 
|  | 6762 | spin_unlock_irq(shost->host_lock); | 
|  | 6763 | mod_timer(&vport->delayed_disc_tmo, | 
|  | 6764 | jiffies + HZ * phba->fc_ratov); | 
|  | 6765 | return; | 
|  | 6766 | } | 
|  | 6767 | spin_unlock_irq(shost->host_lock); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6768 |  | 
|  | 6769 | ndlp = lpfc_findnode_did(vport, NameServer_DID); | 
|  | 6770 | if (!ndlp) { | 
|  | 6771 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | 
|  | 6772 | if (!ndlp) { | 
| James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6773 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6774 | lpfc_disc_start(vport); | 
|  | 6775 | return; | 
|  | 6776 | } | 
|  | 6777 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6778 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 6779 | "0251 NameServer login: no memory\n"); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6780 | return; | 
|  | 6781 | } | 
|  | 6782 | lpfc_nlp_init(vport, ndlp, NameServer_DID); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6783 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | 
|  | 6784 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | 
|  | 6785 | if (!ndlp) { | 
| James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6786 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6787 | lpfc_disc_start(vport); | 
|  | 6788 | return; | 
|  | 6789 | } | 
|  | 6790 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | 
|  | 6791 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 6792 | "0348 NameServer login: node freed\n"); | 
|  | 6793 | return; | 
|  | 6794 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6795 | } | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6796 | ndlp->nlp_type |= NLP_FABRIC; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6797 |  | 
|  | 6798 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); | 
|  | 6799 |  | 
|  | 6800 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { | 
|  | 6801 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6802 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 6803 | "0252 Cannot issue NameServer login\n"); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6804 | return; | 
|  | 6805 | } | 
|  | 6806 |  | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6807 | if (vport->cfg_fdmi_on) { | 
| James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 6808 | /* If this is the first time, allocate an ndlp and initialize | 
|  | 6809 | * it. Otherwise, make sure the node is enabled and then do the | 
|  | 6810 | * login. | 
|  | 6811 | */ | 
|  | 6812 | ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID); | 
|  | 6813 | if (!ndlp_fdmi) { | 
|  | 6814 | ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool, | 
|  | 6815 | GFP_KERNEL); | 
|  | 6816 | if (ndlp_fdmi) { | 
|  | 6817 | lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID); | 
|  | 6818 | ndlp_fdmi->nlp_type |= NLP_FABRIC; | 
|  | 6819 | } else | 
|  | 6820 | return; | 
|  | 6821 | } | 
|  | 6822 | if (!NLP_CHK_NODE_ACT(ndlp_fdmi)) | 
|  | 6823 | ndlp_fdmi = lpfc_enable_node(vport, | 
|  | 6824 | ndlp_fdmi, | 
|  | 6825 | NLP_STE_NPR_NODE); | 
|  | 6826 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6827 | if (ndlp_fdmi) { | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 6828 | lpfc_nlp_set_state(vport, ndlp_fdmi, | 
| James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 6829 | NLP_STE_PLOGI_ISSUE); | 
|  | 6830 | lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6831 | } | 
|  | 6832 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6833 | } | 
|  | 6834 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6835 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6836 | * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6837 | * @phba: pointer to lpfc hba data structure. | 
|  | 6838 | * @pmb: pointer to the driver internal queue element for mailbox command. | 
|  | 6839 | * | 
|  | 6840 | * This routine is the completion callback function to register new vport | 
|  | 6841 | * mailbox command. If the new vport mailbox command completes successfully, | 
|  | 6842 | * the fabric registration login shall be performed on physical port (the | 
|  | 6843 | * new vport created is actually a physical port, with VPI 0) or the port | 
|  | 6844 | * login to Name Server for State Change Request (SCR) will be performed | 
|  | 6845 | * on virtual port (real virtual port, with VPI greater than 0). | 
|  | 6846 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6847 | static void | 
|  | 6848 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) | 
|  | 6849 | { | 
|  | 6850 | struct lpfc_vport *vport = pmb->vport; | 
|  | 6851 | struct Scsi_Host  *shost = lpfc_shost_from_vport(vport); | 
|  | 6852 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; | 
| James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 6853 | MAILBOX_t *mb = &pmb->u.mb; | 
| James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6854 | int rc; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6855 |  | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6856 | spin_lock_irq(shost->host_lock); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6857 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6858 | spin_unlock_irq(shost->host_lock); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6859 |  | 
|  | 6860 | if (mb->mbxStatus) { | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6861 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, | 
| James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6862 | "0915 Register VPI failed : Status: x%x" | 
|  | 6863 | " upd bit: x%x \n", mb->mbxStatus, | 
|  | 6864 | mb->un.varRegVpi.upd); | 
|  | 6865 | if (phba->sli_rev == LPFC_SLI_REV4 && | 
|  | 6866 | mb->un.varRegVpi.upd) | 
|  | 6867 | goto mbox_err_exit ; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6868 |  | 
|  | 6869 | switch (mb->mbxStatus) { | 
|  | 6870 | case 0x11:	/* unsupported feature */ | 
|  | 6871 | case 0x9603:	/* max_vpi exceeded */ | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6872 | case 0x9602:	/* Link event since CLEAR_LA */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6873 | /* giving up on vport registration */ | 
|  | 6874 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | 
|  | 6875 | spin_lock_irq(shost->host_lock); | 
|  | 6876 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); | 
|  | 6877 | spin_unlock_irq(shost->host_lock); | 
|  | 6878 | lpfc_can_disctmo(vport); | 
|  | 6879 | break; | 
| James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6880 | /* If reg_vpi fail with invalid VPI status, re-init VPI */ | 
|  | 6881 | case 0x20: | 
|  | 6882 | spin_lock_irq(shost->host_lock); | 
|  | 6883 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; | 
|  | 6884 | spin_unlock_irq(shost->host_lock); | 
|  | 6885 | lpfc_init_vpi(phba, pmb, vport->vpi); | 
|  | 6886 | pmb->vport = vport; | 
|  | 6887 | pmb->mbox_cmpl = lpfc_init_vpi_cmpl; | 
|  | 6888 | rc = lpfc_sli_issue_mbox(phba, pmb, | 
|  | 6889 | MBX_NOWAIT); | 
|  | 6890 | if (rc == MBX_NOT_FINISHED) { | 
|  | 6891 | lpfc_printf_vlog(vport, | 
|  | 6892 | KERN_ERR, LOG_MBOX, | 
|  | 6893 | "2732 Failed to issue INIT_VPI" | 
|  | 6894 | " mailbox command\n"); | 
|  | 6895 | } else { | 
|  | 6896 | lpfc_nlp_put(ndlp); | 
|  | 6897 | return; | 
|  | 6898 | } | 
|  | 6899 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6900 | default: | 
|  | 6901 | /* Try to recover from this error */ | 
| James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 6902 | if (phba->sli_rev == LPFC_SLI_REV4) | 
|  | 6903 | lpfc_sli4_unreg_all_rpis(vport); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6904 | lpfc_mbx_unreg_vpi(vport); | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6905 | spin_lock_irq(shost->host_lock); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6906 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6907 | spin_unlock_irq(shost->host_lock); | 
| James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 6908 | if (vport->port_type == LPFC_PHYSICAL_PORT | 
|  | 6909 | && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) | 
| James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6910 | lpfc_issue_init_vfi(vport); | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6911 | else | 
|  | 6912 | lpfc_initial_fdisc(vport); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6913 | break; | 
|  | 6914 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6915 | } else { | 
| James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6916 | spin_lock_irq(shost->host_lock); | 
| James Smart | 1987807 | 2009-12-21 17:02:00 -0500 | [diff] [blame] | 6917 | vport->vpi_state |= LPFC_VPI_REGISTERED; | 
| James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6918 | spin_unlock_irq(shost->host_lock); | 
|  | 6919 | if (vport == phba->pport) { | 
| James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6920 | if (phba->sli_rev < LPFC_SLI_REV4) | 
|  | 6921 | lpfc_issue_fabric_reglogin(vport); | 
| James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6922 | else { | 
| James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6923 | /* | 
|  | 6924 | * If the physical port is instantiated using | 
|  | 6925 | * FDISC, do not start vport discovery. | 
|  | 6926 | */ | 
|  | 6927 | if (vport->port_state != LPFC_FDISC) | 
|  | 6928 | lpfc_start_fdiscs(phba); | 
| James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6929 | lpfc_do_scr_ns_plogi(phba, vport); | 
|  | 6930 | } | 
|  | 6931 | } else | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6932 | lpfc_do_scr_ns_plogi(phba, vport); | 
|  | 6933 | } | 
| James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6934 | mbox_err_exit: | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6935 | /* Now, we decrement the ndlp reference count held for this | 
|  | 6936 | * callback function | 
|  | 6937 | */ | 
|  | 6938 | lpfc_nlp_put(ndlp); | 
|  | 6939 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6940 | mempool_free(pmb, phba->mbox_mem_pool); | 
|  | 6941 | return; | 
|  | 6942 | } | 
|  | 6943 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6944 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6945 | * lpfc_register_new_vport - Register a new vport with a HBA | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6946 | * @phba: pointer to lpfc hba data structure. | 
|  | 6947 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 6948 | * @ndlp: pointer to a node-list data structure. | 
|  | 6949 | * | 
|  | 6950 | * This routine registers the @vport as a new virtual port with a HBA. | 
|  | 6951 | * It is done through a registering vpi mailbox command. | 
|  | 6952 | **/ | 
| James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6953 | void | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6954 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, | 
|  | 6955 | struct lpfc_nodelist *ndlp) | 
|  | 6956 | { | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 6957 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6958 | LPFC_MBOXQ_t *mbox; | 
|  | 6959 |  | 
|  | 6960 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | 
|  | 6961 | if (mbox) { | 
| James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 6962 | lpfc_reg_vpi(vport, mbox); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6963 | mbox->vport = vport; | 
|  | 6964 | mbox->context2 = lpfc_nlp_get(ndlp); | 
|  | 6965 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; | 
| James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 6966 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6967 | == MBX_NOT_FINISHED) { | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6968 | /* mailbox command not success, decrement ndlp | 
|  | 6969 | * reference count for this command | 
|  | 6970 | */ | 
|  | 6971 | lpfc_nlp_put(ndlp); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6972 | mempool_free(mbox, phba->mbox_mem_pool); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6973 |  | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6974 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, | 
|  | 6975 | "0253 Register VPI: Can't send mbox\n"); | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6976 | goto mbox_err_exit; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6977 | } | 
|  | 6978 | } else { | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6979 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, | 
|  | 6980 | "0254 Register VPI: no memory\n"); | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6981 | goto mbox_err_exit; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6982 | } | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 6983 | return; | 
|  | 6984 |  | 
|  | 6985 | mbox_err_exit: | 
|  | 6986 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | 
|  | 6987 | spin_lock_irq(shost->host_lock); | 
|  | 6988 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; | 
|  | 6989 | spin_unlock_irq(shost->host_lock); | 
|  | 6990 | return; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6991 | } | 
|  | 6992 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6993 | /** | 
| James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6994 | * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer | 
| James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6995 | * @phba: pointer to lpfc hba data structure. | 
|  | 6996 | * | 
| James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6997 | * This routine cancels the retry delay timers to all the vports. | 
| James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6998 | **/ | 
|  | 6999 | void | 
| James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 7000 | lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba) | 
| James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7001 | { | 
|  | 7002 | struct lpfc_vport **vports; | 
|  | 7003 | struct lpfc_nodelist *ndlp; | 
| James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7004 | uint32_t link_state; | 
| James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 7005 | int i; | 
| James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7006 |  | 
|  | 7007 | /* Treat this failure as linkdown for all vports */ | 
|  | 7008 | link_state = phba->link_state; | 
|  | 7009 | lpfc_linkdown(phba); | 
|  | 7010 | phba->link_state = link_state; | 
|  | 7011 |  | 
|  | 7012 | vports = lpfc_create_vport_work_array(phba); | 
|  | 7013 |  | 
|  | 7014 | if (vports) { | 
|  | 7015 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { | 
|  | 7016 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); | 
|  | 7017 | if (ndlp) | 
|  | 7018 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); | 
|  | 7019 | lpfc_els_flush_cmd(vports[i]); | 
|  | 7020 | } | 
|  | 7021 | lpfc_destroy_vport_work_array(phba, vports); | 
|  | 7022 | } | 
| James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 7023 | } | 
|  | 7024 |  | 
|  | 7025 | /** | 
|  | 7026 | * lpfc_retry_pport_discovery - Start timer to retry FLOGI. | 
|  | 7027 | * @phba: pointer to lpfc hba data structure. | 
|  | 7028 | * | 
|  | 7029 | * This routine abort all pending discovery commands and | 
|  | 7030 | * start a timer to retry FLOGI for the physical port | 
|  | 7031 | * discovery. | 
|  | 7032 | **/ | 
|  | 7033 | void | 
|  | 7034 | lpfc_retry_pport_discovery(struct lpfc_hba *phba) | 
|  | 7035 | { | 
|  | 7036 | struct lpfc_nodelist *ndlp; | 
|  | 7037 | struct Scsi_Host  *shost; | 
|  | 7038 |  | 
|  | 7039 | /* Cancel the all vports retry delay retry timers */ | 
|  | 7040 | lpfc_cancel_all_vport_retry_delay_timer(phba); | 
| James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7041 |  | 
|  | 7042 | /* If fabric require FLOGI, then re-instantiate physical login */ | 
|  | 7043 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); | 
|  | 7044 | if (!ndlp) | 
|  | 7045 | return; | 
|  | 7046 |  | 
| James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7047 | shost = lpfc_shost_from_vport(phba->pport); | 
|  | 7048 | mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ); | 
|  | 7049 | spin_lock_irq(shost->host_lock); | 
|  | 7050 | ndlp->nlp_flag |= NLP_DELAY_TMO; | 
|  | 7051 | spin_unlock_irq(shost->host_lock); | 
|  | 7052 | ndlp->nlp_last_elscmd = ELS_CMD_FLOGI; | 
|  | 7053 | phba->pport->port_state = LPFC_FLOGI; | 
|  | 7054 | return; | 
|  | 7055 | } | 
|  | 7056 |  | 
|  | 7057 | /** | 
|  | 7058 | * lpfc_fabric_login_reqd - Check if FLOGI required. | 
|  | 7059 | * @phba: pointer to lpfc hba data structure. | 
|  | 7060 | * @cmdiocb: pointer to FDISC command iocb. | 
|  | 7061 | * @rspiocb: pointer to FDISC response iocb. | 
|  | 7062 | * | 
|  | 7063 | * This routine checks if a FLOGI is reguired for FDISC | 
|  | 7064 | * to succeed. | 
|  | 7065 | **/ | 
|  | 7066 | static int | 
|  | 7067 | lpfc_fabric_login_reqd(struct lpfc_hba *phba, | 
|  | 7068 | struct lpfc_iocbq *cmdiocb, | 
|  | 7069 | struct lpfc_iocbq *rspiocb) | 
|  | 7070 | { | 
|  | 7071 |  | 
|  | 7072 | if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) || | 
|  | 7073 | (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED)) | 
|  | 7074 | return 0; | 
|  | 7075 | else | 
|  | 7076 | return 1; | 
|  | 7077 | } | 
|  | 7078 |  | 
|  | 7079 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7080 | * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7081 | * @phba: pointer to lpfc hba data structure. | 
|  | 7082 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 7083 | * @rspiocb: pointer to lpfc response iocb data structure. | 
|  | 7084 | * | 
|  | 7085 | * This routine is the completion callback function to a Fabric Discover | 
|  | 7086 | * (FDISC) ELS command. Since all the FDISC ELS commands are issued | 
|  | 7087 | * single threaded, each FDISC completion callback function will reset | 
|  | 7088 | * the discovery timer for all vports such that the timers will not get | 
|  | 7089 | * unnecessary timeout. The function checks the FDISC IOCB status. If error | 
|  | 7090 | * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the | 
|  | 7091 | * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID | 
|  | 7092 | * assigned to the vport has been changed with the completion of the FDISC | 
|  | 7093 | * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) | 
|  | 7094 | * are unregistered from the HBA, and then the lpfc_register_new_vport() | 
|  | 7095 | * routine is invoked to register new vport with the HBA. Otherwise, the | 
|  | 7096 | * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name | 
|  | 7097 | * Server for State Change Request (SCR). | 
|  | 7098 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7099 | static void | 
|  | 7100 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | 
|  | 7101 | struct lpfc_iocbq *rspiocb) | 
|  | 7102 | { | 
|  | 7103 | struct lpfc_vport *vport = cmdiocb->vport; | 
|  | 7104 | struct Scsi_Host  *shost = lpfc_shost_from_vport(vport); | 
|  | 7105 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; | 
|  | 7106 | struct lpfc_nodelist *np; | 
|  | 7107 | struct lpfc_nodelist *next_np; | 
|  | 7108 | IOCB_t *irsp = &rspiocb->iocb; | 
|  | 7109 | struct lpfc_iocbq *piocb; | 
| James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 7110 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; | 
|  | 7111 | struct serv_parm *sp; | 
|  | 7112 | uint8_t fabric_param_changed; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7113 |  | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7114 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 7115 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", | 
|  | 7116 | irsp->ulpStatus, irsp->un.ulpWord[4], | 
|  | 7117 | vport->fc_prevDID); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7118 | /* Since all FDISCs are being single threaded, we | 
|  | 7119 | * must reset the discovery timer for ALL vports | 
|  | 7120 | * waiting to send FDISC when one completes. | 
|  | 7121 | */ | 
|  | 7122 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { | 
|  | 7123 | lpfc_set_disctmo(piocb->vport); | 
|  | 7124 | } | 
|  | 7125 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7126 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 7127 | "FDISC cmpl:      status:x%x/x%x prevdid:x%x", | 
|  | 7128 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); | 
|  | 7129 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7130 | if (irsp->ulpStatus) { | 
| James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7131 |  | 
|  | 7132 | if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) { | 
|  | 7133 | lpfc_retry_pport_discovery(phba); | 
|  | 7134 | goto out; | 
|  | 7135 | } | 
|  | 7136 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7137 | /* Check for retry */ | 
|  | 7138 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) | 
|  | 7139 | goto out; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7140 | /* FDISC failed */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7141 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7142 | "0126 FDISC failed. (%d/%d)\n", | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7143 | irsp->ulpStatus, irsp->un.ulpWord[4]); | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7144 | goto fdisc_failed; | 
|  | 7145 | } | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7146 | spin_lock_irq(shost->host_lock); | 
| James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 7147 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; | 
| James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 7148 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7149 | vport->fc_flag |= FC_FABRIC; | 
| James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7150 | if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP) | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7151 | vport->fc_flag |=  FC_PUBLIC_LOOP; | 
|  | 7152 | spin_unlock_irq(shost->host_lock); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7153 |  | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7154 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; | 
|  | 7155 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); | 
| James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 7156 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); | 
|  | 7157 | sp = prsp->virt + sizeof(uint32_t); | 
|  | 7158 | fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp); | 
|  | 7159 | memcpy(&vport->fabric_portname, &sp->portName, | 
|  | 7160 | sizeof(struct lpfc_name)); | 
|  | 7161 | memcpy(&vport->fabric_nodename, &sp->nodeName, | 
|  | 7162 | sizeof(struct lpfc_name)); | 
|  | 7163 | if (fabric_param_changed && | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7164 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { | 
|  | 7165 | /* If our NportID changed, we need to ensure all | 
|  | 7166 | * remaining NPORTs get unreg_login'ed so we can | 
|  | 7167 | * issue unreg_vpi. | 
|  | 7168 | */ | 
|  | 7169 | list_for_each_entry_safe(np, next_np, | 
|  | 7170 | &vport->fc_nodes, nlp_listp) { | 
|  | 7171 | if (!NLP_CHK_NODE_ACT(ndlp) || | 
|  | 7172 | (np->nlp_state != NLP_STE_NPR_NODE) || | 
|  | 7173 | !(np->nlp_flag & NLP_NPR_ADISC)) | 
|  | 7174 | continue; | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7175 | spin_lock_irq(shost->host_lock); | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7176 | np->nlp_flag &= ~NLP_NPR_ADISC; | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7177 | spin_unlock_irq(shost->host_lock); | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7178 | lpfc_unreg_rpi(vport, np); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7179 | } | 
| James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 7180 | lpfc_cleanup_pending_mbox(vport); | 
| James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 7181 |  | 
|  | 7182 | if (phba->sli_rev == LPFC_SLI_REV4) | 
|  | 7183 | lpfc_sli4_unreg_all_rpis(vport); | 
|  | 7184 |  | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7185 | lpfc_mbx_unreg_vpi(vport); | 
|  | 7186 | spin_lock_irq(shost->host_lock); | 
|  | 7187 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; | 
| James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 7188 | if (phba->sli_rev == LPFC_SLI_REV4) | 
|  | 7189 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; | 
| James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 7190 | else | 
|  | 7191 | vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG; | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7192 | spin_unlock_irq(shost->host_lock); | 
| James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 7193 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && | 
|  | 7194 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { | 
|  | 7195 | /* | 
|  | 7196 | * Driver needs to re-reg VPI in order for f/w | 
|  | 7197 | * to update the MAC address. | 
|  | 7198 | */ | 
|  | 7199 | lpfc_register_new_vport(phba, vport, ndlp); | 
| James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 7200 | goto out; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7201 | } | 
|  | 7202 |  | 
| James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 7203 | if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI) | 
|  | 7204 | lpfc_issue_init_vpi(vport); | 
|  | 7205 | else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 7206 | lpfc_register_new_vport(phba, vport, ndlp); | 
|  | 7207 | else | 
|  | 7208 | lpfc_do_scr_ns_plogi(phba, vport); | 
|  | 7209 | goto out; | 
|  | 7210 | fdisc_failed: | 
|  | 7211 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | 
|  | 7212 | /* Cancel discovery timer */ | 
|  | 7213 | lpfc_can_disctmo(vport); | 
|  | 7214 | lpfc_nlp_put(ndlp); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7215 | out: | 
|  | 7216 | lpfc_els_free_iocb(phba, cmdiocb); | 
|  | 7217 | } | 
|  | 7218 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7219 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7220 | * lpfc_issue_els_fdisc - Issue a fdisc iocb command | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7221 | * @vport: pointer to a virtual N_Port data structure. | 
|  | 7222 | * @ndlp: pointer to a node-list data structure. | 
|  | 7223 | * @retry: number of retries to the command IOCB. | 
|  | 7224 | * | 
|  | 7225 | * This routine prepares and issues a Fabric Discover (FDISC) IOCB to | 
|  | 7226 | * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() | 
|  | 7227 | * routine to issue the IOCB, which makes sure only one outstanding fabric | 
|  | 7228 | * IOCB will be sent off HBA at any given time. | 
|  | 7229 | * | 
|  | 7230 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | 
|  | 7231 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | 
|  | 7232 | * will be stored into the context1 field of the IOCB for the completion | 
|  | 7233 | * callback function to the FDISC ELS command. | 
|  | 7234 | * | 
|  | 7235 | * Return code | 
|  | 7236 | *   0 - Successfully issued fdisc iocb command | 
|  | 7237 | *   1 - Failed to issue fdisc iocb command | 
|  | 7238 | **/ | 
| Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 7239 | static int | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7240 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, | 
|  | 7241 | uint8_t retry) | 
|  | 7242 | { | 
|  | 7243 | struct lpfc_hba *phba = vport->phba; | 
|  | 7244 | IOCB_t *icmd; | 
|  | 7245 | struct lpfc_iocbq *elsiocb; | 
|  | 7246 | struct serv_parm *sp; | 
|  | 7247 | uint8_t *pcmd; | 
|  | 7248 | uint16_t cmdsize; | 
|  | 7249 | int did = ndlp->nlp_DID; | 
|  | 7250 | int rc; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7251 |  | 
| James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7252 | vport->port_state = LPFC_FDISC; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7253 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); | 
|  | 7254 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, | 
|  | 7255 | ELS_CMD_FDISC); | 
|  | 7256 | if (!elsiocb) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7257 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7258 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 7259 | "0255 Issue FDISC: no IOCB\n"); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7260 | return 1; | 
|  | 7261 | } | 
|  | 7262 |  | 
|  | 7263 | icmd = &elsiocb->iocb; | 
|  | 7264 | icmd->un.elsreq64.myID = 0; | 
|  | 7265 | icmd->un.elsreq64.fl = 1; | 
|  | 7266 |  | 
| James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 7267 | /* | 
|  | 7268 | * SLI3 ports require a different context type value than SLI4. | 
|  | 7269 | * Catch SLI3 ports here and override the prep. | 
|  | 7270 | */ | 
|  | 7271 | if (phba->sli_rev == LPFC_SLI_REV3) { | 
| James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7272 | icmd->ulpCt_h = 1; | 
|  | 7273 | icmd->ulpCt_l = 0; | 
|  | 7274 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7275 |  | 
|  | 7276 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 7277 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; | 
|  | 7278 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ | 
|  | 7279 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); | 
|  | 7280 | sp = (struct serv_parm *) pcmd; | 
|  | 7281 | /* Setup CSPs accordingly for Fabric */ | 
|  | 7282 | sp->cmn.e_d_tov = 0; | 
|  | 7283 | sp->cmn.w2.r_a_tov = 0; | 
|  | 7284 | sp->cls1.classValid = 0; | 
|  | 7285 | sp->cls2.seqDelivery = 1; | 
|  | 7286 | sp->cls3.seqDelivery = 1; | 
|  | 7287 |  | 
|  | 7288 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ | 
|  | 7289 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ | 
|  | 7290 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ | 
|  | 7291 | pcmd += sizeof(uint32_t); /* Port Name */ | 
|  | 7292 | memcpy(pcmd, &vport->fc_portname, 8); | 
|  | 7293 | pcmd += sizeof(uint32_t); /* Node Name */ | 
|  | 7294 | pcmd += sizeof(uint32_t); /* Node Name */ | 
|  | 7295 | memcpy(pcmd, &vport->fc_nodename, 8); | 
|  | 7296 |  | 
|  | 7297 | lpfc_set_disctmo(vport); | 
|  | 7298 |  | 
|  | 7299 | phba->fc_stat.elsXmitFDISC++; | 
|  | 7300 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; | 
|  | 7301 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7302 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 7303 | "Issue FDISC:     did:x%x", | 
|  | 7304 | did, 0, 0); | 
|  | 7305 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7306 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); | 
|  | 7307 | if (rc == IOCB_ERROR) { | 
|  | 7308 | lpfc_els_free_iocb(phba, elsiocb); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7309 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7310 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 7311 | "0256 Issue FDISC: Cannot send IOCB\n"); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7312 | return 1; | 
|  | 7313 | } | 
|  | 7314 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7315 | return 0; | 
|  | 7316 | } | 
|  | 7317 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7318 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7319 | * lpfc_cmpl_els_npiv_logo - Completion function with vport logo | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7320 | * @phba: pointer to lpfc hba data structure. | 
|  | 7321 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 7322 | * @rspiocb: pointer to lpfc response iocb data structure. | 
|  | 7323 | * | 
|  | 7324 | * This routine is the completion callback function to the issuing of a LOGO | 
|  | 7325 | * ELS command off a vport. It frees the command IOCB and then decrement the | 
|  | 7326 | * reference count held on ndlp for this completion function, indicating that | 
|  | 7327 | * the reference to the ndlp is no long needed. Note that the | 
|  | 7328 | * lpfc_els_free_iocb() routine decrements the ndlp reference held for this | 
|  | 7329 | * callback function and an additional explicit ndlp reference decrementation | 
|  | 7330 | * will trigger the actual release of the ndlp. | 
|  | 7331 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7332 | static void | 
|  | 7333 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | 
|  | 7334 | struct lpfc_iocbq *rspiocb) | 
|  | 7335 | { | 
|  | 7336 | struct lpfc_vport *vport = cmdiocb->vport; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7337 | IOCB_t *irsp; | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7338 | struct lpfc_nodelist *ndlp; | 
| James Smart | 9589b06 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 7339 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7340 |  | 
| James Smart | 9589b06 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 7341 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7342 | irsp = &rspiocb->iocb; | 
|  | 7343 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 7344 | "LOGO npiv cmpl:  status:x%x/x%x did:x%x", | 
|  | 7345 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7346 |  | 
|  | 7347 | lpfc_els_free_iocb(phba, cmdiocb); | 
|  | 7348 | vport->unreg_vpi_cmpl = VPORT_ERROR; | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 7349 |  | 
|  | 7350 | /* Trigger the release of the ndlp after logo */ | 
|  | 7351 | lpfc_nlp_put(ndlp); | 
| James Smart | 9589b06 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 7352 |  | 
|  | 7353 | /* NPIV LOGO completes to NPort <nlp_DID> */ | 
|  | 7354 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 7355 | "2928 NPIV LOGO completes to NPort x%x " | 
|  | 7356 | "Data: x%x x%x x%x x%x\n", | 
|  | 7357 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], | 
|  | 7358 | irsp->ulpTimeout, vport->num_disc_nodes); | 
|  | 7359 |  | 
|  | 7360 | if (irsp->ulpStatus == IOSTAT_SUCCESS) { | 
|  | 7361 | spin_lock_irq(shost->host_lock); | 
|  | 7362 | vport->fc_flag &= ~FC_FABRIC; | 
|  | 7363 | spin_unlock_irq(shost->host_lock); | 
|  | 7364 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7365 | } | 
|  | 7366 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7367 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7368 | * lpfc_issue_els_npiv_logo - Issue a logo off a vport | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7369 | * @vport: pointer to a virtual N_Port data structure. | 
|  | 7370 | * @ndlp: pointer to a node-list data structure. | 
|  | 7371 | * | 
|  | 7372 | * This routine issues a LOGO ELS command to an @ndlp off a @vport. | 
|  | 7373 | * | 
|  | 7374 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | 
|  | 7375 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | 
|  | 7376 | * will be stored into the context1 field of the IOCB for the completion | 
|  | 7377 | * callback function to the LOGO ELS command. | 
|  | 7378 | * | 
|  | 7379 | * Return codes | 
|  | 7380 | *   0 - Successfully issued logo off the @vport | 
|  | 7381 | *   1 - Failed to issue logo off the @vport | 
|  | 7382 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7383 | int | 
|  | 7384 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) | 
|  | 7385 | { | 
|  | 7386 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | 7387 | struct lpfc_hba  *phba = vport->phba; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7388 | IOCB_t *icmd; | 
|  | 7389 | struct lpfc_iocbq *elsiocb; | 
|  | 7390 | uint8_t *pcmd; | 
|  | 7391 | uint16_t cmdsize; | 
|  | 7392 |  | 
|  | 7393 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); | 
|  | 7394 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, | 
|  | 7395 | ELS_CMD_LOGO); | 
|  | 7396 | if (!elsiocb) | 
|  | 7397 | return 1; | 
|  | 7398 |  | 
|  | 7399 | icmd = &elsiocb->iocb; | 
|  | 7400 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 7401 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; | 
|  | 7402 | pcmd += sizeof(uint32_t); | 
|  | 7403 |  | 
|  | 7404 | /* Fill in LOGO payload */ | 
|  | 7405 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); | 
|  | 7406 | pcmd += sizeof(uint32_t); | 
|  | 7407 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); | 
|  | 7408 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7409 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 7410 | "Issue LOGO npiv  did:x%x flg:x%x", | 
|  | 7411 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | 
|  | 7412 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7413 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; | 
|  | 7414 | spin_lock_irq(shost->host_lock); | 
|  | 7415 | ndlp->nlp_flag |= NLP_LOGO_SND; | 
|  | 7416 | spin_unlock_irq(shost->host_lock); | 
| James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7417 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == | 
|  | 7418 | IOCB_ERROR) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7419 | spin_lock_irq(shost->host_lock); | 
|  | 7420 | ndlp->nlp_flag &= ~NLP_LOGO_SND; | 
|  | 7421 | spin_unlock_irq(shost->host_lock); | 
|  | 7422 | lpfc_els_free_iocb(phba, elsiocb); | 
|  | 7423 | return 1; | 
|  | 7424 | } | 
|  | 7425 | return 0; | 
|  | 7426 | } | 
|  | 7427 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7428 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7429 | * lpfc_fabric_block_timeout - Handler function to the fabric block timer | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7430 | * @ptr: holder for the timer function associated data. | 
|  | 7431 | * | 
|  | 7432 | * This routine is invoked by the fabric iocb block timer after | 
|  | 7433 | * timeout. It posts the fabric iocb block timeout event by setting the | 
|  | 7434 | * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes | 
|  | 7435 | * lpfc_worker_wake_up() routine to wake up the worker thread. It is for | 
|  | 7436 | * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the | 
|  | 7437 | * posted event WORKER_FABRIC_BLOCK_TMO. | 
|  | 7438 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7439 | void | 
|  | 7440 | lpfc_fabric_block_timeout(unsigned long ptr) | 
|  | 7441 | { | 
|  | 7442 | struct lpfc_hba  *phba = (struct lpfc_hba *) ptr; | 
|  | 7443 | unsigned long iflags; | 
|  | 7444 | uint32_t tmo_posted; | 
| James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7445 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7446 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); | 
|  | 7447 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; | 
|  | 7448 | if (!tmo_posted) | 
|  | 7449 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; | 
|  | 7450 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); | 
|  | 7451 |  | 
| James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7452 | if (!tmo_posted) | 
|  | 7453 | lpfc_worker_wake_up(phba); | 
|  | 7454 | return; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7455 | } | 
|  | 7456 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7457 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7458 | * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7459 | * @phba: pointer to lpfc hba data structure. | 
|  | 7460 | * | 
|  | 7461 | * This routine issues one fabric iocb from the driver internal list to | 
|  | 7462 | * the HBA. It first checks whether it's ready to issue one fabric iocb to | 
|  | 7463 | * the HBA (whether there is no outstanding fabric iocb). If so, it shall | 
|  | 7464 | * remove one pending fabric iocb from the driver internal list and invokes | 
|  | 7465 | * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. | 
|  | 7466 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7467 | static void | 
|  | 7468 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) | 
|  | 7469 | { | 
|  | 7470 | struct lpfc_iocbq *iocb; | 
|  | 7471 | unsigned long iflags; | 
|  | 7472 | int ret; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7473 | IOCB_t *cmd; | 
|  | 7474 |  | 
|  | 7475 | repeat: | 
|  | 7476 | iocb = NULL; | 
|  | 7477 | spin_lock_irqsave(&phba->hbalock, iflags); | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7478 | /* Post any pending iocb to the SLI layer */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7479 | if (atomic_read(&phba->fabric_iocb_count) == 0) { | 
|  | 7480 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), | 
|  | 7481 | list); | 
|  | 7482 | if (iocb) | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7483 | /* Increment fabric iocb count to hold the position */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7484 | atomic_inc(&phba->fabric_iocb_count); | 
|  | 7485 | } | 
|  | 7486 | spin_unlock_irqrestore(&phba->hbalock, iflags); | 
|  | 7487 | if (iocb) { | 
|  | 7488 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; | 
|  | 7489 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; | 
|  | 7490 | iocb->iocb_flag |= LPFC_IO_FABRIC; | 
|  | 7491 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7492 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 7493 | "Fabric sched1:   ste:x%x", | 
|  | 7494 | iocb->vport->port_state, 0, 0); | 
|  | 7495 |  | 
| James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7496 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7497 |  | 
|  | 7498 | if (ret == IOCB_ERROR) { | 
|  | 7499 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; | 
|  | 7500 | iocb->fabric_iocb_cmpl = NULL; | 
|  | 7501 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; | 
|  | 7502 | cmd = &iocb->iocb; | 
|  | 7503 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; | 
|  | 7504 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; | 
|  | 7505 | iocb->iocb_cmpl(phba, iocb, iocb); | 
|  | 7506 |  | 
|  | 7507 | atomic_dec(&phba->fabric_iocb_count); | 
|  | 7508 | goto repeat; | 
|  | 7509 | } | 
|  | 7510 | } | 
|  | 7511 |  | 
|  | 7512 | return; | 
|  | 7513 | } | 
|  | 7514 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7515 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7516 | * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7517 | * @phba: pointer to lpfc hba data structure. | 
|  | 7518 | * | 
|  | 7519 | * This routine unblocks the  issuing fabric iocb command. The function | 
|  | 7520 | * will clear the fabric iocb block bit and then invoke the routine | 
|  | 7521 | * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb | 
|  | 7522 | * from the driver internal fabric iocb list. | 
|  | 7523 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7524 | void | 
|  | 7525 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) | 
|  | 7526 | { | 
|  | 7527 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); | 
|  | 7528 |  | 
|  | 7529 | lpfc_resume_fabric_iocbs(phba); | 
|  | 7530 | return; | 
|  | 7531 | } | 
|  | 7532 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7533 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7534 | * lpfc_block_fabric_iocbs - Block issuing fabric iocb command | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7535 | * @phba: pointer to lpfc hba data structure. | 
|  | 7536 | * | 
|  | 7537 | * This routine blocks the issuing fabric iocb for a specified amount of | 
|  | 7538 | * time (currently 100 ms). This is done by set the fabric iocb block bit | 
|  | 7539 | * and set up a timeout timer for 100ms. When the block bit is set, no more | 
|  | 7540 | * fabric iocb will be issued out of the HBA. | 
|  | 7541 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7542 | static void | 
|  | 7543 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) | 
|  | 7544 | { | 
|  | 7545 | int blocked; | 
|  | 7546 |  | 
|  | 7547 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7548 | /* Start a timer to unblock fabric iocbs after 100ms */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7549 | if (!blocked) | 
|  | 7550 | mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 ); | 
|  | 7551 |  | 
|  | 7552 | return; | 
|  | 7553 | } | 
|  | 7554 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7555 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7556 | * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7557 | * @phba: pointer to lpfc hba data structure. | 
|  | 7558 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 7559 | * @rspiocb: pointer to lpfc response iocb data structure. | 
|  | 7560 | * | 
|  | 7561 | * This routine is the callback function that is put to the fabric iocb's | 
|  | 7562 | * callback function pointer (iocb->iocb_cmpl). The original iocb's callback | 
|  | 7563 | * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback | 
|  | 7564 | * function first restores and invokes the original iocb's callback function | 
|  | 7565 | * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next | 
|  | 7566 | * fabric bound iocb from the driver internal fabric iocb list onto the wire. | 
|  | 7567 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7568 | static void | 
|  | 7569 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | 
|  | 7570 | struct lpfc_iocbq *rspiocb) | 
|  | 7571 | { | 
|  | 7572 | struct ls_rjt stat; | 
|  | 7573 |  | 
|  | 7574 | if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC) | 
|  | 7575 | BUG(); | 
|  | 7576 |  | 
|  | 7577 | switch (rspiocb->iocb.ulpStatus) { | 
|  | 7578 | case IOSTAT_NPORT_RJT: | 
|  | 7579 | case IOSTAT_FABRIC_RJT: | 
|  | 7580 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { | 
|  | 7581 | lpfc_block_fabric_iocbs(phba); | 
|  | 7582 | } | 
|  | 7583 | break; | 
|  | 7584 |  | 
|  | 7585 | case IOSTAT_NPORT_BSY: | 
|  | 7586 | case IOSTAT_FABRIC_BSY: | 
|  | 7587 | lpfc_block_fabric_iocbs(phba); | 
|  | 7588 | break; | 
|  | 7589 |  | 
|  | 7590 | case IOSTAT_LS_RJT: | 
|  | 7591 | stat.un.lsRjtError = | 
|  | 7592 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); | 
|  | 7593 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || | 
|  | 7594 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) | 
|  | 7595 | lpfc_block_fabric_iocbs(phba); | 
|  | 7596 | break; | 
|  | 7597 | } | 
|  | 7598 |  | 
|  | 7599 | if (atomic_read(&phba->fabric_iocb_count) == 0) | 
|  | 7600 | BUG(); | 
|  | 7601 |  | 
|  | 7602 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; | 
|  | 7603 | cmdiocb->fabric_iocb_cmpl = NULL; | 
|  | 7604 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; | 
|  | 7605 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); | 
|  | 7606 |  | 
|  | 7607 | atomic_dec(&phba->fabric_iocb_count); | 
|  | 7608 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7609 | /* Post any pending iocbs to HBA */ | 
|  | 7610 | lpfc_resume_fabric_iocbs(phba); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7611 | } | 
|  | 7612 | } | 
|  | 7613 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7614 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7615 | * lpfc_issue_fabric_iocb - Issue a fabric iocb command | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7616 | * @phba: pointer to lpfc hba data structure. | 
|  | 7617 | * @iocb: pointer to lpfc command iocb data structure. | 
|  | 7618 | * | 
|  | 7619 | * This routine is used as the top-level API for issuing a fabric iocb command | 
|  | 7620 | * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver | 
|  | 7621 | * function makes sure that only one fabric bound iocb will be outstanding at | 
|  | 7622 | * any given time. As such, this function will first check to see whether there | 
|  | 7623 | * is already an outstanding fabric iocb on the wire. If so, it will put the | 
|  | 7624 | * newly issued iocb onto the driver internal fabric iocb list, waiting to be | 
|  | 7625 | * issued later. Otherwise, it will issue the iocb on the wire and update the | 
|  | 7626 | * fabric iocb count it indicate that there is one fabric iocb on the wire. | 
|  | 7627 | * | 
|  | 7628 | * Note, this implementation has a potential sending out fabric IOCBs out of | 
|  | 7629 | * order. The problem is caused by the construction of the "ready" boolen does | 
|  | 7630 | * not include the condition that the internal fabric IOCB list is empty. As | 
|  | 7631 | * such, it is possible a fabric IOCB issued by this routine might be "jump" | 
|  | 7632 | * ahead of the fabric IOCBs in the internal list. | 
|  | 7633 | * | 
|  | 7634 | * Return code | 
|  | 7635 | *   IOCB_SUCCESS - either fabric iocb put on the list or issued successfully | 
|  | 7636 | *   IOCB_ERROR - failed to issue fabric iocb | 
|  | 7637 | **/ | 
| Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 7638 | static int | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7639 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) | 
|  | 7640 | { | 
|  | 7641 | unsigned long iflags; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7642 | int ready; | 
|  | 7643 | int ret; | 
|  | 7644 |  | 
|  | 7645 | if (atomic_read(&phba->fabric_iocb_count) > 1) | 
|  | 7646 | BUG(); | 
|  | 7647 |  | 
|  | 7648 | spin_lock_irqsave(&phba->hbalock, iflags); | 
|  | 7649 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && | 
|  | 7650 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); | 
|  | 7651 |  | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 7652 | if (ready) | 
|  | 7653 | /* Increment fabric iocb count to hold the position */ | 
|  | 7654 | atomic_inc(&phba->fabric_iocb_count); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7655 | spin_unlock_irqrestore(&phba->hbalock, iflags); | 
|  | 7656 | if (ready) { | 
|  | 7657 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; | 
|  | 7658 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; | 
|  | 7659 | iocb->iocb_flag |= LPFC_IO_FABRIC; | 
|  | 7660 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7661 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 7662 | "Fabric sched2:   ste:x%x", | 
|  | 7663 | iocb->vport->port_state, 0, 0); | 
|  | 7664 |  | 
| James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7665 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7666 |  | 
|  | 7667 | if (ret == IOCB_ERROR) { | 
|  | 7668 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; | 
|  | 7669 | iocb->fabric_iocb_cmpl = NULL; | 
|  | 7670 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; | 
|  | 7671 | atomic_dec(&phba->fabric_iocb_count); | 
|  | 7672 | } | 
|  | 7673 | } else { | 
|  | 7674 | spin_lock_irqsave(&phba->hbalock, iflags); | 
|  | 7675 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); | 
|  | 7676 | spin_unlock_irqrestore(&phba->hbalock, iflags); | 
|  | 7677 | ret = IOCB_SUCCESS; | 
|  | 7678 | } | 
|  | 7679 | return ret; | 
|  | 7680 | } | 
|  | 7681 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7682 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7683 | * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7684 | * @vport: pointer to a virtual N_Port data structure. | 
|  | 7685 | * | 
|  | 7686 | * This routine aborts all the IOCBs associated with a @vport from the | 
|  | 7687 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be | 
|  | 7688 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB | 
|  | 7689 | * list, removes each IOCB associated with the @vport off the list, set the | 
|  | 7690 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function | 
|  | 7691 | * associated with the IOCB. | 
|  | 7692 | **/ | 
| Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 7693 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7694 | { | 
|  | 7695 | LIST_HEAD(completions); | 
|  | 7696 | struct lpfc_hba  *phba = vport->phba; | 
|  | 7697 | struct lpfc_iocbq *tmp_iocb, *piocb; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7698 |  | 
|  | 7699 | spin_lock_irq(&phba->hbalock); | 
|  | 7700 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, | 
|  | 7701 | list) { | 
|  | 7702 |  | 
|  | 7703 | if (piocb->vport != vport) | 
|  | 7704 | continue; | 
|  | 7705 |  | 
|  | 7706 | list_move_tail(&piocb->list, &completions); | 
|  | 7707 | } | 
|  | 7708 | spin_unlock_irq(&phba->hbalock); | 
|  | 7709 |  | 
| James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7710 | /* Cancel all the IOCBs from the completions list */ | 
|  | 7711 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | 
|  | 7712 | IOERR_SLI_ABORTED); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7713 | } | 
|  | 7714 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7715 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7716 | * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7717 | * @ndlp: pointer to a node-list data structure. | 
|  | 7718 | * | 
|  | 7719 | * This routine aborts all the IOCBs associated with an @ndlp from the | 
|  | 7720 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be | 
|  | 7721 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB | 
|  | 7722 | * list, removes each IOCB associated with the @ndlp off the list, set the | 
|  | 7723 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function | 
|  | 7724 | * associated with the IOCB. | 
|  | 7725 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7726 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) | 
|  | 7727 | { | 
|  | 7728 | LIST_HEAD(completions); | 
| James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7729 | struct lpfc_hba  *phba = ndlp->phba; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7730 | struct lpfc_iocbq *tmp_iocb, *piocb; | 
|  | 7731 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7732 |  | 
|  | 7733 | spin_lock_irq(&phba->hbalock); | 
|  | 7734 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, | 
|  | 7735 | list) { | 
|  | 7736 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { | 
|  | 7737 |  | 
|  | 7738 | list_move_tail(&piocb->list, &completions); | 
|  | 7739 | } | 
|  | 7740 | } | 
|  | 7741 | spin_unlock_irq(&phba->hbalock); | 
|  | 7742 |  | 
| James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7743 | /* Cancel all the IOCBs from the completions list */ | 
|  | 7744 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | 
|  | 7745 | IOERR_SLI_ABORTED); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7746 | } | 
|  | 7747 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7748 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7749 | * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7750 | * @phba: pointer to lpfc hba data structure. | 
|  | 7751 | * | 
|  | 7752 | * This routine aborts all the IOCBs currently on the driver internal | 
|  | 7753 | * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS | 
|  | 7754 | * IOCB ring. This function takes the entire IOCB list off the fabric IOCB | 
|  | 7755 | * list, removes IOCBs off the list, set the status feild to | 
|  | 7756 | * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with | 
|  | 7757 | * the IOCB. | 
|  | 7758 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7759 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) | 
|  | 7760 | { | 
|  | 7761 | LIST_HEAD(completions); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7762 |  | 
|  | 7763 | spin_lock_irq(&phba->hbalock); | 
|  | 7764 | list_splice_init(&phba->fabric_iocb_list, &completions); | 
|  | 7765 | spin_unlock_irq(&phba->hbalock); | 
|  | 7766 |  | 
| James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7767 | /* Cancel all the IOCBs from the completions list */ | 
|  | 7768 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | 
|  | 7769 | IOERR_SLI_ABORTED); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7770 | } | 
| James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7771 |  | 
|  | 7772 | /** | 
| James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 7773 | * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport | 
|  | 7774 | * @vport: pointer to lpfc vport data structure. | 
|  | 7775 | * | 
|  | 7776 | * This routine is invoked by the vport cleanup for deletions and the cleanup | 
|  | 7777 | * for an ndlp on removal. | 
|  | 7778 | **/ | 
|  | 7779 | void | 
|  | 7780 | lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport) | 
|  | 7781 | { | 
|  | 7782 | struct lpfc_hba *phba = vport->phba; | 
|  | 7783 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; | 
|  | 7784 | unsigned long iflag = 0; | 
|  | 7785 |  | 
|  | 7786 | spin_lock_irqsave(&phba->hbalock, iflag); | 
|  | 7787 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); | 
|  | 7788 | list_for_each_entry_safe(sglq_entry, sglq_next, | 
|  | 7789 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { | 
|  | 7790 | if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport) | 
|  | 7791 | sglq_entry->ndlp = NULL; | 
|  | 7792 | } | 
|  | 7793 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); | 
|  | 7794 | spin_unlock_irqrestore(&phba->hbalock, iflag); | 
|  | 7795 | return; | 
|  | 7796 | } | 
|  | 7797 |  | 
|  | 7798 | /** | 
| James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7799 | * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort | 
|  | 7800 | * @phba: pointer to lpfc hba data structure. | 
|  | 7801 | * @axri: pointer to the els xri abort wcqe structure. | 
|  | 7802 | * | 
|  | 7803 | * This routine is invoked by the worker thread to process a SLI4 slow-path | 
|  | 7804 | * ELS aborted xri. | 
|  | 7805 | **/ | 
|  | 7806 | void | 
|  | 7807 | lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba, | 
|  | 7808 | struct sli4_wcqe_xri_aborted *axri) | 
|  | 7809 | { | 
|  | 7810 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); | 
| James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7811 | uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri); | 
| James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7812 | uint16_t lxri = 0; | 
| James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7813 |  | 
| James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7814 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; | 
|  | 7815 | unsigned long iflag = 0; | 
| James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7816 | struct lpfc_nodelist *ndlp; | 
| James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 7817 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | 
| James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7818 |  | 
| James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 7819 | spin_lock_irqsave(&phba->hbalock, iflag); | 
|  | 7820 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); | 
| James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7821 | list_for_each_entry_safe(sglq_entry, sglq_next, | 
|  | 7822 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { | 
|  | 7823 | if (sglq_entry->sli4_xritag == xri) { | 
|  | 7824 | list_del(&sglq_entry->list); | 
| James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7825 | ndlp = sglq_entry->ndlp; | 
|  | 7826 | sglq_entry->ndlp = NULL; | 
| James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7827 | list_add_tail(&sglq_entry->list, | 
|  | 7828 | &phba->sli4_hba.lpfc_sgl_list); | 
| James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 7829 | sglq_entry->state = SGL_FREED; | 
|  | 7830 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); | 
| James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7831 | spin_unlock_irqrestore(&phba->hbalock, iflag); | 
| James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 7832 | lpfc_set_rrq_active(phba, ndlp, xri, rxid, 1); | 
| James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 7833 |  | 
|  | 7834 | /* Check if TXQ queue needs to be serviced */ | 
|  | 7835 | if (pring->txq_cnt) | 
|  | 7836 | lpfc_worker_wake_up(phba); | 
| James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7837 | return; | 
|  | 7838 | } | 
|  | 7839 | } | 
| James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 7840 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); | 
| James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 7841 | lxri = lpfc_sli4_xri_inrange(phba, xri); | 
|  | 7842 | if (lxri == NO_XRI) { | 
|  | 7843 | spin_unlock_irqrestore(&phba->hbalock, iflag); | 
|  | 7844 | return; | 
|  | 7845 | } | 
|  | 7846 | sglq_entry = __lpfc_get_active_sglq(phba, lxri); | 
| James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 7847 | if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) { | 
|  | 7848 | spin_unlock_irqrestore(&phba->hbalock, iflag); | 
|  | 7849 | return; | 
|  | 7850 | } | 
|  | 7851 | sglq_entry->state = SGL_XRI_ABORTED; | 
|  | 7852 | spin_unlock_irqrestore(&phba->hbalock, iflag); | 
|  | 7853 | return; | 
| James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 7854 | } |