|  | 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 | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4 | * Copyright (C) 2004-2008 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> | 
|  | 24 | #include <linux/interrupt.h> | 
|  | 25 |  | 
| James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 26 | #include <scsi/scsi.h> | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 27 | #include <scsi/scsi_device.h> | 
|  | 28 | #include <scsi/scsi_host.h> | 
|  | 29 | #include <scsi/scsi_transport_fc.h> | 
|  | 30 |  | 
|  | 31 | #include "lpfc_hw.h" | 
|  | 32 | #include "lpfc_sli.h" | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 33 | #include "lpfc_nl.h" | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 34 | #include "lpfc_disc.h" | 
|  | 35 | #include "lpfc_scsi.h" | 
|  | 36 | #include "lpfc.h" | 
|  | 37 | #include "lpfc_logmsg.h" | 
|  | 38 | #include "lpfc_crtn.h" | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 39 | #include "lpfc_vport.h" | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 40 | #include "lpfc_debugfs.h" | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 41 |  | 
|  | 42 | static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *, | 
|  | 43 | struct lpfc_iocbq *); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 44 | static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *, | 
|  | 45 | struct lpfc_iocbq *); | 
| Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 46 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport); | 
|  | 47 | static int lpfc_issue_els_fdisc(struct lpfc_vport *vport, | 
|  | 48 | struct lpfc_nodelist *ndlp, uint8_t retry); | 
|  | 49 | static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba, | 
|  | 50 | struct lpfc_iocbq *iocb); | 
|  | 51 | static void lpfc_register_new_vport(struct lpfc_hba *phba, | 
|  | 52 | struct lpfc_vport *vport, | 
|  | 53 | struct lpfc_nodelist *ndlp); | 
| 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 || | 
|  | 87 | phba->link_state == LPFC_LINK_DOWN) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 88 | return 0; | 
|  | 89 |  | 
|  | 90 | /* Read the HBA Host Attention Register */ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 91 | ha_copy = readl(phba->HAregaddr); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 92 |  | 
|  | 93 | if (!(ha_copy & HA_LATT)) | 
|  | 94 | return 0; | 
|  | 95 |  | 
|  | 96 | /* Pending Link Event during Discovery */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 97 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, | 
|  | 98 | "0237 Pending Link Event during " | 
|  | 99 | "Discovery: State x%x\n", | 
|  | 100 | phba->pport->port_state); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 101 |  | 
|  | 102 | /* CLEAR_LA should re-enable link attention events and | 
|  | 103 | * we should then imediately take a LATT event. The | 
|  | 104 | * LATT processing should call lpfc_linkdown() which | 
|  | 105 | * will cleanup any left over in-progress discovery | 
|  | 106 | * events. | 
|  | 107 | */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 108 | spin_lock_irq(shost->host_lock); | 
|  | 109 | vport->fc_flag |= FC_ABORT_DISCOVERY; | 
|  | 110 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 111 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 112 | if (phba->link_state != LPFC_CLEAR_LA) | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 113 | lpfc_issue_clear_la(phba, vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 114 |  | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 115 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 116 | } | 
|  | 117 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 118 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 119 | * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 120 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 121 | * @expectRsp: flag indicating whether response is expected. | 
|  | 122 | * @cmdSize: size of the ELS command. | 
|  | 123 | * @retry: number of retries to the command IOCB when it fails. | 
|  | 124 | * @ndlp: pointer to a node-list data structure. | 
|  | 125 | * @did: destination identifier. | 
|  | 126 | * @elscmd: the ELS command code. | 
|  | 127 | * | 
|  | 128 | * This routine is used for allocating a lpfc-IOCB data structure from | 
|  | 129 | * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters | 
|  | 130 | * passed into the routine for discovery state machine to issue an Extended | 
|  | 131 | * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation | 
|  | 132 | * and preparation routine that is used by all the discovery state machine | 
|  | 133 | * routines and the ELS command-specific fields will be later set up by | 
|  | 134 | * the individual discovery machine routines after calling this routine | 
|  | 135 | * allocating and preparing a generic IOCB data structure. It fills in the | 
|  | 136 | * Buffer Descriptor Entries (BDEs), allocates buffers for both command | 
|  | 137 | * payload and response payload (if expected). The reference count on the | 
|  | 138 | * ndlp is incremented by 1 and the reference to the ndlp is put into | 
|  | 139 | * context1 of the IOCB data structure for this IOCB to hold the ndlp | 
|  | 140 | * reference for the command's callback function to access later. | 
|  | 141 | * | 
|  | 142 | * Return code | 
|  | 143 | *   Pointer to the newly allocated/prepared els iocb data structure | 
|  | 144 | *   NULL - when els iocb data structure allocation/preparation failed | 
|  | 145 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 146 | static struct lpfc_iocbq * | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 147 | lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp, | 
|  | 148 | uint16_t cmdSize, uint8_t retry, | 
|  | 149 | struct lpfc_nodelist *ndlp, uint32_t did, | 
|  | 150 | uint32_t elscmd) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 151 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 152 | struct lpfc_hba  *phba = vport->phba; | 
| James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 153 | struct lpfc_iocbq *elsiocb; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 154 | struct lpfc_dmabuf *pcmd, *prsp, *pbuflist; | 
|  | 155 | struct ulp_bde64 *bpl; | 
|  | 156 | IOCB_t *icmd; | 
|  | 157 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 158 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 159 | if (!lpfc_is_link_up(phba)) | 
|  | 160 | return NULL; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 161 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 162 | /* Allocate buffer for  command iocb */ | 
| James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 163 | elsiocb = lpfc_sli_get_iocbq(phba); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 164 |  | 
|  | 165 | if (elsiocb == NULL) | 
|  | 166 | return NULL; | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 167 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 168 | icmd = &elsiocb->iocb; | 
|  | 169 |  | 
|  | 170 | /* fill in BDEs for command */ | 
|  | 171 | /* Allocate buffer for command payload */ | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 172 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | 
|  | 173 | if (pcmd) | 
|  | 174 | pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys); | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 175 | if (!pcmd || !pcmd->virt) | 
|  | 176 | goto els_iocb_free_pcmb_exit; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 177 |  | 
|  | 178 | INIT_LIST_HEAD(&pcmd->list); | 
|  | 179 |  | 
|  | 180 | /* Allocate buffer for response payload */ | 
|  | 181 | if (expectRsp) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 182 | prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 183 | if (prsp) | 
|  | 184 | prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, | 
|  | 185 | &prsp->phys); | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 186 | if (!prsp || !prsp->virt) | 
|  | 187 | goto els_iocb_free_prsp_exit; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 188 | INIT_LIST_HEAD(&prsp->list); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 189 | } else | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 190 | prsp = NULL; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 191 |  | 
|  | 192 | /* Allocate buffer for Buffer ptr list */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 193 | pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 194 | if (pbuflist) | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 195 | pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI, | 
|  | 196 | &pbuflist->phys); | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 197 | if (!pbuflist || !pbuflist->virt) | 
|  | 198 | goto els_iocb_free_pbuf_exit; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 199 |  | 
|  | 200 | INIT_LIST_HEAD(&pbuflist->list); | 
|  | 201 |  | 
|  | 202 | icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); | 
|  | 203 | icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys); | 
| James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 204 | icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 205 | icmd->un.elsreq64.remoteID = did;	/* DID */ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 206 | if (expectRsp) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 207 | icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 208 | icmd->ulpCommand = CMD_ELS_REQUEST64_CR; | 
| James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 209 | icmd->ulpTimeout = phba->fc_ratov * 2; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 210 | } else { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 211 | icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 212 | icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX; | 
|  | 213 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 214 | icmd->ulpBdeCount = 1; | 
|  | 215 | icmd->ulpLe = 1; | 
|  | 216 | icmd->ulpClass = CLASS3; | 
|  | 217 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 218 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { | 
|  | 219 | icmd->un.elsreq64.myID = vport->fc_myDID; | 
|  | 220 |  | 
|  | 221 | /* For ELS_REQUEST64_CR, use the VPI by default */ | 
|  | 222 | icmd->ulpContext = vport->vpi; | 
|  | 223 | icmd->ulpCt_h = 0; | 
| James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 224 | /* The CT field must be 0=INVALID_RPI for the ECHO cmd */ | 
|  | 225 | if (elscmd == ELS_CMD_ECHO) | 
|  | 226 | icmd->ulpCt_l = 0; /* context = invalid RPI */ | 
|  | 227 | else | 
|  | 228 | icmd->ulpCt_l = 1; /* context = VPI */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 229 | } | 
|  | 230 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 231 | bpl = (struct ulp_bde64 *) pbuflist->virt; | 
|  | 232 | bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys)); | 
|  | 233 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys)); | 
|  | 234 | bpl->tus.f.bdeSize = cmdSize; | 
|  | 235 | bpl->tus.f.bdeFlags = 0; | 
|  | 236 | bpl->tus.w = le32_to_cpu(bpl->tus.w); | 
|  | 237 |  | 
|  | 238 | if (expectRsp) { | 
|  | 239 | bpl++; | 
|  | 240 | bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys)); | 
|  | 241 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys)); | 
|  | 242 | bpl->tus.f.bdeSize = FCELSSIZE; | 
| James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 243 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 244 | bpl->tus.w = le32_to_cpu(bpl->tus.w); | 
|  | 245 | } | 
|  | 246 |  | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 247 | /* prevent preparing iocb with NULL ndlp reference */ | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 248 | elsiocb->context1 = lpfc_nlp_get(ndlp); | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 249 | if (!elsiocb->context1) | 
|  | 250 | goto els_iocb_free_pbuf_exit; | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 251 | elsiocb->context2 = pcmd; | 
|  | 252 | elsiocb->context3 = pbuflist; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 253 | elsiocb->retry = retry; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 254 | elsiocb->vport = vport; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 255 | elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT; | 
|  | 256 |  | 
|  | 257 | if (prsp) { | 
|  | 258 | list_add(&prsp->list, &pcmd->list); | 
|  | 259 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 260 | if (expectRsp) { | 
|  | 261 | /* Xmit ELS command <elsCmd> to remote NPORT <did> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 262 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 263 | "0116 Xmit ELS command x%x to remote " | 
|  | 264 | "NPORT x%x I/O tag: x%x, port state: x%x\n", | 
|  | 265 | elscmd, did, elsiocb->iotag, | 
|  | 266 | vport->port_state); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 267 | } else { | 
|  | 268 | /* Xmit ELS response <elsCmd> to remote NPORT <did> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 269 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 270 | "0117 Xmit ELS response x%x to remote " | 
|  | 271 | "NPORT x%x I/O tag: x%x, size: x%x\n", | 
|  | 272 | elscmd, ndlp->nlp_DID, elsiocb->iotag, | 
|  | 273 | cmdSize); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 274 | } | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 275 | return elsiocb; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 276 |  | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 277 | els_iocb_free_pbuf_exit: | 
| James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 278 | if (expectRsp) | 
|  | 279 | lpfc_mbuf_free(phba, prsp->virt, prsp->phys); | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 280 | kfree(pbuflist); | 
|  | 281 |  | 
|  | 282 | els_iocb_free_prsp_exit: | 
|  | 283 | lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); | 
|  | 284 | kfree(prsp); | 
|  | 285 |  | 
|  | 286 | els_iocb_free_pcmb_exit: | 
|  | 287 | kfree(pcmd); | 
|  | 288 | lpfc_sli_release_iocbq(phba, elsiocb); | 
|  | 289 | return NULL; | 
|  | 290 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 291 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 292 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 293 | * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 294 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 295 | * | 
|  | 296 | * This routine issues a fabric registration login for a @vport. An | 
|  | 297 | * active ndlp node with Fabric_DID must already exist for this @vport. | 
|  | 298 | * The routine invokes two mailbox commands to carry out fabric registration | 
|  | 299 | * login through the HBA firmware: the first mailbox command requests the | 
|  | 300 | * HBA to perform link configuration for the @vport; and the second mailbox | 
|  | 301 | * command requests the HBA to perform the actual fabric registration login | 
|  | 302 | * with the @vport. | 
|  | 303 | * | 
|  | 304 | * Return code | 
|  | 305 | *   0 - successfully issued fabric registration login for @vport | 
|  | 306 | *   -ENXIO -- failed to issue fabric registration login for @vport | 
|  | 307 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 308 | static int | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 309 | lpfc_issue_fabric_reglogin(struct lpfc_vport *vport) | 
|  | 310 | { | 
|  | 311 | struct lpfc_hba  *phba = vport->phba; | 
|  | 312 | LPFC_MBOXQ_t *mbox; | 
|  | 313 | struct lpfc_dmabuf *mp; | 
|  | 314 | struct lpfc_nodelist *ndlp; | 
|  | 315 | struct serv_parm *sp; | 
|  | 316 | int rc; | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 317 | int err = 0; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 318 |  | 
|  | 319 | sp = &phba->fc_fabparam; | 
|  | 320 | ndlp = lpfc_findnode_did(vport, Fabric_DID); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 321 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 322 | err = 1; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 323 | goto fail; | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 324 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 325 |  | 
|  | 326 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 327 | if (!mbox) { | 
|  | 328 | err = 2; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 329 | goto fail; | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 330 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 331 |  | 
|  | 332 | vport->port_state = LPFC_FABRIC_CFG_LINK; | 
|  | 333 | lpfc_config_link(phba, mbox); | 
|  | 334 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | 
|  | 335 | mbox->vport = vport; | 
|  | 336 |  | 
| James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 337 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 338 | if (rc == MBX_NOT_FINISHED) { | 
|  | 339 | err = 3; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 340 | goto fail_free_mbox; | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 341 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 342 |  | 
|  | 343 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 344 | if (!mbox) { | 
|  | 345 | err = 4; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 346 | goto fail; | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 347 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 348 | rc = lpfc_reg_login(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, | 
|  | 349 | 0); | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 350 | if (rc) { | 
|  | 351 | err = 5; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 352 | goto fail_free_mbox; | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 353 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 354 |  | 
|  | 355 | mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login; | 
|  | 356 | mbox->vport = vport; | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 357 | /* increment the reference count on ndlp to hold reference | 
|  | 358 | * for the callback routine. | 
|  | 359 | */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 360 | mbox->context2 = lpfc_nlp_get(ndlp); | 
|  | 361 |  | 
| James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 362 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 363 | if (rc == MBX_NOT_FINISHED) { | 
|  | 364 | err = 6; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 365 | goto fail_issue_reg_login; | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 366 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 367 |  | 
|  | 368 | return 0; | 
|  | 369 |  | 
|  | 370 | fail_issue_reg_login: | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 371 | /* decrement the reference count on ndlp just incremented | 
|  | 372 | * for the failed mbox command. | 
|  | 373 | */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 374 | lpfc_nlp_put(ndlp); | 
|  | 375 | mp = (struct lpfc_dmabuf *) mbox->context1; | 
|  | 376 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | 
|  | 377 | kfree(mp); | 
|  | 378 | fail_free_mbox: | 
|  | 379 | mempool_free(mbox, phba->mbox_mem_pool); | 
|  | 380 |  | 
|  | 381 | fail: | 
|  | 382 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 383 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 384 | "0249 Cannot issue Register Fabric login: Err %d\n", err); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 385 | return -ENXIO; | 
|  | 386 | } | 
|  | 387 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 388 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 389 | * 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] | 390 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 391 | * @ndlp: pointer to a node-list data structure. | 
|  | 392 | * @sp: pointer to service parameter data structure. | 
|  | 393 | * @irsp: pointer to the IOCB within the lpfc response IOCB. | 
|  | 394 | * | 
|  | 395 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback | 
|  | 396 | * function to handle the completion of a Fabric Login (FLOGI) into a fabric | 
|  | 397 | * port in a fabric topology. It properly sets up the parameters to the @ndlp | 
|  | 398 | * from the IOCB response. It also check the newly assigned N_Port ID to the | 
|  | 399 | * @vport against the previously assigned N_Port ID. If it is different from | 
|  | 400 | * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine | 
|  | 401 | * is invoked on all the remaining nodes with the @vport to unregister the | 
|  | 402 | * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin() | 
|  | 403 | * is invoked to register login to the fabric. | 
|  | 404 | * | 
|  | 405 | * Return code | 
|  | 406 | *   0 - Success (currently, always return 0) | 
|  | 407 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 408 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 409 | lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, | 
|  | 410 | struct serv_parm *sp, IOCB_t *irsp) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 411 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 412 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | 413 | struct lpfc_hba  *phba = vport->phba; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 414 | struct lpfc_nodelist *np; | 
|  | 415 | struct lpfc_nodelist *next_np; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 416 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 417 | spin_lock_irq(shost->host_lock); | 
|  | 418 | vport->fc_flag |= FC_FABRIC; | 
|  | 419 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 420 |  | 
|  | 421 | phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov); | 
|  | 422 | if (sp->cmn.edtovResolution)	/* E_D_TOV ticks are in nanoseconds */ | 
|  | 423 | phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000; | 
|  | 424 |  | 
|  | 425 | phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; | 
|  | 426 |  | 
|  | 427 | if (phba->fc_topology == TOPOLOGY_LOOP) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 428 | spin_lock_irq(shost->host_lock); | 
|  | 429 | vport->fc_flag |= FC_PUBLIC_LOOP; | 
|  | 430 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 431 | } else { | 
|  | 432 | /* | 
|  | 433 | * If we are a N-port connected to a Fabric, fixup sparam's so | 
|  | 434 | * logins to devices on remote loops work. | 
|  | 435 | */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 436 | vport->fc_sparam.cmn.altBbCredit = 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 437 | } | 
|  | 438 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 439 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 440 | memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 441 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 442 | ndlp->nlp_class_sup = 0; | 
|  | 443 | if (sp->cls1.classValid) | 
|  | 444 | ndlp->nlp_class_sup |= FC_COS_CLASS1; | 
|  | 445 | if (sp->cls2.classValid) | 
|  | 446 | ndlp->nlp_class_sup |= FC_COS_CLASS2; | 
|  | 447 | if (sp->cls3.classValid) | 
|  | 448 | ndlp->nlp_class_sup |= FC_COS_CLASS3; | 
|  | 449 | if (sp->cls4.classValid) | 
|  | 450 | ndlp->nlp_class_sup |= FC_COS_CLASS4; | 
|  | 451 | ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | | 
|  | 452 | sp->cmn.bbRcvSizeLsb; | 
|  | 453 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); | 
|  | 454 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 455 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { | 
|  | 456 | if (sp->cmn.response_multiple_NPort) { | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 457 | lpfc_printf_vlog(vport, KERN_WARNING, | 
|  | 458 | LOG_ELS | LOG_VPORT, | 
|  | 459 | "1816 FLOGI NPIV supported, " | 
|  | 460 | "response data 0x%x\n", | 
|  | 461 | sp->cmn.response_multiple_NPort); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 462 | phba->link_flag |= LS_NPIV_FAB_SUPPORTED; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 463 | } else { | 
|  | 464 | /* Because we asked f/w for NPIV it still expects us | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 465 | to call reg_vnpid atleast for the physcial host */ | 
|  | 466 | lpfc_printf_vlog(vport, KERN_WARNING, | 
|  | 467 | LOG_ELS | LOG_VPORT, | 
|  | 468 | "1817 Fabric does not support NPIV " | 
|  | 469 | "- configuring single port mode.\n"); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 470 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; | 
|  | 471 | } | 
|  | 472 | } | 
|  | 473 |  | 
|  | 474 | if ((vport->fc_prevDID != vport->fc_myDID) && | 
|  | 475 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { | 
|  | 476 |  | 
|  | 477 | /* If our NportID changed, we need to ensure all | 
|  | 478 | * remaining NPORTs get unreg_login'ed. | 
|  | 479 | */ | 
|  | 480 | list_for_each_entry_safe(np, next_np, | 
|  | 481 | &vport->fc_nodes, nlp_listp) { | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 482 | if (!NLP_CHK_NODE_ACT(np)) | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 483 | continue; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 484 | if ((np->nlp_state != NLP_STE_NPR_NODE) || | 
|  | 485 | !(np->nlp_flag & NLP_NPR_ADISC)) | 
|  | 486 | continue; | 
|  | 487 | spin_lock_irq(shost->host_lock); | 
|  | 488 | np->nlp_flag &= ~NLP_NPR_ADISC; | 
|  | 489 | spin_unlock_irq(shost->host_lock); | 
|  | 490 | lpfc_unreg_rpi(vport, np); | 
|  | 491 | } | 
|  | 492 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { | 
|  | 493 | lpfc_mbx_unreg_vpi(vport); | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 494 | spin_lock_irq(shost->host_lock); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 495 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 496 | spin_unlock_irq(shost->host_lock); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 497 | } | 
|  | 498 | } | 
|  | 499 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 500 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 501 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 502 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED && | 
|  | 503 | vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) { | 
|  | 504 | lpfc_register_new_vport(phba, vport, ndlp); | 
|  | 505 | return 0; | 
|  | 506 | } | 
|  | 507 | lpfc_issue_fabric_reglogin(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 508 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 509 | } | 
|  | 510 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 511 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 512 | * 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] | 513 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 514 | * @ndlp: pointer to a node-list data structure. | 
|  | 515 | * @sp: pointer to service parameter data structure. | 
|  | 516 | * | 
|  | 517 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback | 
|  | 518 | * function to handle the completion of a Fabric Login (FLOGI) into an N_Port | 
|  | 519 | * in a point-to-point topology. First, the @vport's N_Port Name is compared | 
|  | 520 | * with the received N_Port Name: if the @vport's N_Port Name is greater than | 
|  | 521 | * the received N_Port Name lexicographically, this node shall assign local | 
|  | 522 | * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and | 
|  | 523 | * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise, | 
|  | 524 | * this node shall just wait for the remote node to issue PLOGI and assign | 
|  | 525 | * N_Port IDs. | 
|  | 526 | * | 
|  | 527 | * Return code | 
|  | 528 | *   0 - Success | 
|  | 529 | *   -ENXIO - Fail | 
|  | 530 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 531 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 532 | lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, | 
|  | 533 | struct serv_parm *sp) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 534 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 535 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | 536 | struct lpfc_hba  *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 537 | LPFC_MBOXQ_t *mbox; | 
|  | 538 | int rc; | 
|  | 539 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 540 | spin_lock_irq(shost->host_lock); | 
|  | 541 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); | 
|  | 542 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 543 |  | 
|  | 544 | phba->fc_edtov = FF_DEF_EDTOV; | 
|  | 545 | phba->fc_ratov = FF_DEF_RATOV; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 546 | rc = memcmp(&vport->fc_portname, &sp->portName, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 547 | sizeof(vport->fc_portname)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 548 | if (rc >= 0) { | 
|  | 549 | /* This side will initiate the PLOGI */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 550 | spin_lock_irq(shost->host_lock); | 
|  | 551 | vport->fc_flag |= FC_PT2PT_PLOGI; | 
|  | 552 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 553 |  | 
|  | 554 | /* | 
|  | 555 | * N_Port ID cannot be 0, set our to LocalID the other | 
|  | 556 | * side will be RemoteID. | 
|  | 557 | */ | 
|  | 558 |  | 
|  | 559 | /* not equal */ | 
|  | 560 | if (rc) | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 561 | vport->fc_myDID = PT2PT_LocalID; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 562 |  | 
|  | 563 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | 
|  | 564 | if (!mbox) | 
|  | 565 | goto fail; | 
|  | 566 |  | 
|  | 567 | lpfc_config_link(phba, mbox); | 
|  | 568 |  | 
|  | 569 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 570 | mbox->vport = vport; | 
| James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 571 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 572 | if (rc == MBX_NOT_FINISHED) { | 
|  | 573 | mempool_free(mbox, phba->mbox_mem_pool); | 
|  | 574 | goto fail; | 
|  | 575 | } | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 576 | /* Decrement ndlp reference count indicating that ndlp can be | 
|  | 577 | * safely released when other references to it are done. | 
|  | 578 | */ | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 579 | lpfc_nlp_put(ndlp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 580 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 581 | ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 582 | if (!ndlp) { | 
|  | 583 | /* | 
|  | 584 | * Cannot find existing Fabric ndlp, so allocate a | 
|  | 585 | * new one | 
|  | 586 | */ | 
|  | 587 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | 
|  | 588 | if (!ndlp) | 
|  | 589 | goto fail; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 590 | lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 591 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | 
|  | 592 | ndlp = lpfc_enable_node(vport, ndlp, | 
|  | 593 | NLP_STE_UNUSED_NODE); | 
|  | 594 | if(!ndlp) | 
|  | 595 | goto fail; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 596 | } | 
|  | 597 |  | 
|  | 598 | memcpy(&ndlp->nlp_portname, &sp->portName, | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 599 | sizeof(struct lpfc_name)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 600 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 601 | sizeof(struct lpfc_name)); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 602 | /* Set state will put ndlp onto node list if not already done */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 603 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); | 
|  | 604 | spin_lock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 605 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 606 | spin_unlock_irq(shost->host_lock); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 607 | } else | 
|  | 608 | /* This side will wait for the PLOGI, decrement ndlp reference | 
|  | 609 | * count indicating that ndlp can be released when other | 
|  | 610 | * references to it are done. | 
|  | 611 | */ | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 612 | lpfc_nlp_put(ndlp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 613 |  | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 614 | /* If we are pt2pt with another NPort, force NPIV off! */ | 
|  | 615 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; | 
|  | 616 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 617 | spin_lock_irq(shost->host_lock); | 
|  | 618 | vport->fc_flag |= FC_PT2PT; | 
|  | 619 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 620 |  | 
|  | 621 | /* Start discovery - this should just do CLEAR_LA */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 622 | lpfc_disc_start(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 623 | return 0; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 624 | fail: | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 625 | return -ENXIO; | 
|  | 626 | } | 
|  | 627 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 628 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 629 | * lpfc_cmpl_els_flogi - Completion callback function for flogi | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 630 | * @phba: pointer to lpfc hba data structure. | 
|  | 631 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 632 | * @rspiocb: pointer to lpfc response iocb data structure. | 
|  | 633 | * | 
|  | 634 | * This routine is the top-level completion callback function for issuing | 
|  | 635 | * a Fabric Login (FLOGI) command. If the response IOCB reported error, | 
|  | 636 | * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If | 
|  | 637 | * retry has been made (either immediately or delayed with lpfc_els_retry() | 
|  | 638 | * returning 1), the command IOCB will be released and function returned. | 
|  | 639 | * If the retry attempt has been given up (possibly reach the maximum | 
|  | 640 | * number of retries), one additional decrement of ndlp reference shall be | 
|  | 641 | * invoked before going out after releasing the command IOCB. This will | 
|  | 642 | * actually release the remote node (Note, lpfc_els_free_iocb() will also | 
|  | 643 | * invoke one decrement of ndlp reference count). If no error reported in | 
|  | 644 | * the IOCB status, the command Port ID field is used to determine whether | 
|  | 645 | * this is a point-to-point topology or a fabric topology: if the Port ID | 
|  | 646 | * field is assigned, it is a fabric topology; otherwise, it is a | 
|  | 647 | * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or | 
|  | 648 | * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the | 
|  | 649 | * specific topology completion conditions. | 
|  | 650 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 651 | static void | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 652 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | 
|  | 653 | struct lpfc_iocbq *rspiocb) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 654 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 655 | struct lpfc_vport *vport = cmdiocb->vport; | 
|  | 656 | struct Scsi_Host  *shost = lpfc_shost_from_vport(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 657 | IOCB_t *irsp = &rspiocb->iocb; | 
|  | 658 | struct lpfc_nodelist *ndlp = cmdiocb->context1; | 
|  | 659 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; | 
|  | 660 | struct serv_parm *sp; | 
|  | 661 | int rc; | 
|  | 662 |  | 
|  | 663 | /* Check to see if link went down during discovery */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 664 | if (lpfc_els_chk_latt(vport)) { | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 665 | /* One additional decrement on node reference count to | 
|  | 666 | * trigger the release of the node | 
|  | 667 | */ | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 668 | lpfc_nlp_put(ndlp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 669 | goto out; | 
|  | 670 | } | 
|  | 671 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 672 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 673 | "FLOGI cmpl:      status:x%x/x%x state:x%x", | 
|  | 674 | irsp->ulpStatus, irsp->un.ulpWord[4], | 
|  | 675 | vport->port_state); | 
|  | 676 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 677 | if (irsp->ulpStatus) { | 
|  | 678 | /* Check for retry */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 679 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 680 | goto out; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 681 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 682 | /* FLOGI failed, so there is no fabric */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 683 | spin_lock_irq(shost->host_lock); | 
|  | 684 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); | 
|  | 685 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 686 |  | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 687 | /* If private loop, then allow max outstanding els to be | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 688 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no | 
|  | 689 | * alpa map would take too long otherwise. | 
|  | 690 | */ | 
|  | 691 | if (phba->alpa_map[0] == 0) { | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 692 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 693 | } | 
|  | 694 |  | 
|  | 695 | /* FLOGI failure */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 696 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 697 | "0100 FLOGI failure Data: x%x x%x " | 
|  | 698 | "x%x\n", | 
|  | 699 | irsp->ulpStatus, irsp->un.ulpWord[4], | 
|  | 700 | irsp->ulpTimeout); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 701 | goto flogifail; | 
|  | 702 | } | 
|  | 703 |  | 
|  | 704 | /* | 
|  | 705 | * The FLogI succeeded.  Sync the data for the CPU before | 
|  | 706 | * accessing it. | 
|  | 707 | */ | 
|  | 708 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); | 
|  | 709 |  | 
|  | 710 | sp = prsp->virt + sizeof(uint32_t); | 
|  | 711 |  | 
|  | 712 | /* FLOGI completes successfully */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 713 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 714 | "0101 FLOGI completes sucessfully " | 
|  | 715 | "Data: x%x x%x x%x x%x\n", | 
|  | 716 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, | 
|  | 717 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 718 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 719 | if (vport->port_state == LPFC_FLOGI) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 720 | /* | 
|  | 721 | * If Common Service Parameters indicate Nport | 
|  | 722 | * we are point to point, if Fport we are Fabric. | 
|  | 723 | */ | 
|  | 724 | if (sp->cmn.fPort) | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 725 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 726 | else | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 727 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 728 |  | 
|  | 729 | if (!rc) | 
|  | 730 | goto out; | 
|  | 731 | } | 
|  | 732 |  | 
|  | 733 | flogifail: | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 734 | lpfc_nlp_put(ndlp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 735 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 736 | if (!lpfc_error_lost_link(irsp)) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 737 | /* FLOGI failed, so just use loop map to make discovery list */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 738 | lpfc_disc_list_loopmap(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 739 |  | 
|  | 740 | /* Start discovery */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 741 | lpfc_disc_start(vport); | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 742 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || | 
|  | 743 | ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) && | 
|  | 744 | (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) && | 
|  | 745 | (phba->link_state != LPFC_CLEAR_LA)) { | 
|  | 746 | /* If FLOGI failed enable link interrupt. */ | 
|  | 747 | lpfc_issue_clear_la(phba, vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 748 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 749 | out: | 
|  | 750 | lpfc_els_free_iocb(phba, cmdiocb); | 
|  | 751 | } | 
|  | 752 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 753 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 754 | * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 755 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 756 | * @ndlp: pointer to a node-list data structure. | 
|  | 757 | * @retry: number of retries to the command IOCB. | 
|  | 758 | * | 
|  | 759 | * This routine issues a Fabric Login (FLOGI) Request ELS command | 
|  | 760 | * for a @vport. The initiator service parameters are put into the payload | 
|  | 761 | * of the FLOGI Request IOCB and the top-level callback function pointer | 
|  | 762 | * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback | 
|  | 763 | * function field. The lpfc_issue_fabric_iocb routine is invoked to send | 
|  | 764 | * out FLOGI ELS command with one outstanding fabric IOCB at a time. | 
|  | 765 | * | 
|  | 766 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | 
|  | 767 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | 
|  | 768 | * will be stored into the context1 field of the IOCB for the completion | 
|  | 769 | * callback function to the FLOGI ELS command. | 
|  | 770 | * | 
|  | 771 | * Return code | 
|  | 772 | *   0 - successfully issued flogi iocb for @vport | 
|  | 773 | *   1 - failed to issue flogi iocb for @vport | 
|  | 774 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 775 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 776 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 777 | uint8_t retry) | 
|  | 778 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 779 | struct lpfc_hba  *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 780 | struct serv_parm *sp; | 
|  | 781 | IOCB_t *icmd; | 
|  | 782 | struct lpfc_iocbq *elsiocb; | 
|  | 783 | struct lpfc_sli_ring *pring; | 
|  | 784 | uint8_t *pcmd; | 
|  | 785 | uint16_t cmdsize; | 
|  | 786 | uint32_t tmo; | 
|  | 787 | int rc; | 
|  | 788 |  | 
|  | 789 | pring = &phba->sli.ring[LPFC_ELS_RING]; | 
|  | 790 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 791 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 792 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, | 
|  | 793 | ndlp->nlp_DID, ELS_CMD_FLOGI); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 794 |  | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 795 | if (!elsiocb) | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 796 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 797 |  | 
|  | 798 | icmd = &elsiocb->iocb; | 
|  | 799 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 800 |  | 
|  | 801 | /* For FLOGI request, remainder of payload is service parameters */ | 
|  | 802 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 803 | pcmd += sizeof(uint32_t); | 
|  | 804 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 805 | sp = (struct serv_parm *) pcmd; | 
|  | 806 |  | 
|  | 807 | /* Setup CSPs accordingly for Fabric */ | 
|  | 808 | sp->cmn.e_d_tov = 0; | 
|  | 809 | sp->cmn.w2.r_a_tov = 0; | 
|  | 810 | sp->cls1.classValid = 0; | 
|  | 811 | sp->cls2.seqDelivery = 1; | 
|  | 812 | sp->cls3.seqDelivery = 1; | 
|  | 813 | if (sp->cmn.fcphLow < FC_PH3) | 
|  | 814 | sp->cmn.fcphLow = FC_PH3; | 
|  | 815 | if (sp->cmn.fcphHigh < FC_PH3) | 
|  | 816 | sp->cmn.fcphHigh = FC_PH3; | 
|  | 817 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 818 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { | 
|  | 819 | sp->cmn.request_multiple_Nport = 1; | 
|  | 820 |  | 
|  | 821 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ | 
|  | 822 | icmd->ulpCt_h = 1; | 
|  | 823 | icmd->ulpCt_l = 0; | 
|  | 824 | } | 
|  | 825 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 826 | if (phba->fc_topology != TOPOLOGY_LOOP) { | 
|  | 827 | icmd->un.elsreq64.myID = 0; | 
|  | 828 | icmd->un.elsreq64.fl = 1; | 
|  | 829 | } | 
|  | 830 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 831 | tmo = phba->fc_ratov; | 
|  | 832 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 833 | lpfc_set_disctmo(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 834 | phba->fc_ratov = tmo; | 
|  | 835 |  | 
|  | 836 | phba->fc_stat.elsXmitFLOGI++; | 
|  | 837 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 838 |  | 
|  | 839 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 840 | "Issue FLOGI:     opt:x%x", | 
|  | 841 | phba->sli3_options, 0, 0); | 
|  | 842 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 843 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 844 | if (rc == IOCB_ERROR) { | 
|  | 845 | lpfc_els_free_iocb(phba, elsiocb); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 846 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 847 | } | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 848 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 849 | } | 
|  | 850 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 851 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 852 | * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 853 | * @phba: pointer to lpfc hba data structure. | 
|  | 854 | * | 
|  | 855 | * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs | 
|  | 856 | * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq | 
|  | 857 | * list and issues an abort IOCB commond on each outstanding IOCB that | 
|  | 858 | * contains a active Fabric_DID ndlp. Note that this function is to issue | 
|  | 859 | * the abort IOCB command on all the outstanding IOCBs, thus when this | 
|  | 860 | * function returns, it does not guarantee all the IOCBs are actually aborted. | 
|  | 861 | * | 
|  | 862 | * Return code | 
|  | 863 | *   0 - Sucessfully issued abort iocb on all outstanding flogis (Always 0) | 
|  | 864 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 865 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 866 | lpfc_els_abort_flogi(struct lpfc_hba *phba) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 867 | { | 
|  | 868 | struct lpfc_sli_ring *pring; | 
|  | 869 | struct lpfc_iocbq *iocb, *next_iocb; | 
|  | 870 | struct lpfc_nodelist *ndlp; | 
|  | 871 | IOCB_t *icmd; | 
|  | 872 |  | 
|  | 873 | /* Abort outstanding I/O on NPort <nlp_DID> */ | 
|  | 874 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 875 | "0201 Abort outstanding I/O on NPort x%x\n", | 
|  | 876 | Fabric_DID); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 877 |  | 
|  | 878 | pring = &phba->sli.ring[LPFC_ELS_RING]; | 
|  | 879 |  | 
|  | 880 | /* | 
|  | 881 | * Check the txcmplq for an iocb that matches the nport the driver is | 
|  | 882 | * searching for. | 
|  | 883 | */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 884 | spin_lock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 885 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { | 
|  | 886 | icmd = &iocb->iocb; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 887 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR && | 
|  | 888 | icmd->un.elsreq64.bdl.ulpIoTag32) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 889 | ndlp = (struct lpfc_nodelist *)(iocb->context1); | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 890 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && | 
|  | 891 | (ndlp->nlp_DID == Fabric_DID)) | 
| James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 892 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 893 | } | 
|  | 894 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 895 | spin_unlock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 896 |  | 
|  | 897 | return 0; | 
|  | 898 | } | 
|  | 899 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 900 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 901 | * lpfc_initial_flogi - Issue an initial fabric login for a vport | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 902 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 903 | * | 
|  | 904 | * This routine issues an initial Fabric Login (FLOGI) for the @vport | 
|  | 905 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from | 
|  | 906 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and | 
|  | 907 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, | 
|  | 908 | * it will just be enabled and made active. The lpfc_issue_els_flogi() routine | 
|  | 909 | * is then invoked with the @vport and the ndlp to perform the FLOGI for the | 
|  | 910 | * @vport. | 
|  | 911 | * | 
|  | 912 | * Return code | 
|  | 913 | *   0 - failed to issue initial flogi for @vport | 
|  | 914 | *   1 - successfully issued initial flogi for @vport | 
|  | 915 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 916 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 917 | lpfc_initial_flogi(struct lpfc_vport *vport) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 918 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 919 | struct lpfc_hba *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 920 | struct lpfc_nodelist *ndlp; | 
|  | 921 |  | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 922 | vport->port_state = LPFC_FLOGI; | 
|  | 923 | lpfc_set_disctmo(vport); | 
|  | 924 |  | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 925 | /* First look for the Fabric ndlp */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 926 | ndlp = lpfc_findnode_did(vport, Fabric_DID); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 927 | if (!ndlp) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 928 | /* Cannot find existing Fabric ndlp, so allocate a new one */ | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 929 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | 
|  | 930 | if (!ndlp) | 
|  | 931 | return 0; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 932 | lpfc_nlp_init(vport, ndlp, Fabric_DID); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 933 | /* Put ndlp onto node list */ | 
|  | 934 | lpfc_enqueue_node(vport, ndlp); | 
|  | 935 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | 
|  | 936 | /* re-setup ndlp without removing from node list */ | 
|  | 937 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | 
|  | 938 | if (!ndlp) | 
|  | 939 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 940 | } | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 941 |  | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 942 | if (lpfc_issue_els_flogi(vport, ndlp, 0)) | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 943 | /* This decrement of reference count to node shall kick off | 
|  | 944 | * the release of the node. | 
|  | 945 | */ | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 946 | lpfc_nlp_put(ndlp); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 947 |  | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 948 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 949 | } | 
|  | 950 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 951 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 952 | * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 953 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 954 | * | 
|  | 955 | * This routine issues an initial Fabric Discover (FDISC) for the @vport | 
|  | 956 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from | 
|  | 957 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and | 
|  | 958 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, | 
|  | 959 | * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine | 
|  | 960 | * is then invoked with the @vport and the ndlp to perform the FDISC for the | 
|  | 961 | * @vport. | 
|  | 962 | * | 
|  | 963 | * Return code | 
|  | 964 | *   0 - failed to issue initial fdisc for @vport | 
|  | 965 | *   1 - successfully issued initial fdisc for @vport | 
|  | 966 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 967 | int | 
|  | 968 | lpfc_initial_fdisc(struct lpfc_vport *vport) | 
|  | 969 | { | 
|  | 970 | struct lpfc_hba *phba = vport->phba; | 
|  | 971 | struct lpfc_nodelist *ndlp; | 
|  | 972 |  | 
|  | 973 | /* First look for the Fabric ndlp */ | 
|  | 974 | ndlp = lpfc_findnode_did(vport, Fabric_DID); | 
|  | 975 | if (!ndlp) { | 
|  | 976 | /* Cannot find existing Fabric ndlp, so allocate a new one */ | 
|  | 977 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | 
|  | 978 | if (!ndlp) | 
|  | 979 | return 0; | 
|  | 980 | lpfc_nlp_init(vport, ndlp, Fabric_DID); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 981 | /* Put ndlp onto node list */ | 
|  | 982 | lpfc_enqueue_node(vport, ndlp); | 
|  | 983 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | 
|  | 984 | /* re-setup ndlp without removing from node list */ | 
|  | 985 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | 
|  | 986 | if (!ndlp) | 
|  | 987 | return 0; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 988 | } | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 989 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 990 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 991 | /* decrement node reference count to trigger the release of | 
|  | 992 | * the node. | 
|  | 993 | */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 994 | lpfc_nlp_put(ndlp); | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 995 | return 0; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 996 | } | 
|  | 997 | return 1; | 
|  | 998 | } | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 999 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1000 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1001 | * lpfc_more_plogi - Check and issue remaining plogis for a vport | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1002 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 1003 | * | 
|  | 1004 | * This routine checks whether there are more remaining Port Logins | 
|  | 1005 | * (PLOGI) to be issued for the @vport. If so, it will invoke the routine | 
|  | 1006 | * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes | 
|  | 1007 | * to issue ELS PLOGIs up to the configured discover threads with the | 
|  | 1008 | * @vport (@vport->cfg_discovery_threads). The function also decrement | 
|  | 1009 | * the @vport's num_disc_node by 1 if it is not already 0. | 
|  | 1010 | **/ | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1011 | void | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1012 | lpfc_more_plogi(struct lpfc_vport *vport) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1013 | { | 
|  | 1014 | int sentplogi; | 
|  | 1015 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1016 | if (vport->num_disc_nodes) | 
|  | 1017 | vport->num_disc_nodes--; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1018 |  | 
|  | 1019 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1020 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, | 
|  | 1021 | "0232 Continue discovery with %d PLOGIs to go " | 
|  | 1022 | "Data: x%x x%x x%x\n", | 
|  | 1023 | vport->num_disc_nodes, vport->fc_plogi_cnt, | 
|  | 1024 | vport->fc_flag, vport->port_state); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1025 | /* Check to see if there are more PLOGIs to be sent */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1026 | if (vport->fc_flag & FC_NLP_MORE) | 
|  | 1027 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ | 
|  | 1028 | sentplogi = lpfc_els_disc_plogi(vport); | 
|  | 1029 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1030 | return; | 
|  | 1031 | } | 
|  | 1032 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1033 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1034 | * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1035 | * @phba: pointer to lpfc hba data structure. | 
|  | 1036 | * @prsp: pointer to response IOCB payload. | 
|  | 1037 | * @ndlp: pointer to a node-list data structure. | 
|  | 1038 | * | 
|  | 1039 | * This routine checks and indicates whether the WWPN of an N_Port, retrieved | 
|  | 1040 | * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt. | 
|  | 1041 | * The following cases are considered N_Port confirmed: | 
|  | 1042 | * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches | 
|  | 1043 | * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but | 
|  | 1044 | * it does not have WWPN assigned either. If the WWPN is confirmed, the | 
|  | 1045 | * pointer to the @ndlp will be returned. If the WWPN is not confirmed: | 
|  | 1046 | * 1) if there is a node on vport list other than the @ndlp with the same | 
|  | 1047 | * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked | 
|  | 1048 | * on that node to release the RPI associated with the node; 2) if there is | 
|  | 1049 | * no node found on vport list with the same WWPN of the N_Port PLOGI logged | 
|  | 1050 | * into, a new node shall be allocated (or activated). In either case, the | 
|  | 1051 | * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall | 
|  | 1052 | * be released and the new_ndlp shall be put on to the vport node list and | 
|  | 1053 | * its pointer returned as the confirmed node. | 
|  | 1054 | * | 
|  | 1055 | * Note that before the @ndlp got "released", the keepDID from not-matching | 
|  | 1056 | * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID | 
|  | 1057 | * of the @ndlp. This is because the release of @ndlp is actually to put it | 
|  | 1058 | * into an inactive state on the vport node list and the vport node list | 
|  | 1059 | * management algorithm does not allow two node with a same DID. | 
|  | 1060 | * | 
|  | 1061 | * Return code | 
|  | 1062 | *   pointer to the PLOGI N_Port @ndlp | 
|  | 1063 | **/ | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1064 | static struct lpfc_nodelist * | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1065 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1066 | struct lpfc_nodelist *ndlp) | 
|  | 1067 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1068 | struct lpfc_vport    *vport = ndlp->vport; | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1069 | struct lpfc_nodelist *new_ndlp; | 
| James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1070 | struct lpfc_rport_data *rdata; | 
|  | 1071 | struct fc_rport *rport; | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1072 | struct serv_parm *sp; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1073 | uint8_t  name[sizeof(struct lpfc_name)]; | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1074 | uint32_t rc, keepDID = 0; | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1075 |  | 
| James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 1076 | /* Fabric nodes can have the same WWPN so we don't bother searching | 
|  | 1077 | * by WWPN.  Just return the ndlp that was given to us. | 
|  | 1078 | */ | 
|  | 1079 | if (ndlp->nlp_type & NLP_FABRIC) | 
|  | 1080 | return ndlp; | 
|  | 1081 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1082 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); | 
| James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1083 | memset(name, 0, sizeof(struct lpfc_name)); | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1084 |  | 
| James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1085 | /* 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] | 1086 | * we have for that ndlp. If not, we have some work to do. | 
|  | 1087 | */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1088 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1089 |  | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1090 | if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp)) | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1091 | return ndlp; | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1092 |  | 
|  | 1093 | if (!new_ndlp) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1094 | rc = memcmp(&ndlp->nlp_portname, name, | 
|  | 1095 | sizeof(struct lpfc_name)); | 
| James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1096 | if (!rc) | 
|  | 1097 | return ndlp; | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1098 | new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC); | 
|  | 1099 | if (!new_ndlp) | 
|  | 1100 | return ndlp; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1101 | lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1102 | } else if (!NLP_CHK_NODE_ACT(new_ndlp)) { | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1103 | rc = memcmp(&ndlp->nlp_portname, name, | 
|  | 1104 | sizeof(struct lpfc_name)); | 
|  | 1105 | if (!rc) | 
|  | 1106 | return ndlp; | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1107 | new_ndlp = lpfc_enable_node(vport, new_ndlp, | 
|  | 1108 | NLP_STE_UNUSED_NODE); | 
|  | 1109 | if (!new_ndlp) | 
|  | 1110 | return ndlp; | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1111 | keepDID = new_ndlp->nlp_DID; | 
|  | 1112 | } else | 
|  | 1113 | keepDID = new_ndlp->nlp_DID; | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1114 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1115 | lpfc_unreg_rpi(vport, new_ndlp); | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1116 | new_ndlp->nlp_DID = ndlp->nlp_DID; | 
| James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1117 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; | 
| James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1118 |  | 
|  | 1119 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) | 
|  | 1120 | new_ndlp->nlp_flag |= NLP_NPR_2B_DISC; | 
|  | 1121 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; | 
|  | 1122 |  | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1123 | /* 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] | 1124 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1125 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1126 | /* Move this back to NPR state */ | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1127 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { | 
|  | 1128 | /* The new_ndlp is replacing ndlp totally, so we need | 
|  | 1129 | * to put ndlp on UNUSED list and try to free it. | 
|  | 1130 | */ | 
| James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1131 |  | 
|  | 1132 | /* Fix up the rport accordingly */ | 
|  | 1133 | rport =  ndlp->rport; | 
|  | 1134 | if (rport) { | 
|  | 1135 | rdata = rport->dd_data; | 
|  | 1136 | if (rdata->pnode == ndlp) { | 
|  | 1137 | lpfc_nlp_put(ndlp); | 
|  | 1138 | ndlp->rport = NULL; | 
|  | 1139 | rdata->pnode = lpfc_nlp_get(new_ndlp); | 
|  | 1140 | new_ndlp->rport = rport; | 
|  | 1141 | } | 
|  | 1142 | new_ndlp->nlp_type = ndlp->nlp_type; | 
|  | 1143 | } | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1144 | /* We shall actually free the ndlp with both nlp_DID and | 
|  | 1145 | * nlp_portname fields equals 0 to avoid any ndlp on the | 
|  | 1146 | * nodelist never to be used. | 
|  | 1147 | */ | 
|  | 1148 | if (ndlp->nlp_DID == 0) { | 
|  | 1149 | spin_lock_irq(&phba->ndlp_lock); | 
|  | 1150 | NLP_SET_FREE_REQ(ndlp); | 
|  | 1151 | spin_unlock_irq(&phba->ndlp_lock); | 
|  | 1152 | } | 
| James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1153 |  | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1154 | /* Two ndlps cannot have the same did on the nodelist */ | 
|  | 1155 | ndlp->nlp_DID = keepDID; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1156 | lpfc_drop_node(vport, ndlp); | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1157 | } | 
| James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1158 | else { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1159 | lpfc_unreg_rpi(vport, ndlp); | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1160 | /* Two ndlps cannot have the same did */ | 
|  | 1161 | ndlp->nlp_DID = keepDID; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1162 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); | 
| James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1163 | } | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1164 | return new_ndlp; | 
|  | 1165 | } | 
|  | 1166 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1167 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1168 | * lpfc_end_rscn - Check and handle more rscn for a vport | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1169 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 1170 | * | 
|  | 1171 | * This routine checks whether more Registration State Change | 
|  | 1172 | * Notifications (RSCNs) came in while the discovery state machine was in | 
|  | 1173 | * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be | 
|  | 1174 | * invoked to handle the additional RSCNs for the @vport. Otherwise, the | 
|  | 1175 | * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of | 
|  | 1176 | * handling the RSCNs. | 
|  | 1177 | **/ | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1178 | void | 
|  | 1179 | lpfc_end_rscn(struct lpfc_vport *vport) | 
|  | 1180 | { | 
|  | 1181 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | 1182 |  | 
|  | 1183 | if (vport->fc_flag & FC_RSCN_MODE) { | 
|  | 1184 | /* | 
|  | 1185 | * Check to see if more RSCNs came in while we were | 
|  | 1186 | * processing this one. | 
|  | 1187 | */ | 
|  | 1188 | if (vport->fc_rscn_id_cnt || | 
|  | 1189 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) | 
|  | 1190 | lpfc_els_handle_rscn(vport); | 
|  | 1191 | else { | 
|  | 1192 | spin_lock_irq(shost->host_lock); | 
|  | 1193 | vport->fc_flag &= ~FC_RSCN_MODE; | 
|  | 1194 | spin_unlock_irq(shost->host_lock); | 
|  | 1195 | } | 
|  | 1196 | } | 
|  | 1197 | } | 
|  | 1198 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1199 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1200 | * lpfc_cmpl_els_plogi - Completion callback function for plogi | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1201 | * @phba: pointer to lpfc hba data structure. | 
|  | 1202 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 1203 | * @rspiocb: pointer to lpfc response iocb data structure. | 
|  | 1204 | * | 
|  | 1205 | * This routine is the completion callback function for issuing the Port | 
|  | 1206 | * Login (PLOGI) command. For PLOGI completion, there must be an active | 
|  | 1207 | * ndlp on the vport node list that matches the remote node ID from the | 
|  | 1208 | * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply | 
|  | 1209 | * ignored and command IOCB released. The PLOGI response IOCB status is | 
|  | 1210 | * checked for error conditons. If there is error status reported, PLOGI | 
|  | 1211 | * retry shall be attempted by invoking the lpfc_els_retry() routine. | 
|  | 1212 | * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on | 
|  | 1213 | * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine | 
|  | 1214 | * (DSM) is set for this PLOGI completion. Finally, it checks whether | 
|  | 1215 | * there are additional N_Port nodes with the vport that need to perform | 
|  | 1216 | * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition | 
|  | 1217 | * PLOGIs. | 
|  | 1218 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1219 | static void | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1220 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | 
|  | 1221 | struct lpfc_iocbq *rspiocb) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1222 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1223 | struct lpfc_vport *vport = cmdiocb->vport; | 
|  | 1224 | struct Scsi_Host  *shost = lpfc_shost_from_vport(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1225 | IOCB_t *irsp; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1226 | struct lpfc_nodelist *ndlp; | 
| James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1227 | struct lpfc_dmabuf *prsp; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1228 | int disc, rc, did, type; | 
|  | 1229 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1230 | /* we pass cmdiocb to state machine which needs rspiocb as well */ | 
|  | 1231 | cmdiocb->context_un.rsp_iocb = rspiocb; | 
|  | 1232 |  | 
|  | 1233 | irsp = &rspiocb->iocb; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1234 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 1235 | "PLOGI cmpl:      status:x%x/x%x did:x%x", | 
|  | 1236 | irsp->ulpStatus, irsp->un.ulpWord[4], | 
|  | 1237 | irsp->un.elsreq64.remoteID); | 
|  | 1238 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1239 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1240 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1241 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 1242 | "0136 PLOGI completes to NPort x%x " | 
|  | 1243 | "with no ndlp. Data: x%x x%x x%x\n", | 
|  | 1244 | irsp->un.elsreq64.remoteID, | 
|  | 1245 | irsp->ulpStatus, irsp->un.ulpWord[4], | 
|  | 1246 | irsp->ulpIoTag); | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1247 | goto out; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1248 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1249 |  | 
|  | 1250 | /* Since ndlp can be freed in the disc state machine, note if this node | 
|  | 1251 | * is being used during discovery. | 
|  | 1252 | */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1253 | spin_lock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1254 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1255 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1256 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1257 | rc   = 0; | 
|  | 1258 |  | 
|  | 1259 | /* PLOGI completes to NPort <nlp_DID> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1260 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 1261 | "0102 PLOGI completes to NPort x%x " | 
|  | 1262 | "Data: x%x x%x x%x x%x x%x\n", | 
|  | 1263 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], | 
|  | 1264 | irsp->ulpTimeout, disc, vport->num_disc_nodes); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1265 | /* Check to see if link went down during discovery */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1266 | if (lpfc_els_chk_latt(vport)) { | 
|  | 1267 | spin_lock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1268 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1269 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1270 | goto out; | 
|  | 1271 | } | 
|  | 1272 |  | 
|  | 1273 | /* ndlp could be freed in DSM, save these values now */ | 
|  | 1274 | type = ndlp->nlp_type; | 
|  | 1275 | did = ndlp->nlp_DID; | 
|  | 1276 |  | 
|  | 1277 | if (irsp->ulpStatus) { | 
|  | 1278 | /* Check for retry */ | 
|  | 1279 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { | 
|  | 1280 | /* ELS command is being retried */ | 
|  | 1281 | if (disc) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1282 | spin_lock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1283 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1284 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1285 | } | 
|  | 1286 | goto out; | 
|  | 1287 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1288 | /* PLOGI failed */ | 
|  | 1289 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1290 | if (lpfc_error_lost_link(irsp)) | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1291 | rc = NLP_STE_FREED_NODE; | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1292 | else | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1293 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1294 | NLP_EVT_CMPL_PLOGI); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1295 | } else { | 
|  | 1296 | /* Good status, call state machine */ | 
| James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1297 | prsp = list_entry(((struct lpfc_dmabuf *) | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1298 | cmdiocb->context2)->list.next, | 
|  | 1299 | struct lpfc_dmabuf, list); | 
|  | 1300 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1301 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1302 | NLP_EVT_CMPL_PLOGI); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1303 | } | 
|  | 1304 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1305 | if (disc && vport->num_disc_nodes) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1306 | /* Check to see if there are more PLOGIs to be sent */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1307 | lpfc_more_plogi(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1308 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1309 | if (vport->num_disc_nodes == 0) { | 
|  | 1310 | spin_lock_irq(shost->host_lock); | 
|  | 1311 | vport->fc_flag &= ~FC_NDISC_ACTIVE; | 
|  | 1312 | spin_unlock_irq(shost->host_lock); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1313 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1314 | lpfc_can_disctmo(vport); | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1315 | lpfc_end_rscn(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1316 | } | 
|  | 1317 | } | 
|  | 1318 |  | 
|  | 1319 | out: | 
|  | 1320 | lpfc_els_free_iocb(phba, cmdiocb); | 
|  | 1321 | return; | 
|  | 1322 | } | 
|  | 1323 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1324 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1325 | * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1326 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 1327 | * @did: destination port identifier. | 
|  | 1328 | * @retry: number of retries to the command IOCB. | 
|  | 1329 | * | 
|  | 1330 | * This routine issues a Port Login (PLOGI) command to a remote N_Port | 
|  | 1331 | * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, | 
|  | 1332 | * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. | 
|  | 1333 | * This routine constructs the proper feilds of the PLOGI IOCB and invokes | 
|  | 1334 | * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. | 
|  | 1335 | * | 
|  | 1336 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | 
|  | 1337 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | 
|  | 1338 | * will be stored into the context1 field of the IOCB for the completion | 
|  | 1339 | * callback function to the PLOGI ELS command. | 
|  | 1340 | * | 
|  | 1341 | * Return code | 
|  | 1342 | *   0 - Successfully issued a plogi for @vport | 
|  | 1343 | *   1 - failed to issue a plogi for @vport | 
|  | 1344 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1345 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1346 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1347 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1348 | struct lpfc_hba  *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1349 | struct serv_parm *sp; | 
|  | 1350 | IOCB_t *icmd; | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1351 | struct lpfc_nodelist *ndlp; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1352 | struct lpfc_iocbq *elsiocb; | 
|  | 1353 | struct lpfc_sli_ring *pring; | 
|  | 1354 | struct lpfc_sli *psli; | 
|  | 1355 | uint8_t *pcmd; | 
|  | 1356 | uint16_t cmdsize; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1357 | int ret; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1358 |  | 
|  | 1359 | psli = &phba->sli; | 
|  | 1360 | pring = &psli->ring[LPFC_ELS_RING];	/* ELS ring */ | 
|  | 1361 |  | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1362 | ndlp = lpfc_findnode_did(vport, did); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1363 | if (ndlp && !NLP_CHK_NODE_ACT(ndlp)) | 
|  | 1364 | ndlp = NULL; | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1365 |  | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1366 | /* 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] | 1367 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1368 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1369 | ELS_CMD_PLOGI); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1370 | if (!elsiocb) | 
|  | 1371 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1372 |  | 
|  | 1373 | icmd = &elsiocb->iocb; | 
|  | 1374 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 1375 |  | 
|  | 1376 | /* For PLOGI request, remainder of payload is service parameters */ | 
|  | 1377 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1378 | pcmd += sizeof(uint32_t); | 
|  | 1379 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1380 | sp = (struct serv_parm *) pcmd; | 
|  | 1381 |  | 
|  | 1382 | if (sp->cmn.fcphLow < FC_PH_4_3) | 
|  | 1383 | sp->cmn.fcphLow = FC_PH_4_3; | 
|  | 1384 |  | 
|  | 1385 | if (sp->cmn.fcphHigh < FC_PH3) | 
|  | 1386 | sp->cmn.fcphHigh = FC_PH3; | 
|  | 1387 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1388 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 1389 | "Issue PLOGI:     did:x%x", | 
|  | 1390 | did, 0, 0); | 
|  | 1391 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1392 | phba->fc_stat.elsXmitPLOGI++; | 
|  | 1393 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1394 | ret = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); | 
|  | 1395 |  | 
|  | 1396 | if (ret == IOCB_ERROR) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1397 | lpfc_els_free_iocb(phba, elsiocb); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1398 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1399 | } | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1400 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1401 | } | 
|  | 1402 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1403 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1404 | * lpfc_cmpl_els_prli - Completion callback function for prli | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1405 | * @phba: pointer to lpfc hba data structure. | 
|  | 1406 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 1407 | * @rspiocb: pointer to lpfc response iocb data structure. | 
|  | 1408 | * | 
|  | 1409 | * This routine is the completion callback function for a Process Login | 
|  | 1410 | * (PRLI) ELS command. The PRLI response IOCB status is checked for error | 
|  | 1411 | * status. If there is error status reported, PRLI retry shall be attempted | 
|  | 1412 | * by invoking the lpfc_els_retry() routine. Otherwise, the state | 
|  | 1413 | * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this | 
|  | 1414 | * ndlp to mark the PRLI completion. | 
|  | 1415 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1416 | static void | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1417 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | 
|  | 1418 | struct lpfc_iocbq *rspiocb) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1419 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1420 | struct lpfc_vport *vport = cmdiocb->vport; | 
|  | 1421 | struct Scsi_Host  *shost = lpfc_shost_from_vport(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1422 | IOCB_t *irsp; | 
|  | 1423 | struct lpfc_sli *psli; | 
|  | 1424 | struct lpfc_nodelist *ndlp; | 
|  | 1425 |  | 
|  | 1426 | psli = &phba->sli; | 
|  | 1427 | /* we pass cmdiocb to state machine which needs rspiocb as well */ | 
|  | 1428 | cmdiocb->context_un.rsp_iocb = rspiocb; | 
|  | 1429 |  | 
|  | 1430 | irsp = &(rspiocb->iocb); | 
|  | 1431 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1432 | spin_lock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1433 | ndlp->nlp_flag &= ~NLP_PRLI_SND; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1434 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1435 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1436 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 1437 | "PRLI cmpl:       status:x%x/x%x did:x%x", | 
|  | 1438 | irsp->ulpStatus, irsp->un.ulpWord[4], | 
|  | 1439 | ndlp->nlp_DID); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1440 | /* PRLI completes to NPort <nlp_DID> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1441 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 1442 | "0103 PRLI completes to NPort x%x " | 
|  | 1443 | "Data: x%x x%x x%x x%x\n", | 
|  | 1444 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], | 
|  | 1445 | irsp->ulpTimeout, vport->num_disc_nodes); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1446 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1447 | vport->fc_prli_sent--; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1448 | /* Check to see if link went down during discovery */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1449 | if (lpfc_els_chk_latt(vport)) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1450 | goto out; | 
|  | 1451 |  | 
|  | 1452 | if (irsp->ulpStatus) { | 
|  | 1453 | /* Check for retry */ | 
|  | 1454 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { | 
|  | 1455 | /* ELS command is being retried */ | 
|  | 1456 | goto out; | 
|  | 1457 | } | 
|  | 1458 | /* PRLI failed */ | 
|  | 1459 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1460 | if (lpfc_error_lost_link(irsp)) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1461 | goto out; | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1462 | else | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1463 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1464 | NLP_EVT_CMPL_PRLI); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1465 | } else | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1466 | /* Good status, call state machine */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1467 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1468 | NLP_EVT_CMPL_PRLI); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1469 | out: | 
|  | 1470 | lpfc_els_free_iocb(phba, cmdiocb); | 
|  | 1471 | return; | 
|  | 1472 | } | 
|  | 1473 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1474 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1475 | * lpfc_issue_els_prli - Issue a prli iocb command for a vport | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1476 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 1477 | * @ndlp: pointer to a node-list data structure. | 
|  | 1478 | * @retry: number of retries to the command IOCB. | 
|  | 1479 | * | 
|  | 1480 | * This routine issues a Process Login (PRLI) ELS command for the | 
|  | 1481 | * @vport. The PRLI service parameters are set up in the payload of the | 
|  | 1482 | * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine | 
|  | 1483 | * is put to the IOCB completion callback func field before invoking the | 
|  | 1484 | * routine lpfc_sli_issue_iocb() to send out PRLI command. | 
|  | 1485 | * | 
|  | 1486 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | 
|  | 1487 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | 
|  | 1488 | * will be stored into the context1 field of the IOCB for the completion | 
|  | 1489 | * callback function to the PRLI ELS command. | 
|  | 1490 | * | 
|  | 1491 | * Return code | 
|  | 1492 | *   0 - successfully issued prli iocb command for @vport | 
|  | 1493 | *   1 - failed to issue prli iocb command for @vport | 
|  | 1494 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1495 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1496 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1497 | uint8_t retry) | 
|  | 1498 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1499 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | 1500 | struct lpfc_hba *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1501 | PRLI *npr; | 
|  | 1502 | IOCB_t *icmd; | 
|  | 1503 | struct lpfc_iocbq *elsiocb; | 
|  | 1504 | struct lpfc_sli_ring *pring; | 
|  | 1505 | struct lpfc_sli *psli; | 
|  | 1506 | uint8_t *pcmd; | 
|  | 1507 | uint16_t cmdsize; | 
|  | 1508 |  | 
|  | 1509 | psli = &phba->sli; | 
|  | 1510 | pring = &psli->ring[LPFC_ELS_RING];	/* ELS ring */ | 
|  | 1511 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1512 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1513 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, | 
|  | 1514 | ndlp->nlp_DID, ELS_CMD_PRLI); | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1515 | if (!elsiocb) | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1516 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1517 |  | 
|  | 1518 | icmd = &elsiocb->iocb; | 
|  | 1519 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 1520 |  | 
|  | 1521 | /* For PRLI request, remainder of payload is service parameters */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1522 | memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t))); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1523 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLI; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1524 | pcmd += sizeof(uint32_t); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1525 |  | 
|  | 1526 | /* For PRLI, remainder of payload is PRLI parameter page */ | 
|  | 1527 | npr = (PRLI *) pcmd; | 
|  | 1528 | /* | 
|  | 1529 | * If our firmware version is 3.20 or later, | 
|  | 1530 | * set the following bits for FC-TAPE support. | 
|  | 1531 | */ | 
|  | 1532 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { | 
|  | 1533 | npr->ConfmComplAllowed = 1; | 
|  | 1534 | npr->Retry = 1; | 
|  | 1535 | npr->TaskRetryIdReq = 1; | 
|  | 1536 | } | 
|  | 1537 | npr->estabImagePair = 1; | 
|  | 1538 | npr->readXferRdyDis = 1; | 
|  | 1539 |  | 
|  | 1540 | /* For FCP support */ | 
|  | 1541 | npr->prliType = PRLI_FCP_TYPE; | 
|  | 1542 | npr->initiatorFunc = 1; | 
|  | 1543 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1544 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 1545 | "Issue PRLI:      did:x%x", | 
|  | 1546 | ndlp->nlp_DID, 0, 0); | 
|  | 1547 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1548 | phba->fc_stat.elsXmitPRLI++; | 
|  | 1549 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1550 | spin_lock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1551 | ndlp->nlp_flag |= NLP_PRLI_SND; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1552 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1553 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1554 | spin_lock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1555 | ndlp->nlp_flag &= ~NLP_PRLI_SND; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1556 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1557 | lpfc_els_free_iocb(phba, elsiocb); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1558 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1559 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1560 | vport->fc_prli_sent++; | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1561 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1562 | } | 
|  | 1563 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1564 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1565 | * lpfc_rscn_disc - Perform rscn discovery for a vport | 
| James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1566 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 1567 | * | 
|  | 1568 | * This routine performs Registration State Change Notification (RSCN) | 
|  | 1569 | * discovery for a @vport. If the @vport's node port recovery count is not | 
|  | 1570 | * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all | 
|  | 1571 | * the nodes that need recovery. If none of the PLOGI were needed through | 
|  | 1572 | * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be | 
|  | 1573 | * invoked to check and handle possible more RSCN came in during the period | 
|  | 1574 | * of processing the current ones. | 
|  | 1575 | **/ | 
|  | 1576 | static void | 
|  | 1577 | lpfc_rscn_disc(struct lpfc_vport *vport) | 
|  | 1578 | { | 
|  | 1579 | lpfc_can_disctmo(vport); | 
|  | 1580 |  | 
|  | 1581 | /* RSCN discovery */ | 
|  | 1582 | /* go thru NPR nodes and issue ELS PLOGIs */ | 
|  | 1583 | if (vport->fc_npr_cnt) | 
|  | 1584 | if (lpfc_els_disc_plogi(vport)) | 
|  | 1585 | return; | 
|  | 1586 |  | 
|  | 1587 | lpfc_end_rscn(vport); | 
|  | 1588 | } | 
|  | 1589 |  | 
|  | 1590 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1591 | * lpfc_adisc_done - Complete the adisc phase of discovery | 
| James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1592 | * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs. | 
|  | 1593 | * | 
|  | 1594 | * This function is called when the final ADISC is completed during discovery. | 
|  | 1595 | * This function handles clearing link attention or issuing reg_vpi depending | 
|  | 1596 | * on whether npiv is enabled. This function also kicks off the PLOGI phase of | 
|  | 1597 | * discovery. | 
|  | 1598 | * This function is called with no locks held. | 
|  | 1599 | **/ | 
|  | 1600 | static void | 
|  | 1601 | lpfc_adisc_done(struct lpfc_vport *vport) | 
|  | 1602 | { | 
|  | 1603 | struct Scsi_Host   *shost = lpfc_shost_from_vport(vport); | 
|  | 1604 | struct lpfc_hba   *phba = vport->phba; | 
|  | 1605 |  | 
|  | 1606 | /* | 
|  | 1607 | * For NPIV, cmpl_reg_vpi will set port_state to READY, | 
|  | 1608 | * and continue discovery. | 
|  | 1609 | */ | 
|  | 1610 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && | 
|  | 1611 | !(vport->fc_flag & FC_RSCN_MODE)) { | 
|  | 1612 | lpfc_issue_reg_vpi(phba, vport); | 
|  | 1613 | return; | 
|  | 1614 | } | 
|  | 1615 | /* | 
|  | 1616 | * For SLI2, we need to set port_state to READY | 
|  | 1617 | * and continue discovery. | 
|  | 1618 | */ | 
|  | 1619 | if (vport->port_state < LPFC_VPORT_READY) { | 
|  | 1620 | /* If we get here, there is nothing to ADISC */ | 
|  | 1621 | if (vport->port_type == LPFC_PHYSICAL_PORT) | 
|  | 1622 | lpfc_issue_clear_la(phba, vport); | 
|  | 1623 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { | 
|  | 1624 | vport->num_disc_nodes = 0; | 
|  | 1625 | /* go thru NPR list, issue ELS PLOGIs */ | 
|  | 1626 | if (vport->fc_npr_cnt) | 
|  | 1627 | lpfc_els_disc_plogi(vport); | 
|  | 1628 | if (!vport->num_disc_nodes) { | 
|  | 1629 | spin_lock_irq(shost->host_lock); | 
|  | 1630 | vport->fc_flag &= ~FC_NDISC_ACTIVE; | 
|  | 1631 | spin_unlock_irq(shost->host_lock); | 
|  | 1632 | lpfc_can_disctmo(vport); | 
|  | 1633 | lpfc_end_rscn(vport); | 
|  | 1634 | } | 
|  | 1635 | } | 
|  | 1636 | vport->port_state = LPFC_VPORT_READY; | 
|  | 1637 | } else | 
|  | 1638 | lpfc_rscn_disc(vport); | 
|  | 1639 | } | 
|  | 1640 |  | 
|  | 1641 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1642 | * lpfc_more_adisc - Issue more adisc as needed | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1643 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 1644 | * | 
|  | 1645 | * This routine determines whether there are more ndlps on a @vport | 
|  | 1646 | * node list need to have Address Discover (ADISC) issued. If so, it will | 
|  | 1647 | * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's | 
|  | 1648 | * remaining nodes which need to have ADISC sent. | 
|  | 1649 | **/ | 
| James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1650 | void | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1651 | lpfc_more_adisc(struct lpfc_vport *vport) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1652 | { | 
|  | 1653 | int sentadisc; | 
|  | 1654 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1655 | if (vport->num_disc_nodes) | 
|  | 1656 | vport->num_disc_nodes--; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1657 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1658 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, | 
|  | 1659 | "0210 Continue discovery with %d ADISCs to go " | 
|  | 1660 | "Data: x%x x%x x%x\n", | 
|  | 1661 | vport->num_disc_nodes, vport->fc_adisc_cnt, | 
|  | 1662 | vport->fc_flag, vport->port_state); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1663 | /* Check to see if there are more ADISCs to be sent */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1664 | if (vport->fc_flag & FC_NLP_MORE) { | 
|  | 1665 | lpfc_set_disctmo(vport); | 
|  | 1666 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ | 
|  | 1667 | sentadisc = lpfc_els_disc_adisc(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1668 | } | 
| James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1669 | if (!vport->num_disc_nodes) | 
|  | 1670 | lpfc_adisc_done(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1671 | return; | 
|  | 1672 | } | 
|  | 1673 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1674 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1675 | * lpfc_cmpl_els_adisc - Completion callback function for adisc | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1676 | * @phba: pointer to lpfc hba data structure. | 
|  | 1677 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 1678 | * @rspiocb: pointer to lpfc response iocb data structure. | 
|  | 1679 | * | 
|  | 1680 | * This routine is the completion function for issuing the Address Discover | 
|  | 1681 | * (ADISC) command. It first checks to see whether link went down during | 
|  | 1682 | * the discovery process. If so, the node will be marked as node port | 
|  | 1683 | * recovery for issuing discover IOCB by the link attention handler and | 
|  | 1684 | * exit. Otherwise, the response status is checked. If error was reported | 
|  | 1685 | * in the response status, the ADISC command shall be retried by invoking | 
|  | 1686 | * the lpfc_els_retry() routine. Otherwise, if no error was reported in | 
|  | 1687 | * the response status, the state machine is invoked to set transition | 
|  | 1688 | * with respect to NLP_EVT_CMPL_ADISC event. | 
|  | 1689 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1690 | static void | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1691 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | 
|  | 1692 | struct lpfc_iocbq *rspiocb) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1693 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1694 | struct lpfc_vport *vport = cmdiocb->vport; | 
|  | 1695 | struct Scsi_Host  *shost = lpfc_shost_from_vport(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1696 | IOCB_t *irsp; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1697 | struct lpfc_nodelist *ndlp; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1698 | int  disc; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1699 |  | 
|  | 1700 | /* we pass cmdiocb to state machine which needs rspiocb as well */ | 
|  | 1701 | cmdiocb->context_un.rsp_iocb = rspiocb; | 
|  | 1702 |  | 
|  | 1703 | irsp = &(rspiocb->iocb); | 
|  | 1704 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1705 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1706 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 1707 | "ADISC cmpl:      status:x%x/x%x did:x%x", | 
|  | 1708 | irsp->ulpStatus, irsp->un.ulpWord[4], | 
|  | 1709 | ndlp->nlp_DID); | 
|  | 1710 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1711 | /* Since ndlp can be freed in the disc state machine, note if this node | 
|  | 1712 | * is being used during discovery. | 
|  | 1713 | */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1714 | spin_lock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1715 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1716 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1717 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1718 | /* ADISC completes to NPort <nlp_DID> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1719 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 1720 | "0104 ADISC completes to NPort x%x " | 
|  | 1721 | "Data: x%x x%x x%x x%x x%x\n", | 
|  | 1722 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], | 
|  | 1723 | irsp->ulpTimeout, disc, vport->num_disc_nodes); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1724 | /* Check to see if link went down during discovery */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1725 | if (lpfc_els_chk_latt(vport)) { | 
|  | 1726 | spin_lock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1727 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1728 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1729 | goto out; | 
|  | 1730 | } | 
|  | 1731 |  | 
|  | 1732 | if (irsp->ulpStatus) { | 
|  | 1733 | /* Check for retry */ | 
|  | 1734 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { | 
|  | 1735 | /* ELS command is being retried */ | 
|  | 1736 | if (disc) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1737 | spin_lock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1738 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1739 | spin_unlock_irq(shost->host_lock); | 
|  | 1740 | lpfc_set_disctmo(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1741 | } | 
|  | 1742 | goto out; | 
|  | 1743 | } | 
|  | 1744 | /* ADISC failed */ | 
|  | 1745 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1746 | if (!lpfc_error_lost_link(irsp)) | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1747 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1748 | NLP_EVT_CMPL_ADISC); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1749 | } else | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1750 | /* Good status, call state machine */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1751 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1752 | NLP_EVT_CMPL_ADISC); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1753 |  | 
| James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1754 | /* Check to see if there are more ADISCs to be sent */ | 
|  | 1755 | if (disc && vport->num_disc_nodes) | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1756 | lpfc_more_adisc(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1757 | out: | 
|  | 1758 | lpfc_els_free_iocb(phba, cmdiocb); | 
|  | 1759 | return; | 
|  | 1760 | } | 
|  | 1761 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1762 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1763 | * 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] | 1764 | * @vport: pointer to a virtual N_Port data structure. | 
|  | 1765 | * @ndlp: pointer to a node-list data structure. | 
|  | 1766 | * @retry: number of retries to the command IOCB. | 
|  | 1767 | * | 
|  | 1768 | * This routine issues an Address Discover (ADISC) for an @ndlp on a | 
|  | 1769 | * @vport. It prepares the payload of the ADISC ELS command, updates the | 
|  | 1770 | * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine | 
|  | 1771 | * to issue the ADISC ELS command. | 
|  | 1772 | * | 
|  | 1773 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | 
|  | 1774 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | 
|  | 1775 | * will be stored into the context1 field of the IOCB for the completion | 
|  | 1776 | * callback function to the ADISC ELS command. | 
|  | 1777 | * | 
|  | 1778 | * Return code | 
|  | 1779 | *   0 - successfully issued adisc | 
|  | 1780 | *   1 - failed to issue adisc | 
|  | 1781 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1782 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1783 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1784 | uint8_t retry) | 
|  | 1785 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1786 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | 1787 | struct lpfc_hba  *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1788 | ADISC *ap; | 
|  | 1789 | IOCB_t *icmd; | 
|  | 1790 | struct lpfc_iocbq *elsiocb; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1791 | struct lpfc_sli *psli = &phba->sli; | 
|  | 1792 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1793 | uint8_t *pcmd; | 
|  | 1794 | uint16_t cmdsize; | 
|  | 1795 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1796 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1797 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, | 
|  | 1798 | ndlp->nlp_DID, ELS_CMD_ADISC); | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1799 | if (!elsiocb) | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1800 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1801 |  | 
|  | 1802 | icmd = &elsiocb->iocb; | 
|  | 1803 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 1804 |  | 
|  | 1805 | /* For ADISC request, remainder of payload is service parameters */ | 
|  | 1806 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1807 | pcmd += sizeof(uint32_t); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1808 |  | 
|  | 1809 | /* Fill in ADISC payload */ | 
|  | 1810 | ap = (ADISC *) pcmd; | 
|  | 1811 | ap->hardAL_PA = phba->fc_pref_ALPA; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1812 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); | 
|  | 1813 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1814 | ap->DID = be32_to_cpu(vport->fc_myDID); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1815 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1816 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 1817 | "Issue ADISC:     did:x%x", | 
|  | 1818 | ndlp->nlp_DID, 0, 0); | 
|  | 1819 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1820 | phba->fc_stat.elsXmitADISC++; | 
|  | 1821 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1822 | spin_lock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1823 | ndlp->nlp_flag |= NLP_ADISC_SND; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1824 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1825 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1826 | spin_lock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1827 | ndlp->nlp_flag &= ~NLP_ADISC_SND; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1828 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1829 | lpfc_els_free_iocb(phba, elsiocb); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1830 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1831 | } | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1832 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1833 | } | 
|  | 1834 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1835 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1836 | * lpfc_cmpl_els_logo - Completion callback function for logo | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1837 | * @phba: pointer to lpfc hba data structure. | 
|  | 1838 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 1839 | * @rspiocb: pointer to lpfc response iocb data structure. | 
|  | 1840 | * | 
|  | 1841 | * This routine is the completion function for issuing the ELS Logout (LOGO) | 
|  | 1842 | * command. If no error status was reported from the LOGO response, the | 
|  | 1843 | * state machine of the associated ndlp shall be invoked for transition with | 
|  | 1844 | * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported, | 
|  | 1845 | * the lpfc_els_retry() routine will be invoked to retry the LOGO command. | 
|  | 1846 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1847 | static void | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1848 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | 
|  | 1849 | struct lpfc_iocbq *rspiocb) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1850 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1851 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; | 
|  | 1852 | struct lpfc_vport *vport = ndlp->vport; | 
|  | 1853 | struct Scsi_Host  *shost = lpfc_shost_from_vport(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1854 | IOCB_t *irsp; | 
|  | 1855 | struct lpfc_sli *psli; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1856 |  | 
|  | 1857 | psli = &phba->sli; | 
|  | 1858 | /* we pass cmdiocb to state machine which needs rspiocb as well */ | 
|  | 1859 | cmdiocb->context_un.rsp_iocb = rspiocb; | 
|  | 1860 |  | 
|  | 1861 | irsp = &(rspiocb->iocb); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1862 | spin_lock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1863 | ndlp->nlp_flag &= ~NLP_LOGO_SND; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1864 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1865 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1866 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 1867 | "LOGO cmpl:       status:x%x/x%x did:x%x", | 
|  | 1868 | irsp->ulpStatus, irsp->un.ulpWord[4], | 
|  | 1869 | ndlp->nlp_DID); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1870 | /* LOGO completes to NPort <nlp_DID> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1871 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 1872 | "0105 LOGO completes to NPort x%x " | 
|  | 1873 | "Data: x%x x%x x%x x%x\n", | 
|  | 1874 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], | 
|  | 1875 | irsp->ulpTimeout, vport->num_disc_nodes); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1876 | /* Check to see if link went down during discovery */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1877 | if (lpfc_els_chk_latt(vport)) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1878 | goto out; | 
|  | 1879 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1880 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { | 
|  | 1881 | /* NLP_EVT_DEVICE_RM should unregister the RPI | 
|  | 1882 | * which should abort all outstanding IOs. | 
|  | 1883 | */ | 
|  | 1884 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, | 
|  | 1885 | NLP_EVT_DEVICE_RM); | 
|  | 1886 | goto out; | 
|  | 1887 | } | 
|  | 1888 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1889 | if (irsp->ulpStatus) { | 
|  | 1890 | /* Check for retry */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1891 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1892 | /* ELS command is being retried */ | 
|  | 1893 | goto out; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1894 | /* LOGO failed */ | 
|  | 1895 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1896 | if (lpfc_error_lost_link(irsp)) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1897 | goto out; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1898 | else | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1899 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1900 | NLP_EVT_CMPL_LOGO); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1901 | } else | 
| Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 1902 | /* Good status, call state machine. | 
|  | 1903 | * This will unregister the rpi if needed. | 
|  | 1904 | */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1905 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1906 | NLP_EVT_CMPL_LOGO); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1907 | out: | 
|  | 1908 | lpfc_els_free_iocb(phba, cmdiocb); | 
|  | 1909 | return; | 
|  | 1910 | } | 
|  | 1911 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1912 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1913 | * 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] | 1914 | * @vport: pointer to a virtual N_Port data structure. | 
|  | 1915 | * @ndlp: pointer to a node-list data structure. | 
|  | 1916 | * @retry: number of retries to the command IOCB. | 
|  | 1917 | * | 
|  | 1918 | * This routine constructs and issues an ELS Logout (LOGO) iocb command | 
|  | 1919 | * to a remote node, referred by an @ndlp on a @vport. It constructs the | 
|  | 1920 | * payload of the IOCB, properly sets up the @ndlp state, and invokes the | 
|  | 1921 | * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. | 
|  | 1922 | * | 
|  | 1923 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | 
|  | 1924 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | 
|  | 1925 | * will be stored into the context1 field of the IOCB for the completion | 
|  | 1926 | * callback function to the LOGO ELS command. | 
|  | 1927 | * | 
|  | 1928 | * Return code | 
|  | 1929 | *   0 - successfully issued logo | 
|  | 1930 | *   1 - failed to issue logo | 
|  | 1931 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1932 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1933 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1934 | uint8_t retry) | 
|  | 1935 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1936 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | 1937 | struct lpfc_hba  *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1938 | IOCB_t *icmd; | 
|  | 1939 | struct lpfc_iocbq *elsiocb; | 
|  | 1940 | struct lpfc_sli_ring *pring; | 
|  | 1941 | struct lpfc_sli *psli; | 
|  | 1942 | uint8_t *pcmd; | 
|  | 1943 | uint16_t cmdsize; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1944 | int rc; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1945 |  | 
|  | 1946 | psli = &phba->sli; | 
|  | 1947 | pring = &psli->ring[LPFC_ELS_RING]; | 
|  | 1948 |  | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1949 | spin_lock_irq(shost->host_lock); | 
|  | 1950 | if (ndlp->nlp_flag & NLP_LOGO_SND) { | 
|  | 1951 | spin_unlock_irq(shost->host_lock); | 
|  | 1952 | return 0; | 
|  | 1953 | } | 
|  | 1954 | spin_unlock_irq(shost->host_lock); | 
|  | 1955 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1956 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1957 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, | 
|  | 1958 | ndlp->nlp_DID, ELS_CMD_LOGO); | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1959 | if (!elsiocb) | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1960 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1961 |  | 
|  | 1962 | icmd = &elsiocb->iocb; | 
|  | 1963 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 1964 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1965 | pcmd += sizeof(uint32_t); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1966 |  | 
|  | 1967 | /* Fill in LOGO payload */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1968 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1969 | pcmd += sizeof(uint32_t); | 
|  | 1970 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1971 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1972 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 1973 | "Issue LOGO:      did:x%x", | 
|  | 1974 | ndlp->nlp_DID, 0, 0); | 
|  | 1975 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1976 | phba->fc_stat.elsXmitLOGO++; | 
|  | 1977 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1978 | spin_lock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1979 | ndlp->nlp_flag |= NLP_LOGO_SND; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1980 | spin_unlock_irq(shost->host_lock); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1981 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); | 
|  | 1982 |  | 
|  | 1983 | if (rc == IOCB_ERROR) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1984 | spin_lock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1985 | ndlp->nlp_flag &= ~NLP_LOGO_SND; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1986 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1987 | lpfc_els_free_iocb(phba, elsiocb); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1988 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1989 | } | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1990 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1991 | } | 
|  | 1992 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1993 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1994 | * lpfc_cmpl_els_cmd - Completion callback function for generic els command | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1995 | * @phba: pointer to lpfc hba data structure. | 
|  | 1996 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 1997 | * @rspiocb: pointer to lpfc response iocb data structure. | 
|  | 1998 | * | 
|  | 1999 | * This routine is a generic completion callback function for ELS commands. | 
|  | 2000 | * Specifically, it is the callback function which does not need to perform | 
|  | 2001 | * any command specific operations. It is currently used by the ELS command | 
|  | 2002 | * issuing routines for the ELS State Change  Request (SCR), | 
|  | 2003 | * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution | 
|  | 2004 | * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than | 
|  | 2005 | * certain debug loggings, this callback function simply invokes the | 
|  | 2006 | * lpfc_els_chk_latt() routine to check whether link went down during the | 
|  | 2007 | * discovery process. | 
|  | 2008 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2009 | static void | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2010 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | 
|  | 2011 | struct lpfc_iocbq *rspiocb) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2012 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2013 | struct lpfc_vport *vport = cmdiocb->vport; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2014 | IOCB_t *irsp; | 
|  | 2015 |  | 
|  | 2016 | irsp = &rspiocb->iocb; | 
|  | 2017 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2018 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 2019 | "ELS cmd cmpl:    status:x%x/x%x did:x%x", | 
|  | 2020 | irsp->ulpStatus, irsp->un.ulpWord[4], | 
|  | 2021 | irsp->un.elsreq64.remoteID); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2022 | /* ELS cmd tag <ulpIoTag> completes */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2023 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 2024 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", | 
|  | 2025 | irsp->ulpIoTag, irsp->ulpStatus, | 
|  | 2026 | irsp->un.ulpWord[4], irsp->ulpTimeout); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2027 | /* Check to see if link went down during discovery */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2028 | lpfc_els_chk_latt(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2029 | lpfc_els_free_iocb(phba, cmdiocb); | 
|  | 2030 | return; | 
|  | 2031 | } | 
|  | 2032 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2033 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2034 | * 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] | 2035 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 2036 | * @nportid: N_Port identifier to the remote node. | 
|  | 2037 | * @retry: number of retries to the command IOCB. | 
|  | 2038 | * | 
|  | 2039 | * This routine issues a State Change Request (SCR) to a fabric node | 
|  | 2040 | * on a @vport. The remote node @nportid is passed into the function. It | 
|  | 2041 | * first search the @vport node list to find the matching ndlp. If no such | 
|  | 2042 | * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An | 
|  | 2043 | * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() | 
|  | 2044 | * routine is invoked to send the SCR IOCB. | 
|  | 2045 | * | 
|  | 2046 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | 
|  | 2047 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | 
|  | 2048 | * will be stored into the context1 field of the IOCB for the completion | 
|  | 2049 | * callback function to the SCR ELS command. | 
|  | 2050 | * | 
|  | 2051 | * Return code | 
|  | 2052 | *   0 - Successfully issued scr command | 
|  | 2053 | *   1 - Failed to issue scr command | 
|  | 2054 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2055 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2056 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2057 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2058 | struct lpfc_hba  *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2059 | IOCB_t *icmd; | 
|  | 2060 | struct lpfc_iocbq *elsiocb; | 
|  | 2061 | struct lpfc_sli_ring *pring; | 
|  | 2062 | struct lpfc_sli *psli; | 
|  | 2063 | uint8_t *pcmd; | 
|  | 2064 | uint16_t cmdsize; | 
|  | 2065 | struct lpfc_nodelist *ndlp; | 
|  | 2066 |  | 
|  | 2067 | psli = &phba->sli; | 
|  | 2068 | pring = &psli->ring[LPFC_ELS_RING];	/* ELS ring */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2069 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2070 |  | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2071 | ndlp = lpfc_findnode_did(vport, nportid); | 
|  | 2072 | if (!ndlp) { | 
|  | 2073 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | 
|  | 2074 | if (!ndlp) | 
|  | 2075 | return 1; | 
|  | 2076 | lpfc_nlp_init(vport, ndlp, nportid); | 
|  | 2077 | lpfc_enqueue_node(vport, ndlp); | 
|  | 2078 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | 
|  | 2079 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | 
|  | 2080 | if (!ndlp) | 
|  | 2081 | return 1; | 
|  | 2082 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2083 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2084 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, | 
|  | 2085 | ndlp->nlp_DID, ELS_CMD_SCR); | 
|  | 2086 |  | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2087 | if (!elsiocb) { | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2088 | /* This will trigger the release of the node just | 
|  | 2089 | * allocated | 
|  | 2090 | */ | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2091 | lpfc_nlp_put(ndlp); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2092 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2093 | } | 
|  | 2094 |  | 
|  | 2095 | icmd = &elsiocb->iocb; | 
|  | 2096 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 2097 |  | 
|  | 2098 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2099 | pcmd += sizeof(uint32_t); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2100 |  | 
|  | 2101 | /* For SCR, remainder of payload is SCR parameter page */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2102 | memset(pcmd, 0, sizeof(SCR)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2103 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; | 
|  | 2104 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2105 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 2106 | "Issue SCR:       did:x%x", | 
|  | 2107 | ndlp->nlp_DID, 0, 0); | 
|  | 2108 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2109 | phba->fc_stat.elsXmitSCR++; | 
|  | 2110 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2111 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2112 | /* The additional lpfc_nlp_put will cause the following | 
|  | 2113 | * lpfc_els_free_iocb routine to trigger the rlease of | 
|  | 2114 | * the node. | 
|  | 2115 | */ | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2116 | lpfc_nlp_put(ndlp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2117 | lpfc_els_free_iocb(phba, elsiocb); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2118 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2119 | } | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2120 | /* This will cause the callback-function lpfc_cmpl_els_cmd to | 
|  | 2121 | * trigger the release of node. | 
|  | 2122 | */ | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2123 | lpfc_nlp_put(ndlp); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2124 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2125 | } | 
|  | 2126 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2127 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2128 | * 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] | 2129 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 2130 | * @nportid: N_Port identifier to the remote node. | 
|  | 2131 | * @retry: number of retries to the command IOCB. | 
|  | 2132 | * | 
|  | 2133 | * This routine issues a Fibre Channel Address Resolution Response | 
|  | 2134 | * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) | 
|  | 2135 | * is passed into the function. It first search the @vport node list to find | 
|  | 2136 | * the matching ndlp. If no such ndlp is found, a new ndlp shall be created | 
|  | 2137 | * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the | 
|  | 2138 | * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. | 
|  | 2139 | * | 
|  | 2140 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | 
|  | 2141 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | 
|  | 2142 | * will be stored into the context1 field of the IOCB for the completion | 
|  | 2143 | * callback function to the PARPR ELS command. | 
|  | 2144 | * | 
|  | 2145 | * Return code | 
|  | 2146 | *   0 - Successfully issued farpr command | 
|  | 2147 | *   1 - Failed to issue farpr command | 
|  | 2148 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2149 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2150 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2151 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2152 | struct lpfc_hba  *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2153 | IOCB_t *icmd; | 
|  | 2154 | struct lpfc_iocbq *elsiocb; | 
|  | 2155 | struct lpfc_sli_ring *pring; | 
|  | 2156 | struct lpfc_sli *psli; | 
|  | 2157 | FARP *fp; | 
|  | 2158 | uint8_t *pcmd; | 
|  | 2159 | uint32_t *lp; | 
|  | 2160 | uint16_t cmdsize; | 
|  | 2161 | struct lpfc_nodelist *ondlp; | 
|  | 2162 | struct lpfc_nodelist *ndlp; | 
|  | 2163 |  | 
|  | 2164 | psli = &phba->sli; | 
|  | 2165 | pring = &psli->ring[LPFC_ELS_RING];	/* ELS ring */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2166 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2167 |  | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2168 | ndlp = lpfc_findnode_did(vport, nportid); | 
|  | 2169 | if (!ndlp) { | 
|  | 2170 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | 
|  | 2171 | if (!ndlp) | 
|  | 2172 | return 1; | 
|  | 2173 | lpfc_nlp_init(vport, ndlp, nportid); | 
|  | 2174 | lpfc_enqueue_node(vport, ndlp); | 
|  | 2175 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | 
|  | 2176 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | 
|  | 2177 | if (!ndlp) | 
|  | 2178 | return 1; | 
|  | 2179 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2180 |  | 
|  | 2181 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, | 
|  | 2182 | ndlp->nlp_DID, ELS_CMD_RNID); | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2183 | if (!elsiocb) { | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2184 | /* This will trigger the release of the node just | 
|  | 2185 | * allocated | 
|  | 2186 | */ | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2187 | lpfc_nlp_put(ndlp); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2188 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2189 | } | 
|  | 2190 |  | 
|  | 2191 | icmd = &elsiocb->iocb; | 
|  | 2192 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 2193 |  | 
|  | 2194 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2195 | pcmd += sizeof(uint32_t); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2196 |  | 
|  | 2197 | /* Fill in FARPR payload */ | 
|  | 2198 | fp = (FARP *) (pcmd); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2199 | memset(fp, 0, sizeof(FARP)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2200 | lp = (uint32_t *) pcmd; | 
|  | 2201 | *lp++ = be32_to_cpu(nportid); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2202 | *lp++ = be32_to_cpu(vport->fc_myDID); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2203 | fp->Rflags = 0; | 
|  | 2204 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); | 
|  | 2205 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2206 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); | 
|  | 2207 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2208 | ondlp = lpfc_findnode_did(vport, nportid); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2209 | if (ondlp && NLP_CHK_NODE_ACT(ondlp)) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2210 | memcpy(&fp->OportName, &ondlp->nlp_portname, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2211 | sizeof(struct lpfc_name)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2212 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2213 | sizeof(struct lpfc_name)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2214 | } | 
|  | 2215 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2216 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 2217 | "Issue FARPR:     did:x%x", | 
|  | 2218 | ndlp->nlp_DID, 0, 0); | 
|  | 2219 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2220 | phba->fc_stat.elsXmitFARPR++; | 
|  | 2221 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2222 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2223 | /* The additional lpfc_nlp_put will cause the following | 
|  | 2224 | * lpfc_els_free_iocb routine to trigger the release of | 
|  | 2225 | * the node. | 
|  | 2226 | */ | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2227 | lpfc_nlp_put(ndlp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2228 | lpfc_els_free_iocb(phba, elsiocb); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2229 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2230 | } | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2231 | /* This will cause the callback-function lpfc_cmpl_els_cmd to | 
|  | 2232 | * trigger the release of the node. | 
|  | 2233 | */ | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2234 | lpfc_nlp_put(ndlp); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2235 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2236 | } | 
|  | 2237 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2238 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2239 | * 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] | 2240 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 2241 | * @nlp: pointer to a node-list data structure. | 
|  | 2242 | * | 
|  | 2243 | * This routine cancels the timer with a delayed IOCB-command retry for | 
|  | 2244 | * a @vport's @ndlp. It stops the timer for the delayed function retrial and | 
|  | 2245 | * removes the ELS retry event if it presents. In addition, if the | 
|  | 2246 | * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB | 
|  | 2247 | * commands are sent for the @vport's nodes that require issuing discovery | 
|  | 2248 | * ADISC. | 
|  | 2249 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2250 | void | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2251 | 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] | 2252 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2253 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2254 | struct lpfc_work_evt *evtp; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2255 |  | 
| James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2256 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) | 
|  | 2257 | return; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2258 | spin_lock_irq(shost->host_lock); | 
| James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2259 | nlp->nlp_flag &= ~NLP_DELAY_TMO; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2260 | spin_unlock_irq(shost->host_lock); | 
| James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2261 | del_timer_sync(&nlp->nlp_delayfunc); | 
|  | 2262 | nlp->nlp_last_elscmd = 0; | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2263 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { | 
| James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2264 | list_del_init(&nlp->els_retry_evt.evt_listp); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2265 | /* Decrement nlp reference count held for the delayed retry */ | 
|  | 2266 | evtp = &nlp->els_retry_evt; | 
|  | 2267 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); | 
|  | 2268 | } | 
| James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2269 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2270 | spin_lock_irq(shost->host_lock); | 
| James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2271 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2272 | spin_unlock_irq(shost->host_lock); | 
|  | 2273 | if (vport->num_disc_nodes) { | 
| James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2274 | if (vport->port_state < LPFC_VPORT_READY) { | 
|  | 2275 | /* Check if there are more ADISCs to be sent */ | 
|  | 2276 | lpfc_more_adisc(vport); | 
| James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2277 | } else { | 
|  | 2278 | /* Check if there are more PLOGIs to be sent */ | 
|  | 2279 | lpfc_more_plogi(vport); | 
| James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2280 | if (vport->num_disc_nodes == 0) { | 
|  | 2281 | spin_lock_irq(shost->host_lock); | 
|  | 2282 | vport->fc_flag &= ~FC_NDISC_ACTIVE; | 
|  | 2283 | spin_unlock_irq(shost->host_lock); | 
|  | 2284 | lpfc_can_disctmo(vport); | 
|  | 2285 | lpfc_end_rscn(vport); | 
|  | 2286 | } | 
| James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2287 | } | 
|  | 2288 | } | 
|  | 2289 | } | 
|  | 2290 | return; | 
|  | 2291 | } | 
|  | 2292 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2293 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2294 | * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2295 | * @ptr: holder for the pointer to the timer function associated data (ndlp). | 
|  | 2296 | * | 
|  | 2297 | * This routine is invoked by the ndlp delayed-function timer to check | 
|  | 2298 | * whether there is any pending ELS retry event(s) with the node. If not, it | 
|  | 2299 | * simply returns. Otherwise, if there is at least one ELS delayed event, it | 
|  | 2300 | * adds the delayed events to the HBA work list and invokes the | 
|  | 2301 | * lpfc_worker_wake_up() routine to wake up worker thread to process the | 
|  | 2302 | * event. Note that lpfc_nlp_get() is called before posting the event to | 
|  | 2303 | * the work list to hold reference count of ndlp so that it guarantees the | 
|  | 2304 | * reference to ndlp will still be available when the worker thread gets | 
|  | 2305 | * to the event associated with the ndlp. | 
|  | 2306 | **/ | 
| James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2307 | void | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2308 | lpfc_els_retry_delay(unsigned long ptr) | 
|  | 2309 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2310 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr; | 
|  | 2311 | struct lpfc_vport *vport = ndlp->vport; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2312 | struct lpfc_hba   *phba = vport->phba; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2313 | unsigned long flags; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2314 | struct lpfc_work_evt  *evtp = &ndlp->els_retry_evt; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2315 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2316 | spin_lock_irqsave(&phba->hbalock, flags); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2317 | if (!list_empty(&evtp->evt_listp)) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2318 | spin_unlock_irqrestore(&phba->hbalock, flags); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2319 | return; | 
|  | 2320 | } | 
|  | 2321 |  | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2322 | /* We need to hold the node by incrementing the reference | 
|  | 2323 | * count until the queued work is done | 
|  | 2324 | */ | 
|  | 2325 | evtp->evt_arg1  = lpfc_nlp_get(ndlp); | 
| James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2326 | if (evtp->evt_arg1) { | 
|  | 2327 | evtp->evt = LPFC_EVT_ELS_RETRY; | 
|  | 2328 | list_add_tail(&evtp->evt_listp, &phba->work_list); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2329 | lpfc_worker_wake_up(phba); | 
| James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2330 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2331 | spin_unlock_irqrestore(&phba->hbalock, flags); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2332 | return; | 
|  | 2333 | } | 
|  | 2334 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2335 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2336 | * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2337 | * @ndlp: pointer to a node-list data structure. | 
|  | 2338 | * | 
|  | 2339 | * This routine is the worker-thread handler for processing the @ndlp delayed | 
|  | 2340 | * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves | 
|  | 2341 | * the last ELS command from the associated ndlp and invokes the proper ELS | 
|  | 2342 | * function according to the delayed ELS command to retry the command. | 
|  | 2343 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2344 | void | 
|  | 2345 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) | 
|  | 2346 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2347 | struct lpfc_vport *vport = ndlp->vport; | 
|  | 2348 | struct Scsi_Host  *shost = lpfc_shost_from_vport(vport); | 
|  | 2349 | uint32_t cmd, did, retry; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2350 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2351 | spin_lock_irq(shost->host_lock); | 
| Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2352 | did = ndlp->nlp_DID; | 
|  | 2353 | cmd = ndlp->nlp_last_elscmd; | 
|  | 2354 | ndlp->nlp_last_elscmd = 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2355 |  | 
|  | 2356 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2357 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2358 | return; | 
|  | 2359 | } | 
|  | 2360 |  | 
|  | 2361 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2362 | spin_unlock_irq(shost->host_lock); | 
| James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 2363 | /* | 
|  | 2364 | * If a discovery event readded nlp_delayfunc after timer | 
|  | 2365 | * firing and before processing the timer, cancel the | 
|  | 2366 | * nlp_delayfunc. | 
|  | 2367 | */ | 
|  | 2368 | del_timer_sync(&ndlp->nlp_delayfunc); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2369 | retry = ndlp->nlp_retry; | 
|  | 2370 |  | 
|  | 2371 | switch (cmd) { | 
|  | 2372 | case ELS_CMD_FLOGI: | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2373 | lpfc_issue_els_flogi(vport, ndlp, retry); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2374 | break; | 
|  | 2375 | case ELS_CMD_PLOGI: | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2376 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { | 
| Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2377 | ndlp->nlp_prev_state = ndlp->nlp_state; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2378 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); | 
| Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2379 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2380 | break; | 
|  | 2381 | case ELS_CMD_ADISC: | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2382 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { | 
| Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2383 | ndlp->nlp_prev_state = ndlp->nlp_state; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2384 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); | 
| Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2385 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2386 | break; | 
|  | 2387 | case ELS_CMD_PRLI: | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2388 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { | 
| Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2389 | ndlp->nlp_prev_state = ndlp->nlp_state; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2390 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); | 
| Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2391 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2392 | break; | 
|  | 2393 | case ELS_CMD_LOGO: | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2394 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { | 
| Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2395 | ndlp->nlp_prev_state = ndlp->nlp_state; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2396 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); | 
| Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2397 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2398 | break; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2399 | case ELS_CMD_FDISC: | 
|  | 2400 | lpfc_issue_els_fdisc(vport, ndlp, retry); | 
|  | 2401 | break; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2402 | } | 
|  | 2403 | return; | 
|  | 2404 | } | 
|  | 2405 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2406 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2407 | * lpfc_els_retry - Make retry decision on an els command iocb | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2408 | * @phba: pointer to lpfc hba data structure. | 
|  | 2409 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 2410 | * @rspiocb: pointer to lpfc response iocb data structure. | 
|  | 2411 | * | 
|  | 2412 | * This routine makes a retry decision on an ELS command IOCB, which has | 
|  | 2413 | * failed. The following ELS IOCBs use this function for retrying the command | 
|  | 2414 | * when previously issued command responsed with error status: FLOGI, PLOGI, | 
|  | 2415 | * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the | 
|  | 2416 | * returned error status, it makes the decision whether a retry shall be | 
|  | 2417 | * issued for the command, and whether a retry shall be made immediately or | 
|  | 2418 | * delayed. In the former case, the corresponding ELS command issuing-function | 
|  | 2419 | * is called to retry the command. In the later case, the ELS command shall | 
|  | 2420 | * be posted to the ndlp delayed event and delayed function timer set to the | 
|  | 2421 | * ndlp for the delayed command issusing. | 
|  | 2422 | * | 
|  | 2423 | * Return code | 
|  | 2424 | *   0 - No retry of els command is made | 
|  | 2425 | *   1 - Immediate or delayed retry of els command is made | 
|  | 2426 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2427 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2428 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | 
|  | 2429 | struct lpfc_iocbq *rspiocb) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2430 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2431 | struct lpfc_vport *vport = cmdiocb->vport; | 
|  | 2432 | struct Scsi_Host  *shost = lpfc_shost_from_vport(vport); | 
|  | 2433 | IOCB_t *irsp = &rspiocb->iocb; | 
|  | 2434 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; | 
|  | 2435 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2436 | uint32_t *elscmd; | 
|  | 2437 | struct ls_rjt stat; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2438 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2439 | int logerr = 0; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2440 | uint32_t cmd = 0; | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2441 | uint32_t did; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2442 |  | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2443 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2444 | /* Note: context2 may be 0 for internal driver abort | 
|  | 2445 | * of delays ELS command. | 
|  | 2446 | */ | 
|  | 2447 |  | 
|  | 2448 | if (pcmd && pcmd->virt) { | 
|  | 2449 | elscmd = (uint32_t *) (pcmd->virt); | 
|  | 2450 | cmd = *elscmd++; | 
|  | 2451 | } | 
|  | 2452 |  | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2453 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2454 | did = ndlp->nlp_DID; | 
|  | 2455 | else { | 
|  | 2456 | /* We should only hit this case for retrying PLOGI */ | 
|  | 2457 | did = irsp->un.elsreq64.remoteID; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2458 | ndlp = lpfc_findnode_did(vport, did); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2459 | if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp)) | 
|  | 2460 | && (cmd != ELS_CMD_PLOGI)) | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2461 | return 1; | 
|  | 2462 | } | 
|  | 2463 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2464 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 2465 | "Retry ELS:       wd7:x%x wd4:x%x did:x%x", | 
|  | 2466 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); | 
|  | 2467 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2468 | switch (irsp->ulpStatus) { | 
|  | 2469 | case IOSTAT_FCP_RSP_ERROR: | 
|  | 2470 | case IOSTAT_REMOTE_STOP: | 
|  | 2471 | break; | 
|  | 2472 |  | 
|  | 2473 | case IOSTAT_LOCAL_REJECT: | 
|  | 2474 | switch ((irsp->un.ulpWord[4] & 0xff)) { | 
|  | 2475 | case IOERR_LOOP_OPEN_FAILURE: | 
| James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 2476 | if (cmd == ELS_CMD_FLOGI) { | 
|  | 2477 | if (PCI_DEVICE_ID_HORNET == | 
|  | 2478 | phba->pcidev->device) { | 
|  | 2479 | phba->fc_topology = TOPOLOGY_LOOP; | 
|  | 2480 | phba->pport->fc_myDID = 0; | 
|  | 2481 | phba->alpa_map[0] = 0; | 
|  | 2482 | phba->alpa_map[1] = 0; | 
|  | 2483 | } | 
|  | 2484 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2485 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2486 | delay = 1000; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2487 | retry = 1; | 
|  | 2488 | break; | 
|  | 2489 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2490 | case IOERR_ILLEGAL_COMMAND: | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2491 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 2492 | "0124 Retry illegal cmd x%x " | 
|  | 2493 | "retry:x%x delay:x%x\n", | 
|  | 2494 | cmd, cmdiocb->retry, delay); | 
|  | 2495 | retry = 1; | 
|  | 2496 | /* All command's retry policy */ | 
|  | 2497 | maxretry = 8; | 
|  | 2498 | if (cmdiocb->retry > 2) | 
|  | 2499 | delay = 1000; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2500 | break; | 
|  | 2501 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2502 | case IOERR_NO_RESOURCES: | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2503 | logerr = 1; /* HBA out of resources */ | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2504 | retry = 1; | 
|  | 2505 | if (cmdiocb->retry > 100) | 
|  | 2506 | delay = 100; | 
|  | 2507 | maxretry = 250; | 
|  | 2508 | break; | 
|  | 2509 |  | 
|  | 2510 | case IOERR_ILLEGAL_FRAME: | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2511 | delay = 100; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2512 | retry = 1; | 
|  | 2513 | break; | 
|  | 2514 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2515 | case IOERR_SEQUENCE_TIMEOUT: | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2516 | case IOERR_INVALID_RPI: | 
|  | 2517 | retry = 1; | 
|  | 2518 | break; | 
|  | 2519 | } | 
|  | 2520 | break; | 
|  | 2521 |  | 
|  | 2522 | case IOSTAT_NPORT_RJT: | 
|  | 2523 | case IOSTAT_FABRIC_RJT: | 
|  | 2524 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { | 
|  | 2525 | retry = 1; | 
|  | 2526 | break; | 
|  | 2527 | } | 
|  | 2528 | break; | 
|  | 2529 |  | 
|  | 2530 | case IOSTAT_NPORT_BSY: | 
|  | 2531 | case IOSTAT_FABRIC_BSY: | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2532 | logerr = 1; /* Fabric / Remote NPort out of resources */ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2533 | retry = 1; | 
|  | 2534 | break; | 
|  | 2535 |  | 
|  | 2536 | case IOSTAT_LS_RJT: | 
|  | 2537 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); | 
|  | 2538 | /* Added for Vendor specifc support | 
|  | 2539 | * Just keep retrying for these Rsn / Exp codes | 
|  | 2540 | */ | 
|  | 2541 | switch (stat.un.b.lsRjtRsnCode) { | 
|  | 2542 | case LSRJT_UNABLE_TPC: | 
|  | 2543 | if (stat.un.b.lsRjtRsnCodeExp == | 
|  | 2544 | LSEXP_CMD_IN_PROGRESS) { | 
|  | 2545 | if (cmd == ELS_CMD_PLOGI) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2546 | delay = 1000; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2547 | maxretry = 48; | 
|  | 2548 | } | 
|  | 2549 | retry = 1; | 
|  | 2550 | break; | 
|  | 2551 | } | 
|  | 2552 | if (cmd == ELS_CMD_PLOGI) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2553 | delay = 1000; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2554 | maxretry = lpfc_max_els_tries + 1; | 
|  | 2555 | retry = 1; | 
|  | 2556 | break; | 
|  | 2557 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2558 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && | 
|  | 2559 | (cmd == ELS_CMD_FDISC) && | 
|  | 2560 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2561 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 2562 | "0125 FDISC Failed (x%x). " | 
|  | 2563 | "Fabric out of resources\n", | 
|  | 2564 | stat.un.lsRjtError); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2565 | lpfc_vport_set_state(vport, | 
|  | 2566 | FC_VPORT_NO_FABRIC_RSCS); | 
|  | 2567 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2568 | break; | 
|  | 2569 |  | 
|  | 2570 | case LSRJT_LOGICAL_BSY: | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2571 | if ((cmd == ELS_CMD_PLOGI) || | 
|  | 2572 | (cmd == ELS_CMD_PRLI)) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2573 | delay = 1000; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2574 | maxretry = 48; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2575 | } else if (cmd == ELS_CMD_FDISC) { | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2576 | /* FDISC retry policy */ | 
|  | 2577 | maxretry = 48; | 
|  | 2578 | if (cmdiocb->retry >= 32) | 
|  | 2579 | delay = 1000; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2580 | } | 
|  | 2581 | retry = 1; | 
|  | 2582 | break; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2583 |  | 
|  | 2584 | case LSRJT_LOGICAL_ERR: | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2585 | /* There are some cases where switches return this | 
|  | 2586 | * error when they are not ready and should be returning | 
|  | 2587 | * Logical Busy. We should delay every time. | 
|  | 2588 | */ | 
|  | 2589 | if (cmd == ELS_CMD_FDISC && | 
|  | 2590 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { | 
|  | 2591 | maxretry = 3; | 
|  | 2592 | delay = 1000; | 
|  | 2593 | retry = 1; | 
|  | 2594 | break; | 
|  | 2595 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2596 | case LSRJT_PROTOCOL_ERR: | 
|  | 2597 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && | 
|  | 2598 | (cmd == ELS_CMD_FDISC) && | 
|  | 2599 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || | 
|  | 2600 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) | 
|  | 2601 | ) { | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2602 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2603 | "0122 FDISC Failed (x%x). " | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2604 | "Fabric Detected Bad WWN\n", | 
|  | 2605 | stat.un.lsRjtError); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2606 | lpfc_vport_set_state(vport, | 
|  | 2607 | FC_VPORT_FABRIC_REJ_WWN); | 
|  | 2608 | } | 
|  | 2609 | break; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2610 | } | 
|  | 2611 | break; | 
|  | 2612 |  | 
|  | 2613 | case IOSTAT_INTERMED_RSP: | 
|  | 2614 | case IOSTAT_BA_RJT: | 
|  | 2615 | break; | 
|  | 2616 |  | 
|  | 2617 | default: | 
|  | 2618 | break; | 
|  | 2619 | } | 
|  | 2620 |  | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2621 | if (did == FDMI_DID) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2622 | retry = 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2623 |  | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2624 | if ((cmd == ELS_CMD_FLOGI) && | 
| James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 2625 | (phba->fc_topology != TOPOLOGY_LOOP) && | 
|  | 2626 | !lpfc_error_lost_link(irsp)) { | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2627 | /* FLOGI retry policy */ | 
|  | 2628 | retry = 1; | 
|  | 2629 | maxretry = 48; | 
|  | 2630 | if (cmdiocb->retry >= 32) | 
|  | 2631 | delay = 1000; | 
|  | 2632 | } | 
|  | 2633 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2634 | if ((++cmdiocb->retry) >= maxretry) { | 
|  | 2635 | phba->fc_stat.elsRetryExceeded++; | 
|  | 2636 | retry = 0; | 
|  | 2637 | } | 
|  | 2638 |  | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2639 | if ((vport->load_flag & FC_UNLOADING) != 0) | 
|  | 2640 | retry = 0; | 
|  | 2641 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2642 | if (retry) { | 
|  | 2643 |  | 
|  | 2644 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2645 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 2646 | "0107 Retry ELS command x%x to remote " | 
|  | 2647 | "NPORT x%x Data: x%x x%x\n", | 
|  | 2648 | cmd, did, cmdiocb->retry, delay); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2649 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2650 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && | 
|  | 2651 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || | 
|  | 2652 | ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) { | 
|  | 2653 | /* Don't reset timer for no resources */ | 
|  | 2654 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2655 | /* If discovery / RSCN timer is running, reset it */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2656 | if (timer_pending(&vport->fc_disctmo) || | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2657 | (vport->fc_flag & FC_RSCN_MODE)) | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2658 | lpfc_set_disctmo(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2659 | } | 
|  | 2660 |  | 
|  | 2661 | phba->fc_stat.elsXmitRetry++; | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2662 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2663 | phba->fc_stat.elsDelayRetry++; | 
|  | 2664 | ndlp->nlp_retry = cmdiocb->retry; | 
|  | 2665 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2666 | /* delay is specified in milliseconds */ | 
|  | 2667 | mod_timer(&ndlp->nlp_delayfunc, | 
|  | 2668 | jiffies + msecs_to_jiffies(delay)); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2669 | spin_lock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2670 | ndlp->nlp_flag |= NLP_DELAY_TMO; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2671 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2672 |  | 
| Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2673 | ndlp->nlp_prev_state = ndlp->nlp_state; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2674 | if (cmd == ELS_CMD_PRLI) | 
|  | 2675 | lpfc_nlp_set_state(vport, ndlp, | 
|  | 2676 | NLP_STE_REG_LOGIN_ISSUE); | 
|  | 2677 | else | 
|  | 2678 | lpfc_nlp_set_state(vport, ndlp, | 
|  | 2679 | NLP_STE_NPR_NODE); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2680 | ndlp->nlp_last_elscmd = cmd; | 
|  | 2681 |  | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2682 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2683 | } | 
|  | 2684 | switch (cmd) { | 
|  | 2685 | case ELS_CMD_FLOGI: | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2686 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2687 | return 1; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2688 | case ELS_CMD_FDISC: | 
|  | 2689 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); | 
|  | 2690 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2691 | case ELS_CMD_PLOGI: | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2692 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2693 | ndlp->nlp_prev_state = ndlp->nlp_state; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2694 | lpfc_nlp_set_state(vport, ndlp, | 
| James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2695 | NLP_STE_PLOGI_ISSUE); | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2696 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2697 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2698 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2699 | case ELS_CMD_ADISC: | 
| Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2700 | ndlp->nlp_prev_state = ndlp->nlp_state; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2701 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); | 
|  | 2702 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2703 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2704 | case ELS_CMD_PRLI: | 
| Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2705 | ndlp->nlp_prev_state = ndlp->nlp_state; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2706 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); | 
|  | 2707 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2708 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2709 | case ELS_CMD_LOGO: | 
| Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2710 | ndlp->nlp_prev_state = ndlp->nlp_state; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2711 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); | 
|  | 2712 | lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2713 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2714 | } | 
|  | 2715 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2716 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2717 | if (logerr) { | 
|  | 2718 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 2719 | "0137 No retry ELS command x%x to remote " | 
|  | 2720 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", | 
|  | 2721 | cmd, did, irsp->ulpStatus, | 
|  | 2722 | irsp->un.ulpWord[4]); | 
|  | 2723 | } | 
|  | 2724 | else { | 
|  | 2725 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
| James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 2726 | "0108 No retry ELS command x%x to remote " | 
|  | 2727 | "NPORT x%x Retried:%d Error:x%x/%x\n", | 
|  | 2728 | cmd, did, cmdiocb->retry, irsp->ulpStatus, | 
|  | 2729 | irsp->un.ulpWord[4]); | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2730 | } | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2731 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2732 | } | 
|  | 2733 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2734 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2735 | * 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] | 2736 | * @phba: pointer to lpfc hba data structure. | 
|  | 2737 | * @buf_ptr1: pointer to the lpfc DMA buffer data structure. | 
|  | 2738 | * | 
|  | 2739 | * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) | 
|  | 2740 | * associated with a command IOCB back to the lpfc DMA buffer pool. It first | 
|  | 2741 | * checks to see whether there is a lpfc DMA buffer associated with the | 
|  | 2742 | * response of the command IOCB. If so, it will be released before releasing | 
|  | 2743 | * the lpfc DMA buffer associated with the IOCB itself. | 
|  | 2744 | * | 
|  | 2745 | * Return code | 
|  | 2746 | *   0 - Successfully released lpfc DMA buffer (currently, always return 0) | 
|  | 2747 | **/ | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2748 | static int | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2749 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) | 
|  | 2750 | { | 
|  | 2751 | struct lpfc_dmabuf *buf_ptr; | 
|  | 2752 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2753 | /* Free the response before processing the command. */ | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2754 | if (!list_empty(&buf_ptr1->list)) { | 
|  | 2755 | list_remove_head(&buf_ptr1->list, buf_ptr, | 
|  | 2756 | struct lpfc_dmabuf, | 
|  | 2757 | list); | 
|  | 2758 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | 
|  | 2759 | kfree(buf_ptr); | 
|  | 2760 | } | 
|  | 2761 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); | 
|  | 2762 | kfree(buf_ptr1); | 
|  | 2763 | return 0; | 
|  | 2764 | } | 
|  | 2765 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2766 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2767 | * 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] | 2768 | * @phba: pointer to lpfc hba data structure. | 
|  | 2769 | * @buf_ptr: pointer to the lpfc dma buffer data structure. | 
|  | 2770 | * | 
|  | 2771 | * This routine releases the lpfc Direct Memory Access (DMA) buffer | 
|  | 2772 | * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer | 
|  | 2773 | * pool. | 
|  | 2774 | * | 
|  | 2775 | * Return code | 
|  | 2776 | *   0 - Successfully released lpfc DMA buffer (currently, always return 0) | 
|  | 2777 | **/ | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2778 | static int | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2779 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) | 
|  | 2780 | { | 
|  | 2781 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | 
|  | 2782 | kfree(buf_ptr); | 
|  | 2783 | return 0; | 
|  | 2784 | } | 
|  | 2785 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2786 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2787 | * lpfc_els_free_iocb - Free a command iocb and its associated resources | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2788 | * @phba: pointer to lpfc hba data structure. | 
|  | 2789 | * @elsiocb: pointer to lpfc els command iocb data structure. | 
|  | 2790 | * | 
|  | 2791 | * This routine frees a command IOCB and its associated resources. The | 
|  | 2792 | * command IOCB data structure contains the reference to various associated | 
|  | 2793 | * resources, these fields must be set to NULL if the associated reference | 
|  | 2794 | * not present: | 
|  | 2795 | *   context1 - reference to ndlp | 
|  | 2796 | *   context2 - reference to cmd | 
|  | 2797 | *   context2->next - reference to rsp | 
|  | 2798 | *   context3 - reference to bpl | 
|  | 2799 | * | 
|  | 2800 | * It first properly decrements the reference count held on ndlp for the | 
|  | 2801 | * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not | 
|  | 2802 | * set, it invokes the lpfc_els_free_data() routine to release the Direct | 
|  | 2803 | * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it | 
|  | 2804 | * adds the DMA buffer the @phba data structure for the delayed release. | 
|  | 2805 | * If reference to the Buffer Pointer List (BPL) is present, the | 
|  | 2806 | * lpfc_els_free_bpl() routine is invoked to release the DMA memory | 
|  | 2807 | * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is | 
|  | 2808 | * invoked to release the IOCB data structure back to @phba IOCBQ list. | 
|  | 2809 | * | 
|  | 2810 | * Return code | 
|  | 2811 | *   0 - Success (currently, always return 0) | 
|  | 2812 | **/ | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2813 | int | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2814 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2815 | { | 
|  | 2816 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; | 
| James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2817 | struct lpfc_nodelist *ndlp; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2818 |  | 
| James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2819 | ndlp = (struct lpfc_nodelist *)elsiocb->context1; | 
|  | 2820 | if (ndlp) { | 
|  | 2821 | if (ndlp->nlp_flag & NLP_DEFER_RM) { | 
|  | 2822 | lpfc_nlp_put(ndlp); | 
|  | 2823 |  | 
|  | 2824 | /* If the ndlp is not being used by another discovery | 
|  | 2825 | * thread, free it. | 
|  | 2826 | */ | 
|  | 2827 | if (!lpfc_nlp_not_used(ndlp)) { | 
|  | 2828 | /* If ndlp is being used by another discovery | 
|  | 2829 | * thread, just clear NLP_DEFER_RM | 
|  | 2830 | */ | 
|  | 2831 | ndlp->nlp_flag &= ~NLP_DEFER_RM; | 
|  | 2832 | } | 
|  | 2833 | } | 
|  | 2834 | else | 
|  | 2835 | lpfc_nlp_put(ndlp); | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2836 | elsiocb->context1 = NULL; | 
|  | 2837 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2838 | /* context2  = cmd,  context2->next = rsp, context3 = bpl */ | 
|  | 2839 | if (elsiocb->context2) { | 
| James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2840 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { | 
|  | 2841 | /* Firmware could still be in progress of DMAing | 
|  | 2842 | * payload, so don't free data buffer till after | 
|  | 2843 | * a hbeat. | 
|  | 2844 | */ | 
|  | 2845 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; | 
|  | 2846 | buf_ptr = elsiocb->context2; | 
|  | 2847 | elsiocb->context2 = NULL; | 
|  | 2848 | if (buf_ptr) { | 
|  | 2849 | buf_ptr1 = NULL; | 
|  | 2850 | spin_lock_irq(&phba->hbalock); | 
|  | 2851 | if (!list_empty(&buf_ptr->list)) { | 
|  | 2852 | list_remove_head(&buf_ptr->list, | 
|  | 2853 | buf_ptr1, struct lpfc_dmabuf, | 
|  | 2854 | list); | 
|  | 2855 | INIT_LIST_HEAD(&buf_ptr1->list); | 
|  | 2856 | list_add_tail(&buf_ptr1->list, | 
|  | 2857 | &phba->elsbuf); | 
|  | 2858 | phba->elsbuf_cnt++; | 
|  | 2859 | } | 
|  | 2860 | INIT_LIST_HEAD(&buf_ptr->list); | 
|  | 2861 | list_add_tail(&buf_ptr->list, &phba->elsbuf); | 
|  | 2862 | phba->elsbuf_cnt++; | 
|  | 2863 | spin_unlock_irq(&phba->hbalock); | 
|  | 2864 | } | 
|  | 2865 | } else { | 
|  | 2866 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; | 
|  | 2867 | lpfc_els_free_data(phba, buf_ptr1); | 
|  | 2868 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2869 | } | 
|  | 2870 |  | 
|  | 2871 | if (elsiocb->context3) { | 
|  | 2872 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2873 | lpfc_els_free_bpl(phba, buf_ptr); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2874 | } | 
| James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2875 | lpfc_sli_release_iocbq(phba, elsiocb); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2876 | return 0; | 
|  | 2877 | } | 
|  | 2878 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2879 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2880 | * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2881 | * @phba: pointer to lpfc hba data structure. | 
|  | 2882 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 2883 | * @rspiocb: pointer to lpfc response iocb data structure. | 
|  | 2884 | * | 
|  | 2885 | * This routine is the completion callback function to the Logout (LOGO) | 
|  | 2886 | * Accept (ACC) Response ELS command. This routine is invoked to indicate | 
|  | 2887 | * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to | 
|  | 2888 | * release the ndlp if it has the last reference remaining (reference count | 
|  | 2889 | * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1 | 
|  | 2890 | * field to NULL to inform the following lpfc_els_free_iocb() routine no | 
|  | 2891 | * ndlp reference count needs to be decremented. Otherwise, the ndlp | 
|  | 2892 | * reference use-count shall be decremented by the lpfc_els_free_iocb() | 
|  | 2893 | * routine. Finally, the lpfc_els_free_iocb() is invoked to release the | 
|  | 2894 | * IOCB data structure. | 
|  | 2895 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2896 | static void | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2897 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | 
|  | 2898 | struct lpfc_iocbq *rspiocb) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2899 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2900 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; | 
|  | 2901 | struct lpfc_vport *vport = cmdiocb->vport; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2902 | IOCB_t *irsp; | 
|  | 2903 |  | 
|  | 2904 | irsp = &rspiocb->iocb; | 
|  | 2905 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, | 
|  | 2906 | "ACC LOGO cmpl:   status:x%x/x%x did:x%x", | 
|  | 2907 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2908 | /* ACC to LOGO completes to NPort <nlp_DID> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2909 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 2910 | "0109 ACC to LOGO completes to NPort x%x " | 
|  | 2911 | "Data: x%x x%x x%x\n", | 
|  | 2912 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | 
|  | 2913 | ndlp->nlp_rpi); | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2914 |  | 
|  | 2915 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { | 
|  | 2916 | /* NPort Recovery mode or node is just allocated */ | 
|  | 2917 | if (!lpfc_nlp_not_used(ndlp)) { | 
|  | 2918 | /* If the ndlp is being used by another discovery | 
|  | 2919 | * thread, just unregister the RPI. | 
|  | 2920 | */ | 
|  | 2921 | lpfc_unreg_rpi(vport, ndlp); | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2922 | } else { | 
|  | 2923 | /* Indicate the node has already released, should | 
|  | 2924 | * not reference to it from within lpfc_els_free_iocb. | 
|  | 2925 | */ | 
|  | 2926 | cmdiocb->context1 = NULL; | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2927 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2928 | } | 
|  | 2929 | lpfc_els_free_iocb(phba, cmdiocb); | 
|  | 2930 | return; | 
|  | 2931 | } | 
|  | 2932 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2933 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2934 | * 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] | 2935 | * @phba: pointer to lpfc hba data structure. | 
|  | 2936 | * @pmb: pointer to the driver internal queue element for mailbox command. | 
|  | 2937 | * | 
|  | 2938 | * This routine is the completion callback function for unregister default | 
|  | 2939 | * RPI (Remote Port Index) mailbox command to the @phba. It simply releases | 
|  | 2940 | * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and | 
|  | 2941 | * decrements the ndlp reference count held for this completion callback | 
|  | 2942 | * function. After that, it invokes the lpfc_nlp_not_used() to check | 
|  | 2943 | * whether there is only one reference left on the ndlp. If so, it will | 
|  | 2944 | * perform one more decrement and trigger the release of the ndlp. | 
|  | 2945 | **/ | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2946 | void | 
|  | 2947 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) | 
|  | 2948 | { | 
|  | 2949 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); | 
|  | 2950 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; | 
|  | 2951 |  | 
|  | 2952 | pmb->context1 = NULL; | 
|  | 2953 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | 
|  | 2954 | kfree(mp); | 
|  | 2955 | mempool_free(pmb, phba->mbox_mem_pool); | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2956 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { | 
| James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2957 | lpfc_nlp_put(ndlp); | 
| James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2958 | /* This is the end of the default RPI cleanup logic for this | 
|  | 2959 | * ndlp. If no other discovery threads are using this ndlp. | 
|  | 2960 | * we should free all resources associated with it. | 
|  | 2961 | */ | 
|  | 2962 | lpfc_nlp_not_used(ndlp); | 
|  | 2963 | } | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2964 | return; | 
|  | 2965 | } | 
|  | 2966 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2967 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2968 | * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2969 | * @phba: pointer to lpfc hba data structure. | 
|  | 2970 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 2971 | * @rspiocb: pointer to lpfc response iocb data structure. | 
|  | 2972 | * | 
|  | 2973 | * This routine is the completion callback function for ELS Response IOCB | 
|  | 2974 | * command. In normal case, this callback function just properly sets the | 
|  | 2975 | * nlp_flag bitmap in the ndlp data structure, if the mbox command reference | 
|  | 2976 | * field in the command IOCB is not NULL, the referred mailbox command will | 
|  | 2977 | * be send out, and then invokes the lpfc_els_free_iocb() routine to release | 
|  | 2978 | * the IOCB. Under error conditions, such as when a LS_RJT is returned or a | 
|  | 2979 | * link down event occurred during the discovery, the lpfc_nlp_not_used() | 
|  | 2980 | * routine shall be invoked trying to release the ndlp if no other threads | 
|  | 2981 | * are currently referring it. | 
|  | 2982 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2983 | static void | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2984 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2985 | struct lpfc_iocbq *rspiocb) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2986 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2987 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; | 
|  | 2988 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; | 
|  | 2989 | struct Scsi_Host  *shost = vport ? lpfc_shost_from_vport(vport) : NULL; | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2990 | IOCB_t  *irsp; | 
|  | 2991 | uint8_t *pcmd; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2992 | LPFC_MBOXQ_t *mbox = NULL; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2993 | struct lpfc_dmabuf *mp = NULL; | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2994 | uint32_t ls_rjt = 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2995 |  | 
| James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 2996 | irsp = &rspiocb->iocb; | 
|  | 2997 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2998 | if (cmdiocb->context_un.mbox) | 
|  | 2999 | mbox = cmdiocb->context_un.mbox; | 
|  | 3000 |  | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3001 | /* First determine if this is a LS_RJT cmpl. Note, this callback | 
|  | 3002 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. | 
|  | 3003 | */ | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3004 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3005 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && | 
|  | 3006 | (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3007 | /* A LS_RJT associated with Default RPI cleanup has its own | 
|  | 3008 | * seperate code path. | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3009 | */ | 
|  | 3010 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) | 
|  | 3011 | ls_rjt = 1; | 
|  | 3012 | } | 
|  | 3013 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3014 | /* Check to see if link went down during discovery */ | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3015 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3016 | if (mbox) { | 
| James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3017 | mp = (struct lpfc_dmabuf *) mbox->context1; | 
|  | 3018 | if (mp) { | 
|  | 3019 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | 
|  | 3020 | kfree(mp); | 
|  | 3021 | } | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3022 | mempool_free(mbox, phba->mbox_mem_pool); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3023 | } | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3024 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && | 
|  | 3025 | (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3026 | if (lpfc_nlp_not_used(ndlp)) { | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3027 | ndlp = NULL; | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3028 | /* Indicate the node has already released, | 
|  | 3029 | * should not reference to it from within | 
|  | 3030 | * the routine lpfc_els_free_iocb. | 
|  | 3031 | */ | 
|  | 3032 | cmdiocb->context1 = NULL; | 
|  | 3033 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3034 | goto out; | 
|  | 3035 | } | 
|  | 3036 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3037 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3038 | "ELS rsp cmpl:    status:x%x/x%x did:x%x", | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3039 | irsp->ulpStatus, irsp->un.ulpWord[4], | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3040 | cmdiocb->iocb.un.elsreq64.remoteID); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3041 | /* ELS response tag <ulpIoTag> completes */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3042 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 3043 | "0110 ELS response tag x%x completes " | 
|  | 3044 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", | 
|  | 3045 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, | 
|  | 3046 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, | 
|  | 3047 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | 
|  | 3048 | ndlp->nlp_rpi); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3049 | if (mbox) { | 
|  | 3050 | if ((rspiocb->iocb.ulpStatus == 0) | 
|  | 3051 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3052 | lpfc_unreg_rpi(vport, ndlp); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3053 | /* Increment reference count to ndlp to hold the | 
|  | 3054 | * reference to ndlp for the callback function. | 
|  | 3055 | */ | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3056 | mbox->context2 = lpfc_nlp_get(ndlp); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3057 | mbox->vport = vport; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3058 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { | 
|  | 3059 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; | 
|  | 3060 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; | 
|  | 3061 | } | 
|  | 3062 | else { | 
|  | 3063 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; | 
|  | 3064 | ndlp->nlp_prev_state = ndlp->nlp_state; | 
|  | 3065 | lpfc_nlp_set_state(vport, ndlp, | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3066 | NLP_STE_REG_LOGIN_ISSUE); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3067 | } | 
| James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3068 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3069 | != MBX_NOT_FINISHED) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3070 | goto out; | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3071 | else | 
|  | 3072 | /* Decrement the ndlp reference count we | 
|  | 3073 | * set for this failed mailbox command. | 
|  | 3074 | */ | 
|  | 3075 | lpfc_nlp_put(ndlp); | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3076 |  | 
|  | 3077 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ | 
|  | 3078 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 3079 | "0138 ELS rsp: Cannot issue reg_login for x%x " | 
|  | 3080 | "Data: x%x x%x x%x\n", | 
|  | 3081 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | 
|  | 3082 | ndlp->nlp_rpi); | 
|  | 3083 |  | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3084 | if (lpfc_nlp_not_used(ndlp)) { | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3085 | ndlp = NULL; | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3086 | /* Indicate node has already been released, | 
|  | 3087 | * should not reference to it from within | 
|  | 3088 | * the routine lpfc_els_free_iocb. | 
|  | 3089 | */ | 
|  | 3090 | cmdiocb->context1 = NULL; | 
|  | 3091 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3092 | } else { | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3093 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ | 
|  | 3094 | if (!lpfc_error_lost_link(irsp) && | 
|  | 3095 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3096 | if (lpfc_nlp_not_used(ndlp)) { | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3097 | ndlp = NULL; | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3098 | /* Indicate node has already been | 
|  | 3099 | * released, should not reference | 
|  | 3100 | * to it from within the routine | 
|  | 3101 | * lpfc_els_free_iocb. | 
|  | 3102 | */ | 
|  | 3103 | cmdiocb->context1 = NULL; | 
|  | 3104 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3105 | } | 
|  | 3106 | } | 
| James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3107 | mp = (struct lpfc_dmabuf *) mbox->context1; | 
|  | 3108 | if (mp) { | 
|  | 3109 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | 
|  | 3110 | kfree(mp); | 
|  | 3111 | } | 
|  | 3112 | mempool_free(mbox, phba->mbox_mem_pool); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3113 | } | 
|  | 3114 | out: | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3115 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3116 | spin_lock_irq(shost->host_lock); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3117 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3118 | spin_unlock_irq(shost->host_lock); | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3119 |  | 
|  | 3120 | /* If the node is not being used by another discovery thread, | 
|  | 3121 | * and we are sending a reject, we are done with it. | 
|  | 3122 | * Release driver reference count here and free associated | 
|  | 3123 | * resources. | 
|  | 3124 | */ | 
|  | 3125 | if (ls_rjt) | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3126 | if (lpfc_nlp_not_used(ndlp)) | 
|  | 3127 | /* Indicate node has already been released, | 
|  | 3128 | * should not reference to it from within | 
|  | 3129 | * the routine lpfc_els_free_iocb. | 
|  | 3130 | */ | 
|  | 3131 | cmdiocb->context1 = NULL; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3132 | } | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3133 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3134 | lpfc_els_free_iocb(phba, cmdiocb); | 
|  | 3135 | return; | 
|  | 3136 | } | 
|  | 3137 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3138 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3139 | * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3140 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 3141 | * @flag: the els command code to be accepted. | 
|  | 3142 | * @oldiocb: pointer to the original lpfc command iocb data structure. | 
|  | 3143 | * @ndlp: pointer to a node-list data structure. | 
|  | 3144 | * @mbox: pointer to the driver internal queue element for mailbox command. | 
|  | 3145 | * | 
|  | 3146 | * This routine prepares and issues an Accept (ACC) response IOCB | 
|  | 3147 | * command. It uses the @flag to properly set up the IOCB field for the | 
|  | 3148 | * specific ACC response command to be issued and invokes the | 
|  | 3149 | * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a | 
|  | 3150 | * @mbox pointer is passed in, it will be put into the context_un.mbox | 
|  | 3151 | * field of the IOCB for the completion callback function to issue the | 
|  | 3152 | * mailbox command to the HBA later when callback is invoked. | 
|  | 3153 | * | 
|  | 3154 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | 
|  | 3155 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | 
|  | 3156 | * will be stored into the context1 field of the IOCB for the completion | 
|  | 3157 | * callback function to the corresponding response ELS IOCB command. | 
|  | 3158 | * | 
|  | 3159 | * Return code | 
|  | 3160 | *   0 - Successfully issued acc response | 
|  | 3161 | *   1 - Failed to issue acc response | 
|  | 3162 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3163 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3164 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, | 
|  | 3165 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3166 | LPFC_MBOXQ_t *mbox) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3167 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3168 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | 3169 | struct lpfc_hba  *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3170 | IOCB_t *icmd; | 
|  | 3171 | IOCB_t *oldcmd; | 
|  | 3172 | struct lpfc_iocbq *elsiocb; | 
|  | 3173 | struct lpfc_sli_ring *pring; | 
|  | 3174 | struct lpfc_sli *psli; | 
|  | 3175 | uint8_t *pcmd; | 
|  | 3176 | uint16_t cmdsize; | 
|  | 3177 | int rc; | 
| James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3178 | ELS_PKT *els_pkt_ptr; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3179 |  | 
|  | 3180 | psli = &phba->sli; | 
|  | 3181 | pring = &psli->ring[LPFC_ELS_RING];	/* ELS ring */ | 
|  | 3182 | oldcmd = &oldiocb->iocb; | 
|  | 3183 |  | 
|  | 3184 | switch (flag) { | 
|  | 3185 | case ELS_CMD_ACC: | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3186 | cmdsize = sizeof(uint32_t); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3187 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, | 
|  | 3188 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3189 | if (!elsiocb) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3190 | spin_lock_irq(shost->host_lock); | 
| Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3191 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3192 | spin_unlock_irq(shost->host_lock); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3193 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3194 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3195 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3196 | icmd = &elsiocb->iocb; | 
|  | 3197 | icmd->ulpContext = oldcmd->ulpContext;	/* Xri */ | 
|  | 3198 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 3199 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3200 | pcmd += sizeof(uint32_t); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3201 |  | 
|  | 3202 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, | 
|  | 3203 | "Issue ACC:       did:x%x flg:x%x", | 
|  | 3204 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3205 | break; | 
|  | 3206 | case ELS_CMD_PLOGI: | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3207 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3208 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, | 
|  | 3209 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3210 | if (!elsiocb) | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3211 | return 1; | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3212 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3213 | icmd = &elsiocb->iocb; | 
|  | 3214 | icmd->ulpContext = oldcmd->ulpContext;	/* Xri */ | 
|  | 3215 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 3216 |  | 
|  | 3217 | if (mbox) | 
|  | 3218 | elsiocb->context_un.mbox = mbox; | 
|  | 3219 |  | 
|  | 3220 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3221 | pcmd += sizeof(uint32_t); | 
|  | 3222 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3223 |  | 
|  | 3224 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, | 
|  | 3225 | "Issue ACC PLOGI: did:x%x flg:x%x", | 
|  | 3226 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3227 | break; | 
| James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3228 | case ELS_CMD_PRLO: | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3229 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3230 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, | 
| James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3231 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); | 
|  | 3232 | if (!elsiocb) | 
|  | 3233 | return 1; | 
|  | 3234 |  | 
|  | 3235 | icmd = &elsiocb->iocb; | 
|  | 3236 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ | 
|  | 3237 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 3238 |  | 
|  | 3239 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3240 | sizeof(uint32_t) + sizeof(PRLO)); | 
| James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3241 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; | 
|  | 3242 | els_pkt_ptr = (ELS_PKT *) pcmd; | 
|  | 3243 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3244 |  | 
|  | 3245 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, | 
|  | 3246 | "Issue ACC PRLO:  did:x%x flg:x%x", | 
|  | 3247 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | 
| James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3248 | break; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3249 | default: | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3250 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3251 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3252 | /* Xmit ELS ACC response tag <ulpIoTag> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3253 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 3254 | "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " | 
|  | 3255 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n", | 
|  | 3256 | elsiocb->iotag, elsiocb->iocb.ulpContext, | 
|  | 3257 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | 
|  | 3258 | ndlp->nlp_rpi); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3259 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3260 | spin_lock_irq(shost->host_lock); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3261 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3262 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3263 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; | 
|  | 3264 | } else { | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3265 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3266 | } | 
|  | 3267 |  | 
|  | 3268 | phba->fc_stat.elsXmitACC++; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3269 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3270 | if (rc == IOCB_ERROR) { | 
|  | 3271 | lpfc_els_free_iocb(phba, elsiocb); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3272 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3273 | } | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3274 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3275 | } | 
|  | 3276 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3277 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3278 | * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3279 | * @vport: pointer to a virtual N_Port data structure. | 
|  | 3280 | * @rejectError: | 
|  | 3281 | * @oldiocb: pointer to the original lpfc command iocb data structure. | 
|  | 3282 | * @ndlp: pointer to a node-list data structure. | 
|  | 3283 | * @mbox: pointer to the driver internal queue element for mailbox command. | 
|  | 3284 | * | 
|  | 3285 | * This routine prepares and issue an Reject (RJT) response IOCB | 
|  | 3286 | * command. If a @mbox pointer is passed in, it will be put into the | 
|  | 3287 | * context_un.mbox field of the IOCB for the completion callback function | 
|  | 3288 | * to issue to the HBA later. | 
|  | 3289 | * | 
|  | 3290 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | 
|  | 3291 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | 
|  | 3292 | * will be stored into the context1 field of the IOCB for the completion | 
|  | 3293 | * callback function to the reject response ELS IOCB command. | 
|  | 3294 | * | 
|  | 3295 | * Return code | 
|  | 3296 | *   0 - Successfully issued reject response | 
|  | 3297 | *   1 - Failed to issue reject response | 
|  | 3298 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3299 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3300 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3301 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, | 
|  | 3302 | LPFC_MBOXQ_t *mbox) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3303 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3304 | struct lpfc_hba  *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3305 | IOCB_t *icmd; | 
|  | 3306 | IOCB_t *oldcmd; | 
|  | 3307 | struct lpfc_iocbq *elsiocb; | 
|  | 3308 | struct lpfc_sli_ring *pring; | 
|  | 3309 | struct lpfc_sli *psli; | 
|  | 3310 | uint8_t *pcmd; | 
|  | 3311 | uint16_t cmdsize; | 
|  | 3312 | int rc; | 
|  | 3313 |  | 
|  | 3314 | psli = &phba->sli; | 
|  | 3315 | pring = &psli->ring[LPFC_ELS_RING];	/* ELS ring */ | 
|  | 3316 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3317 | cmdsize = 2 * sizeof(uint32_t); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3318 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, | 
|  | 3319 | ndlp->nlp_DID, ELS_CMD_LS_RJT); | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3320 | if (!elsiocb) | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3321 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3322 |  | 
|  | 3323 | icmd = &elsiocb->iocb; | 
|  | 3324 | oldcmd = &oldiocb->iocb; | 
|  | 3325 | icmd->ulpContext = oldcmd->ulpContext;	/* Xri */ | 
|  | 3326 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 3327 |  | 
|  | 3328 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3329 | pcmd += sizeof(uint32_t); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3330 | *((uint32_t *) (pcmd)) = rejectError; | 
|  | 3331 |  | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3332 | if (mbox) | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3333 | elsiocb->context_un.mbox = mbox; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3334 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3335 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3336 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 3337 | "0129 Xmit ELS RJT x%x response tag x%x " | 
|  | 3338 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " | 
|  | 3339 | "rpi x%x\n", | 
|  | 3340 | rejectError, elsiocb->iotag, | 
|  | 3341 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, | 
|  | 3342 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3343 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, | 
|  | 3344 | "Issue LS_RJT:    did:x%x flg:x%x err:x%x", | 
|  | 3345 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); | 
|  | 3346 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3347 | phba->fc_stat.elsXmitLSRJT++; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3348 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3349 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3350 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3351 | if (rc == IOCB_ERROR) { | 
|  | 3352 | lpfc_els_free_iocb(phba, elsiocb); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3353 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3354 | } | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3355 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3356 | } | 
|  | 3357 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3358 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3359 | * 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] | 3360 | * @vport: pointer to a virtual N_Port data structure. | 
|  | 3361 | * @oldiocb: pointer to the original lpfc command iocb data structure. | 
|  | 3362 | * @ndlp: pointer to a node-list data structure. | 
|  | 3363 | * | 
|  | 3364 | * This routine prepares and issues an Accept (ACC) response to Address | 
|  | 3365 | * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB | 
|  | 3366 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. | 
|  | 3367 | * | 
|  | 3368 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | 
|  | 3369 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | 
|  | 3370 | * will be stored into the context1 field of the IOCB for the completion | 
|  | 3371 | * callback function to the ADISC Accept response ELS IOCB command. | 
|  | 3372 | * | 
|  | 3373 | * Return code | 
|  | 3374 | *   0 - Successfully issued acc adisc response | 
|  | 3375 | *   1 - Failed to issue adisc acc response | 
|  | 3376 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3377 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3378 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, | 
|  | 3379 | struct lpfc_nodelist *ndlp) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3380 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3381 | struct lpfc_hba  *phba = vport->phba; | 
|  | 3382 | struct lpfc_sli  *psli = &phba->sli; | 
|  | 3383 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3384 | ADISC *ap; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3385 | IOCB_t *icmd, *oldcmd; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3386 | struct lpfc_iocbq *elsiocb; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3387 | uint8_t *pcmd; | 
|  | 3388 | uint16_t cmdsize; | 
|  | 3389 | int rc; | 
|  | 3390 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3391 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3392 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, | 
|  | 3393 | ndlp->nlp_DID, ELS_CMD_ACC); | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3394 | if (!elsiocb) | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3395 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3396 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3397 | icmd = &elsiocb->iocb; | 
|  | 3398 | oldcmd = &oldiocb->iocb; | 
|  | 3399 | icmd->ulpContext = oldcmd->ulpContext;	/* Xri */ | 
| James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3400 |  | 
|  | 3401 | /* Xmit ADISC ACC response tag <ulpIoTag> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3402 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 3403 | "0130 Xmit ADISC ACC response iotag x%x xri: " | 
|  | 3404 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", | 
|  | 3405 | elsiocb->iotag, elsiocb->iocb.ulpContext, | 
|  | 3406 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | 
|  | 3407 | ndlp->nlp_rpi); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3408 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 3409 |  | 
|  | 3410 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3411 | pcmd += sizeof(uint32_t); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3412 |  | 
|  | 3413 | ap = (ADISC *) (pcmd); | 
|  | 3414 | ap->hardAL_PA = phba->fc_pref_ALPA; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3415 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); | 
|  | 3416 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3417 | ap->DID = be32_to_cpu(vport->fc_myDID); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3418 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3419 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, | 
|  | 3420 | "Issue ACC ADISC: did:x%x flg:x%x", | 
|  | 3421 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | 
|  | 3422 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3423 | phba->fc_stat.elsXmitACC++; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3424 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3425 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3426 | if (rc == IOCB_ERROR) { | 
|  | 3427 | lpfc_els_free_iocb(phba, elsiocb); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3428 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3429 | } | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3430 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3431 | } | 
|  | 3432 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3433 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3434 | * 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] | 3435 | * @vport: pointer to a virtual N_Port data structure. | 
|  | 3436 | * @oldiocb: pointer to the original lpfc command iocb data structure. | 
|  | 3437 | * @ndlp: pointer to a node-list data structure. | 
|  | 3438 | * | 
|  | 3439 | * This routine prepares and issues an Accept (ACC) response to Process | 
|  | 3440 | * Login (PRLI) ELS command. It simply prepares the payload of the IOCB | 
|  | 3441 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. | 
|  | 3442 | * | 
|  | 3443 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | 
|  | 3444 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | 
|  | 3445 | * will be stored into the context1 field of the IOCB for the completion | 
|  | 3446 | * callback function to the PRLI Accept response ELS IOCB command. | 
|  | 3447 | * | 
|  | 3448 | * Return code | 
|  | 3449 | *   0 - Successfully issued acc prli response | 
|  | 3450 | *   1 - Failed to issue acc prli response | 
|  | 3451 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3452 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3453 | 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] | 3454 | struct lpfc_nodelist *ndlp) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3455 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3456 | struct lpfc_hba  *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3457 | PRLI *npr; | 
|  | 3458 | lpfc_vpd_t *vpd; | 
|  | 3459 | IOCB_t *icmd; | 
|  | 3460 | IOCB_t *oldcmd; | 
|  | 3461 | struct lpfc_iocbq *elsiocb; | 
|  | 3462 | struct lpfc_sli_ring *pring; | 
|  | 3463 | struct lpfc_sli *psli; | 
|  | 3464 | uint8_t *pcmd; | 
|  | 3465 | uint16_t cmdsize; | 
|  | 3466 | int rc; | 
|  | 3467 |  | 
|  | 3468 | psli = &phba->sli; | 
|  | 3469 | pring = &psli->ring[LPFC_ELS_RING];	/* ELS ring */ | 
|  | 3470 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3471 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3472 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3473 | ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK))); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3474 | if (!elsiocb) | 
|  | 3475 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3476 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3477 | icmd = &elsiocb->iocb; | 
|  | 3478 | oldcmd = &oldiocb->iocb; | 
|  | 3479 | icmd->ulpContext = oldcmd->ulpContext;	/* Xri */ | 
| James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3480 | /* Xmit PRLI ACC response tag <ulpIoTag> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3481 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 3482 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " | 
|  | 3483 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", | 
|  | 3484 | elsiocb->iotag, elsiocb->iocb.ulpContext, | 
|  | 3485 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | 
|  | 3486 | ndlp->nlp_rpi); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3487 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 3488 |  | 
|  | 3489 | *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3490 | pcmd += sizeof(uint32_t); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3491 |  | 
|  | 3492 | /* For PRLI, remainder of payload is PRLI parameter page */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3493 | memset(pcmd, 0, sizeof(PRLI)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3494 |  | 
|  | 3495 | npr = (PRLI *) pcmd; | 
|  | 3496 | vpd = &phba->vpd; | 
|  | 3497 | /* | 
| James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3498 | * If the remote port is a target and our firmware version is 3.20 or | 
|  | 3499 | * later, set the following bits for FC-TAPE support. | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3500 | */ | 
| James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3501 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && | 
|  | 3502 | (vpd->rev.feaLevelHigh >= 0x02)) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3503 | npr->ConfmComplAllowed = 1; | 
|  | 3504 | npr->Retry = 1; | 
|  | 3505 | npr->TaskRetryIdReq = 1; | 
|  | 3506 | } | 
|  | 3507 |  | 
|  | 3508 | npr->acceptRspCode = PRLI_REQ_EXECUTED; | 
|  | 3509 | npr->estabImagePair = 1; | 
|  | 3510 | npr->readXferRdyDis = 1; | 
|  | 3511 | npr->ConfmComplAllowed = 1; | 
|  | 3512 |  | 
|  | 3513 | npr->prliType = PRLI_FCP_TYPE; | 
|  | 3514 | npr->initiatorFunc = 1; | 
|  | 3515 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3516 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, | 
|  | 3517 | "Issue ACC PRLI:  did:x%x flg:x%x", | 
|  | 3518 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | 
|  | 3519 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3520 | phba->fc_stat.elsXmitACC++; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3521 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3522 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3523 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3524 | if (rc == IOCB_ERROR) { | 
|  | 3525 | lpfc_els_free_iocb(phba, elsiocb); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3526 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3527 | } | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3528 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3529 | } | 
|  | 3530 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3531 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3532 | * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3533 | * @vport: pointer to a virtual N_Port data structure. | 
|  | 3534 | * @format: rnid command format. | 
|  | 3535 | * @oldiocb: pointer to the original lpfc command iocb data structure. | 
|  | 3536 | * @ndlp: pointer to a node-list data structure. | 
|  | 3537 | * | 
|  | 3538 | * This routine issues a Request Node Identification Data (RNID) Accept | 
|  | 3539 | * (ACC) response. It constructs the RNID ACC response command according to | 
|  | 3540 | * the proper @format and then calls the lpfc_sli_issue_iocb() routine to | 
|  | 3541 | * issue the response. Note that this command does not need to hold the ndlp | 
|  | 3542 | * reference count for the callback. So, the ndlp reference count taken by | 
|  | 3543 | * the lpfc_prep_els_iocb() routine is put back and the context1 field of | 
|  | 3544 | * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that | 
|  | 3545 | * there is no ndlp reference available. | 
|  | 3546 | * | 
|  | 3547 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | 
|  | 3548 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | 
|  | 3549 | * will be stored into the context1 field of the IOCB for the completion | 
|  | 3550 | * callback function. However, for the RNID Accept Response ELS command, | 
|  | 3551 | * this is undone later by this routine after the IOCB is allocated. | 
|  | 3552 | * | 
|  | 3553 | * Return code | 
|  | 3554 | *   0 - Successfully issued acc rnid response | 
|  | 3555 | *   1 - Failed to issue acc rnid response | 
|  | 3556 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3557 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3558 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3559 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3560 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3561 | struct lpfc_hba  *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3562 | RNID *rn; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3563 | IOCB_t *icmd, *oldcmd; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3564 | struct lpfc_iocbq *elsiocb; | 
|  | 3565 | struct lpfc_sli_ring *pring; | 
|  | 3566 | struct lpfc_sli *psli; | 
|  | 3567 | uint8_t *pcmd; | 
|  | 3568 | uint16_t cmdsize; | 
|  | 3569 | int rc; | 
|  | 3570 |  | 
|  | 3571 | psli = &phba->sli; | 
|  | 3572 | pring = &psli->ring[LPFC_ELS_RING]; | 
|  | 3573 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3574 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) | 
|  | 3575 | + (2 * sizeof(struct lpfc_name)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3576 | if (format) | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3577 | cmdsize += sizeof(RNID_TOP_DISC); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3578 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3579 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, | 
|  | 3580 | ndlp->nlp_DID, ELS_CMD_ACC); | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3581 | if (!elsiocb) | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3582 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3583 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3584 | icmd = &elsiocb->iocb; | 
|  | 3585 | oldcmd = &oldiocb->iocb; | 
|  | 3586 | icmd->ulpContext = oldcmd->ulpContext;	/* Xri */ | 
| James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3587 | /* Xmit RNID ACC response tag <ulpIoTag> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3588 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 3589 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", | 
|  | 3590 | elsiocb->iotag, elsiocb->iocb.ulpContext); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3591 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3592 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3593 | pcmd += sizeof(uint32_t); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3594 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3595 | memset(pcmd, 0, sizeof(RNID)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3596 | rn = (RNID *) (pcmd); | 
|  | 3597 | rn->Format = format; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3598 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); | 
|  | 3599 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); | 
|  | 3600 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3601 | switch (format) { | 
|  | 3602 | case 0: | 
|  | 3603 | rn->SpecificLen = 0; | 
|  | 3604 | break; | 
|  | 3605 | case RNID_TOPOLOGY_DISC: | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3606 | rn->SpecificLen = sizeof(RNID_TOP_DISC); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3607 | memcpy(&rn->un.topologyDisc.portName, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3608 | &vport->fc_portname, sizeof(struct lpfc_name)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3609 | rn->un.topologyDisc.unitType = RNID_HBA; | 
|  | 3610 | rn->un.topologyDisc.physPort = 0; | 
|  | 3611 | rn->un.topologyDisc.attachedNodes = 0; | 
|  | 3612 | break; | 
|  | 3613 | default: | 
|  | 3614 | rn->CommonLen = 0; | 
|  | 3615 | rn->SpecificLen = 0; | 
|  | 3616 | break; | 
|  | 3617 | } | 
|  | 3618 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3619 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, | 
|  | 3620 | "Issue ACC RNID:  did:x%x flg:x%x", | 
|  | 3621 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | 
|  | 3622 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3623 | phba->fc_stat.elsXmitACC++; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3624 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3625 | lpfc_nlp_put(ndlp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3626 | elsiocb->context1 = NULL;  /* Don't need ndlp for cmpl, | 
|  | 3627 | * it could be freed */ | 
|  | 3628 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3629 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3630 | if (rc == IOCB_ERROR) { | 
|  | 3631 | lpfc_els_free_iocb(phba, elsiocb); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3632 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3633 | } | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3634 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3635 | } | 
|  | 3636 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3637 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3638 | * 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] | 3639 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 3640 | * | 
|  | 3641 | * This routine issues Address Discover (ADISC) ELS commands to those | 
|  | 3642 | * N_Ports which are in node port recovery state and ADISC has not been issued | 
|  | 3643 | * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the | 
|  | 3644 | * lpfc_issue_els_adisc() routine, the per @vport number of discover count | 
|  | 3645 | * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a | 
|  | 3646 | * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will | 
|  | 3647 | * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC | 
|  | 3648 | * IOCBs quit for later pick up. On the other hand, after walking through | 
|  | 3649 | * all the ndlps with the @vport and there is none ADISC IOCB issued, the | 
|  | 3650 | * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is | 
|  | 3651 | * no more ADISC need to be sent. | 
|  | 3652 | * | 
|  | 3653 | * Return code | 
|  | 3654 | *    The number of N_Ports with adisc issued. | 
|  | 3655 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3656 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3657 | lpfc_els_disc_adisc(struct lpfc_vport *vport) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3658 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3659 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3660 | struct lpfc_nodelist *ndlp, *next_ndlp; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3661 | int sentadisc = 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3662 |  | 
| James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3663 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3664 | 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] | 3665 | if (!NLP_CHK_NODE_ACT(ndlp)) | 
|  | 3666 | continue; | 
| James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3667 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && | 
|  | 3668 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && | 
|  | 3669 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3670 | spin_lock_irq(shost->host_lock); | 
| James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3671 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3672 | spin_unlock_irq(shost->host_lock); | 
| James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3673 | ndlp->nlp_prev_state = ndlp->nlp_state; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3674 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); | 
|  | 3675 | lpfc_issue_els_adisc(vport, ndlp, 0); | 
| James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3676 | sentadisc++; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3677 | vport->num_disc_nodes++; | 
|  | 3678 | if (vport->num_disc_nodes >= | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3679 | vport->cfg_discovery_threads) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3680 | spin_lock_irq(shost->host_lock); | 
|  | 3681 | vport->fc_flag |= FC_NLP_MORE; | 
|  | 3682 | spin_unlock_irq(shost->host_lock); | 
| James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3683 | break; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3684 | } | 
|  | 3685 | } | 
|  | 3686 | } | 
|  | 3687 | if (sentadisc == 0) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3688 | spin_lock_irq(shost->host_lock); | 
|  | 3689 | vport->fc_flag &= ~FC_NLP_MORE; | 
|  | 3690 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3691 | } | 
| Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3692 | return sentadisc; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3693 | } | 
|  | 3694 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3695 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3696 | * 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] | 3697 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 3698 | * | 
|  | 3699 | * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports | 
|  | 3700 | * which are in node port recovery state, with a @vport. Each time an ELS | 
|  | 3701 | * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, | 
|  | 3702 | * the per @vport number of discover count (num_disc_nodes) shall be | 
|  | 3703 | * incremented. If the num_disc_nodes reaches a pre-configured threshold | 
|  | 3704 | * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE | 
|  | 3705 | * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for | 
|  | 3706 | * later pick up. On the other hand, after walking through all the ndlps with | 
|  | 3707 | * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag | 
|  | 3708 | * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC | 
|  | 3709 | * PLOGI need to be sent. | 
|  | 3710 | * | 
|  | 3711 | * Return code | 
|  | 3712 | *   The number of N_Ports with plogi issued. | 
|  | 3713 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3714 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3715 | lpfc_els_disc_plogi(struct lpfc_vport *vport) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3716 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3717 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3718 | struct lpfc_nodelist *ndlp, *next_ndlp; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3719 | int sentplogi = 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3720 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3721 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ | 
|  | 3722 | 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] | 3723 | if (!NLP_CHK_NODE_ACT(ndlp)) | 
|  | 3724 | continue; | 
| James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3725 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && | 
|  | 3726 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && | 
|  | 3727 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && | 
|  | 3728 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { | 
|  | 3729 | ndlp->nlp_prev_state = ndlp->nlp_state; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3730 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); | 
|  | 3731 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); | 
| James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3732 | sentplogi++; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3733 | vport->num_disc_nodes++; | 
|  | 3734 | if (vport->num_disc_nodes >= | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3735 | vport->cfg_discovery_threads) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3736 | spin_lock_irq(shost->host_lock); | 
|  | 3737 | vport->fc_flag |= FC_NLP_MORE; | 
|  | 3738 | spin_unlock_irq(shost->host_lock); | 
| James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3739 | break; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3740 | } | 
|  | 3741 | } | 
|  | 3742 | } | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3743 | if (sentplogi) { | 
|  | 3744 | lpfc_set_disctmo(vport); | 
|  | 3745 | } | 
|  | 3746 | else { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3747 | spin_lock_irq(shost->host_lock); | 
|  | 3748 | vport->fc_flag &= ~FC_NLP_MORE; | 
|  | 3749 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3750 | } | 
| Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3751 | return sentplogi; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3752 | } | 
|  | 3753 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3754 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3755 | * lpfc_els_flush_rscn - Clean up any rscn activities with a vport | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3756 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 3757 | * | 
|  | 3758 | * This routine cleans up any Registration State Change Notification | 
|  | 3759 | * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the | 
|  | 3760 | * @vport together with the host_lock is used to prevent multiple thread | 
|  | 3761 | * trying to access the RSCN array on a same @vport at the same time. | 
|  | 3762 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3763 | void | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3764 | lpfc_els_flush_rscn(struct lpfc_vport *vport) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3765 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3766 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | 3767 | struct lpfc_hba  *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3768 | int i; | 
|  | 3769 |  | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3770 | spin_lock_irq(shost->host_lock); | 
|  | 3771 | if (vport->fc_rscn_flush) { | 
|  | 3772 | /* Another thread is walking fc_rscn_id_list on this vport */ | 
|  | 3773 | spin_unlock_irq(shost->host_lock); | 
|  | 3774 | return; | 
|  | 3775 | } | 
|  | 3776 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ | 
|  | 3777 | vport->fc_rscn_flush = 1; | 
|  | 3778 | spin_unlock_irq(shost->host_lock); | 
|  | 3779 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3780 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3781 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3782 | vport->fc_rscn_id_list[i] = NULL; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3783 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3784 | spin_lock_irq(shost->host_lock); | 
|  | 3785 | vport->fc_rscn_id_cnt = 0; | 
|  | 3786 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); | 
|  | 3787 | spin_unlock_irq(shost->host_lock); | 
|  | 3788 | lpfc_can_disctmo(vport); | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3789 | /* Indicate we are done walking this fc_rscn_id_list */ | 
|  | 3790 | vport->fc_rscn_flush = 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3791 | } | 
|  | 3792 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3793 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3794 | * 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] | 3795 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 3796 | * @did: remote destination port identifier. | 
|  | 3797 | * | 
|  | 3798 | * This routine checks whether there is any pending Registration State | 
|  | 3799 | * Configuration Notification (RSCN) to a @did on @vport. | 
|  | 3800 | * | 
|  | 3801 | * Return code | 
|  | 3802 | *   None zero - The @did matched with a pending rscn | 
|  | 3803 | *   0 - not able to match @did with a pending rscn | 
|  | 3804 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3805 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3806 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3807 | { | 
|  | 3808 | D_ID ns_did; | 
|  | 3809 | D_ID rscn_did; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3810 | uint32_t *lp; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3811 | uint32_t payload_len, i; | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3812 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3813 |  | 
|  | 3814 | ns_did.un.word = did; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3815 |  | 
|  | 3816 | /* Never match fabric nodes for RSCNs */ | 
|  | 3817 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3818 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3819 |  | 
|  | 3820 | /* If we are doing a FULL RSCN rediscovery, match everything */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3821 | if (vport->fc_flag & FC_RSCN_DISCOVERY) | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3822 | return did; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3823 |  | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3824 | spin_lock_irq(shost->host_lock); | 
|  | 3825 | if (vport->fc_rscn_flush) { | 
|  | 3826 | /* Another thread is walking fc_rscn_id_list on this vport */ | 
|  | 3827 | spin_unlock_irq(shost->host_lock); | 
|  | 3828 | return 0; | 
|  | 3829 | } | 
|  | 3830 | /* Indicate we are walking fc_rscn_id_list on this vport */ | 
|  | 3831 | vport->fc_rscn_flush = 1; | 
|  | 3832 | spin_unlock_irq(shost->host_lock); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3833 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3834 | lp = vport->fc_rscn_id_list[i]->virt; | 
|  | 3835 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); | 
|  | 3836 | payload_len -= sizeof(uint32_t);	/* take off word 0 */ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3837 | while (payload_len) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3838 | rscn_did.un.word = be32_to_cpu(*lp++); | 
|  | 3839 | payload_len -= sizeof(uint32_t); | 
| James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3840 | switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) { | 
|  | 3841 | case RSCN_ADDRESS_FORMAT_PORT: | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3842 | if (ns_did.un.word == rscn_did.un.word) | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3843 | goto return_did_out; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3844 | break; | 
| James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3845 | case RSCN_ADDRESS_FORMAT_AREA: | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3846 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) | 
|  | 3847 | && (ns_did.un.b.area == rscn_did.un.b.area)) | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3848 | goto return_did_out; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3849 | break; | 
| James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3850 | case RSCN_ADDRESS_FORMAT_DOMAIN: | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3851 | if (ns_did.un.b.domain == rscn_did.un.b.domain) | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3852 | goto return_did_out; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3853 | break; | 
| James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 3854 | case RSCN_ADDRESS_FORMAT_FABRIC: | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3855 | goto return_did_out; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3856 | } | 
|  | 3857 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3858 | } | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3859 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ | 
|  | 3860 | vport->fc_rscn_flush = 0; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3861 | return 0; | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3862 | return_did_out: | 
|  | 3863 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ | 
|  | 3864 | vport->fc_rscn_flush = 0; | 
|  | 3865 | return did; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3866 | } | 
|  | 3867 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3868 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3869 | * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3870 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 3871 | * | 
|  | 3872 | * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the | 
|  | 3873 | * state machine for a @vport's nodes that are with pending RSCN (Registration | 
|  | 3874 | * State Change Notification). | 
|  | 3875 | * | 
|  | 3876 | * Return code | 
|  | 3877 | *   0 - Successful (currently alway return 0) | 
|  | 3878 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3879 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3880 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3881 | { | 
| James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3882 | struct lpfc_nodelist *ndlp = NULL; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3883 |  | 
| James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3884 | /* Move all affected nodes by pending RSCNs to NPR state. */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3885 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3886 | if (!NLP_CHK_NODE_ACT(ndlp) || | 
| James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3887 | (ndlp->nlp_state == NLP_STE_UNUSED_NODE) || | 
|  | 3888 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3889 | continue; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3890 | lpfc_disc_state_machine(vport, ndlp, NULL, | 
| James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3891 | NLP_EVT_DEVICE_RECOVERY); | 
|  | 3892 | lpfc_cancel_retry_delay_tmo(vport, ndlp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3893 | } | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3894 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3895 | } | 
|  | 3896 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3897 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3898 | * lpfc_send_rscn_event - Send an RSCN event to management application | 
| James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 3899 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 3900 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 3901 | * | 
|  | 3902 | * lpfc_send_rscn_event sends an RSCN netlink event to management | 
|  | 3903 | * applications. | 
|  | 3904 | */ | 
|  | 3905 | static void | 
|  | 3906 | lpfc_send_rscn_event(struct lpfc_vport *vport, | 
|  | 3907 | struct lpfc_iocbq *cmdiocb) | 
|  | 3908 | { | 
|  | 3909 | struct lpfc_dmabuf *pcmd; | 
|  | 3910 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | 3911 | uint32_t *payload_ptr; | 
|  | 3912 | uint32_t payload_len; | 
|  | 3913 | struct lpfc_rscn_event_header *rscn_event_data; | 
|  | 3914 |  | 
|  | 3915 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | 
|  | 3916 | payload_ptr = (uint32_t *) pcmd->virt; | 
|  | 3917 | payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK); | 
|  | 3918 |  | 
|  | 3919 | rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) + | 
|  | 3920 | payload_len, GFP_KERNEL); | 
|  | 3921 | if (!rscn_event_data) { | 
|  | 3922 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 3923 | "0147 Failed to allocate memory for RSCN event\n"); | 
|  | 3924 | return; | 
|  | 3925 | } | 
|  | 3926 | rscn_event_data->event_type = FC_REG_RSCN_EVENT; | 
|  | 3927 | rscn_event_data->payload_length = payload_len; | 
|  | 3928 | memcpy(rscn_event_data->rscn_payload, payload_ptr, | 
|  | 3929 | payload_len); | 
|  | 3930 |  | 
|  | 3931 | fc_host_post_vendor_event(shost, | 
|  | 3932 | fc_get_event_number(), | 
|  | 3933 | sizeof(struct lpfc_els_event_header) + payload_len, | 
|  | 3934 | (char *)rscn_event_data, | 
|  | 3935 | LPFC_NL_VENDOR_ID); | 
|  | 3936 |  | 
|  | 3937 | kfree(rscn_event_data); | 
|  | 3938 | } | 
|  | 3939 |  | 
|  | 3940 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3941 | * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3942 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 3943 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 3944 | * @ndlp: pointer to a node-list data structure. | 
|  | 3945 | * | 
|  | 3946 | * This routine processes an unsolicited RSCN (Registration State Change | 
|  | 3947 | * Notification) IOCB. First, the payload of the unsolicited RSCN is walked | 
|  | 3948 | * to invoke fc_host_post_event() routine to the FC transport layer. If the | 
|  | 3949 | * discover state machine is about to begin discovery, it just accepts the | 
|  | 3950 | * RSCN and the discovery process will satisfy the RSCN. If this RSCN only | 
|  | 3951 | * contains N_Port IDs for other vports on this HBA, it just accepts the | 
|  | 3952 | * RSCN and ignore processing it. If the state machine is in the recovery | 
|  | 3953 | * state, the fc_rscn_id_list of this @vport is walked and the | 
|  | 3954 | * lpfc_rscn_recovery_check() routine is invoked to send recovery event for | 
|  | 3955 | * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() | 
|  | 3956 | * routine is invoked to handle the RSCN event. | 
|  | 3957 | * | 
|  | 3958 | * Return code | 
|  | 3959 | *   0 - Just sent the acc response | 
|  | 3960 | *   1 - Sent the acc response and waited for name server completion | 
|  | 3961 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3962 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3963 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3964 | struct lpfc_nodelist *ndlp) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3965 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3966 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | 3967 | struct lpfc_hba  *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3968 | struct lpfc_dmabuf *pcmd; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3969 | uint32_t *lp, *datap; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3970 | IOCB_t *icmd; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3971 | uint32_t payload_len, length, nportid, *cmd; | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3972 | int rscn_cnt; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3973 | int rscn_id = 0, hba_id = 0; | 
| James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 3974 | int i; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3975 |  | 
|  | 3976 | icmd = &cmdiocb->iocb; | 
|  | 3977 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | 
|  | 3978 | lp = (uint32_t *) pcmd->virt; | 
|  | 3979 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3980 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); | 
|  | 3981 | payload_len -= sizeof(uint32_t);	/* take off word 0 */ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3982 | /* RSCN received */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3983 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, | 
|  | 3984 | "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] | 3985 | vport->fc_flag, payload_len, *lp, | 
|  | 3986 | vport->fc_rscn_id_cnt); | 
| James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 3987 |  | 
|  | 3988 | /* Send an RSCN event to the management application */ | 
|  | 3989 | lpfc_send_rscn_event(vport, cmdiocb); | 
|  | 3990 |  | 
| James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 3991 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3992 | fc_host_post_event(shost, fc_get_event_number(), | 
| James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 3993 | FCH_EVT_RSCN, lp[i]); | 
|  | 3994 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3995 | /* If we are about to begin discovery, just ACC the RSCN. | 
|  | 3996 | * Discovery processing will satisfy it. | 
|  | 3997 | */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3998 | if (vport->port_state <= LPFC_NS_QRY) { | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3999 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 4000 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", | 
|  | 4001 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); | 
|  | 4002 |  | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4003 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4004 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4005 | } | 
|  | 4006 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4007 | /* If this RSCN just contains NPortIDs for other vports on this HBA, | 
|  | 4008 | * just ACC and ignore it. | 
|  | 4009 | */ | 
|  | 4010 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4011 | !(vport->cfg_peer_port_login)) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4012 | i = payload_len; | 
|  | 4013 | datap = lp; | 
|  | 4014 | while (i > 0) { | 
|  | 4015 | nportid = *datap++; | 
|  | 4016 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); | 
|  | 4017 | i -= sizeof(uint32_t); | 
|  | 4018 | rscn_id++; | 
| James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 4019 | if (lpfc_find_vport_by_did(phba, nportid)) | 
|  | 4020 | hba_id++; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4021 | } | 
|  | 4022 | if (rscn_id == hba_id) { | 
|  | 4023 | /* ALL NPortIDs in RSCN are on HBA */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4024 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4025 | "0219 Ignore RSCN " | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4026 | "Data: x%x x%x x%x x%x\n", | 
|  | 4027 | vport->fc_flag, payload_len, | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4028 | *lp, vport->fc_rscn_id_cnt); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4029 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 4030 | "RCV RSCN vport:  did:x%x/ste:x%x flg:x%x", | 
|  | 4031 | ndlp->nlp_DID, vport->port_state, | 
|  | 4032 | ndlp->nlp_flag); | 
|  | 4033 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4034 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4035 | ndlp, NULL); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4036 | return 0; | 
|  | 4037 | } | 
|  | 4038 | } | 
|  | 4039 |  | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4040 | spin_lock_irq(shost->host_lock); | 
|  | 4041 | if (vport->fc_rscn_flush) { | 
|  | 4042 | /* Another thread is walking fc_rscn_id_list on this vport */ | 
|  | 4043 | spin_unlock_irq(shost->host_lock); | 
|  | 4044 | vport->fc_flag |= FC_RSCN_DISCOVERY; | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4045 | /* Send back ACC */ | 
|  | 4046 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4047 | return 0; | 
|  | 4048 | } | 
|  | 4049 | /* Indicate we are walking fc_rscn_id_list on this vport */ | 
|  | 4050 | vport->fc_rscn_flush = 1; | 
|  | 4051 | spin_unlock_irq(shost->host_lock); | 
|  | 4052 | /* Get the array count after sucessfully have the token */ | 
|  | 4053 | rscn_cnt = vport->fc_rscn_id_cnt; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4054 | /* If we are already processing an RSCN, save the received | 
|  | 4055 | * RSCN payload buffer, cmdiocb->context2 to process later. | 
|  | 4056 | */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4057 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4058 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 4059 | "RCV RSCN defer:  did:x%x/ste:x%x flg:x%x", | 
|  | 4060 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); | 
|  | 4061 |  | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4062 | spin_lock_irq(shost->host_lock); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4063 | vport->fc_flag |= FC_RSCN_DEFERRED; | 
|  | 4064 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4065 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4066 | vport->fc_flag |= FC_RSCN_MODE; | 
|  | 4067 | spin_unlock_irq(shost->host_lock); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4068 | if (rscn_cnt) { | 
|  | 4069 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; | 
|  | 4070 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); | 
|  | 4071 | } | 
|  | 4072 | if ((rscn_cnt) && | 
|  | 4073 | (payload_len + length <= LPFC_BPL_SIZE)) { | 
|  | 4074 | *cmd &= ELS_CMD_MASK; | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4075 | *cmd |= cpu_to_be32(payload_len + length); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4076 | memcpy(((uint8_t *)cmd) + length, lp, | 
|  | 4077 | payload_len); | 
|  | 4078 | } else { | 
|  | 4079 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; | 
|  | 4080 | vport->fc_rscn_id_cnt++; | 
|  | 4081 | /* If we zero, cmdiocb->context2, the calling | 
|  | 4082 | * routine will not try to free it. | 
|  | 4083 | */ | 
|  | 4084 | cmdiocb->context2 = NULL; | 
|  | 4085 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4086 | /* Deferred RSCN */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4087 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, | 
|  | 4088 | "0235 Deferred RSCN " | 
|  | 4089 | "Data: x%x x%x x%x\n", | 
|  | 4090 | vport->fc_rscn_id_cnt, vport->fc_flag, | 
|  | 4091 | vport->port_state); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4092 | } else { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4093 | vport->fc_flag |= FC_RSCN_DISCOVERY; | 
|  | 4094 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4095 | /* ReDiscovery RSCN */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4096 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, | 
|  | 4097 | "0234 ReDiscovery RSCN " | 
|  | 4098 | "Data: x%x x%x x%x\n", | 
|  | 4099 | vport->fc_rscn_id_cnt, vport->fc_flag, | 
|  | 4100 | vport->port_state); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4101 | } | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4102 | /* Indicate we are done walking fc_rscn_id_list on this vport */ | 
|  | 4103 | vport->fc_rscn_flush = 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4104 | /* Send back ACC */ | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4105 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4106 | /* send RECOVERY event for ALL nodes that match RSCN payload */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4107 | lpfc_rscn_recovery_check(vport); | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4108 | spin_lock_irq(shost->host_lock); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4109 | vport->fc_flag &= ~FC_RSCN_DEFERRED; | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4110 | spin_unlock_irq(shost->host_lock); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4111 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4112 | } | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4113 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 4114 | "RCV RSCN:        did:x%x/ste:x%x flg:x%x", | 
|  | 4115 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); | 
|  | 4116 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4117 | spin_lock_irq(shost->host_lock); | 
|  | 4118 | vport->fc_flag |= FC_RSCN_MODE; | 
|  | 4119 | spin_unlock_irq(shost->host_lock); | 
|  | 4120 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4121 | /* Indicate we are done walking fc_rscn_id_list on this vport */ | 
|  | 4122 | vport->fc_rscn_flush = 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4123 | /* | 
|  | 4124 | * If we zero, cmdiocb->context2, the calling routine will | 
|  | 4125 | * not try to free it. | 
|  | 4126 | */ | 
|  | 4127 | cmdiocb->context2 = NULL; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4128 | lpfc_set_disctmo(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4129 | /* Send back ACC */ | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4130 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4131 | /* send RECOVERY event for ALL nodes that match RSCN payload */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4132 | lpfc_rscn_recovery_check(vport); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4133 | return lpfc_els_handle_rscn(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4134 | } | 
|  | 4135 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4136 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4137 | * lpfc_els_handle_rscn - Handle rscn for a vport | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4138 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 4139 | * | 
|  | 4140 | * This routine handles the Registration State Configuration Notification | 
|  | 4141 | * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall | 
|  | 4142 | * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, | 
|  | 4143 | * if the ndlp to NameServer exists, a Common Transport (CT) command to the | 
|  | 4144 | * NameServer shall be issued. If CT command to the NameServer fails to be | 
|  | 4145 | * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any | 
|  | 4146 | * RSCN activities with the @vport. | 
|  | 4147 | * | 
|  | 4148 | * Return code | 
|  | 4149 | *   0 - Cleaned up rscn on the @vport | 
|  | 4150 | *   1 - Wait for plogi to name server before proceed | 
|  | 4151 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4152 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4153 | lpfc_els_handle_rscn(struct lpfc_vport *vport) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4154 | { | 
|  | 4155 | struct lpfc_nodelist *ndlp; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4156 | struct lpfc_hba *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4157 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4158 | /* Ignore RSCN if the port is being torn down. */ | 
|  | 4159 | if (vport->load_flag & FC_UNLOADING) { | 
|  | 4160 | lpfc_els_flush_rscn(vport); | 
|  | 4161 | return 0; | 
|  | 4162 | } | 
|  | 4163 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4164 | /* Start timer for RSCN processing */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4165 | lpfc_set_disctmo(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4166 |  | 
|  | 4167 | /* RSCN processed */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4168 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, | 
|  | 4169 | "0215 RSCN processed Data: x%x x%x x%x x%x\n", | 
|  | 4170 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, | 
|  | 4171 | vport->port_state); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4172 |  | 
|  | 4173 | /* To process RSCN, first compare RSCN data with NameServer */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4174 | vport->fc_ns_retry = 0; | 
| James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4175 | vport->num_disc_nodes = 0; | 
|  | 4176 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4177 | ndlp = lpfc_findnode_did(vport, NameServer_DID); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4178 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) | 
|  | 4179 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4180 | /* Good ndlp, issue CT Request to NameServer */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4181 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4182 | /* Wait for NameServer query cmpl before we can | 
|  | 4183 | continue */ | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4184 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4185 | } else { | 
|  | 4186 | /* If login to NameServer does not exist, issue one */ | 
|  | 4187 | /* Good status, issue PLOGI to NameServer */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4188 | ndlp = lpfc_findnode_did(vport, NameServer_DID); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4189 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4190 | /* Wait for NameServer login cmpl before we can | 
|  | 4191 | continue */ | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4192 | return 1; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4193 |  | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4194 | if (ndlp) { | 
|  | 4195 | ndlp = lpfc_enable_node(vport, ndlp, | 
|  | 4196 | NLP_STE_PLOGI_ISSUE); | 
|  | 4197 | if (!ndlp) { | 
|  | 4198 | lpfc_els_flush_rscn(vport); | 
|  | 4199 | return 0; | 
|  | 4200 | } | 
|  | 4201 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4202 | } else { | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4203 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | 
|  | 4204 | if (!ndlp) { | 
|  | 4205 | lpfc_els_flush_rscn(vport); | 
|  | 4206 | return 0; | 
|  | 4207 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4208 | lpfc_nlp_init(vport, ndlp, NameServer_DID); | 
| Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4209 | ndlp->nlp_prev_state = ndlp->nlp_state; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4210 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4211 | } | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4212 | ndlp->nlp_type |= NLP_FABRIC; | 
|  | 4213 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); | 
|  | 4214 | /* Wait for NameServer login cmpl before we can | 
|  | 4215 | * continue | 
|  | 4216 | */ | 
|  | 4217 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4218 | } | 
|  | 4219 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4220 | lpfc_els_flush_rscn(vport); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4221 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4222 | } | 
|  | 4223 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4224 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4225 | * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4226 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 4227 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 4228 | * @ndlp: pointer to a node-list data structure. | 
|  | 4229 | * | 
|  | 4230 | * This routine processes Fabric Login (FLOGI) IOCB received as an ELS | 
|  | 4231 | * unsolicited event. An unsolicited FLOGI can be received in a point-to- | 
|  | 4232 | * point topology. As an unsolicited FLOGI should not be received in a loop | 
|  | 4233 | * mode, any unsolicited FLOGI received in loop mode shall be ignored. The | 
|  | 4234 | * lpfc_check_sparm() routine is invoked to check the parameters in the | 
|  | 4235 | * unsolicited FLOGI. If parameters validation failed, the routine | 
|  | 4236 | * lpfc_els_rsp_reject() shall be called with reject reason code set to | 
|  | 4237 | * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the | 
|  | 4238 | * FLOGI shall be compared with the Port WWN of the @vport to determine who | 
|  | 4239 | * will initiate PLOGI. The higher lexicographical value party shall has | 
|  | 4240 | * higher priority (as the winning port) and will initiate PLOGI and | 
|  | 4241 | * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result | 
|  | 4242 | * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI | 
|  | 4243 | * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. | 
|  | 4244 | * | 
|  | 4245 | * Return code | 
|  | 4246 | *   0 - Successfully processed the unsolicited flogi | 
|  | 4247 | *   1 - Failed to process the unsolicited flogi | 
|  | 4248 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4249 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4250 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4251 | struct lpfc_nodelist *ndlp) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4252 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4253 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | 4254 | struct lpfc_hba  *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4255 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | 
|  | 4256 | uint32_t *lp = (uint32_t *) pcmd->virt; | 
|  | 4257 | IOCB_t *icmd = &cmdiocb->iocb; | 
|  | 4258 | struct serv_parm *sp; | 
|  | 4259 | LPFC_MBOXQ_t *mbox; | 
|  | 4260 | struct ls_rjt stat; | 
|  | 4261 | uint32_t cmd, did; | 
|  | 4262 | int rc; | 
|  | 4263 |  | 
|  | 4264 | cmd = *lp++; | 
|  | 4265 | sp = (struct serv_parm *) lp; | 
|  | 4266 |  | 
|  | 4267 | /* FLOGI received */ | 
|  | 4268 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4269 | lpfc_set_disctmo(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4270 |  | 
|  | 4271 | if (phba->fc_topology == TOPOLOGY_LOOP) { | 
|  | 4272 | /* We should never receive a FLOGI in loop mode, ignore it */ | 
|  | 4273 | did = icmd->un.elsreq64.remoteID; | 
|  | 4274 |  | 
|  | 4275 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in | 
|  | 4276 | Loop Mode */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4277 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 4278 | "0113 An FLOGI ELS command x%x was " | 
|  | 4279 | "received from DID x%x in Loop Mode\n", | 
|  | 4280 | cmd, did); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4281 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4282 | } | 
|  | 4283 |  | 
|  | 4284 | did = Fabric_DID; | 
|  | 4285 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4286 | if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4287 | /* For a FLOGI we accept, then if our portname is greater | 
|  | 4288 | * then the remote portname we initiate Nport login. | 
|  | 4289 | */ | 
|  | 4290 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4291 | rc = memcmp(&vport->fc_portname, &sp->portName, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4292 | sizeof(struct lpfc_name)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4293 |  | 
|  | 4294 | if (!rc) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4295 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | 
|  | 4296 | if (!mbox) | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4297 | return 1; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4298 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4299 | lpfc_linkdown(phba); | 
|  | 4300 | lpfc_init_link(phba, mbox, | 
|  | 4301 | phba->cfg_topology, | 
|  | 4302 | phba->cfg_link_speed); | 
|  | 4303 | mbox->mb.un.varInitLnk.lipsr_AL_PA = 0; | 
|  | 4304 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4305 | mbox->vport = vport; | 
| James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4306 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); | 
| James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4307 | lpfc_set_loopback_flag(phba); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4308 | if (rc == MBX_NOT_FINISHED) { | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4309 | mempool_free(mbox, phba->mbox_mem_pool); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4310 | } | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4311 | return 1; | 
| Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4312 | } else if (rc > 0) {	/* greater than */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4313 | spin_lock_irq(shost->host_lock); | 
|  | 4314 | vport->fc_flag |= FC_PT2PT_PLOGI; | 
|  | 4315 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4316 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4317 | spin_lock_irq(shost->host_lock); | 
|  | 4318 | vport->fc_flag |= FC_PT2PT; | 
|  | 4319 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); | 
|  | 4320 | spin_unlock_irq(shost->host_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4321 | } else { | 
|  | 4322 | /* Reject this request because invalid parameters */ | 
|  | 4323 | stat.un.b.lsRjtRsvd0 = 0; | 
|  | 4324 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | 
|  | 4325 | stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; | 
|  | 4326 | stat.un.b.vendorUnique = 0; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4327 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, | 
|  | 4328 | NULL); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4329 | return 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4330 | } | 
|  | 4331 |  | 
|  | 4332 | /* Send back ACC */ | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4333 | lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4334 |  | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4335 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4336 | } | 
|  | 4337 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4338 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4339 | * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4340 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 4341 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 4342 | * @ndlp: pointer to a node-list data structure. | 
|  | 4343 | * | 
|  | 4344 | * This routine processes Request Node Identification Data (RNID) IOCB | 
|  | 4345 | * received as an ELS unsolicited event. Only when the RNID specified format | 
|  | 4346 | * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) | 
|  | 4347 | * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to | 
|  | 4348 | * Accept (ACC) the RNID ELS command. All the other RNID formats are | 
|  | 4349 | * rejected by invoking the lpfc_els_rsp_reject() routine. | 
|  | 4350 | * | 
|  | 4351 | * Return code | 
|  | 4352 | *   0 - Successfully processed rnid iocb (currently always return 0) | 
|  | 4353 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4354 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4355 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, | 
|  | 4356 | struct lpfc_nodelist *ndlp) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4357 | { | 
|  | 4358 | struct lpfc_dmabuf *pcmd; | 
|  | 4359 | uint32_t *lp; | 
|  | 4360 | IOCB_t *icmd; | 
|  | 4361 | RNID *rn; | 
|  | 4362 | struct ls_rjt stat; | 
|  | 4363 | uint32_t cmd, did; | 
|  | 4364 |  | 
|  | 4365 | icmd = &cmdiocb->iocb; | 
|  | 4366 | did = icmd->un.elsreq64.remoteID; | 
|  | 4367 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | 
|  | 4368 | lp = (uint32_t *) pcmd->virt; | 
|  | 4369 |  | 
|  | 4370 | cmd = *lp++; | 
|  | 4371 | rn = (RNID *) lp; | 
|  | 4372 |  | 
|  | 4373 | /* RNID received */ | 
|  | 4374 |  | 
|  | 4375 | switch (rn->Format) { | 
|  | 4376 | case 0: | 
|  | 4377 | case RNID_TOPOLOGY_DISC: | 
|  | 4378 | /* Send back ACC */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4379 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4380 | break; | 
|  | 4381 | default: | 
|  | 4382 | /* Reject this request because format not supported */ | 
|  | 4383 | stat.un.b.lsRjtRsvd0 = 0; | 
|  | 4384 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | 
|  | 4385 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; | 
|  | 4386 | stat.un.b.vendorUnique = 0; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4387 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, | 
|  | 4388 | NULL); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4389 | } | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4390 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4391 | } | 
|  | 4392 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4393 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4394 | * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4395 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 4396 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 4397 | * @ndlp: pointer to a node-list data structure. | 
|  | 4398 | * | 
|  | 4399 | * This routine processes a Link Incident Report Registration(LIRR) IOCB | 
|  | 4400 | * received as an ELS unsolicited event. Currently, this function just invokes | 
|  | 4401 | * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. | 
|  | 4402 | * | 
|  | 4403 | * Return code | 
|  | 4404 | *   0 - Successfully processed lirr iocb (currently always return 0) | 
|  | 4405 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4406 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4407 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, | 
|  | 4408 | struct lpfc_nodelist *ndlp) | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4409 | { | 
|  | 4410 | struct ls_rjt stat; | 
|  | 4411 |  | 
|  | 4412 | /* For now, unconditionally reject this command */ | 
|  | 4413 | stat.un.b.lsRjtRsvd0 = 0; | 
|  | 4414 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | 
|  | 4415 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; | 
|  | 4416 | stat.un.b.vendorUnique = 0; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4417 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4418 | return 0; | 
|  | 4419 | } | 
|  | 4420 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4421 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4422 | * 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] | 4423 | * @phba: pointer to lpfc hba data structure. | 
|  | 4424 | * @pmb: pointer to the driver internal queue element for mailbox command. | 
|  | 4425 | * | 
|  | 4426 | * This routine is the completion callback function for the MBX_READ_LNK_STAT | 
|  | 4427 | * mailbox command. This callback function is to actually send the Accept | 
|  | 4428 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It | 
|  | 4429 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT | 
|  | 4430 | * mailbox command, constructs the RPS response with the link statistics | 
|  | 4431 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC | 
|  | 4432 | * response to the RPS. | 
|  | 4433 | * | 
|  | 4434 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | 
|  | 4435 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | 
|  | 4436 | * will be stored into the context1 field of the IOCB for the completion | 
|  | 4437 | * callback function to the RPS Accept Response ELS IOCB command. | 
|  | 4438 | * | 
|  | 4439 | **/ | 
| Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 4440 | static void | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4441 | 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] | 4442 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4443 | struct lpfc_sli *psli = &phba->sli; | 
|  | 4444 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4445 | MAILBOX_t *mb; | 
|  | 4446 | IOCB_t *icmd; | 
|  | 4447 | RPS_RSP *rps_rsp; | 
|  | 4448 | uint8_t *pcmd; | 
|  | 4449 | struct lpfc_iocbq *elsiocb; | 
|  | 4450 | struct lpfc_nodelist *ndlp; | 
|  | 4451 | uint16_t xri, status; | 
|  | 4452 | uint32_t cmdsize; | 
|  | 4453 |  | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4454 | mb = &pmb->mb; | 
|  | 4455 |  | 
|  | 4456 | ndlp = (struct lpfc_nodelist *) pmb->context2; | 
|  | 4457 | xri = (uint16_t) ((unsigned long)(pmb->context1)); | 
| Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 4458 | pmb->context1 = NULL; | 
|  | 4459 | pmb->context2 = NULL; | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4460 |  | 
|  | 4461 | if (mb->mbxStatus) { | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4462 | mempool_free(pmb, phba->mbox_mem_pool); | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4463 | return; | 
|  | 4464 | } | 
|  | 4465 |  | 
|  | 4466 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4467 | mempool_free(pmb, phba->mbox_mem_pool); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4468 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, | 
|  | 4469 | lpfc_max_els_tries, ndlp, | 
|  | 4470 | ndlp->nlp_DID, ELS_CMD_ACC); | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4471 |  | 
|  | 4472 | /* Decrement the ndlp reference count from previous mbox command */ | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4473 | lpfc_nlp_put(ndlp); | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4474 |  | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4475 | if (!elsiocb) | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4476 | return; | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4477 |  | 
|  | 4478 | icmd = &elsiocb->iocb; | 
|  | 4479 | icmd->ulpContext = xri; | 
|  | 4480 |  | 
|  | 4481 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 4482 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4483 | pcmd += sizeof(uint32_t); /* Skip past command */ | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4484 | rps_rsp = (RPS_RSP *)pcmd; | 
|  | 4485 |  | 
|  | 4486 | if (phba->fc_topology != TOPOLOGY_LOOP) | 
|  | 4487 | status = 0x10; | 
|  | 4488 | else | 
|  | 4489 | status = 0x8; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4490 | if (phba->pport->fc_flag & FC_FABRIC) | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4491 | status |= 0x4; | 
|  | 4492 |  | 
|  | 4493 | rps_rsp->rsvd1 = 0; | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4494 | rps_rsp->portStatus = cpu_to_be16(status); | 
|  | 4495 | rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); | 
|  | 4496 | rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); | 
|  | 4497 | rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); | 
|  | 4498 | rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); | 
|  | 4499 | rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); | 
|  | 4500 | rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4501 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4502 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, | 
|  | 4503 | "0118 Xmit ELS RPS ACC response tag x%x xri x%x, " | 
|  | 4504 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", | 
|  | 4505 | elsiocb->iotag, elsiocb->iocb.ulpContext, | 
|  | 4506 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | 
|  | 4507 | ndlp->nlp_rpi); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4508 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4509 | phba->fc_stat.elsXmitACC++; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4510 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4511 | lpfc_els_free_iocb(phba, elsiocb); | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4512 | return; | 
|  | 4513 | } | 
|  | 4514 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4515 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4516 | * lpfc_els_rcv_rps - Process an unsolicited rps 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 Read Port Status (RPS) IOCB received as an | 
|  | 4522 | * ELS unsolicited event. It first checks the remote port state. If the | 
|  | 4523 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE | 
|  | 4524 | * state, it invokes the lpfc_els_rsp_reject() routine to send the reject | 
|  | 4525 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command | 
|  | 4526 | * for reading the HBA link statistics. It is for the callback function, | 
|  | 4527 | * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command | 
|  | 4528 | * to actually sending out RPS Accept (ACC) response. | 
|  | 4529 | * | 
|  | 4530 | * Return codes | 
|  | 4531 | *   0 - Successfully processed rps iocb (currently always return 0) | 
|  | 4532 | **/ | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4533 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4534 | lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, | 
|  | 4535 | struct lpfc_nodelist *ndlp) | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4536 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4537 | struct lpfc_hba *phba = vport->phba; | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4538 | uint32_t *lp; | 
|  | 4539 | uint8_t flag; | 
|  | 4540 | LPFC_MBOXQ_t *mbox; | 
|  | 4541 | struct lpfc_dmabuf *pcmd; | 
|  | 4542 | RPS *rps; | 
|  | 4543 | struct ls_rjt stat; | 
|  | 4544 |  | 
| Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4545 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && | 
| James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4546 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) | 
|  | 4547 | /* reject the unsolicited RPS request and done with it */ | 
|  | 4548 | goto reject_out; | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4549 |  | 
|  | 4550 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | 
|  | 4551 | lp = (uint32_t *) pcmd->virt; | 
|  | 4552 | flag = (be32_to_cpu(*lp++) & 0xf); | 
|  | 4553 | rps = (RPS *) lp; | 
|  | 4554 |  | 
|  | 4555 | if ((flag == 0) || | 
|  | 4556 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4557 | ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4558 | sizeof(struct lpfc_name)) == 0))) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4559 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4560 | printk("Fix me....\n"); | 
|  | 4561 | dump_stack(); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4562 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); | 
|  | 4563 | if (mbox) { | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4564 | lpfc_read_lnk_stat(phba, mbox); | 
|  | 4565 | mbox->context1 = | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4566 | (void *)((unsigned long) cmdiocb->iocb.ulpContext); | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4567 | mbox->context2 = lpfc_nlp_get(ndlp); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4568 | mbox->vport = vport; | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4569 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4570 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) | 
| James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4571 | != MBX_NOT_FINISHED) | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4572 | /* Mbox completion will send ELS Response */ | 
|  | 4573 | return 0; | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4574 | /* Decrement reference count used for the failed mbox | 
|  | 4575 | * command. | 
|  | 4576 | */ | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4577 | lpfc_nlp_put(ndlp); | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4578 | mempool_free(mbox, phba->mbox_mem_pool); | 
|  | 4579 | } | 
|  | 4580 | } | 
| James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4581 |  | 
|  | 4582 | reject_out: | 
|  | 4583 | /* issue rejection response */ | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4584 | stat.un.b.lsRjtRsvd0 = 0; | 
|  | 4585 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | 
|  | 4586 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; | 
|  | 4587 | stat.un.b.vendorUnique = 0; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4588 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4589 | return 0; | 
|  | 4590 | } | 
|  | 4591 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4592 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4593 | * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4594 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 4595 | * @cmdsize: size of the ELS command. | 
|  | 4596 | * @oldiocb: pointer to the original lpfc command iocb data structure. | 
|  | 4597 | * @ndlp: pointer to a node-list data structure. | 
|  | 4598 | * | 
|  | 4599 | * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. | 
|  | 4600 | * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. | 
|  | 4601 | * | 
|  | 4602 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | 
|  | 4603 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | 
|  | 4604 | * will be stored into the context1 field of the IOCB for the completion | 
|  | 4605 | * callback function to the RPL Accept Response ELS command. | 
|  | 4606 | * | 
|  | 4607 | * Return code | 
|  | 4608 | *   0 - Successfully issued ACC RPL ELS command | 
|  | 4609 | *   1 - Failed to issue ACC RPL ELS command | 
|  | 4610 | **/ | 
| Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 4611 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4612 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, | 
|  | 4613 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4614 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4615 | struct lpfc_hba *phba = vport->phba; | 
|  | 4616 | IOCB_t *icmd, *oldcmd; | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4617 | RPL_RSP rpl_rsp; | 
|  | 4618 | struct lpfc_iocbq *elsiocb; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4619 | struct lpfc_sli *psli = &phba->sli; | 
|  | 4620 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4621 | uint8_t *pcmd; | 
|  | 4622 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4623 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, | 
|  | 4624 | ndlp->nlp_DID, ELS_CMD_ACC); | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4625 |  | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4626 | if (!elsiocb) | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4627 | return 1; | 
| James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4628 |  | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4629 | icmd = &elsiocb->iocb; | 
|  | 4630 | oldcmd = &oldiocb->iocb; | 
|  | 4631 | icmd->ulpContext = oldcmd->ulpContext;	/* Xri */ | 
|  | 4632 |  | 
|  | 4633 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 4634 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4635 | pcmd += sizeof(uint16_t); | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4636 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); | 
|  | 4637 | pcmd += sizeof(uint16_t); | 
|  | 4638 |  | 
|  | 4639 | /* Setup the RPL ACC payload */ | 
|  | 4640 | rpl_rsp.listLen = be32_to_cpu(1); | 
|  | 4641 | rpl_rsp.index = 0; | 
|  | 4642 | rpl_rsp.port_num_blk.portNum = 0; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4643 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); | 
|  | 4644 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4645 | sizeof(struct lpfc_name)); | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4646 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4647 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4648 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 4649 | "0120 Xmit ELS RPL ACC response tag x%x " | 
|  | 4650 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " | 
|  | 4651 | "rpi x%x\n", | 
|  | 4652 | elsiocb->iotag, elsiocb->iocb.ulpContext, | 
|  | 4653 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | 
|  | 4654 | ndlp->nlp_rpi); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4655 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4656 | phba->fc_stat.elsXmitACC++; | 
|  | 4657 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { | 
|  | 4658 | lpfc_els_free_iocb(phba, elsiocb); | 
|  | 4659 | return 1; | 
|  | 4660 | } | 
|  | 4661 | return 0; | 
|  | 4662 | } | 
|  | 4663 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4664 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4665 | * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4666 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 4667 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 4668 | * @ndlp: pointer to a node-list data structure. | 
|  | 4669 | * | 
|  | 4670 | * This routine processes Read Port List (RPL) IOCB received as an ELS | 
|  | 4671 | * unsolicited event. It first checks the remote port state. If the remote | 
|  | 4672 | * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it | 
|  | 4673 | * invokes the lpfc_els_rsp_reject() routine to send reject response. | 
|  | 4674 | * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine | 
|  | 4675 | * to accept the RPL. | 
|  | 4676 | * | 
|  | 4677 | * Return code | 
|  | 4678 | *   0 - Successfully processed rpl iocb (currently always return 0) | 
|  | 4679 | **/ | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4680 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4681 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, | 
|  | 4682 | struct lpfc_nodelist *ndlp) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4683 | { | 
|  | 4684 | struct lpfc_dmabuf *pcmd; | 
|  | 4685 | uint32_t *lp; | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4686 | uint32_t maxsize; | 
|  | 4687 | uint16_t cmdsize; | 
|  | 4688 | RPL *rpl; | 
|  | 4689 | struct ls_rjt stat; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4690 |  | 
| Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4691 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && | 
|  | 4692 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { | 
| James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4693 | /* issue rejection response */ | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4694 | stat.un.b.lsRjtRsvd0 = 0; | 
|  | 4695 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | 
|  | 4696 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; | 
|  | 4697 | stat.un.b.vendorUnique = 0; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4698 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, | 
|  | 4699 | NULL); | 
| James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4700 | /* rejected the unsolicited RPL request and done with it */ | 
|  | 4701 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4702 | } | 
|  | 4703 |  | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4704 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | 
|  | 4705 | lp = (uint32_t *) pcmd->virt; | 
|  | 4706 | rpl = (RPL *) (lp + 1); | 
|  | 4707 |  | 
|  | 4708 | maxsize = be32_to_cpu(rpl->maxsize); | 
|  | 4709 |  | 
|  | 4710 | /* We support only one port */ | 
|  | 4711 | if ((rpl->index == 0) && | 
|  | 4712 | ((maxsize == 0) || | 
|  | 4713 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { | 
|  | 4714 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); | 
| Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4715 | } else { | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4716 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); | 
|  | 4717 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4718 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4719 |  | 
|  | 4720 | return 0; | 
|  | 4721 | } | 
|  | 4722 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4723 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4724 | * lpfc_els_rcv_farp - Process an unsolicited farp request els command | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4725 | * @vport: pointer to a virtual N_Port data structure. | 
|  | 4726 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 4727 | * @ndlp: pointer to a node-list data structure. | 
|  | 4728 | * | 
|  | 4729 | * This routine processes Fibre Channel Address Resolution Protocol | 
|  | 4730 | * (FARP) Request IOCB received as an ELS unsolicited event. Currently, | 
|  | 4731 | * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, | 
|  | 4732 | * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the | 
|  | 4733 | * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the | 
|  | 4734 | * remote PortName is compared against the FC PortName stored in the @vport | 
|  | 4735 | * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is | 
|  | 4736 | * compared against the FC NodeName stored in the @vport data structure. | 
|  | 4737 | * If any of these matches and the FARP_REQUEST_FARPR flag is set in the | 
|  | 4738 | * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is | 
|  | 4739 | * invoked to send out FARP Response to the remote node. Before sending the | 
|  | 4740 | * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP | 
|  | 4741 | * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() | 
|  | 4742 | * routine is invoked to log into the remote port first. | 
|  | 4743 | * | 
|  | 4744 | * Return code | 
|  | 4745 | *   0 - Either the FARP Match Mode not supported or successfully processed | 
|  | 4746 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4747 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4748 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, | 
|  | 4749 | struct lpfc_nodelist *ndlp) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4750 | { | 
|  | 4751 | struct lpfc_dmabuf *pcmd; | 
|  | 4752 | uint32_t *lp; | 
|  | 4753 | IOCB_t *icmd; | 
|  | 4754 | FARP *fp; | 
|  | 4755 | uint32_t cmd, cnt, did; | 
|  | 4756 |  | 
|  | 4757 | icmd = &cmdiocb->iocb; | 
|  | 4758 | did = icmd->un.elsreq64.remoteID; | 
|  | 4759 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | 
|  | 4760 | lp = (uint32_t *) pcmd->virt; | 
|  | 4761 |  | 
|  | 4762 | cmd = *lp++; | 
|  | 4763 | fp = (FARP *) lp; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4764 | /* FARP-REQ received from DID <did> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4765 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 4766 | "0601 FARP-REQ received from DID x%x\n", did); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4767 | /* We will only support match on WWPN or WWNN */ | 
|  | 4768 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4769 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4770 | } | 
|  | 4771 |  | 
|  | 4772 | cnt = 0; | 
|  | 4773 | /* If this FARP command is searching for my portname */ | 
|  | 4774 | if (fp->Mflags & FARP_MATCH_PORT) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4775 | if (memcmp(&fp->RportName, &vport->fc_portname, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4776 | sizeof(struct lpfc_name)) == 0) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4777 | cnt = 1; | 
|  | 4778 | } | 
|  | 4779 |  | 
|  | 4780 | /* If this FARP command is searching for my nodename */ | 
|  | 4781 | if (fp->Mflags & FARP_MATCH_NODE) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4782 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4783 | sizeof(struct lpfc_name)) == 0) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4784 | cnt = 1; | 
|  | 4785 | } | 
|  | 4786 |  | 
|  | 4787 | if (cnt) { | 
|  | 4788 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || | 
|  | 4789 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { | 
|  | 4790 | /* Log back into the node before sending the FARP. */ | 
|  | 4791 | if (fp->Rflags & FARP_REQUEST_PLOGI) { | 
| Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4792 | ndlp->nlp_prev_state = ndlp->nlp_state; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4793 | lpfc_nlp_set_state(vport, ndlp, | 
| James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4794 | NLP_STE_PLOGI_ISSUE); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4795 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4796 | } | 
|  | 4797 |  | 
|  | 4798 | /* Send a FARP response to that node */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4799 | if (fp->Rflags & FARP_REQUEST_FARPR) | 
|  | 4800 | lpfc_issue_els_farpr(vport, did, 0); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4801 | } | 
|  | 4802 | } | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4803 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4804 | } | 
|  | 4805 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4806 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4807 | * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4808 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 4809 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 4810 | * @ndlp: pointer to a node-list data structure. | 
|  | 4811 | * | 
|  | 4812 | * This routine processes Fibre Channel Address Resolution Protocol | 
|  | 4813 | * Response (FARPR) IOCB received as an ELS unsolicited event. It simply | 
|  | 4814 | * invokes the lpfc_els_rsp_acc() routine to the remote node to accept | 
|  | 4815 | * the FARP response request. | 
|  | 4816 | * | 
|  | 4817 | * Return code | 
|  | 4818 | *   0 - Successfully processed FARPR IOCB (currently always return 0) | 
|  | 4819 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4820 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4821 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, | 
|  | 4822 | struct lpfc_nodelist  *ndlp) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4823 | { | 
|  | 4824 | struct lpfc_dmabuf *pcmd; | 
|  | 4825 | uint32_t *lp; | 
|  | 4826 | IOCB_t *icmd; | 
|  | 4827 | uint32_t cmd, did; | 
|  | 4828 |  | 
|  | 4829 | icmd = &cmdiocb->iocb; | 
|  | 4830 | did = icmd->un.elsreq64.remoteID; | 
|  | 4831 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | 
|  | 4832 | lp = (uint32_t *) pcmd->virt; | 
|  | 4833 |  | 
|  | 4834 | cmd = *lp++; | 
|  | 4835 | /* FARP-RSP received from DID <did> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4836 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 4837 | "0600 FARP-RSP received from DID x%x\n", did); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4838 | /* ACCEPT the Farp resp request */ | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4839 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4840 |  | 
|  | 4841 | return 0; | 
|  | 4842 | } | 
|  | 4843 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4844 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4845 | * lpfc_els_rcv_fan - Process an unsolicited fan iocb command | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4846 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 4847 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 4848 | * @fan_ndlp: pointer to a node-list data structure. | 
|  | 4849 | * | 
|  | 4850 | * This routine processes a Fabric Address Notification (FAN) IOCB | 
|  | 4851 | * command received as an ELS unsolicited event. The FAN ELS command will | 
|  | 4852 | * only be processed on a physical port (i.e., the @vport represents the | 
|  | 4853 | * physical port). The fabric NodeName and PortName from the FAN IOCB are | 
|  | 4854 | * compared against those in the phba data structure. If any of those is | 
|  | 4855 | * different, the lpfc_initial_flogi() routine is invoked to initialize | 
|  | 4856 | * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, | 
|  | 4857 | * if both of those are identical, the lpfc_issue_fabric_reglogin() routine | 
|  | 4858 | * is invoked to register login to the fabric. | 
|  | 4859 | * | 
|  | 4860 | * Return code | 
|  | 4861 | *   0 - Successfully processed fan iocb (currently always return 0). | 
|  | 4862 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4863 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4864 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, | 
|  | 4865 | struct lpfc_nodelist *fan_ndlp) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4866 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4867 | struct lpfc_hba *phba = vport->phba; | 
| James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4868 | uint32_t *lp; | 
|  | 4869 | FAN *fp; | 
| Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4870 |  | 
| James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4871 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); | 
|  | 4872 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; | 
|  | 4873 | fp = (FAN *) ++lp; | 
| Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4874 | /* FAN received; Fan does not have a reply sequence */ | 
| James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4875 | if ((vport == phba->pport) && | 
|  | 4876 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { | 
| Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4877 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, | 
| James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4878 | sizeof(struct lpfc_name))) || | 
| Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4879 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, | 
| James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4880 | sizeof(struct lpfc_name)))) { | 
|  | 4881 | /* This port has switched fabrics. FLOGI is required */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4882 | lpfc_initial_flogi(vport); | 
| James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4883 | } else { | 
|  | 4884 | /* FAN verified - skip FLOGI */ | 
|  | 4885 | vport->fc_myDID = vport->fc_prevDID; | 
|  | 4886 | lpfc_issue_fabric_reglogin(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4887 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4888 | } | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4889 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4890 | } | 
|  | 4891 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4892 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4893 | * lpfc_els_timeout - Handler funciton to the els timer | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4894 | * @ptr: holder for the timer function associated data. | 
|  | 4895 | * | 
|  | 4896 | * This routine is invoked by the ELS timer after timeout. It posts the ELS | 
|  | 4897 | * timer timeout event by setting the WORKER_ELS_TMO bit to the work port | 
|  | 4898 | * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake | 
|  | 4899 | * up the worker thread. It is for the worker thread to invoke the routine | 
|  | 4900 | * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. | 
|  | 4901 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4902 | void | 
|  | 4903 | lpfc_els_timeout(unsigned long ptr) | 
|  | 4904 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4905 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; | 
|  | 4906 | struct lpfc_hba   *phba = vport->phba; | 
| James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4907 | uint32_t tmo_posted; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4908 | unsigned long iflag; | 
|  | 4909 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4910 | spin_lock_irqsave(&vport->work_port_lock, iflag); | 
| James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4911 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; | 
|  | 4912 | if (!tmo_posted) | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4913 | vport->work_port_events |= WORKER_ELS_TMO; | 
| James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4914 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4915 |  | 
| James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4916 | if (!tmo_posted) | 
|  | 4917 | lpfc_worker_wake_up(phba); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4918 | return; | 
|  | 4919 | } | 
|  | 4920 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4921 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4922 | * lpfc_els_timeout_handler - Process an els timeout event | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4923 | * @vport: pointer to a virtual N_Port data structure. | 
|  | 4924 | * | 
|  | 4925 | * This routine is the actual handler function that processes an ELS timeout | 
|  | 4926 | * event. It walks the ELS ring to get and abort all the IOCBs (except the | 
|  | 4927 | * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by | 
|  | 4928 | * invoking the lpfc_sli_issue_abort_iotag() routine. | 
|  | 4929 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4930 | void | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4931 | lpfc_els_timeout_handler(struct lpfc_vport *vport) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4932 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4933 | struct lpfc_hba  *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4934 | struct lpfc_sli_ring *pring; | 
|  | 4935 | struct lpfc_iocbq *tmp_iocb, *piocb; | 
|  | 4936 | IOCB_t *cmd = NULL; | 
|  | 4937 | struct lpfc_dmabuf *pcmd; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4938 | uint32_t els_command = 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4939 | uint32_t timeout; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4940 | uint32_t remote_ID = 0xffffffff; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4941 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4942 | spin_lock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4943 | timeout = (uint32_t)(phba->fc_ratov << 1); | 
|  | 4944 |  | 
|  | 4945 | pring = &phba->sli.ring[LPFC_ELS_RING]; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4946 |  | 
|  | 4947 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { | 
|  | 4948 | cmd = &piocb->iocb; | 
|  | 4949 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4950 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || | 
|  | 4951 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || | 
|  | 4952 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4953 | continue; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4954 |  | 
|  | 4955 | if (piocb->vport != vport) | 
|  | 4956 | continue; | 
|  | 4957 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4958 | pcmd = (struct lpfc_dmabuf *) piocb->context2; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4959 | if (pcmd) | 
|  | 4960 | els_command = *(uint32_t *) (pcmd->virt); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4961 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4962 | if (els_command == ELS_CMD_FARP || | 
|  | 4963 | els_command == ELS_CMD_FARPR || | 
|  | 4964 | els_command == ELS_CMD_FDISC) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4965 | continue; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4966 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4967 | if (piocb->drvrTimeout > 0) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4968 | if (piocb->drvrTimeout >= timeout) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4969 | piocb->drvrTimeout -= timeout; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4970 | else | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4971 | piocb->drvrTimeout = 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4972 | continue; | 
|  | 4973 | } | 
|  | 4974 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4975 | remote_ID = 0xffffffff; | 
|  | 4976 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4977 | remote_ID = cmd->un.elsreq64.remoteID; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4978 | else { | 
|  | 4979 | struct lpfc_nodelist *ndlp; | 
|  | 4980 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4981 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4982 | remote_ID = ndlp->nlp_DID; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4983 | } | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4984 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 4985 | "0127 ELS timeout Data: x%x x%x x%x " | 
|  | 4986 | "x%x\n", els_command, | 
|  | 4987 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); | 
| James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4988 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4989 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4990 | spin_unlock_irq(&phba->hbalock); | 
| James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 4991 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4992 | if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) | 
|  | 4993 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4994 | } | 
|  | 4995 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4996 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4997 | * 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] | 4998 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 4999 | * | 
|  | 5000 | * This routine is used to clean up all the outstanding ELS commands on a | 
|  | 5001 | * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() | 
|  | 5002 | * routine. After that, it walks the ELS transmit queue to remove all the | 
|  | 5003 | * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For | 
|  | 5004 | * the IOCBs with a non-NULL completion callback function, the callback | 
|  | 5005 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and | 
|  | 5006 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion | 
|  | 5007 | * callback function, the IOCB will simply be released. Finally, it walks | 
|  | 5008 | * the ELS transmit completion queue to issue an abort IOCB to any transmit | 
|  | 5009 | * completion queue IOCB that is associated with the @vport and is not | 
|  | 5010 | * an IOCB from libdfc (i.e., the management plane IOCBs that are not | 
|  | 5011 | * part of the discovery state machine) out to HBA by invoking the | 
|  | 5012 | * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the | 
|  | 5013 | * abort IOCB to any transmit completion queueed IOCB, it does not guarantee | 
|  | 5014 | * the IOCBs are aborted when this function returns. | 
|  | 5015 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5016 | void | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5017 | lpfc_els_flush_cmd(struct lpfc_vport *vport) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5018 | { | 
| James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5019 | LIST_HEAD(completions); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5020 | struct lpfc_hba  *phba = vport->phba; | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5021 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5022 | struct lpfc_iocbq *tmp_iocb, *piocb; | 
|  | 5023 | IOCB_t *cmd = NULL; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5024 |  | 
|  | 5025 | lpfc_fabric_abort_vport(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5026 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5027 | spin_lock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5028 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { | 
|  | 5029 | cmd = &piocb->iocb; | 
|  | 5030 |  | 
|  | 5031 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { | 
|  | 5032 | continue; | 
|  | 5033 | } | 
|  | 5034 |  | 
|  | 5035 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5036 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || | 
|  | 5037 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || | 
|  | 5038 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || | 
|  | 5039 | cmd->ulpCommand == CMD_ABORT_XRI_CN) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5040 | continue; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5041 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5042 | if (piocb->vport != vport) | 
|  | 5043 | continue; | 
|  | 5044 |  | 
| James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5045 | list_move_tail(&piocb->list, &completions); | 
| James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 5046 | pring->txq_cnt--; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5047 | } | 
|  | 5048 |  | 
|  | 5049 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5050 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { | 
|  | 5051 | continue; | 
|  | 5052 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5053 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5054 | if (piocb->vport != vport) | 
|  | 5055 | continue; | 
|  | 5056 |  | 
| James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 5057 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5058 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5059 | spin_unlock_irq(&phba->hbalock); | 
| James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5060 |  | 
| James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5061 | /* Cancell all the IOCBs from the completions list */ | 
|  | 5062 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | 
|  | 5063 | IOERR_SLI_ABORTED); | 
| James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5064 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5065 | return; | 
|  | 5066 | } | 
|  | 5067 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5068 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5069 | * 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] | 5070 | * @phba: pointer to lpfc hba data structure. | 
|  | 5071 | * | 
|  | 5072 | * This routine is used to clean up all the outstanding ELS commands on a | 
|  | 5073 | * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() | 
|  | 5074 | * routine. After that, it walks the ELS transmit queue to remove all the | 
|  | 5075 | * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For | 
|  | 5076 | * the IOCBs with the completion callback function associated, the callback | 
|  | 5077 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and | 
|  | 5078 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion | 
|  | 5079 | * callback function associated, the IOCB will simply be released. Finally, | 
|  | 5080 | * it walks the ELS transmit completion queue to issue an abort IOCB to any | 
|  | 5081 | * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the | 
|  | 5082 | * management plane IOCBs that are not part of the discovery state machine) | 
|  | 5083 | * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. | 
|  | 5084 | **/ | 
| James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5085 | void | 
|  | 5086 | lpfc_els_flush_all_cmd(struct lpfc_hba  *phba) | 
|  | 5087 | { | 
|  | 5088 | LIST_HEAD(completions); | 
|  | 5089 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | 
|  | 5090 | struct lpfc_iocbq *tmp_iocb, *piocb; | 
|  | 5091 | IOCB_t *cmd = NULL; | 
|  | 5092 |  | 
|  | 5093 | lpfc_fabric_abort_hba(phba); | 
|  | 5094 | spin_lock_irq(&phba->hbalock); | 
|  | 5095 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { | 
|  | 5096 | cmd = &piocb->iocb; | 
|  | 5097 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) | 
|  | 5098 | continue; | 
|  | 5099 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ | 
|  | 5100 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || | 
|  | 5101 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || | 
|  | 5102 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || | 
|  | 5103 | cmd->ulpCommand == CMD_ABORT_XRI_CN) | 
|  | 5104 | continue; | 
|  | 5105 | list_move_tail(&piocb->list, &completions); | 
|  | 5106 | pring->txq_cnt--; | 
|  | 5107 | } | 
|  | 5108 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { | 
|  | 5109 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) | 
|  | 5110 | continue; | 
|  | 5111 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); | 
|  | 5112 | } | 
|  | 5113 | spin_unlock_irq(&phba->hbalock); | 
| James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 5114 |  | 
|  | 5115 | /* Cancel all the IOCBs from the completions list */ | 
|  | 5116 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | 
|  | 5117 | IOERR_SLI_ABORTED); | 
|  | 5118 |  | 
| James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5119 | return; | 
|  | 5120 | } | 
|  | 5121 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5122 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5123 | * lpfc_send_els_failure_event - Posts an ELS command failure event | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5124 | * @phba: Pointer to hba context object. | 
|  | 5125 | * @cmdiocbp: Pointer to command iocb which reported error. | 
|  | 5126 | * @rspiocbp: Pointer to response iocb which reported error. | 
|  | 5127 | * | 
|  | 5128 | * This function sends an event when there is an ELS command | 
|  | 5129 | * failure. | 
|  | 5130 | **/ | 
|  | 5131 | void | 
|  | 5132 | lpfc_send_els_failure_event(struct lpfc_hba *phba, | 
|  | 5133 | struct lpfc_iocbq *cmdiocbp, | 
|  | 5134 | struct lpfc_iocbq *rspiocbp) | 
|  | 5135 | { | 
|  | 5136 | struct lpfc_vport *vport = cmdiocbp->vport; | 
|  | 5137 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | 5138 | struct lpfc_lsrjt_event lsrjt_event; | 
|  | 5139 | struct lpfc_fabric_event_header fabric_event; | 
|  | 5140 | struct ls_rjt stat; | 
|  | 5141 | struct lpfc_nodelist *ndlp; | 
|  | 5142 | uint32_t *pcmd; | 
|  | 5143 |  | 
|  | 5144 | ndlp = cmdiocbp->context1; | 
|  | 5145 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) | 
|  | 5146 | return; | 
|  | 5147 |  | 
|  | 5148 | if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) { | 
|  | 5149 | lsrjt_event.header.event_type = FC_REG_ELS_EVENT; | 
|  | 5150 | lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV; | 
|  | 5151 | memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname, | 
|  | 5152 | sizeof(struct lpfc_name)); | 
|  | 5153 | memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename, | 
|  | 5154 | sizeof(struct lpfc_name)); | 
|  | 5155 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) | 
|  | 5156 | cmdiocbp->context2)->virt); | 
|  | 5157 | lsrjt_event.command = *pcmd; | 
|  | 5158 | stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]); | 
|  | 5159 | lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode; | 
|  | 5160 | lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp; | 
|  | 5161 | fc_host_post_vendor_event(shost, | 
|  | 5162 | fc_get_event_number(), | 
|  | 5163 | sizeof(lsrjt_event), | 
|  | 5164 | (char *)&lsrjt_event, | 
| James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5165 | LPFC_NL_VENDOR_ID); | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5166 | return; | 
|  | 5167 | } | 
|  | 5168 | if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) || | 
|  | 5169 | (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) { | 
|  | 5170 | fabric_event.event_type = FC_REG_FABRIC_EVENT; | 
|  | 5171 | if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) | 
|  | 5172 | fabric_event.subcategory = LPFC_EVENT_PORT_BUSY; | 
|  | 5173 | else | 
|  | 5174 | fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY; | 
|  | 5175 | memcpy(fabric_event.wwpn, &ndlp->nlp_portname, | 
|  | 5176 | sizeof(struct lpfc_name)); | 
|  | 5177 | memcpy(fabric_event.wwnn, &ndlp->nlp_nodename, | 
|  | 5178 | sizeof(struct lpfc_name)); | 
|  | 5179 | fc_host_post_vendor_event(shost, | 
|  | 5180 | fc_get_event_number(), | 
|  | 5181 | sizeof(fabric_event), | 
|  | 5182 | (char *)&fabric_event, | 
| James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5183 | LPFC_NL_VENDOR_ID); | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5184 | return; | 
|  | 5185 | } | 
|  | 5186 |  | 
|  | 5187 | } | 
|  | 5188 |  | 
|  | 5189 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5190 | * lpfc_send_els_event - Posts unsolicited els event | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5191 | * @vport: Pointer to vport object. | 
|  | 5192 | * @ndlp: Pointer FC node object. | 
|  | 5193 | * @cmd: ELS command code. | 
|  | 5194 | * | 
|  | 5195 | * This function posts an event when there is an incoming | 
|  | 5196 | * unsolicited ELS command. | 
|  | 5197 | **/ | 
|  | 5198 | static void | 
|  | 5199 | lpfc_send_els_event(struct lpfc_vport *vport, | 
|  | 5200 | struct lpfc_nodelist *ndlp, | 
| James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5201 | uint32_t *payload) | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5202 | { | 
| James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5203 | struct lpfc_els_event_header *els_data = NULL; | 
|  | 5204 | struct lpfc_logo_event *logo_data = NULL; | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5205 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | 5206 |  | 
| James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5207 | if (*payload == ELS_CMD_LOGO) { | 
|  | 5208 | logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL); | 
|  | 5209 | if (!logo_data) { | 
|  | 5210 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 5211 | "0148 Failed to allocate memory " | 
|  | 5212 | "for LOGO event\n"); | 
|  | 5213 | return; | 
|  | 5214 | } | 
|  | 5215 | els_data = &logo_data->header; | 
|  | 5216 | } else { | 
|  | 5217 | els_data = kmalloc(sizeof(struct lpfc_els_event_header), | 
|  | 5218 | GFP_KERNEL); | 
|  | 5219 | if (!els_data) { | 
|  | 5220 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 5221 | "0149 Failed to allocate memory " | 
|  | 5222 | "for ELS event\n"); | 
|  | 5223 | return; | 
|  | 5224 | } | 
|  | 5225 | } | 
|  | 5226 | els_data->event_type = FC_REG_ELS_EVENT; | 
|  | 5227 | switch (*payload) { | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5228 | case ELS_CMD_PLOGI: | 
| James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5229 | els_data->subcategory = LPFC_EVENT_PLOGI_RCV; | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5230 | break; | 
|  | 5231 | case ELS_CMD_PRLO: | 
| James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5232 | els_data->subcategory = LPFC_EVENT_PRLO_RCV; | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5233 | break; | 
|  | 5234 | case ELS_CMD_ADISC: | 
| James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5235 | els_data->subcategory = LPFC_EVENT_ADISC_RCV; | 
|  | 5236 | break; | 
|  | 5237 | case ELS_CMD_LOGO: | 
|  | 5238 | els_data->subcategory = LPFC_EVENT_LOGO_RCV; | 
|  | 5239 | /* Copy the WWPN in the LOGO payload */ | 
|  | 5240 | memcpy(logo_data->logo_wwpn, &payload[2], | 
|  | 5241 | sizeof(struct lpfc_name)); | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5242 | break; | 
|  | 5243 | default: | 
| Julia Lawall | e916141 | 2009-02-08 22:43:19 +0100 | [diff] [blame] | 5244 | kfree(els_data); | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5245 | return; | 
|  | 5246 | } | 
| James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5247 | memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name)); | 
|  | 5248 | memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name)); | 
|  | 5249 | if (*payload == ELS_CMD_LOGO) { | 
|  | 5250 | fc_host_post_vendor_event(shost, | 
|  | 5251 | fc_get_event_number(), | 
|  | 5252 | sizeof(struct lpfc_logo_event), | 
|  | 5253 | (char *)logo_data, | 
|  | 5254 | LPFC_NL_VENDOR_ID); | 
|  | 5255 | kfree(logo_data); | 
|  | 5256 | } else { | 
|  | 5257 | fc_host_post_vendor_event(shost, | 
|  | 5258 | fc_get_event_number(), | 
|  | 5259 | sizeof(struct lpfc_els_event_header), | 
|  | 5260 | (char *)els_data, | 
|  | 5261 | LPFC_NL_VENDOR_ID); | 
|  | 5262 | kfree(els_data); | 
|  | 5263 | } | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5264 |  | 
|  | 5265 | return; | 
|  | 5266 | } | 
|  | 5267 |  | 
|  | 5268 |  | 
|  | 5269 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5270 | * lpfc_els_unsol_buffer - Process an unsolicited event data buffer | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5271 | * @phba: pointer to lpfc hba data structure. | 
|  | 5272 | * @pring: pointer to a SLI ring. | 
|  | 5273 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 5274 | * @elsiocb: pointer to lpfc els command iocb data structure. | 
|  | 5275 | * | 
|  | 5276 | * This routine is used for processing the IOCB associated with a unsolicited | 
|  | 5277 | * event. It first determines whether there is an existing ndlp that matches | 
|  | 5278 | * the DID from the unsolicited IOCB. If not, it will create a new one with | 
|  | 5279 | * the DID from the unsolicited IOCB. The ELS command from the unsolicited | 
|  | 5280 | * IOCB is then used to invoke the proper routine and to set up proper state | 
|  | 5281 | * of the discovery state machine. | 
|  | 5282 | **/ | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5283 | static void | 
|  | 5284 | 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] | 5285 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5286 | { | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5287 | struct Scsi_Host  *shost; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5288 | struct lpfc_nodelist *ndlp; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5289 | struct ls_rjt stat; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5290 | uint32_t *payload; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5291 | uint32_t cmd, did, newnode, rjt_err = 0; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5292 | IOCB_t *icmd = &elsiocb->iocb; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5293 |  | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5294 | if (!vport || !(elsiocb->context2)) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5295 | goto dropit; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5296 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5297 | newnode = 0; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5298 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; | 
|  | 5299 | cmd = *payload; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5300 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) | 
| James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5301 | lpfc_post_buffer(phba, pring, 1); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5302 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5303 | did = icmd->un.rcvels.remoteID; | 
|  | 5304 | if (icmd->ulpStatus) { | 
|  | 5305 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 5306 | "RCV Unsol ELS:  status:x%x/x%x did:x%x", | 
|  | 5307 | icmd->ulpStatus, icmd->un.ulpWord[4], did); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5308 | goto dropit; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5309 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5310 |  | 
|  | 5311 | /* Check to see if link went down during discovery */ | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5312 | if (lpfc_els_chk_latt(vport)) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5313 | goto dropit; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5314 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5315 | /* Ignore traffic recevied during vport shutdown. */ | 
|  | 5316 | if (vport->load_flag & FC_UNLOADING) | 
|  | 5317 | goto dropit; | 
|  | 5318 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5319 | ndlp = lpfc_findnode_did(vport, did); | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5320 | if (!ndlp) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5321 | /* Cannot find existing Fabric ndlp, so allocate a new one */ | 
| Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5322 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5323 | if (!ndlp) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5324 | goto dropit; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5325 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5326 | lpfc_nlp_init(vport, ndlp, did); | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5327 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5328 | newnode = 1; | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5329 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5330 | ndlp->nlp_type |= NLP_FABRIC; | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5331 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | 
|  | 5332 | ndlp = lpfc_enable_node(vport, ndlp, | 
|  | 5333 | NLP_STE_UNUSED_NODE); | 
|  | 5334 | if (!ndlp) | 
|  | 5335 | goto dropit; | 
|  | 5336 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); | 
|  | 5337 | newnode = 1; | 
|  | 5338 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) | 
|  | 5339 | ndlp->nlp_type |= NLP_FABRIC; | 
|  | 5340 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { | 
|  | 5341 | /* This is similar to the new node path */ | 
|  | 5342 | ndlp = lpfc_nlp_get(ndlp); | 
|  | 5343 | if (!ndlp) | 
|  | 5344 | goto dropit; | 
|  | 5345 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); | 
|  | 5346 | newnode = 1; | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5347 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5348 |  | 
|  | 5349 | phba->fc_stat.elsRcvFrame++; | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5350 |  | 
| James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5351 | elsiocb->context1 = lpfc_nlp_get(ndlp); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5352 | elsiocb->vport = vport; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5353 |  | 
|  | 5354 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { | 
|  | 5355 | cmd &= ELS_CMD_MASK; | 
|  | 5356 | } | 
|  | 5357 | /* ELS command <elsCmd> received from NPORT <did> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5358 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 5359 | "0112 ELS command x%x received from NPORT x%x " | 
|  | 5360 | "Data: x%x\n", cmd, did, vport->port_state); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5361 | switch (cmd) { | 
|  | 5362 | case ELS_CMD_PLOGI: | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5363 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 5364 | "RCV PLOGI:       did:x%x/ste:x%x flg:x%x", | 
|  | 5365 | did, vport->port_state, ndlp->nlp_flag); | 
|  | 5366 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5367 | phba->fc_stat.elsRcvPLOGI++; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5368 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); | 
|  | 5369 |  | 
| James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5370 | lpfc_send_els_event(vport, ndlp, payload); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5371 | if (vport->port_state < LPFC_DISC_AUTH) { | 
| James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 5372 | if (!(phba->pport->fc_flag & FC_PT2PT) || | 
|  | 5373 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { | 
|  | 5374 | rjt_err = LSRJT_UNABLE_TPC; | 
|  | 5375 | break; | 
|  | 5376 | } | 
|  | 5377 | /* We get here, and drop thru, if we are PT2PT with | 
|  | 5378 | * another NPort and the other side has initiated | 
|  | 5379 | * the PLOGI before responding to our FLOGI. | 
|  | 5380 | */ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5381 | } | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5382 |  | 
|  | 5383 | shost = lpfc_shost_from_vport(vport); | 
|  | 5384 | spin_lock_irq(shost->host_lock); | 
|  | 5385 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; | 
|  | 5386 | spin_unlock_irq(shost->host_lock); | 
|  | 5387 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5388 | lpfc_disc_state_machine(vport, ndlp, elsiocb, | 
|  | 5389 | NLP_EVT_RCV_PLOGI); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5390 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5391 | break; | 
|  | 5392 | case ELS_CMD_FLOGI: | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5393 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 5394 | "RCV FLOGI:       did:x%x/ste:x%x flg:x%x", | 
|  | 5395 | did, vport->port_state, ndlp->nlp_flag); | 
|  | 5396 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5397 | phba->fc_stat.elsRcvFLOGI++; | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5398 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5399 | if (newnode) | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5400 | lpfc_nlp_put(ndlp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5401 | break; | 
|  | 5402 | case ELS_CMD_LOGO: | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5403 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 5404 | "RCV LOGO:        did:x%x/ste:x%x flg:x%x", | 
|  | 5405 | did, vport->port_state, ndlp->nlp_flag); | 
|  | 5406 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5407 | phba->fc_stat.elsRcvLOGO++; | 
| James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5408 | lpfc_send_els_event(vport, ndlp, payload); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5409 | if (vport->port_state < LPFC_DISC_AUTH) { | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5410 | rjt_err = LSRJT_UNABLE_TPC; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5411 | break; | 
|  | 5412 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5413 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5414 | break; | 
|  | 5415 | case ELS_CMD_PRLO: | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5416 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 5417 | "RCV PRLO:        did:x%x/ste:x%x flg:x%x", | 
|  | 5418 | did, vport->port_state, ndlp->nlp_flag); | 
|  | 5419 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5420 | phba->fc_stat.elsRcvPRLO++; | 
| James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5421 | lpfc_send_els_event(vport, ndlp, payload); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5422 | if (vport->port_state < LPFC_DISC_AUTH) { | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5423 | rjt_err = LSRJT_UNABLE_TPC; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5424 | break; | 
|  | 5425 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5426 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5427 | break; | 
|  | 5428 | case ELS_CMD_RSCN: | 
|  | 5429 | phba->fc_stat.elsRcvRSCN++; | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5430 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5431 | if (newnode) | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5432 | lpfc_nlp_put(ndlp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5433 | break; | 
|  | 5434 | case ELS_CMD_ADISC: | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5435 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 5436 | "RCV ADISC:       did:x%x/ste:x%x flg:x%x", | 
|  | 5437 | did, vport->port_state, ndlp->nlp_flag); | 
|  | 5438 |  | 
| James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 5439 | lpfc_send_els_event(vport, ndlp, payload); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5440 | phba->fc_stat.elsRcvADISC++; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5441 | if (vport->port_state < LPFC_DISC_AUTH) { | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5442 | rjt_err = LSRJT_UNABLE_TPC; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5443 | break; | 
|  | 5444 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5445 | lpfc_disc_state_machine(vport, ndlp, elsiocb, | 
|  | 5446 | NLP_EVT_RCV_ADISC); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5447 | break; | 
|  | 5448 | case ELS_CMD_PDISC: | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5449 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 5450 | "RCV PDISC:       did:x%x/ste:x%x flg:x%x", | 
|  | 5451 | did, vport->port_state, ndlp->nlp_flag); | 
|  | 5452 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5453 | phba->fc_stat.elsRcvPDISC++; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5454 | if (vport->port_state < LPFC_DISC_AUTH) { | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5455 | rjt_err = LSRJT_UNABLE_TPC; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5456 | break; | 
|  | 5457 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5458 | lpfc_disc_state_machine(vport, ndlp, elsiocb, | 
|  | 5459 | NLP_EVT_RCV_PDISC); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5460 | break; | 
|  | 5461 | case ELS_CMD_FARPR: | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5462 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 5463 | "RCV FARPR:       did:x%x/ste:x%x flg:x%x", | 
|  | 5464 | did, vport->port_state, ndlp->nlp_flag); | 
|  | 5465 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5466 | phba->fc_stat.elsRcvFARPR++; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5467 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5468 | break; | 
|  | 5469 | case ELS_CMD_FARP: | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5470 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 5471 | "RCV FARP:        did:x%x/ste:x%x flg:x%x", | 
|  | 5472 | did, vport->port_state, ndlp->nlp_flag); | 
|  | 5473 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5474 | phba->fc_stat.elsRcvFARP++; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5475 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5476 | break; | 
|  | 5477 | case ELS_CMD_FAN: | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5478 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 5479 | "RCV FAN:         did:x%x/ste:x%x flg:x%x", | 
|  | 5480 | did, vport->port_state, ndlp->nlp_flag); | 
|  | 5481 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5482 | phba->fc_stat.elsRcvFAN++; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5483 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5484 | break; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5485 | case ELS_CMD_PRLI: | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5486 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 5487 | "RCV PRLI:        did:x%x/ste:x%x flg:x%x", | 
|  | 5488 | did, vport->port_state, ndlp->nlp_flag); | 
|  | 5489 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5490 | phba->fc_stat.elsRcvPRLI++; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5491 | if (vport->port_state < LPFC_DISC_AUTH) { | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5492 | rjt_err = LSRJT_UNABLE_TPC; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5493 | break; | 
|  | 5494 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5495 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5496 | break; | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5497 | case ELS_CMD_LIRR: | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5498 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 5499 | "RCV LIRR:        did:x%x/ste:x%x flg:x%x", | 
|  | 5500 | did, vport->port_state, ndlp->nlp_flag); | 
|  | 5501 |  | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5502 | phba->fc_stat.elsRcvLIRR++; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5503 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5504 | if (newnode) | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5505 | lpfc_nlp_put(ndlp); | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5506 | break; | 
|  | 5507 | case ELS_CMD_RPS: | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5508 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 5509 | "RCV RPS:         did:x%x/ste:x%x flg:x%x", | 
|  | 5510 | did, vport->port_state, ndlp->nlp_flag); | 
|  | 5511 |  | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5512 | phba->fc_stat.elsRcvRPS++; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5513 | lpfc_els_rcv_rps(vport, elsiocb, ndlp); | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5514 | if (newnode) | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5515 | lpfc_nlp_put(ndlp); | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5516 | break; | 
|  | 5517 | case ELS_CMD_RPL: | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5518 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 5519 | "RCV RPL:         did:x%x/ste:x%x flg:x%x", | 
|  | 5520 | did, vport->port_state, ndlp->nlp_flag); | 
|  | 5521 |  | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5522 | phba->fc_stat.elsRcvRPL++; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5523 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5524 | if (newnode) | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5525 | lpfc_nlp_put(ndlp); | 
| Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5526 | break; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5527 | case ELS_CMD_RNID: | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5528 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 5529 | "RCV RNID:        did:x%x/ste:x%x flg:x%x", | 
|  | 5530 | did, vport->port_state, ndlp->nlp_flag); | 
|  | 5531 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5532 | phba->fc_stat.elsRcvRNID++; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5533 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5534 | if (newnode) | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5535 | lpfc_nlp_put(ndlp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5536 | break; | 
|  | 5537 | default: | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5538 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | 
|  | 5539 | "RCV ELS cmd:     cmd:x%x did:x%x/ste:x%x", | 
|  | 5540 | cmd, did, vport->port_state); | 
|  | 5541 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5542 | /* Unsupported ELS command, reject */ | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5543 | rjt_err = LSRJT_INVALID_CMD; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5544 |  | 
|  | 5545 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5546 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 5547 | "0115 Unknown ELS command x%x " | 
|  | 5548 | "received from NPORT x%x\n", cmd, did); | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5549 | if (newnode) | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5550 | lpfc_nlp_put(ndlp); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5551 | break; | 
|  | 5552 | } | 
|  | 5553 |  | 
|  | 5554 | /* check if need to LS_RJT received ELS cmd */ | 
|  | 5555 | if (rjt_err) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5556 | memset(&stat, 0, sizeof(stat)); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5557 | stat.un.b.lsRjtRsnCode = rjt_err; | 
| James.Smart@Emulex.Com | 1f679ca | 2005-06-25 10:34:27 -0400 | [diff] [blame] | 5558 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5559 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, | 
|  | 5560 | NULL); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5561 | } | 
|  | 5562 |  | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5563 | lpfc_nlp_put(elsiocb->context1); | 
|  | 5564 | elsiocb->context1 = NULL; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5565 | return; | 
|  | 5566 |  | 
|  | 5567 | dropit: | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5568 | if (vport && !(vport->load_flag & FC_UNLOADING)) | 
|  | 5569 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5570 | "(%d):0111 Dropping received ELS cmd " | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5571 | "Data: x%x x%x x%x\n", | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5572 | vport->vpi, icmd->ulpStatus, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5573 | icmd->un.ulpWord[4], icmd->ulpTimeout); | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5574 | phba->fc_stat.elsRcvDrop++; | 
|  | 5575 | } | 
|  | 5576 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5577 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5578 | * 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] | 5579 | * @phba: pointer to lpfc hba data structure. | 
|  | 5580 | * @vpi: host virtual N_Port identifier. | 
|  | 5581 | * | 
|  | 5582 | * This routine finds a vport on a HBA (referred by @phba) through a | 
|  | 5583 | * @vpi. The function walks the HBA's vport list and returns the address | 
|  | 5584 | * of the vport with the matching @vpi. | 
|  | 5585 | * | 
|  | 5586 | * Return code | 
|  | 5587 | *    NULL - No vport with the matching @vpi found | 
|  | 5588 | *    Otherwise - Address to the vport with the matching @vpi. | 
|  | 5589 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5590 | static struct lpfc_vport * | 
|  | 5591 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) | 
|  | 5592 | { | 
|  | 5593 | struct lpfc_vport *vport; | 
| James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5594 | unsigned long flags; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5595 |  | 
| James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5596 | spin_lock_irqsave(&phba->hbalock, flags); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5597 | list_for_each_entry(vport, &phba->port_list, listentry) { | 
| James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5598 | if (vport->vpi == vpi) { | 
|  | 5599 | spin_unlock_irqrestore(&phba->hbalock, flags); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5600 | return vport; | 
| James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5601 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5602 | } | 
| James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5603 | spin_unlock_irqrestore(&phba->hbalock, flags); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5604 | return NULL; | 
|  | 5605 | } | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5606 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5607 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5608 | * 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] | 5609 | * @phba: pointer to lpfc hba data structure. | 
|  | 5610 | * @pring: pointer to a SLI ring. | 
|  | 5611 | * @elsiocb: pointer to lpfc els iocb data structure. | 
|  | 5612 | * | 
|  | 5613 | * This routine is used to process an unsolicited event received from a SLI | 
|  | 5614 | * (Service Level Interface) ring. The actual processing of the data buffer | 
|  | 5615 | * associated with the unsolicited event is done by invoking the routine | 
|  | 5616 | * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the | 
|  | 5617 | * SLI ring on which the unsolicited event was received. | 
|  | 5618 | **/ | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5619 | void | 
|  | 5620 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | 
|  | 5621 | struct lpfc_iocbq *elsiocb) | 
|  | 5622 | { | 
|  | 5623 | struct lpfc_vport *vport = phba->pport; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5624 | IOCB_t *icmd = &elsiocb->iocb; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5625 | dma_addr_t paddr; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5626 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; | 
|  | 5627 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5628 |  | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5629 | elsiocb->context1 = NULL; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5630 | elsiocb->context2 = NULL; | 
|  | 5631 | elsiocb->context3 = NULL; | 
|  | 5632 |  | 
|  | 5633 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { | 
|  | 5634 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); | 
|  | 5635 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && | 
|  | 5636 | (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) { | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5637 | phba->fc_stat.NoRcvBuf++; | 
|  | 5638 | /* Not enough posted buffers; Try posting more buffers */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5639 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) | 
| James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5640 | lpfc_post_buffer(phba, pring, 0); | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5641 | return; | 
|  | 5642 | } | 
|  | 5643 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5644 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && | 
|  | 5645 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || | 
|  | 5646 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { | 
|  | 5647 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) | 
|  | 5648 | vport = phba->pport; | 
|  | 5649 | else { | 
|  | 5650 | uint16_t vpi = icmd->unsli3.rcvsli3.vpi; | 
|  | 5651 | vport = lpfc_find_vport_by_vpid(phba, vpi); | 
|  | 5652 | } | 
|  | 5653 | } | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5654 | /* If there are no BDEs associated | 
|  | 5655 | * with this IOCB, there is nothing to do. | 
|  | 5656 | */ | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5657 | if (icmd->ulpBdeCount == 0) | 
|  | 5658 | return; | 
|  | 5659 |  | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5660 | /* type of ELS cmd is first 32bit word | 
|  | 5661 | * in packet | 
|  | 5662 | */ | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5663 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5664 | elsiocb->context2 = bdeBuf1; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5665 | } else { | 
|  | 5666 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, | 
|  | 5667 | icmd->un.cont64[0].addrLow); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5668 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, | 
|  | 5669 | paddr); | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5670 | } | 
|  | 5671 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5672 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); | 
|  | 5673 | /* | 
|  | 5674 | * The different unsolicited event handlers would tell us | 
|  | 5675 | * if they are done with "mp" by setting context2 to NULL. | 
|  | 5676 | */ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5677 | if (elsiocb->context2) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5678 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); | 
|  | 5679 | elsiocb->context2 = NULL; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5680 | } | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5681 |  | 
|  | 5682 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5683 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5684 | icmd->ulpBdeCount == 2) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5685 | elsiocb->context2 = bdeBuf2; | 
|  | 5686 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5687 | /* free mp if we are done with it */ | 
|  | 5688 | if (elsiocb->context2) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5689 | lpfc_in_buf_free(phba, elsiocb->context2); | 
|  | 5690 | elsiocb->context2 = NULL; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5691 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5692 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5693 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5694 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5695 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5696 | * 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] | 5697 | * @phba: pointer to lpfc hba data structure. | 
|  | 5698 | * @vport: pointer to a virtual N_Port data structure. | 
|  | 5699 | * | 
|  | 5700 | * This routine issues a Port Login (PLOGI) to the Name Server with | 
|  | 5701 | * State Change Request (SCR) for a @vport. This routine will create an | 
|  | 5702 | * ndlp for the Name Server associated to the @vport if such node does | 
|  | 5703 | * not already exist. The PLOGI to Name Server is issued by invoking the | 
|  | 5704 | * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface | 
|  | 5705 | * (FDMI) is configured to the @vport, a FDMI node will be created and | 
|  | 5706 | * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. | 
|  | 5707 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5708 | void | 
|  | 5709 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) | 
|  | 5710 | { | 
|  | 5711 | struct lpfc_nodelist *ndlp, *ndlp_fdmi; | 
|  | 5712 |  | 
|  | 5713 | ndlp = lpfc_findnode_did(vport, NameServer_DID); | 
|  | 5714 | if (!ndlp) { | 
|  | 5715 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | 
|  | 5716 | if (!ndlp) { | 
|  | 5717 | if (phba->fc_topology == TOPOLOGY_LOOP) { | 
|  | 5718 | lpfc_disc_start(vport); | 
|  | 5719 | return; | 
|  | 5720 | } | 
|  | 5721 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5722 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 5723 | "0251 NameServer login: no memory\n"); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5724 | return; | 
|  | 5725 | } | 
|  | 5726 | lpfc_nlp_init(vport, ndlp, NameServer_DID); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5727 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | 
|  | 5728 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | 
|  | 5729 | if (!ndlp) { | 
|  | 5730 | if (phba->fc_topology == TOPOLOGY_LOOP) { | 
|  | 5731 | lpfc_disc_start(vport); | 
|  | 5732 | return; | 
|  | 5733 | } | 
|  | 5734 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | 
|  | 5735 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 5736 | "0348 NameServer login: node freed\n"); | 
|  | 5737 | return; | 
|  | 5738 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5739 | } | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5740 | ndlp->nlp_type |= NLP_FABRIC; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5741 |  | 
|  | 5742 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); | 
|  | 5743 |  | 
|  | 5744 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { | 
|  | 5745 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5746 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 5747 | "0252 Cannot issue NameServer login\n"); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5748 | return; | 
|  | 5749 | } | 
|  | 5750 |  | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5751 | if (vport->cfg_fdmi_on) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5752 | ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool, | 
|  | 5753 | GFP_KERNEL); | 
|  | 5754 | if (ndlp_fdmi) { | 
|  | 5755 | lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID); | 
|  | 5756 | ndlp_fdmi->nlp_type |= NLP_FABRIC; | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5757 | lpfc_nlp_set_state(vport, ndlp_fdmi, | 
|  | 5758 | NLP_STE_PLOGI_ISSUE); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5759 | lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, | 
|  | 5760 | 0); | 
|  | 5761 | } | 
|  | 5762 | } | 
|  | 5763 | return; | 
|  | 5764 | } | 
|  | 5765 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5766 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5767 | * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5768 | * @phba: pointer to lpfc hba data structure. | 
|  | 5769 | * @pmb: pointer to the driver internal queue element for mailbox command. | 
|  | 5770 | * | 
|  | 5771 | * This routine is the completion callback function to register new vport | 
|  | 5772 | * mailbox command. If the new vport mailbox command completes successfully, | 
|  | 5773 | * the fabric registration login shall be performed on physical port (the | 
|  | 5774 | * new vport created is actually a physical port, with VPI 0) or the port | 
|  | 5775 | * login to Name Server for State Change Request (SCR) will be performed | 
|  | 5776 | * on virtual port (real virtual port, with VPI greater than 0). | 
|  | 5777 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5778 | static void | 
|  | 5779 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) | 
|  | 5780 | { | 
|  | 5781 | struct lpfc_vport *vport = pmb->vport; | 
|  | 5782 | struct Scsi_Host  *shost = lpfc_shost_from_vport(vport); | 
|  | 5783 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; | 
|  | 5784 | MAILBOX_t *mb = &pmb->mb; | 
|  | 5785 |  | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5786 | spin_lock_irq(shost->host_lock); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5787 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5788 | spin_unlock_irq(shost->host_lock); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5789 |  | 
|  | 5790 | if (mb->mbxStatus) { | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5791 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, | 
|  | 5792 | "0915 Register VPI failed: 0x%x\n", | 
|  | 5793 | mb->mbxStatus); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5794 |  | 
|  | 5795 | switch (mb->mbxStatus) { | 
|  | 5796 | case 0x11:	/* unsupported feature */ | 
|  | 5797 | case 0x9603:	/* max_vpi exceeded */ | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5798 | case 0x9602:	/* Link event since CLEAR_LA */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5799 | /* giving up on vport registration */ | 
|  | 5800 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | 
|  | 5801 | spin_lock_irq(shost->host_lock); | 
|  | 5802 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); | 
|  | 5803 | spin_unlock_irq(shost->host_lock); | 
|  | 5804 | lpfc_can_disctmo(vport); | 
|  | 5805 | break; | 
|  | 5806 | default: | 
|  | 5807 | /* Try to recover from this error */ | 
|  | 5808 | lpfc_mbx_unreg_vpi(vport); | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5809 | spin_lock_irq(shost->host_lock); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5810 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5811 | spin_unlock_irq(shost->host_lock); | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5812 | if (vport->port_type == LPFC_PHYSICAL_PORT) | 
|  | 5813 | lpfc_initial_flogi(vport); | 
|  | 5814 | else | 
|  | 5815 | lpfc_initial_fdisc(vport); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5816 | break; | 
|  | 5817 | } | 
|  | 5818 |  | 
|  | 5819 | } else { | 
|  | 5820 | if (vport == phba->pport) | 
|  | 5821 | lpfc_issue_fabric_reglogin(vport); | 
|  | 5822 | else | 
|  | 5823 | lpfc_do_scr_ns_plogi(phba, vport); | 
|  | 5824 | } | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5825 |  | 
|  | 5826 | /* Now, we decrement the ndlp reference count held for this | 
|  | 5827 | * callback function | 
|  | 5828 | */ | 
|  | 5829 | lpfc_nlp_put(ndlp); | 
|  | 5830 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5831 | mempool_free(pmb, phba->mbox_mem_pool); | 
|  | 5832 | return; | 
|  | 5833 | } | 
|  | 5834 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5835 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5836 | * lpfc_register_new_vport - Register a new vport with a HBA | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5837 | * @phba: pointer to lpfc hba data structure. | 
|  | 5838 | * @vport: pointer to a host virtual N_Port data structure. | 
|  | 5839 | * @ndlp: pointer to a node-list data structure. | 
|  | 5840 | * | 
|  | 5841 | * This routine registers the @vport as a new virtual port with a HBA. | 
|  | 5842 | * It is done through a registering vpi mailbox command. | 
|  | 5843 | **/ | 
| Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 5844 | static void | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5845 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, | 
|  | 5846 | struct lpfc_nodelist *ndlp) | 
|  | 5847 | { | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5848 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5849 | LPFC_MBOXQ_t *mbox; | 
|  | 5850 |  | 
|  | 5851 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | 
|  | 5852 | if (mbox) { | 
|  | 5853 | lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, mbox); | 
|  | 5854 | mbox->vport = vport; | 
|  | 5855 | mbox->context2 = lpfc_nlp_get(ndlp); | 
|  | 5856 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; | 
| James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5857 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5858 | == MBX_NOT_FINISHED) { | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5859 | /* mailbox command not success, decrement ndlp | 
|  | 5860 | * reference count for this command | 
|  | 5861 | */ | 
|  | 5862 | lpfc_nlp_put(ndlp); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5863 | mempool_free(mbox, phba->mbox_mem_pool); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5864 |  | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5865 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, | 
|  | 5866 | "0253 Register VPI: Can't send mbox\n"); | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5867 | goto mbox_err_exit; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5868 | } | 
|  | 5869 | } else { | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5870 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, | 
|  | 5871 | "0254 Register VPI: no memory\n"); | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5872 | goto mbox_err_exit; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5873 | } | 
| James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5874 | return; | 
|  | 5875 |  | 
|  | 5876 | mbox_err_exit: | 
|  | 5877 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | 
|  | 5878 | spin_lock_irq(shost->host_lock); | 
|  | 5879 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; | 
|  | 5880 | spin_unlock_irq(shost->host_lock); | 
|  | 5881 | return; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5882 | } | 
|  | 5883 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5884 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5885 | * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5886 | * @phba: pointer to lpfc hba data structure. | 
|  | 5887 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 5888 | * @rspiocb: pointer to lpfc response iocb data structure. | 
|  | 5889 | * | 
|  | 5890 | * This routine is the completion callback function to a Fabric Discover | 
|  | 5891 | * (FDISC) ELS command. Since all the FDISC ELS commands are issued | 
|  | 5892 | * single threaded, each FDISC completion callback function will reset | 
|  | 5893 | * the discovery timer for all vports such that the timers will not get | 
|  | 5894 | * unnecessary timeout. The function checks the FDISC IOCB status. If error | 
|  | 5895 | * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the | 
|  | 5896 | * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID | 
|  | 5897 | * assigned to the vport has been changed with the completion of the FDISC | 
|  | 5898 | * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) | 
|  | 5899 | * are unregistered from the HBA, and then the lpfc_register_new_vport() | 
|  | 5900 | * routine is invoked to register new vport with the HBA. Otherwise, the | 
|  | 5901 | * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name | 
|  | 5902 | * Server for State Change Request (SCR). | 
|  | 5903 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5904 | static void | 
|  | 5905 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | 
|  | 5906 | struct lpfc_iocbq *rspiocb) | 
|  | 5907 | { | 
|  | 5908 | struct lpfc_vport *vport = cmdiocb->vport; | 
|  | 5909 | struct Scsi_Host  *shost = lpfc_shost_from_vport(vport); | 
|  | 5910 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; | 
|  | 5911 | struct lpfc_nodelist *np; | 
|  | 5912 | struct lpfc_nodelist *next_np; | 
|  | 5913 | IOCB_t *irsp = &rspiocb->iocb; | 
|  | 5914 | struct lpfc_iocbq *piocb; | 
|  | 5915 |  | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5916 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | 
|  | 5917 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", | 
|  | 5918 | irsp->ulpStatus, irsp->un.ulpWord[4], | 
|  | 5919 | vport->fc_prevDID); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5920 | /* Since all FDISCs are being single threaded, we | 
|  | 5921 | * must reset the discovery timer for ALL vports | 
|  | 5922 | * waiting to send FDISC when one completes. | 
|  | 5923 | */ | 
|  | 5924 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { | 
|  | 5925 | lpfc_set_disctmo(piocb->vport); | 
|  | 5926 | } | 
|  | 5927 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5928 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 5929 | "FDISC cmpl:      status:x%x/x%x prevdid:x%x", | 
|  | 5930 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); | 
|  | 5931 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5932 | if (irsp->ulpStatus) { | 
|  | 5933 | /* Check for retry */ | 
|  | 5934 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) | 
|  | 5935 | goto out; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5936 | /* FDISC failed */ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5937 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5938 | "0126 FDISC failed. (%d/%d)\n", | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5939 | irsp->ulpStatus, irsp->un.ulpWord[4]); | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5940 | goto fdisc_failed; | 
|  | 5941 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5942 | if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING) | 
|  | 5943 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5944 | lpfc_nlp_put(ndlp); | 
|  | 5945 | /* giving up on FDISC. Cancel discovery timer */ | 
|  | 5946 | lpfc_can_disctmo(vport); | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5947 | spin_lock_irq(shost->host_lock); | 
|  | 5948 | vport->fc_flag |= FC_FABRIC; | 
|  | 5949 | if (vport->phba->fc_topology == TOPOLOGY_LOOP) | 
|  | 5950 | vport->fc_flag |=  FC_PUBLIC_LOOP; | 
|  | 5951 | spin_unlock_irq(shost->host_lock); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5952 |  | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5953 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; | 
|  | 5954 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); | 
|  | 5955 | if ((vport->fc_prevDID != vport->fc_myDID) && | 
|  | 5956 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { | 
|  | 5957 | /* If our NportID changed, we need to ensure all | 
|  | 5958 | * remaining NPORTs get unreg_login'ed so we can | 
|  | 5959 | * issue unreg_vpi. | 
|  | 5960 | */ | 
|  | 5961 | list_for_each_entry_safe(np, next_np, | 
|  | 5962 | &vport->fc_nodes, nlp_listp) { | 
|  | 5963 | if (!NLP_CHK_NODE_ACT(ndlp) || | 
|  | 5964 | (np->nlp_state != NLP_STE_NPR_NODE) || | 
|  | 5965 | !(np->nlp_flag & NLP_NPR_ADISC)) | 
|  | 5966 | continue; | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5967 | spin_lock_irq(shost->host_lock); | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5968 | np->nlp_flag &= ~NLP_NPR_ADISC; | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5969 | spin_unlock_irq(shost->host_lock); | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5970 | lpfc_unreg_rpi(vport, np); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5971 | } | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5972 | lpfc_mbx_unreg_vpi(vport); | 
|  | 5973 | spin_lock_irq(shost->host_lock); | 
|  | 5974 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; | 
|  | 5975 | spin_unlock_irq(shost->host_lock); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5976 | } | 
|  | 5977 |  | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5978 | if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) | 
|  | 5979 | lpfc_register_new_vport(phba, vport, ndlp); | 
|  | 5980 | else | 
|  | 5981 | lpfc_do_scr_ns_plogi(phba, vport); | 
|  | 5982 | goto out; | 
|  | 5983 | fdisc_failed: | 
|  | 5984 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | 
|  | 5985 | /* Cancel discovery timer */ | 
|  | 5986 | lpfc_can_disctmo(vport); | 
|  | 5987 | lpfc_nlp_put(ndlp); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5988 | out: | 
|  | 5989 | lpfc_els_free_iocb(phba, cmdiocb); | 
|  | 5990 | } | 
|  | 5991 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5992 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5993 | * lpfc_issue_els_fdisc - Issue a fdisc iocb command | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5994 | * @vport: pointer to a virtual N_Port data structure. | 
|  | 5995 | * @ndlp: pointer to a node-list data structure. | 
|  | 5996 | * @retry: number of retries to the command IOCB. | 
|  | 5997 | * | 
|  | 5998 | * This routine prepares and issues a Fabric Discover (FDISC) IOCB to | 
|  | 5999 | * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() | 
|  | 6000 | * routine to issue the IOCB, which makes sure only one outstanding fabric | 
|  | 6001 | * IOCB will be sent off HBA at any given time. | 
|  | 6002 | * | 
|  | 6003 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | 
|  | 6004 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | 
|  | 6005 | * will be stored into the context1 field of the IOCB for the completion | 
|  | 6006 | * callback function to the FDISC ELS command. | 
|  | 6007 | * | 
|  | 6008 | * Return code | 
|  | 6009 | *   0 - Successfully issued fdisc iocb command | 
|  | 6010 | *   1 - Failed to issue fdisc iocb command | 
|  | 6011 | **/ | 
| Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6012 | static int | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6013 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, | 
|  | 6014 | uint8_t retry) | 
|  | 6015 | { | 
|  | 6016 | struct lpfc_hba *phba = vport->phba; | 
|  | 6017 | IOCB_t *icmd; | 
|  | 6018 | struct lpfc_iocbq *elsiocb; | 
|  | 6019 | struct serv_parm *sp; | 
|  | 6020 | uint8_t *pcmd; | 
|  | 6021 | uint16_t cmdsize; | 
|  | 6022 | int did = ndlp->nlp_DID; | 
|  | 6023 | int rc; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6024 |  | 
|  | 6025 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); | 
|  | 6026 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, | 
|  | 6027 | ELS_CMD_FDISC); | 
|  | 6028 | if (!elsiocb) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6029 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6030 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 6031 | "0255 Issue FDISC: no IOCB\n"); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6032 | return 1; | 
|  | 6033 | } | 
|  | 6034 |  | 
|  | 6035 | icmd = &elsiocb->iocb; | 
|  | 6036 | icmd->un.elsreq64.myID = 0; | 
|  | 6037 | icmd->un.elsreq64.fl = 1; | 
|  | 6038 |  | 
|  | 6039 | /* For FDISC, Let FDISC rsp set the NPortID for this VPI */ | 
|  | 6040 | icmd->ulpCt_h = 1; | 
|  | 6041 | icmd->ulpCt_l = 0; | 
|  | 6042 |  | 
|  | 6043 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 6044 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; | 
|  | 6045 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ | 
|  | 6046 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); | 
|  | 6047 | sp = (struct serv_parm *) pcmd; | 
|  | 6048 | /* Setup CSPs accordingly for Fabric */ | 
|  | 6049 | sp->cmn.e_d_tov = 0; | 
|  | 6050 | sp->cmn.w2.r_a_tov = 0; | 
|  | 6051 | sp->cls1.classValid = 0; | 
|  | 6052 | sp->cls2.seqDelivery = 1; | 
|  | 6053 | sp->cls3.seqDelivery = 1; | 
|  | 6054 |  | 
|  | 6055 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ | 
|  | 6056 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ | 
|  | 6057 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ | 
|  | 6058 | pcmd += sizeof(uint32_t); /* Port Name */ | 
|  | 6059 | memcpy(pcmd, &vport->fc_portname, 8); | 
|  | 6060 | pcmd += sizeof(uint32_t); /* Node Name */ | 
|  | 6061 | pcmd += sizeof(uint32_t); /* Node Name */ | 
|  | 6062 | memcpy(pcmd, &vport->fc_nodename, 8); | 
|  | 6063 |  | 
|  | 6064 | lpfc_set_disctmo(vport); | 
|  | 6065 |  | 
|  | 6066 | phba->fc_stat.elsXmitFDISC++; | 
|  | 6067 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; | 
|  | 6068 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6069 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 6070 | "Issue FDISC:     did:x%x", | 
|  | 6071 | did, 0, 0); | 
|  | 6072 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6073 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); | 
|  | 6074 | if (rc == IOCB_ERROR) { | 
|  | 6075 | lpfc_els_free_iocb(phba, elsiocb); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6076 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 6077 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | 
|  | 6078 | "0256 Issue FDISC: Cannot send IOCB\n"); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6079 | return 1; | 
|  | 6080 | } | 
|  | 6081 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); | 
|  | 6082 | vport->port_state = LPFC_FDISC; | 
|  | 6083 | return 0; | 
|  | 6084 | } | 
|  | 6085 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6086 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6087 | * lpfc_cmpl_els_npiv_logo - Completion function with vport logo | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6088 | * @phba: pointer to lpfc hba data structure. | 
|  | 6089 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 6090 | * @rspiocb: pointer to lpfc response iocb data structure. | 
|  | 6091 | * | 
|  | 6092 | * This routine is the completion callback function to the issuing of a LOGO | 
|  | 6093 | * ELS command off a vport. It frees the command IOCB and then decrement the | 
|  | 6094 | * reference count held on ndlp for this completion function, indicating that | 
|  | 6095 | * the reference to the ndlp is no long needed. Note that the | 
|  | 6096 | * lpfc_els_free_iocb() routine decrements the ndlp reference held for this | 
|  | 6097 | * callback function and an additional explicit ndlp reference decrementation | 
|  | 6098 | * will trigger the actual release of the ndlp. | 
|  | 6099 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6100 | static void | 
|  | 6101 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | 
|  | 6102 | struct lpfc_iocbq *rspiocb) | 
|  | 6103 | { | 
|  | 6104 | struct lpfc_vport *vport = cmdiocb->vport; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6105 | IOCB_t *irsp; | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6106 | struct lpfc_nodelist *ndlp; | 
|  | 6107 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6108 |  | 
|  | 6109 | irsp = &rspiocb->iocb; | 
|  | 6110 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 6111 | "LOGO npiv cmpl:  status:x%x/x%x did:x%x", | 
|  | 6112 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6113 |  | 
|  | 6114 | lpfc_els_free_iocb(phba, cmdiocb); | 
|  | 6115 | vport->unreg_vpi_cmpl = VPORT_ERROR; | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 6116 |  | 
|  | 6117 | /* Trigger the release of the ndlp after logo */ | 
|  | 6118 | lpfc_nlp_put(ndlp); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6119 | } | 
|  | 6120 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6121 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6122 | * lpfc_issue_els_npiv_logo - Issue a logo off a vport | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6123 | * @vport: pointer to a virtual N_Port data structure. | 
|  | 6124 | * @ndlp: pointer to a node-list data structure. | 
|  | 6125 | * | 
|  | 6126 | * This routine issues a LOGO ELS command to an @ndlp off a @vport. | 
|  | 6127 | * | 
|  | 6128 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | 
|  | 6129 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | 
|  | 6130 | * will be stored into the context1 field of the IOCB for the completion | 
|  | 6131 | * callback function to the LOGO ELS command. | 
|  | 6132 | * | 
|  | 6133 | * Return codes | 
|  | 6134 | *   0 - Successfully issued logo off the @vport | 
|  | 6135 | *   1 - Failed to issue logo off the @vport | 
|  | 6136 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6137 | int | 
|  | 6138 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) | 
|  | 6139 | { | 
|  | 6140 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | 6141 | struct lpfc_hba  *phba = vport->phba; | 
|  | 6142 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | 
|  | 6143 | IOCB_t *icmd; | 
|  | 6144 | struct lpfc_iocbq *elsiocb; | 
|  | 6145 | uint8_t *pcmd; | 
|  | 6146 | uint16_t cmdsize; | 
|  | 6147 |  | 
|  | 6148 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); | 
|  | 6149 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, | 
|  | 6150 | ELS_CMD_LOGO); | 
|  | 6151 | if (!elsiocb) | 
|  | 6152 | return 1; | 
|  | 6153 |  | 
|  | 6154 | icmd = &elsiocb->iocb; | 
|  | 6155 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | 
|  | 6156 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; | 
|  | 6157 | pcmd += sizeof(uint32_t); | 
|  | 6158 |  | 
|  | 6159 | /* Fill in LOGO payload */ | 
|  | 6160 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); | 
|  | 6161 | pcmd += sizeof(uint32_t); | 
|  | 6162 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); | 
|  | 6163 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6164 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 6165 | "Issue LOGO npiv  did:x%x flg:x%x", | 
|  | 6166 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | 
|  | 6167 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6168 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; | 
|  | 6169 | spin_lock_irq(shost->host_lock); | 
|  | 6170 | ndlp->nlp_flag |= NLP_LOGO_SND; | 
|  | 6171 | spin_unlock_irq(shost->host_lock); | 
|  | 6172 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { | 
|  | 6173 | spin_lock_irq(shost->host_lock); | 
|  | 6174 | ndlp->nlp_flag &= ~NLP_LOGO_SND; | 
|  | 6175 | spin_unlock_irq(shost->host_lock); | 
|  | 6176 | lpfc_els_free_iocb(phba, elsiocb); | 
|  | 6177 | return 1; | 
|  | 6178 | } | 
|  | 6179 | return 0; | 
|  | 6180 | } | 
|  | 6181 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6182 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6183 | * lpfc_fabric_block_timeout - Handler function to the fabric block timer | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6184 | * @ptr: holder for the timer function associated data. | 
|  | 6185 | * | 
|  | 6186 | * This routine is invoked by the fabric iocb block timer after | 
|  | 6187 | * timeout. It posts the fabric iocb block timeout event by setting the | 
|  | 6188 | * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes | 
|  | 6189 | * lpfc_worker_wake_up() routine to wake up the worker thread. It is for | 
|  | 6190 | * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the | 
|  | 6191 | * posted event WORKER_FABRIC_BLOCK_TMO. | 
|  | 6192 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6193 | void | 
|  | 6194 | lpfc_fabric_block_timeout(unsigned long ptr) | 
|  | 6195 | { | 
|  | 6196 | struct lpfc_hba  *phba = (struct lpfc_hba *) ptr; | 
|  | 6197 | unsigned long iflags; | 
|  | 6198 | uint32_t tmo_posted; | 
| James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6199 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6200 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); | 
|  | 6201 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; | 
|  | 6202 | if (!tmo_posted) | 
|  | 6203 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; | 
|  | 6204 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); | 
|  | 6205 |  | 
| James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6206 | if (!tmo_posted) | 
|  | 6207 | lpfc_worker_wake_up(phba); | 
|  | 6208 | return; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6209 | } | 
|  | 6210 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6211 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6212 | * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6213 | * @phba: pointer to lpfc hba data structure. | 
|  | 6214 | * | 
|  | 6215 | * This routine issues one fabric iocb from the driver internal list to | 
|  | 6216 | * the HBA. It first checks whether it's ready to issue one fabric iocb to | 
|  | 6217 | * the HBA (whether there is no outstanding fabric iocb). If so, it shall | 
|  | 6218 | * remove one pending fabric iocb from the driver internal list and invokes | 
|  | 6219 | * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. | 
|  | 6220 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6221 | static void | 
|  | 6222 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) | 
|  | 6223 | { | 
|  | 6224 | struct lpfc_iocbq *iocb; | 
|  | 6225 | unsigned long iflags; | 
|  | 6226 | int ret; | 
|  | 6227 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | 
|  | 6228 | IOCB_t *cmd; | 
|  | 6229 |  | 
|  | 6230 | repeat: | 
|  | 6231 | iocb = NULL; | 
|  | 6232 | spin_lock_irqsave(&phba->hbalock, iflags); | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6233 | /* Post any pending iocb to the SLI layer */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6234 | if (atomic_read(&phba->fabric_iocb_count) == 0) { | 
|  | 6235 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), | 
|  | 6236 | list); | 
|  | 6237 | if (iocb) | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6238 | /* Increment fabric iocb count to hold the position */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6239 | atomic_inc(&phba->fabric_iocb_count); | 
|  | 6240 | } | 
|  | 6241 | spin_unlock_irqrestore(&phba->hbalock, iflags); | 
|  | 6242 | if (iocb) { | 
|  | 6243 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; | 
|  | 6244 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; | 
|  | 6245 | iocb->iocb_flag |= LPFC_IO_FABRIC; | 
|  | 6246 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6247 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 6248 | "Fabric sched1:   ste:x%x", | 
|  | 6249 | iocb->vport->port_state, 0, 0); | 
|  | 6250 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6251 | ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0); | 
|  | 6252 |  | 
|  | 6253 | if (ret == IOCB_ERROR) { | 
|  | 6254 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; | 
|  | 6255 | iocb->fabric_iocb_cmpl = NULL; | 
|  | 6256 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; | 
|  | 6257 | cmd = &iocb->iocb; | 
|  | 6258 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; | 
|  | 6259 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; | 
|  | 6260 | iocb->iocb_cmpl(phba, iocb, iocb); | 
|  | 6261 |  | 
|  | 6262 | atomic_dec(&phba->fabric_iocb_count); | 
|  | 6263 | goto repeat; | 
|  | 6264 | } | 
|  | 6265 | } | 
|  | 6266 |  | 
|  | 6267 | return; | 
|  | 6268 | } | 
|  | 6269 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6270 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6271 | * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6272 | * @phba: pointer to lpfc hba data structure. | 
|  | 6273 | * | 
|  | 6274 | * This routine unblocks the  issuing fabric iocb command. The function | 
|  | 6275 | * will clear the fabric iocb block bit and then invoke the routine | 
|  | 6276 | * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb | 
|  | 6277 | * from the driver internal fabric iocb list. | 
|  | 6278 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6279 | void | 
|  | 6280 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) | 
|  | 6281 | { | 
|  | 6282 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); | 
|  | 6283 |  | 
|  | 6284 | lpfc_resume_fabric_iocbs(phba); | 
|  | 6285 | return; | 
|  | 6286 | } | 
|  | 6287 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6288 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6289 | * lpfc_block_fabric_iocbs - Block issuing fabric iocb command | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6290 | * @phba: pointer to lpfc hba data structure. | 
|  | 6291 | * | 
|  | 6292 | * This routine blocks the issuing fabric iocb for a specified amount of | 
|  | 6293 | * time (currently 100 ms). This is done by set the fabric iocb block bit | 
|  | 6294 | * and set up a timeout timer for 100ms. When the block bit is set, no more | 
|  | 6295 | * fabric iocb will be issued out of the HBA. | 
|  | 6296 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6297 | static void | 
|  | 6298 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) | 
|  | 6299 | { | 
|  | 6300 | int blocked; | 
|  | 6301 |  | 
|  | 6302 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6303 | /* Start a timer to unblock fabric iocbs after 100ms */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6304 | if (!blocked) | 
|  | 6305 | mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 ); | 
|  | 6306 |  | 
|  | 6307 | return; | 
|  | 6308 | } | 
|  | 6309 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6310 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6311 | * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6312 | * @phba: pointer to lpfc hba data structure. | 
|  | 6313 | * @cmdiocb: pointer to lpfc command iocb data structure. | 
|  | 6314 | * @rspiocb: pointer to lpfc response iocb data structure. | 
|  | 6315 | * | 
|  | 6316 | * This routine is the callback function that is put to the fabric iocb's | 
|  | 6317 | * callback function pointer (iocb->iocb_cmpl). The original iocb's callback | 
|  | 6318 | * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback | 
|  | 6319 | * function first restores and invokes the original iocb's callback function | 
|  | 6320 | * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next | 
|  | 6321 | * fabric bound iocb from the driver internal fabric iocb list onto the wire. | 
|  | 6322 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6323 | static void | 
|  | 6324 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | 
|  | 6325 | struct lpfc_iocbq *rspiocb) | 
|  | 6326 | { | 
|  | 6327 | struct ls_rjt stat; | 
|  | 6328 |  | 
|  | 6329 | if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC) | 
|  | 6330 | BUG(); | 
|  | 6331 |  | 
|  | 6332 | switch (rspiocb->iocb.ulpStatus) { | 
|  | 6333 | case IOSTAT_NPORT_RJT: | 
|  | 6334 | case IOSTAT_FABRIC_RJT: | 
|  | 6335 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { | 
|  | 6336 | lpfc_block_fabric_iocbs(phba); | 
|  | 6337 | } | 
|  | 6338 | break; | 
|  | 6339 |  | 
|  | 6340 | case IOSTAT_NPORT_BSY: | 
|  | 6341 | case IOSTAT_FABRIC_BSY: | 
|  | 6342 | lpfc_block_fabric_iocbs(phba); | 
|  | 6343 | break; | 
|  | 6344 |  | 
|  | 6345 | case IOSTAT_LS_RJT: | 
|  | 6346 | stat.un.lsRjtError = | 
|  | 6347 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); | 
|  | 6348 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || | 
|  | 6349 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) | 
|  | 6350 | lpfc_block_fabric_iocbs(phba); | 
|  | 6351 | break; | 
|  | 6352 | } | 
|  | 6353 |  | 
|  | 6354 | if (atomic_read(&phba->fabric_iocb_count) == 0) | 
|  | 6355 | BUG(); | 
|  | 6356 |  | 
|  | 6357 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; | 
|  | 6358 | cmdiocb->fabric_iocb_cmpl = NULL; | 
|  | 6359 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; | 
|  | 6360 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); | 
|  | 6361 |  | 
|  | 6362 | atomic_dec(&phba->fabric_iocb_count); | 
|  | 6363 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6364 | /* Post any pending iocbs to HBA */ | 
|  | 6365 | lpfc_resume_fabric_iocbs(phba); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6366 | } | 
|  | 6367 | } | 
|  | 6368 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6369 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6370 | * lpfc_issue_fabric_iocb - Issue a fabric iocb command | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6371 | * @phba: pointer to lpfc hba data structure. | 
|  | 6372 | * @iocb: pointer to lpfc command iocb data structure. | 
|  | 6373 | * | 
|  | 6374 | * This routine is used as the top-level API for issuing a fabric iocb command | 
|  | 6375 | * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver | 
|  | 6376 | * function makes sure that only one fabric bound iocb will be outstanding at | 
|  | 6377 | * any given time. As such, this function will first check to see whether there | 
|  | 6378 | * is already an outstanding fabric iocb on the wire. If so, it will put the | 
|  | 6379 | * newly issued iocb onto the driver internal fabric iocb list, waiting to be | 
|  | 6380 | * issued later. Otherwise, it will issue the iocb on the wire and update the | 
|  | 6381 | * fabric iocb count it indicate that there is one fabric iocb on the wire. | 
|  | 6382 | * | 
|  | 6383 | * Note, this implementation has a potential sending out fabric IOCBs out of | 
|  | 6384 | * order. The problem is caused by the construction of the "ready" boolen does | 
|  | 6385 | * not include the condition that the internal fabric IOCB list is empty. As | 
|  | 6386 | * such, it is possible a fabric IOCB issued by this routine might be "jump" | 
|  | 6387 | * ahead of the fabric IOCBs in the internal list. | 
|  | 6388 | * | 
|  | 6389 | * Return code | 
|  | 6390 | *   IOCB_SUCCESS - either fabric iocb put on the list or issued successfully | 
|  | 6391 | *   IOCB_ERROR - failed to issue fabric iocb | 
|  | 6392 | **/ | 
| Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6393 | static int | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6394 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) | 
|  | 6395 | { | 
|  | 6396 | unsigned long iflags; | 
|  | 6397 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | 
|  | 6398 | int ready; | 
|  | 6399 | int ret; | 
|  | 6400 |  | 
|  | 6401 | if (atomic_read(&phba->fabric_iocb_count) > 1) | 
|  | 6402 | BUG(); | 
|  | 6403 |  | 
|  | 6404 | spin_lock_irqsave(&phba->hbalock, iflags); | 
|  | 6405 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && | 
|  | 6406 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); | 
|  | 6407 |  | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6408 | if (ready) | 
|  | 6409 | /* Increment fabric iocb count to hold the position */ | 
|  | 6410 | atomic_inc(&phba->fabric_iocb_count); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6411 | spin_unlock_irqrestore(&phba->hbalock, iflags); | 
|  | 6412 | if (ready) { | 
|  | 6413 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; | 
|  | 6414 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; | 
|  | 6415 | iocb->iocb_flag |= LPFC_IO_FABRIC; | 
|  | 6416 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6417 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, | 
|  | 6418 | "Fabric sched2:   ste:x%x", | 
|  | 6419 | iocb->vport->port_state, 0, 0); | 
|  | 6420 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6421 | ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0); | 
|  | 6422 |  | 
|  | 6423 | if (ret == IOCB_ERROR) { | 
|  | 6424 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; | 
|  | 6425 | iocb->fabric_iocb_cmpl = NULL; | 
|  | 6426 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; | 
|  | 6427 | atomic_dec(&phba->fabric_iocb_count); | 
|  | 6428 | } | 
|  | 6429 | } else { | 
|  | 6430 | spin_lock_irqsave(&phba->hbalock, iflags); | 
|  | 6431 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); | 
|  | 6432 | spin_unlock_irqrestore(&phba->hbalock, iflags); | 
|  | 6433 | ret = IOCB_SUCCESS; | 
|  | 6434 | } | 
|  | 6435 | return ret; | 
|  | 6436 | } | 
|  | 6437 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6438 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6439 | * 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] | 6440 | * @vport: pointer to a virtual N_Port data structure. | 
|  | 6441 | * | 
|  | 6442 | * This routine aborts all the IOCBs associated with a @vport from the | 
|  | 6443 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be | 
|  | 6444 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB | 
|  | 6445 | * list, removes each IOCB associated with the @vport off the list, set the | 
|  | 6446 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function | 
|  | 6447 | * associated with the IOCB. | 
|  | 6448 | **/ | 
| Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6449 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6450 | { | 
|  | 6451 | LIST_HEAD(completions); | 
|  | 6452 | struct lpfc_hba  *phba = vport->phba; | 
|  | 6453 | struct lpfc_iocbq *tmp_iocb, *piocb; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6454 |  | 
|  | 6455 | spin_lock_irq(&phba->hbalock); | 
|  | 6456 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, | 
|  | 6457 | list) { | 
|  | 6458 |  | 
|  | 6459 | if (piocb->vport != vport) | 
|  | 6460 | continue; | 
|  | 6461 |  | 
|  | 6462 | list_move_tail(&piocb->list, &completions); | 
|  | 6463 | } | 
|  | 6464 | spin_unlock_irq(&phba->hbalock); | 
|  | 6465 |  | 
| James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6466 | /* Cancel all the IOCBs from the completions list */ | 
|  | 6467 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | 
|  | 6468 | IOERR_SLI_ABORTED); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6469 | } | 
|  | 6470 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6471 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6472 | * 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] | 6473 | * @ndlp: pointer to a node-list data structure. | 
|  | 6474 | * | 
|  | 6475 | * This routine aborts all the IOCBs associated with an @ndlp from the | 
|  | 6476 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be | 
|  | 6477 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB | 
|  | 6478 | * list, removes each IOCB associated with the @ndlp off the list, set the | 
|  | 6479 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function | 
|  | 6480 | * associated with the IOCB. | 
|  | 6481 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6482 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) | 
|  | 6483 | { | 
|  | 6484 | LIST_HEAD(completions); | 
| James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6485 | struct lpfc_hba  *phba = ndlp->phba; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6486 | struct lpfc_iocbq *tmp_iocb, *piocb; | 
|  | 6487 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6488 |  | 
|  | 6489 | spin_lock_irq(&phba->hbalock); | 
|  | 6490 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, | 
|  | 6491 | list) { | 
|  | 6492 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { | 
|  | 6493 |  | 
|  | 6494 | list_move_tail(&piocb->list, &completions); | 
|  | 6495 | } | 
|  | 6496 | } | 
|  | 6497 | spin_unlock_irq(&phba->hbalock); | 
|  | 6498 |  | 
| James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6499 | /* Cancel all the IOCBs from the completions list */ | 
|  | 6500 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | 
|  | 6501 | IOERR_SLI_ABORTED); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6502 | } | 
|  | 6503 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6504 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6505 | * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6506 | * @phba: pointer to lpfc hba data structure. | 
|  | 6507 | * | 
|  | 6508 | * This routine aborts all the IOCBs currently on the driver internal | 
|  | 6509 | * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS | 
|  | 6510 | * IOCB ring. This function takes the entire IOCB list off the fabric IOCB | 
|  | 6511 | * list, removes IOCBs off the list, set the status feild to | 
|  | 6512 | * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with | 
|  | 6513 | * the IOCB. | 
|  | 6514 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6515 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) | 
|  | 6516 | { | 
|  | 6517 | LIST_HEAD(completions); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6518 |  | 
|  | 6519 | spin_lock_irq(&phba->hbalock); | 
|  | 6520 | list_splice_init(&phba->fabric_iocb_list, &completions); | 
|  | 6521 | spin_unlock_irq(&phba->hbalock); | 
|  | 6522 |  | 
| James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 6523 | /* Cancel all the IOCBs from the completions list */ | 
|  | 6524 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | 
|  | 6525 | IOERR_SLI_ABORTED); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6526 | } |