| 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" |
| 33 | #include "lpfc_disc.h" |
| 34 | #include "lpfc_scsi.h" |
| 35 | #include "lpfc.h" |
| 36 | #include "lpfc_logmsg.h" |
| 37 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 38 | #include "lpfc_vport.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 39 | #include "lpfc_debugfs.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 40 | |
| 41 | static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *, |
| 42 | struct lpfc_iocbq *); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 43 | static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *, |
| 44 | struct lpfc_iocbq *); |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 45 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport); |
| 46 | static int lpfc_issue_els_fdisc(struct lpfc_vport *vport, |
| 47 | struct lpfc_nodelist *ndlp, uint8_t retry); |
| 48 | static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba, |
| 49 | struct lpfc_iocbq *iocb); |
| 50 | static void lpfc_register_new_vport(struct lpfc_hba *phba, |
| 51 | struct lpfc_vport *vport, |
| 52 | struct lpfc_nodelist *ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 53 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 54 | static int lpfc_max_els_tries = 3; |
| 55 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 56 | /** |
| 57 | * lpfc_els_chk_latt: Check host link attention event for a vport. |
| 58 | * @vport: pointer to a host virtual N_Port data structure. |
| 59 | * |
| 60 | * This routine checks whether there is an outstanding host link |
| 61 | * attention event during the discovery process with the @vport. It is done |
| 62 | * by reading the HBA's Host Attention (HA) register. If there is any host |
| 63 | * link attention events during this @vport's discovery process, the @vport |
| 64 | * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall |
| 65 | * be issued if the link state is not already in host link cleared state, |
| 66 | * and a return code shall indicate whether the host link attention event |
| 67 | * had happened. |
| 68 | * |
| 69 | * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport |
| 70 | * state in LPFC_VPORT_READY, the request for checking host link attention |
| 71 | * event will be ignored and a return code shall indicate no host link |
| 72 | * attention event had happened. |
| 73 | * |
| 74 | * Return codes |
| 75 | * 0 - no host link attention event happened |
| 76 | * 1 - host link attention event happened |
| 77 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 78 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 79 | lpfc_els_chk_latt(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 80 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 81 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 82 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 83 | uint32_t ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 84 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 85 | if (vport->port_state >= LPFC_VPORT_READY || |
| 86 | phba->link_state == LPFC_LINK_DOWN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 87 | return 0; |
| 88 | |
| 89 | /* Read the HBA Host Attention Register */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 90 | ha_copy = readl(phba->HAregaddr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 91 | |
| 92 | if (!(ha_copy & HA_LATT)) |
| 93 | return 0; |
| 94 | |
| 95 | /* Pending Link Event during Discovery */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 96 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 97 | "0237 Pending Link Event during " |
| 98 | "Discovery: State x%x\n", |
| 99 | phba->pport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 100 | |
| 101 | /* CLEAR_LA should re-enable link attention events and |
| 102 | * we should then imediately take a LATT event. The |
| 103 | * LATT processing should call lpfc_linkdown() which |
| 104 | * will cleanup any left over in-progress discovery |
| 105 | * events. |
| 106 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 107 | spin_lock_irq(shost->host_lock); |
| 108 | vport->fc_flag |= FC_ABORT_DISCOVERY; |
| 109 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 110 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 111 | if (phba->link_state != LPFC_CLEAR_LA) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 112 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 113 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 114 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 115 | } |
| 116 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 117 | /** |
| 118 | * lpfc_prep_els_iocb: Allocate and prepare a lpfc iocb data structure. |
| 119 | * @vport: pointer to a host virtual N_Port data structure. |
| 120 | * @expectRsp: flag indicating whether response is expected. |
| 121 | * @cmdSize: size of the ELS command. |
| 122 | * @retry: number of retries to the command IOCB when it fails. |
| 123 | * @ndlp: pointer to a node-list data structure. |
| 124 | * @did: destination identifier. |
| 125 | * @elscmd: the ELS command code. |
| 126 | * |
| 127 | * This routine is used for allocating a lpfc-IOCB data structure from |
| 128 | * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters |
| 129 | * passed into the routine for discovery state machine to issue an Extended |
| 130 | * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation |
| 131 | * and preparation routine that is used by all the discovery state machine |
| 132 | * routines and the ELS command-specific fields will be later set up by |
| 133 | * the individual discovery machine routines after calling this routine |
| 134 | * allocating and preparing a generic IOCB data structure. It fills in the |
| 135 | * Buffer Descriptor Entries (BDEs), allocates buffers for both command |
| 136 | * payload and response payload (if expected). The reference count on the |
| 137 | * ndlp is incremented by 1 and the reference to the ndlp is put into |
| 138 | * context1 of the IOCB data structure for this IOCB to hold the ndlp |
| 139 | * reference for the command's callback function to access later. |
| 140 | * |
| 141 | * Return code |
| 142 | * Pointer to the newly allocated/prepared els iocb data structure |
| 143 | * NULL - when els iocb data structure allocation/preparation failed |
| 144 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 145 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 146 | lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp, |
| 147 | uint16_t cmdSize, uint8_t retry, |
| 148 | struct lpfc_nodelist *ndlp, uint32_t did, |
| 149 | uint32_t elscmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 150 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 151 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 152 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 153 | struct lpfc_dmabuf *pcmd, *prsp, *pbuflist; |
| 154 | struct ulp_bde64 *bpl; |
| 155 | IOCB_t *icmd; |
| 156 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 157 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 158 | if (!lpfc_is_link_up(phba)) |
| 159 | return NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 160 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 161 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 162 | elsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 163 | |
| 164 | if (elsiocb == NULL) |
| 165 | return NULL; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 166 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 167 | icmd = &elsiocb->iocb; |
| 168 | |
| 169 | /* fill in BDEs for command */ |
| 170 | /* Allocate buffer for command payload */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 171 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 172 | if (pcmd) |
| 173 | pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 174 | if (!pcmd || !pcmd->virt) |
| 175 | goto els_iocb_free_pcmb_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 176 | |
| 177 | INIT_LIST_HEAD(&pcmd->list); |
| 178 | |
| 179 | /* Allocate buffer for response payload */ |
| 180 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 181 | prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 182 | if (prsp) |
| 183 | prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 184 | &prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 185 | if (!prsp || !prsp->virt) |
| 186 | goto els_iocb_free_prsp_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 187 | INIT_LIST_HEAD(&prsp->list); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 188 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 189 | prsp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 190 | |
| 191 | /* Allocate buffer for Buffer ptr list */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 192 | pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 193 | if (pbuflist) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 194 | pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 195 | &pbuflist->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 196 | if (!pbuflist || !pbuflist->virt) |
| 197 | goto els_iocb_free_pbuf_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 198 | |
| 199 | INIT_LIST_HEAD(&pbuflist->list); |
| 200 | |
| 201 | icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); |
| 202 | icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 203 | icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 204 | icmd->un.elsreq64.remoteID = did; /* DID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 205 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 206 | icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 207 | icmd->ulpCommand = CMD_ELS_REQUEST64_CR; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 208 | icmd->ulpTimeout = phba->fc_ratov * 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 209 | } else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 210 | icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 211 | icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX; |
| 212 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 213 | icmd->ulpBdeCount = 1; |
| 214 | icmd->ulpLe = 1; |
| 215 | icmd->ulpClass = CLASS3; |
| 216 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 217 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 218 | icmd->un.elsreq64.myID = vport->fc_myDID; |
| 219 | |
| 220 | /* For ELS_REQUEST64_CR, use the VPI by default */ |
| 221 | icmd->ulpContext = vport->vpi; |
| 222 | icmd->ulpCt_h = 0; |
| 223 | icmd->ulpCt_l = 1; |
| 224 | } |
| 225 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 226 | bpl = (struct ulp_bde64 *) pbuflist->virt; |
| 227 | bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys)); |
| 228 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys)); |
| 229 | bpl->tus.f.bdeSize = cmdSize; |
| 230 | bpl->tus.f.bdeFlags = 0; |
| 231 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 232 | |
| 233 | if (expectRsp) { |
| 234 | bpl++; |
| 235 | bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys)); |
| 236 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys)); |
| 237 | bpl->tus.f.bdeSize = FCELSSIZE; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 238 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 239 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 240 | } |
| 241 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 242 | /* prevent preparing iocb with NULL ndlp reference */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 243 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 244 | if (!elsiocb->context1) |
| 245 | goto els_iocb_free_pbuf_exit; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 246 | elsiocb->context2 = pcmd; |
| 247 | elsiocb->context3 = pbuflist; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 248 | elsiocb->retry = retry; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 249 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 250 | elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT; |
| 251 | |
| 252 | if (prsp) { |
| 253 | list_add(&prsp->list, &pcmd->list); |
| 254 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 255 | if (expectRsp) { |
| 256 | /* Xmit ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 257 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 258 | "0116 Xmit ELS command x%x to remote " |
| 259 | "NPORT x%x I/O tag: x%x, port state: x%x\n", |
| 260 | elscmd, did, elsiocb->iotag, |
| 261 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 262 | } else { |
| 263 | /* Xmit ELS response <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 264 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 265 | "0117 Xmit ELS response x%x to remote " |
| 266 | "NPORT x%x I/O tag: x%x, size: x%x\n", |
| 267 | elscmd, ndlp->nlp_DID, elsiocb->iotag, |
| 268 | cmdSize); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 269 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 270 | return elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 271 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 272 | els_iocb_free_pbuf_exit: |
| 273 | lpfc_mbuf_free(phba, prsp->virt, prsp->phys); |
| 274 | kfree(pbuflist); |
| 275 | |
| 276 | els_iocb_free_prsp_exit: |
| 277 | lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); |
| 278 | kfree(prsp); |
| 279 | |
| 280 | els_iocb_free_pcmb_exit: |
| 281 | kfree(pcmd); |
| 282 | lpfc_sli_release_iocbq(phba, elsiocb); |
| 283 | return NULL; |
| 284 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 285 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 286 | /** |
| 287 | * lpfc_issue_fabric_reglogin: Issue fabric registration login for a vport. |
| 288 | * @vport: pointer to a host virtual N_Port data structure. |
| 289 | * |
| 290 | * This routine issues a fabric registration login for a @vport. An |
| 291 | * active ndlp node with Fabric_DID must already exist for this @vport. |
| 292 | * The routine invokes two mailbox commands to carry out fabric registration |
| 293 | * login through the HBA firmware: the first mailbox command requests the |
| 294 | * HBA to perform link configuration for the @vport; and the second mailbox |
| 295 | * command requests the HBA to perform the actual fabric registration login |
| 296 | * with the @vport. |
| 297 | * |
| 298 | * Return code |
| 299 | * 0 - successfully issued fabric registration login for @vport |
| 300 | * -ENXIO -- failed to issue fabric registration login for @vport |
| 301 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 302 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 303 | lpfc_issue_fabric_reglogin(struct lpfc_vport *vport) |
| 304 | { |
| 305 | struct lpfc_hba *phba = vport->phba; |
| 306 | LPFC_MBOXQ_t *mbox; |
| 307 | struct lpfc_dmabuf *mp; |
| 308 | struct lpfc_nodelist *ndlp; |
| 309 | struct serv_parm *sp; |
| 310 | int rc; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 311 | int err = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 312 | |
| 313 | sp = &phba->fc_fabparam; |
| 314 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 315 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 316 | err = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 317 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 318 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 319 | |
| 320 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 321 | if (!mbox) { |
| 322 | err = 2; |
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 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 327 | lpfc_config_link(phba, mbox); |
| 328 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 329 | mbox->vport = vport; |
| 330 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 331 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 332 | if (rc == MBX_NOT_FINISHED) { |
| 333 | err = 3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 334 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 335 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 336 | |
| 337 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 338 | if (!mbox) { |
| 339 | err = 4; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 340 | goto fail; |
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 | rc = lpfc_reg_login(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, |
| 343 | 0); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 344 | if (rc) { |
| 345 | err = 5; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 346 | goto fail_free_mbox; |
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 | |
| 349 | mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login; |
| 350 | mbox->vport = vport; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 351 | /* increment the reference count on ndlp to hold reference |
| 352 | * for the callback routine. |
| 353 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 354 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 355 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 356 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 357 | if (rc == MBX_NOT_FINISHED) { |
| 358 | err = 6; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 359 | goto fail_issue_reg_login; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 360 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 361 | |
| 362 | return 0; |
| 363 | |
| 364 | fail_issue_reg_login: |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 365 | /* decrement the reference count on ndlp just incremented |
| 366 | * for the failed mbox command. |
| 367 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 368 | lpfc_nlp_put(ndlp); |
| 369 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 370 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 371 | kfree(mp); |
| 372 | fail_free_mbox: |
| 373 | mempool_free(mbox, phba->mbox_mem_pool); |
| 374 | |
| 375 | fail: |
| 376 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 377 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 378 | "0249 Cannot issue Register Fabric login: Err %d\n", err); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 379 | return -ENXIO; |
| 380 | } |
| 381 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 382 | /** |
| 383 | * lpfc_cmpl_els_flogi_fabric: Completion function for flogi to a fabric port. |
| 384 | * @vport: pointer to a host virtual N_Port data structure. |
| 385 | * @ndlp: pointer to a node-list data structure. |
| 386 | * @sp: pointer to service parameter data structure. |
| 387 | * @irsp: pointer to the IOCB within the lpfc response IOCB. |
| 388 | * |
| 389 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 390 | * function to handle the completion of a Fabric Login (FLOGI) into a fabric |
| 391 | * port in a fabric topology. It properly sets up the parameters to the @ndlp |
| 392 | * from the IOCB response. It also check the newly assigned N_Port ID to the |
| 393 | * @vport against the previously assigned N_Port ID. If it is different from |
| 394 | * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine |
| 395 | * is invoked on all the remaining nodes with the @vport to unregister the |
| 396 | * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin() |
| 397 | * is invoked to register login to the fabric. |
| 398 | * |
| 399 | * Return code |
| 400 | * 0 - Success (currently, always return 0) |
| 401 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 402 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 403 | lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 404 | struct serv_parm *sp, IOCB_t *irsp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 405 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 406 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 407 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 408 | struct lpfc_nodelist *np; |
| 409 | struct lpfc_nodelist *next_np; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 410 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 411 | spin_lock_irq(shost->host_lock); |
| 412 | vport->fc_flag |= FC_FABRIC; |
| 413 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 414 | |
| 415 | phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov); |
| 416 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ |
| 417 | phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000; |
| 418 | |
| 419 | phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; |
| 420 | |
| 421 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 422 | spin_lock_irq(shost->host_lock); |
| 423 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 424 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 425 | } else { |
| 426 | /* |
| 427 | * If we are a N-port connected to a Fabric, fixup sparam's so |
| 428 | * logins to devices on remote loops work. |
| 429 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 430 | vport->fc_sparam.cmn.altBbCredit = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 431 | } |
| 432 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 433 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 434 | memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 435 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 436 | ndlp->nlp_class_sup = 0; |
| 437 | if (sp->cls1.classValid) |
| 438 | ndlp->nlp_class_sup |= FC_COS_CLASS1; |
| 439 | if (sp->cls2.classValid) |
| 440 | ndlp->nlp_class_sup |= FC_COS_CLASS2; |
| 441 | if (sp->cls3.classValid) |
| 442 | ndlp->nlp_class_sup |= FC_COS_CLASS3; |
| 443 | if (sp->cls4.classValid) |
| 444 | ndlp->nlp_class_sup |= FC_COS_CLASS4; |
| 445 | ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 446 | sp->cmn.bbRcvSizeLsb; |
| 447 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
| 448 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 449 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 450 | if (sp->cmn.response_multiple_NPort) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 451 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 452 | LOG_ELS | LOG_VPORT, |
| 453 | "1816 FLOGI NPIV supported, " |
| 454 | "response data 0x%x\n", |
| 455 | sp->cmn.response_multiple_NPort); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 456 | phba->link_flag |= LS_NPIV_FAB_SUPPORTED; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 457 | } else { |
| 458 | /* Because we asked f/w for NPIV it still expects us |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 459 | to call reg_vnpid atleast for the physcial host */ |
| 460 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 461 | LOG_ELS | LOG_VPORT, |
| 462 | "1817 Fabric does not support NPIV " |
| 463 | "- configuring single port mode.\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 464 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 469 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 470 | |
| 471 | /* If our NportID changed, we need to ensure all |
| 472 | * remaining NPORTs get unreg_login'ed. |
| 473 | */ |
| 474 | list_for_each_entry_safe(np, next_np, |
| 475 | &vport->fc_nodes, nlp_listp) { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame^] | 476 | if (!NLP_CHK_NODE_ACT(np)) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 477 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 478 | if ((np->nlp_state != NLP_STE_NPR_NODE) || |
| 479 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 480 | continue; |
| 481 | spin_lock_irq(shost->host_lock); |
| 482 | np->nlp_flag &= ~NLP_NPR_ADISC; |
| 483 | spin_unlock_irq(shost->host_lock); |
| 484 | lpfc_unreg_rpi(vport, np); |
| 485 | } |
| 486 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 487 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 488 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 489 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 490 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 491 | } |
| 492 | } |
| 493 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 494 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 495 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 496 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED && |
| 497 | vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) { |
| 498 | lpfc_register_new_vport(phba, vport, ndlp); |
| 499 | return 0; |
| 500 | } |
| 501 | lpfc_issue_fabric_reglogin(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 502 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 503 | } |
| 504 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 505 | /** |
| 506 | * lpfc_cmpl_els_flogi_nport: Completion function for flogi to an N_Port. |
| 507 | * @vport: pointer to a host virtual N_Port data structure. |
| 508 | * @ndlp: pointer to a node-list data structure. |
| 509 | * @sp: pointer to service parameter data structure. |
| 510 | * |
| 511 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback |
| 512 | * function to handle the completion of a Fabric Login (FLOGI) into an N_Port |
| 513 | * in a point-to-point topology. First, the @vport's N_Port Name is compared |
| 514 | * with the received N_Port Name: if the @vport's N_Port Name is greater than |
| 515 | * the received N_Port Name lexicographically, this node shall assign local |
| 516 | * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and |
| 517 | * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise, |
| 518 | * this node shall just wait for the remote node to issue PLOGI and assign |
| 519 | * N_Port IDs. |
| 520 | * |
| 521 | * Return code |
| 522 | * 0 - Success |
| 523 | * -ENXIO - Fail |
| 524 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 525 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 526 | lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 527 | struct serv_parm *sp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 528 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 529 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 530 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 531 | LPFC_MBOXQ_t *mbox; |
| 532 | int rc; |
| 533 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 534 | spin_lock_irq(shost->host_lock); |
| 535 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 536 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 537 | |
| 538 | phba->fc_edtov = FF_DEF_EDTOV; |
| 539 | phba->fc_ratov = FF_DEF_RATOV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 540 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 541 | sizeof(vport->fc_portname)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 542 | if (rc >= 0) { |
| 543 | /* This side will initiate the PLOGI */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 544 | spin_lock_irq(shost->host_lock); |
| 545 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 546 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 547 | |
| 548 | /* |
| 549 | * N_Port ID cannot be 0, set our to LocalID the other |
| 550 | * side will be RemoteID. |
| 551 | */ |
| 552 | |
| 553 | /* not equal */ |
| 554 | if (rc) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 555 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 556 | |
| 557 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 558 | if (!mbox) |
| 559 | goto fail; |
| 560 | |
| 561 | lpfc_config_link(phba, mbox); |
| 562 | |
| 563 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 564 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 565 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 566 | if (rc == MBX_NOT_FINISHED) { |
| 567 | mempool_free(mbox, phba->mbox_mem_pool); |
| 568 | goto fail; |
| 569 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 570 | /* Decrement ndlp reference count indicating that ndlp can be |
| 571 | * safely released when other references to it are done. |
| 572 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 573 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 574 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 575 | ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 576 | if (!ndlp) { |
| 577 | /* |
| 578 | * Cannot find existing Fabric ndlp, so allocate a |
| 579 | * new one |
| 580 | */ |
| 581 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 582 | if (!ndlp) |
| 583 | goto fail; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 584 | lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 585 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 586 | ndlp = lpfc_enable_node(vport, ndlp, |
| 587 | NLP_STE_UNUSED_NODE); |
| 588 | if(!ndlp) |
| 589 | goto fail; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | memcpy(&ndlp->nlp_portname, &sp->portName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 593 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 594 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 595 | sizeof(struct lpfc_name)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 596 | /* Set state will put ndlp onto node list if not already done */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 597 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 598 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 599 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 600 | spin_unlock_irq(shost->host_lock); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 601 | } else |
| 602 | /* This side will wait for the PLOGI, decrement ndlp reference |
| 603 | * count indicating that ndlp can be released when other |
| 604 | * references to it are done. |
| 605 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 606 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 607 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 608 | /* If we are pt2pt with another NPort, force NPIV off! */ |
| 609 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| 610 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 611 | spin_lock_irq(shost->host_lock); |
| 612 | vport->fc_flag |= FC_PT2PT; |
| 613 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 614 | |
| 615 | /* Start discovery - this should just do CLEAR_LA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 616 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 617 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 618 | fail: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 619 | return -ENXIO; |
| 620 | } |
| 621 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 622 | /** |
| 623 | * lpfc_cmpl_els_flogi: Completion callback function for flogi. |
| 624 | * @phba: pointer to lpfc hba data structure. |
| 625 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 626 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 627 | * |
| 628 | * This routine is the top-level completion callback function for issuing |
| 629 | * a Fabric Login (FLOGI) command. If the response IOCB reported error, |
| 630 | * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If |
| 631 | * retry has been made (either immediately or delayed with lpfc_els_retry() |
| 632 | * returning 1), the command IOCB will be released and function returned. |
| 633 | * If the retry attempt has been given up (possibly reach the maximum |
| 634 | * number of retries), one additional decrement of ndlp reference shall be |
| 635 | * invoked before going out after releasing the command IOCB. This will |
| 636 | * actually release the remote node (Note, lpfc_els_free_iocb() will also |
| 637 | * invoke one decrement of ndlp reference count). If no error reported in |
| 638 | * the IOCB status, the command Port ID field is used to determine whether |
| 639 | * this is a point-to-point topology or a fabric topology: if the Port ID |
| 640 | * field is assigned, it is a fabric topology; otherwise, it is a |
| 641 | * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or |
| 642 | * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the |
| 643 | * specific topology completion conditions. |
| 644 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 645 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 646 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 647 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 648 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 649 | struct lpfc_vport *vport = cmdiocb->vport; |
| 650 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 651 | IOCB_t *irsp = &rspiocb->iocb; |
| 652 | struct lpfc_nodelist *ndlp = cmdiocb->context1; |
| 653 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 654 | struct serv_parm *sp; |
| 655 | int rc; |
| 656 | |
| 657 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 658 | if (lpfc_els_chk_latt(vport)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 659 | /* One additional decrement on node reference count to |
| 660 | * trigger the release of the node |
| 661 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 662 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 663 | goto out; |
| 664 | } |
| 665 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 666 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 667 | "FLOGI cmpl: status:x%x/x%x state:x%x", |
| 668 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 669 | vport->port_state); |
| 670 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 671 | if (irsp->ulpStatus) { |
| 672 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 673 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 674 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 675 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 676 | /* FLOGI failed, so there is no fabric */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 677 | spin_lock_irq(shost->host_lock); |
| 678 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 679 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 680 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 681 | /* If private loop, then allow max outstanding els to be |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 682 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no |
| 683 | * alpa map would take too long otherwise. |
| 684 | */ |
| 685 | if (phba->alpa_map[0] == 0) { |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 686 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | /* FLOGI failure */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 690 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 691 | "0100 FLOGI failure Data: x%x x%x " |
| 692 | "x%x\n", |
| 693 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 694 | irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 695 | goto flogifail; |
| 696 | } |
| 697 | |
| 698 | /* |
| 699 | * The FLogI succeeded. Sync the data for the CPU before |
| 700 | * accessing it. |
| 701 | */ |
| 702 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
| 703 | |
| 704 | sp = prsp->virt + sizeof(uint32_t); |
| 705 | |
| 706 | /* FLOGI completes successfully */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 707 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 708 | "0101 FLOGI completes sucessfully " |
| 709 | "Data: x%x x%x x%x x%x\n", |
| 710 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, |
| 711 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 712 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 713 | if (vport->port_state == LPFC_FLOGI) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 714 | /* |
| 715 | * If Common Service Parameters indicate Nport |
| 716 | * we are point to point, if Fport we are Fabric. |
| 717 | */ |
| 718 | if (sp->cmn.fPort) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 719 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 720 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 721 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 722 | |
| 723 | if (!rc) |
| 724 | goto out; |
| 725 | } |
| 726 | |
| 727 | flogifail: |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 728 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 729 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 730 | if (!lpfc_error_lost_link(irsp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 731 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 732 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 733 | |
| 734 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 735 | lpfc_disc_start(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 736 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 737 | ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) && |
| 738 | (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) && |
| 739 | (phba->link_state != LPFC_CLEAR_LA)) { |
| 740 | /* If FLOGI failed enable link interrupt. */ |
| 741 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 742 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 743 | out: |
| 744 | lpfc_els_free_iocb(phba, cmdiocb); |
| 745 | } |
| 746 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 747 | /** |
| 748 | * lpfc_issue_els_flogi: Issue an flogi iocb command for a vport. |
| 749 | * @vport: pointer to a host virtual N_Port data structure. |
| 750 | * @ndlp: pointer to a node-list data structure. |
| 751 | * @retry: number of retries to the command IOCB. |
| 752 | * |
| 753 | * This routine issues a Fabric Login (FLOGI) Request ELS command |
| 754 | * for a @vport. The initiator service parameters are put into the payload |
| 755 | * of the FLOGI Request IOCB and the top-level callback function pointer |
| 756 | * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback |
| 757 | * function field. The lpfc_issue_fabric_iocb routine is invoked to send |
| 758 | * out FLOGI ELS command with one outstanding fabric IOCB at a time. |
| 759 | * |
| 760 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 761 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 762 | * will be stored into the context1 field of the IOCB for the completion |
| 763 | * callback function to the FLOGI ELS command. |
| 764 | * |
| 765 | * Return code |
| 766 | * 0 - successfully issued flogi iocb for @vport |
| 767 | * 1 - failed to issue flogi iocb for @vport |
| 768 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 769 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 770 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 771 | uint8_t retry) |
| 772 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 773 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 774 | struct serv_parm *sp; |
| 775 | IOCB_t *icmd; |
| 776 | struct lpfc_iocbq *elsiocb; |
| 777 | struct lpfc_sli_ring *pring; |
| 778 | uint8_t *pcmd; |
| 779 | uint16_t cmdsize; |
| 780 | uint32_t tmo; |
| 781 | int rc; |
| 782 | |
| 783 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 784 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 785 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 786 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 787 | ndlp->nlp_DID, ELS_CMD_FLOGI); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 788 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 789 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 790 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 791 | |
| 792 | icmd = &elsiocb->iocb; |
| 793 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 794 | |
| 795 | /* For FLOGI request, remainder of payload is service parameters */ |
| 796 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 797 | pcmd += sizeof(uint32_t); |
| 798 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 799 | sp = (struct serv_parm *) pcmd; |
| 800 | |
| 801 | /* Setup CSPs accordingly for Fabric */ |
| 802 | sp->cmn.e_d_tov = 0; |
| 803 | sp->cmn.w2.r_a_tov = 0; |
| 804 | sp->cls1.classValid = 0; |
| 805 | sp->cls2.seqDelivery = 1; |
| 806 | sp->cls3.seqDelivery = 1; |
| 807 | if (sp->cmn.fcphLow < FC_PH3) |
| 808 | sp->cmn.fcphLow = FC_PH3; |
| 809 | if (sp->cmn.fcphHigh < FC_PH3) |
| 810 | sp->cmn.fcphHigh = FC_PH3; |
| 811 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 812 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 813 | sp->cmn.request_multiple_Nport = 1; |
| 814 | |
| 815 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ |
| 816 | icmd->ulpCt_h = 1; |
| 817 | icmd->ulpCt_l = 0; |
| 818 | } |
| 819 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 820 | if (phba->fc_topology != TOPOLOGY_LOOP) { |
| 821 | icmd->un.elsreq64.myID = 0; |
| 822 | icmd->un.elsreq64.fl = 1; |
| 823 | } |
| 824 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 825 | tmo = phba->fc_ratov; |
| 826 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 827 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 828 | phba->fc_ratov = tmo; |
| 829 | |
| 830 | phba->fc_stat.elsXmitFLOGI++; |
| 831 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 832 | |
| 833 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 834 | "Issue FLOGI: opt:x%x", |
| 835 | phba->sli3_options, 0, 0); |
| 836 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 837 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 838 | if (rc == IOCB_ERROR) { |
| 839 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 840 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 841 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 842 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 843 | } |
| 844 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 845 | /** |
| 846 | * lpfc_els_abort_flogi: Abort all outstanding flogi iocbs. |
| 847 | * @phba: pointer to lpfc hba data structure. |
| 848 | * |
| 849 | * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs |
| 850 | * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq |
| 851 | * list and issues an abort IOCB commond on each outstanding IOCB that |
| 852 | * contains a active Fabric_DID ndlp. Note that this function is to issue |
| 853 | * the abort IOCB command on all the outstanding IOCBs, thus when this |
| 854 | * function returns, it does not guarantee all the IOCBs are actually aborted. |
| 855 | * |
| 856 | * Return code |
| 857 | * 0 - Sucessfully issued abort iocb on all outstanding flogis (Always 0) |
| 858 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 859 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 860 | lpfc_els_abort_flogi(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 861 | { |
| 862 | struct lpfc_sli_ring *pring; |
| 863 | struct lpfc_iocbq *iocb, *next_iocb; |
| 864 | struct lpfc_nodelist *ndlp; |
| 865 | IOCB_t *icmd; |
| 866 | |
| 867 | /* Abort outstanding I/O on NPort <nlp_DID> */ |
| 868 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 869 | "0201 Abort outstanding I/O on NPort x%x\n", |
| 870 | Fabric_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 871 | |
| 872 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 873 | |
| 874 | /* |
| 875 | * Check the txcmplq for an iocb that matches the nport the driver is |
| 876 | * searching for. |
| 877 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 878 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 879 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 880 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 881 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR && |
| 882 | icmd->un.elsreq64.bdl.ulpIoTag32) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 883 | ndlp = (struct lpfc_nodelist *)(iocb->context1); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 884 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 885 | (ndlp->nlp_DID == Fabric_DID)) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 886 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 887 | } |
| 888 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 889 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 890 | |
| 891 | return 0; |
| 892 | } |
| 893 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 894 | /** |
| 895 | * lpfc_initial_flogi: Issue an initial fabric login for a vport. |
| 896 | * @vport: pointer to a host virtual N_Port data structure. |
| 897 | * |
| 898 | * This routine issues an initial Fabric Login (FLOGI) for the @vport |
| 899 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 900 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 901 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 902 | * it will just be enabled and made active. The lpfc_issue_els_flogi() routine |
| 903 | * is then invoked with the @vport and the ndlp to perform the FLOGI for the |
| 904 | * @vport. |
| 905 | * |
| 906 | * Return code |
| 907 | * 0 - failed to issue initial flogi for @vport |
| 908 | * 1 - successfully issued initial flogi for @vport |
| 909 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 910 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 911 | lpfc_initial_flogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 912 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 913 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 914 | struct lpfc_nodelist *ndlp; |
| 915 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 916 | vport->port_state = LPFC_FLOGI; |
| 917 | lpfc_set_disctmo(vport); |
| 918 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 919 | /* First look for the Fabric ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 920 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 921 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 922 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 923 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 924 | if (!ndlp) |
| 925 | return 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 926 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 927 | /* Put ndlp onto node list */ |
| 928 | lpfc_enqueue_node(vport, ndlp); |
| 929 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 930 | /* re-setup ndlp without removing from node list */ |
| 931 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 932 | if (!ndlp) |
| 933 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 934 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 935 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 936 | if (lpfc_issue_els_flogi(vport, ndlp, 0)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 937 | /* This decrement of reference count to node shall kick off |
| 938 | * the release of the node. |
| 939 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 940 | lpfc_nlp_put(ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 941 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 942 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 943 | } |
| 944 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 945 | /** |
| 946 | * lpfc_initial_fdisc: Issue an initial fabric discovery for a vport. |
| 947 | * @vport: pointer to a host virtual N_Port data structure. |
| 948 | * |
| 949 | * This routine issues an initial Fabric Discover (FDISC) for the @vport |
| 950 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from |
| 951 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and |
| 952 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, |
| 953 | * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine |
| 954 | * is then invoked with the @vport and the ndlp to perform the FDISC for the |
| 955 | * @vport. |
| 956 | * |
| 957 | * Return code |
| 958 | * 0 - failed to issue initial fdisc for @vport |
| 959 | * 1 - successfully issued initial fdisc for @vport |
| 960 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 961 | int |
| 962 | lpfc_initial_fdisc(struct lpfc_vport *vport) |
| 963 | { |
| 964 | struct lpfc_hba *phba = vport->phba; |
| 965 | struct lpfc_nodelist *ndlp; |
| 966 | |
| 967 | /* First look for the Fabric ndlp */ |
| 968 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 969 | if (!ndlp) { |
| 970 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
| 971 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 972 | if (!ndlp) |
| 973 | return 0; |
| 974 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 975 | /* Put ndlp onto node list */ |
| 976 | lpfc_enqueue_node(vport, ndlp); |
| 977 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 978 | /* re-setup ndlp without removing from node list */ |
| 979 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 980 | if (!ndlp) |
| 981 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 982 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 983 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 984 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 985 | /* decrement node reference count to trigger the release of |
| 986 | * the node. |
| 987 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 988 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 989 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 990 | } |
| 991 | return 1; |
| 992 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 993 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 994 | /** |
| 995 | * lpfc_more_plogi: Check and issue remaining plogis for a vport. |
| 996 | * @vport: pointer to a host virtual N_Port data structure. |
| 997 | * |
| 998 | * This routine checks whether there are more remaining Port Logins |
| 999 | * (PLOGI) to be issued for the @vport. If so, it will invoke the routine |
| 1000 | * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes |
| 1001 | * to issue ELS PLOGIs up to the configured discover threads with the |
| 1002 | * @vport (@vport->cfg_discovery_threads). The function also decrement |
| 1003 | * the @vport's num_disc_node by 1 if it is not already 0. |
| 1004 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1005 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1006 | lpfc_more_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1007 | { |
| 1008 | int sentplogi; |
| 1009 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1010 | if (vport->num_disc_nodes) |
| 1011 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1012 | |
| 1013 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1014 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1015 | "0232 Continue discovery with %d PLOGIs to go " |
| 1016 | "Data: x%x x%x x%x\n", |
| 1017 | vport->num_disc_nodes, vport->fc_plogi_cnt, |
| 1018 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1019 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1020 | if (vport->fc_flag & FC_NLP_MORE) |
| 1021 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 1022 | sentplogi = lpfc_els_disc_plogi(vport); |
| 1023 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1024 | return; |
| 1025 | } |
| 1026 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1027 | /** |
| 1028 | * lpfc_plogi_confirm_nport: Confirm pologi wwpn matches stored ndlp. |
| 1029 | * @phba: pointer to lpfc hba data structure. |
| 1030 | * @prsp: pointer to response IOCB payload. |
| 1031 | * @ndlp: pointer to a node-list data structure. |
| 1032 | * |
| 1033 | * This routine checks and indicates whether the WWPN of an N_Port, retrieved |
| 1034 | * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt. |
| 1035 | * The following cases are considered N_Port confirmed: |
| 1036 | * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches |
| 1037 | * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but |
| 1038 | * it does not have WWPN assigned either. If the WWPN is confirmed, the |
| 1039 | * pointer to the @ndlp will be returned. If the WWPN is not confirmed: |
| 1040 | * 1) if there is a node on vport list other than the @ndlp with the same |
| 1041 | * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked |
| 1042 | * on that node to release the RPI associated with the node; 2) if there is |
| 1043 | * no node found on vport list with the same WWPN of the N_Port PLOGI logged |
| 1044 | * into, a new node shall be allocated (or activated). In either case, the |
| 1045 | * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall |
| 1046 | * be released and the new_ndlp shall be put on to the vport node list and |
| 1047 | * its pointer returned as the confirmed node. |
| 1048 | * |
| 1049 | * Note that before the @ndlp got "released", the keepDID from not-matching |
| 1050 | * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID |
| 1051 | * of the @ndlp. This is because the release of @ndlp is actually to put it |
| 1052 | * into an inactive state on the vport node list and the vport node list |
| 1053 | * management algorithm does not allow two node with a same DID. |
| 1054 | * |
| 1055 | * Return code |
| 1056 | * pointer to the PLOGI N_Port @ndlp |
| 1057 | **/ |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1058 | static struct lpfc_nodelist * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1059 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1060 | struct lpfc_nodelist *ndlp) |
| 1061 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1062 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1063 | struct lpfc_nodelist *new_ndlp; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1064 | struct lpfc_rport_data *rdata; |
| 1065 | struct fc_rport *rport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1066 | struct serv_parm *sp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1067 | uint8_t name[sizeof(struct lpfc_name)]; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1068 | uint32_t rc, keepDID = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1069 | |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 1070 | /* Fabric nodes can have the same WWPN so we don't bother searching |
| 1071 | * by WWPN. Just return the ndlp that was given to us. |
| 1072 | */ |
| 1073 | if (ndlp->nlp_type & NLP_FABRIC) |
| 1074 | return ndlp; |
| 1075 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1076 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1077 | memset(name, 0, sizeof(struct lpfc_name)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1078 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 1079 | /* 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] | 1080 | * we have for that ndlp. If not, we have some work to do. |
| 1081 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1082 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1083 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1084 | if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1085 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1086 | |
| 1087 | if (!new_ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1088 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1089 | sizeof(struct lpfc_name)); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1090 | if (!rc) |
| 1091 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1092 | new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC); |
| 1093 | if (!new_ndlp) |
| 1094 | return ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1095 | lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1096 | } else if (!NLP_CHK_NODE_ACT(new_ndlp)) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1097 | rc = memcmp(&ndlp->nlp_portname, name, |
| 1098 | sizeof(struct lpfc_name)); |
| 1099 | if (!rc) |
| 1100 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1101 | new_ndlp = lpfc_enable_node(vport, new_ndlp, |
| 1102 | NLP_STE_UNUSED_NODE); |
| 1103 | if (!new_ndlp) |
| 1104 | return ndlp; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1105 | keepDID = new_ndlp->nlp_DID; |
| 1106 | } else |
| 1107 | keepDID = new_ndlp->nlp_DID; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1108 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1109 | lpfc_unreg_rpi(vport, new_ndlp); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1110 | new_ndlp->nlp_DID = ndlp->nlp_DID; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1111 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1112 | |
| 1113 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) |
| 1114 | new_ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 1115 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
| 1116 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1117 | /* 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] | 1118 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1119 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1120 | /* Move this back to NPR state */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1121 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { |
| 1122 | /* The new_ndlp is replacing ndlp totally, so we need |
| 1123 | * to put ndlp on UNUSED list and try to free it. |
| 1124 | */ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1125 | |
| 1126 | /* Fix up the rport accordingly */ |
| 1127 | rport = ndlp->rport; |
| 1128 | if (rport) { |
| 1129 | rdata = rport->dd_data; |
| 1130 | if (rdata->pnode == ndlp) { |
| 1131 | lpfc_nlp_put(ndlp); |
| 1132 | ndlp->rport = NULL; |
| 1133 | rdata->pnode = lpfc_nlp_get(new_ndlp); |
| 1134 | new_ndlp->rport = rport; |
| 1135 | } |
| 1136 | new_ndlp->nlp_type = ndlp->nlp_type; |
| 1137 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1138 | /* We shall actually free the ndlp with both nlp_DID and |
| 1139 | * nlp_portname fields equals 0 to avoid any ndlp on the |
| 1140 | * nodelist never to be used. |
| 1141 | */ |
| 1142 | if (ndlp->nlp_DID == 0) { |
| 1143 | spin_lock_irq(&phba->ndlp_lock); |
| 1144 | NLP_SET_FREE_REQ(ndlp); |
| 1145 | spin_unlock_irq(&phba->ndlp_lock); |
| 1146 | } |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1147 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1148 | /* Two ndlps cannot have the same did on the nodelist */ |
| 1149 | ndlp->nlp_DID = keepDID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1150 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1151 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1152 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1153 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1154 | /* Two ndlps cannot have the same did */ |
| 1155 | ndlp->nlp_DID = keepDID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1156 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1157 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1158 | return new_ndlp; |
| 1159 | } |
| 1160 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1161 | /** |
| 1162 | * lpfc_end_rscn: Check and handle more rscn for a vport. |
| 1163 | * @vport: pointer to a host virtual N_Port data structure. |
| 1164 | * |
| 1165 | * This routine checks whether more Registration State Change |
| 1166 | * Notifications (RSCNs) came in while the discovery state machine was in |
| 1167 | * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be |
| 1168 | * invoked to handle the additional RSCNs for the @vport. Otherwise, the |
| 1169 | * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of |
| 1170 | * handling the RSCNs. |
| 1171 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1172 | void |
| 1173 | lpfc_end_rscn(struct lpfc_vport *vport) |
| 1174 | { |
| 1175 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1176 | |
| 1177 | if (vport->fc_flag & FC_RSCN_MODE) { |
| 1178 | /* |
| 1179 | * Check to see if more RSCNs came in while we were |
| 1180 | * processing this one. |
| 1181 | */ |
| 1182 | if (vport->fc_rscn_id_cnt || |
| 1183 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) |
| 1184 | lpfc_els_handle_rscn(vport); |
| 1185 | else { |
| 1186 | spin_lock_irq(shost->host_lock); |
| 1187 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 1188 | spin_unlock_irq(shost->host_lock); |
| 1189 | } |
| 1190 | } |
| 1191 | } |
| 1192 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1193 | /** |
| 1194 | * lpfc_cmpl_els_plogi: Completion callback function for plogi. |
| 1195 | * @phba: pointer to lpfc hba data structure. |
| 1196 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1197 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1198 | * |
| 1199 | * This routine is the completion callback function for issuing the Port |
| 1200 | * Login (PLOGI) command. For PLOGI completion, there must be an active |
| 1201 | * ndlp on the vport node list that matches the remote node ID from the |
| 1202 | * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply |
| 1203 | * ignored and command IOCB released. The PLOGI response IOCB status is |
| 1204 | * checked for error conditons. If there is error status reported, PLOGI |
| 1205 | * retry shall be attempted by invoking the lpfc_els_retry() routine. |
| 1206 | * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on |
| 1207 | * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine |
| 1208 | * (DSM) is set for this PLOGI completion. Finally, it checks whether |
| 1209 | * there are additional N_Port nodes with the vport that need to perform |
| 1210 | * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition |
| 1211 | * PLOGIs. |
| 1212 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1213 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1214 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1215 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1216 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1217 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1218 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1219 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1220 | struct lpfc_nodelist *ndlp; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1221 | struct lpfc_dmabuf *prsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1222 | int disc, rc, did, type; |
| 1223 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1224 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1225 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1226 | |
| 1227 | irsp = &rspiocb->iocb; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1228 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1229 | "PLOGI cmpl: status:x%x/x%x did:x%x", |
| 1230 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1231 | irsp->un.elsreq64.remoteID); |
| 1232 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1233 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1234 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1235 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1236 | "0136 PLOGI completes to NPort x%x " |
| 1237 | "with no ndlp. Data: x%x x%x x%x\n", |
| 1238 | irsp->un.elsreq64.remoteID, |
| 1239 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1240 | irsp->ulpIoTag); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1241 | goto out; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1242 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1243 | |
| 1244 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1245 | * is being used during discovery. |
| 1246 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1247 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1248 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1249 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1250 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1251 | rc = 0; |
| 1252 | |
| 1253 | /* PLOGI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1254 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1255 | "0102 PLOGI completes to NPort x%x " |
| 1256 | "Data: x%x x%x x%x x%x x%x\n", |
| 1257 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1258 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1259 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1260 | if (lpfc_els_chk_latt(vport)) { |
| 1261 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1262 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1263 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1264 | goto out; |
| 1265 | } |
| 1266 | |
| 1267 | /* ndlp could be freed in DSM, save these values now */ |
| 1268 | type = ndlp->nlp_type; |
| 1269 | did = ndlp->nlp_DID; |
| 1270 | |
| 1271 | if (irsp->ulpStatus) { |
| 1272 | /* Check for retry */ |
| 1273 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1274 | /* ELS command is being retried */ |
| 1275 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1276 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1277 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1278 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1279 | } |
| 1280 | goto out; |
| 1281 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1282 | /* PLOGI failed */ |
| 1283 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1284 | if (lpfc_error_lost_link(irsp)) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1285 | rc = NLP_STE_FREED_NODE; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1286 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1287 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1288 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1289 | } else { |
| 1290 | /* Good status, call state machine */ |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1291 | prsp = list_entry(((struct lpfc_dmabuf *) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1292 | cmdiocb->context2)->list.next, |
| 1293 | struct lpfc_dmabuf, list); |
| 1294 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1295 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1296 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1297 | } |
| 1298 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1299 | if (disc && vport->num_disc_nodes) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1300 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1301 | lpfc_more_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1302 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1303 | if (vport->num_disc_nodes == 0) { |
| 1304 | spin_lock_irq(shost->host_lock); |
| 1305 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1306 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1307 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1308 | lpfc_can_disctmo(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1309 | lpfc_end_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1310 | } |
| 1311 | } |
| 1312 | |
| 1313 | out: |
| 1314 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1315 | return; |
| 1316 | } |
| 1317 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1318 | /** |
| 1319 | * lpfc_issue_els_plogi: Issue an plogi iocb command for a vport. |
| 1320 | * @vport: pointer to a host virtual N_Port data structure. |
| 1321 | * @did: destination port identifier. |
| 1322 | * @retry: number of retries to the command IOCB. |
| 1323 | * |
| 1324 | * This routine issues a Port Login (PLOGI) command to a remote N_Port |
| 1325 | * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, |
| 1326 | * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. |
| 1327 | * This routine constructs the proper feilds of the PLOGI IOCB and invokes |
| 1328 | * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. |
| 1329 | * |
| 1330 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1331 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1332 | * will be stored into the context1 field of the IOCB for the completion |
| 1333 | * callback function to the PLOGI ELS command. |
| 1334 | * |
| 1335 | * Return code |
| 1336 | * 0 - Successfully issued a plogi for @vport |
| 1337 | * 1 - failed to issue a plogi for @vport |
| 1338 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1339 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1340 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1341 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1342 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1343 | struct serv_parm *sp; |
| 1344 | IOCB_t *icmd; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1345 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1346 | struct lpfc_iocbq *elsiocb; |
| 1347 | struct lpfc_sli_ring *pring; |
| 1348 | struct lpfc_sli *psli; |
| 1349 | uint8_t *pcmd; |
| 1350 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1351 | int ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1352 | |
| 1353 | psli = &phba->sli; |
| 1354 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 1355 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1356 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1357 | if (ndlp && !NLP_CHK_NODE_ACT(ndlp)) |
| 1358 | ndlp = NULL; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1359 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1360 | /* 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] | 1361 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1362 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1363 | ELS_CMD_PLOGI); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1364 | if (!elsiocb) |
| 1365 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1366 | |
| 1367 | icmd = &elsiocb->iocb; |
| 1368 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1369 | |
| 1370 | /* For PLOGI request, remainder of payload is service parameters */ |
| 1371 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1372 | pcmd += sizeof(uint32_t); |
| 1373 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1374 | sp = (struct serv_parm *) pcmd; |
| 1375 | |
| 1376 | if (sp->cmn.fcphLow < FC_PH_4_3) |
| 1377 | sp->cmn.fcphLow = FC_PH_4_3; |
| 1378 | |
| 1379 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1380 | sp->cmn.fcphHigh = FC_PH3; |
| 1381 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1382 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1383 | "Issue PLOGI: did:x%x", |
| 1384 | did, 0, 0); |
| 1385 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1386 | phba->fc_stat.elsXmitPLOGI++; |
| 1387 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1388 | ret = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| 1389 | |
| 1390 | if (ret == IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1391 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1392 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1393 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1394 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1395 | } |
| 1396 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1397 | /** |
| 1398 | * lpfc_cmpl_els_prli: Completion callback function for prli. |
| 1399 | * @phba: pointer to lpfc hba data structure. |
| 1400 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1401 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1402 | * |
| 1403 | * This routine is the completion callback function for a Process Login |
| 1404 | * (PRLI) ELS command. The PRLI response IOCB status is checked for error |
| 1405 | * status. If there is error status reported, PRLI retry shall be attempted |
| 1406 | * by invoking the lpfc_els_retry() routine. Otherwise, the state |
| 1407 | * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this |
| 1408 | * ndlp to mark the PRLI completion. |
| 1409 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1410 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1411 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1412 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1413 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1414 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1415 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1416 | IOCB_t *irsp; |
| 1417 | struct lpfc_sli *psli; |
| 1418 | struct lpfc_nodelist *ndlp; |
| 1419 | |
| 1420 | psli = &phba->sli; |
| 1421 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1422 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1423 | |
| 1424 | irsp = &(rspiocb->iocb); |
| 1425 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1426 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1427 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1428 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1429 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1430 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1431 | "PRLI cmpl: status:x%x/x%x did:x%x", |
| 1432 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1433 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1434 | /* PRLI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1435 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1436 | "0103 PRLI completes to NPort x%x " |
| 1437 | "Data: x%x x%x x%x x%x\n", |
| 1438 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1439 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1440 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1441 | vport->fc_prli_sent--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1442 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1443 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1444 | goto out; |
| 1445 | |
| 1446 | if (irsp->ulpStatus) { |
| 1447 | /* Check for retry */ |
| 1448 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1449 | /* ELS command is being retried */ |
| 1450 | goto out; |
| 1451 | } |
| 1452 | /* PRLI failed */ |
| 1453 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1454 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1455 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1456 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1457 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1458 | NLP_EVT_CMPL_PRLI); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1459 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1460 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1461 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1462 | NLP_EVT_CMPL_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1463 | out: |
| 1464 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1465 | return; |
| 1466 | } |
| 1467 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1468 | /** |
| 1469 | * lpfc_issue_els_prli: Issue a prli iocb command for a vport. |
| 1470 | * @vport: pointer to a host virtual N_Port data structure. |
| 1471 | * @ndlp: pointer to a node-list data structure. |
| 1472 | * @retry: number of retries to the command IOCB. |
| 1473 | * |
| 1474 | * This routine issues a Process Login (PRLI) ELS command for the |
| 1475 | * @vport. The PRLI service parameters are set up in the payload of the |
| 1476 | * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine |
| 1477 | * is put to the IOCB completion callback func field before invoking the |
| 1478 | * routine lpfc_sli_issue_iocb() to send out PRLI command. |
| 1479 | * |
| 1480 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1481 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1482 | * will be stored into the context1 field of the IOCB for the completion |
| 1483 | * callback function to the PRLI ELS command. |
| 1484 | * |
| 1485 | * Return code |
| 1486 | * 0 - successfully issued prli iocb command for @vport |
| 1487 | * 1 - failed to issue prli iocb command for @vport |
| 1488 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1489 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1490 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1491 | uint8_t retry) |
| 1492 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1493 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1494 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1495 | PRLI *npr; |
| 1496 | IOCB_t *icmd; |
| 1497 | struct lpfc_iocbq *elsiocb; |
| 1498 | struct lpfc_sli_ring *pring; |
| 1499 | struct lpfc_sli *psli; |
| 1500 | uint8_t *pcmd; |
| 1501 | uint16_t cmdsize; |
| 1502 | |
| 1503 | psli = &phba->sli; |
| 1504 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 1505 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1506 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1507 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1508 | ndlp->nlp_DID, ELS_CMD_PRLI); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1509 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1510 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1511 | |
| 1512 | icmd = &elsiocb->iocb; |
| 1513 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1514 | |
| 1515 | /* For PRLI request, remainder of payload is service parameters */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1516 | memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1517 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1518 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1519 | |
| 1520 | /* For PRLI, remainder of payload is PRLI parameter page */ |
| 1521 | npr = (PRLI *) pcmd; |
| 1522 | /* |
| 1523 | * If our firmware version is 3.20 or later, |
| 1524 | * set the following bits for FC-TAPE support. |
| 1525 | */ |
| 1526 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { |
| 1527 | npr->ConfmComplAllowed = 1; |
| 1528 | npr->Retry = 1; |
| 1529 | npr->TaskRetryIdReq = 1; |
| 1530 | } |
| 1531 | npr->estabImagePair = 1; |
| 1532 | npr->readXferRdyDis = 1; |
| 1533 | |
| 1534 | /* For FCP support */ |
| 1535 | npr->prliType = PRLI_FCP_TYPE; |
| 1536 | npr->initiatorFunc = 1; |
| 1537 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1538 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1539 | "Issue PRLI: did:x%x", |
| 1540 | ndlp->nlp_DID, 0, 0); |
| 1541 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1542 | phba->fc_stat.elsXmitPRLI++; |
| 1543 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1544 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1545 | ndlp->nlp_flag |= NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1546 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1547 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1548 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1549 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1550 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1551 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1552 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1553 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1554 | vport->fc_prli_sent++; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1555 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1556 | } |
| 1557 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1558 | /** |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1559 | * lpfc_rscn_disc: Perform rscn discovery for a vport. |
| 1560 | * @vport: pointer to a host virtual N_Port data structure. |
| 1561 | * |
| 1562 | * This routine performs Registration State Change Notification (RSCN) |
| 1563 | * discovery for a @vport. If the @vport's node port recovery count is not |
| 1564 | * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all |
| 1565 | * the nodes that need recovery. If none of the PLOGI were needed through |
| 1566 | * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be |
| 1567 | * invoked to check and handle possible more RSCN came in during the period |
| 1568 | * of processing the current ones. |
| 1569 | **/ |
| 1570 | static void |
| 1571 | lpfc_rscn_disc(struct lpfc_vport *vport) |
| 1572 | { |
| 1573 | lpfc_can_disctmo(vport); |
| 1574 | |
| 1575 | /* RSCN discovery */ |
| 1576 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 1577 | if (vport->fc_npr_cnt) |
| 1578 | if (lpfc_els_disc_plogi(vport)) |
| 1579 | return; |
| 1580 | |
| 1581 | lpfc_end_rscn(vport); |
| 1582 | } |
| 1583 | |
| 1584 | /** |
| 1585 | * lpfc_adisc_done: Complete the adisc phase of discovery. |
| 1586 | * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs. |
| 1587 | * |
| 1588 | * This function is called when the final ADISC is completed during discovery. |
| 1589 | * This function handles clearing link attention or issuing reg_vpi depending |
| 1590 | * on whether npiv is enabled. This function also kicks off the PLOGI phase of |
| 1591 | * discovery. |
| 1592 | * This function is called with no locks held. |
| 1593 | **/ |
| 1594 | static void |
| 1595 | lpfc_adisc_done(struct lpfc_vport *vport) |
| 1596 | { |
| 1597 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1598 | struct lpfc_hba *phba = vport->phba; |
| 1599 | |
| 1600 | /* |
| 1601 | * For NPIV, cmpl_reg_vpi will set port_state to READY, |
| 1602 | * and continue discovery. |
| 1603 | */ |
| 1604 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 1605 | !(vport->fc_flag & FC_RSCN_MODE)) { |
| 1606 | lpfc_issue_reg_vpi(phba, vport); |
| 1607 | return; |
| 1608 | } |
| 1609 | /* |
| 1610 | * For SLI2, we need to set port_state to READY |
| 1611 | * and continue discovery. |
| 1612 | */ |
| 1613 | if (vport->port_state < LPFC_VPORT_READY) { |
| 1614 | /* If we get here, there is nothing to ADISC */ |
| 1615 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 1616 | lpfc_issue_clear_la(phba, vport); |
| 1617 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
| 1618 | vport->num_disc_nodes = 0; |
| 1619 | /* go thru NPR list, issue ELS PLOGIs */ |
| 1620 | if (vport->fc_npr_cnt) |
| 1621 | lpfc_els_disc_plogi(vport); |
| 1622 | if (!vport->num_disc_nodes) { |
| 1623 | spin_lock_irq(shost->host_lock); |
| 1624 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1625 | spin_unlock_irq(shost->host_lock); |
| 1626 | lpfc_can_disctmo(vport); |
| 1627 | lpfc_end_rscn(vport); |
| 1628 | } |
| 1629 | } |
| 1630 | vport->port_state = LPFC_VPORT_READY; |
| 1631 | } else |
| 1632 | lpfc_rscn_disc(vport); |
| 1633 | } |
| 1634 | |
| 1635 | /** |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1636 | * lpfc_more_adisc: Issue more adisc as needed. |
| 1637 | * @vport: pointer to a host virtual N_Port data structure. |
| 1638 | * |
| 1639 | * This routine determines whether there are more ndlps on a @vport |
| 1640 | * node list need to have Address Discover (ADISC) issued. If so, it will |
| 1641 | * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's |
| 1642 | * remaining nodes which need to have ADISC sent. |
| 1643 | **/ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1644 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1645 | lpfc_more_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1646 | { |
| 1647 | int sentadisc; |
| 1648 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1649 | if (vport->num_disc_nodes) |
| 1650 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1651 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1652 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1653 | "0210 Continue discovery with %d ADISCs to go " |
| 1654 | "Data: x%x x%x x%x\n", |
| 1655 | vport->num_disc_nodes, vport->fc_adisc_cnt, |
| 1656 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1657 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1658 | if (vport->fc_flag & FC_NLP_MORE) { |
| 1659 | lpfc_set_disctmo(vport); |
| 1660 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
| 1661 | sentadisc = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1662 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1663 | if (!vport->num_disc_nodes) |
| 1664 | lpfc_adisc_done(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1665 | return; |
| 1666 | } |
| 1667 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1668 | /** |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1669 | * lpfc_cmpl_els_adisc: Completion callback function for adisc. |
| 1670 | * @phba: pointer to lpfc hba data structure. |
| 1671 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1672 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1673 | * |
| 1674 | * This routine is the completion function for issuing the Address Discover |
| 1675 | * (ADISC) command. It first checks to see whether link went down during |
| 1676 | * the discovery process. If so, the node will be marked as node port |
| 1677 | * recovery for issuing discover IOCB by the link attention handler and |
| 1678 | * exit. Otherwise, the response status is checked. If error was reported |
| 1679 | * in the response status, the ADISC command shall be retried by invoking |
| 1680 | * the lpfc_els_retry() routine. Otherwise, if no error was reported in |
| 1681 | * the response status, the state machine is invoked to set transition |
| 1682 | * with respect to NLP_EVT_CMPL_ADISC event. |
| 1683 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1684 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1685 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1686 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1687 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1688 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1689 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1690 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1691 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1692 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1693 | |
| 1694 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1695 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1696 | |
| 1697 | irsp = &(rspiocb->iocb); |
| 1698 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1699 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1700 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1701 | "ADISC cmpl: status:x%x/x%x did:x%x", |
| 1702 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1703 | ndlp->nlp_DID); |
| 1704 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1705 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1706 | * is being used during discovery. |
| 1707 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1708 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1709 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1710 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1711 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1712 | /* ADISC completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1713 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1714 | "0104 ADISC completes to NPort x%x " |
| 1715 | "Data: x%x x%x x%x x%x x%x\n", |
| 1716 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1717 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1718 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1719 | if (lpfc_els_chk_latt(vport)) { |
| 1720 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1721 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1722 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1723 | goto out; |
| 1724 | } |
| 1725 | |
| 1726 | if (irsp->ulpStatus) { |
| 1727 | /* Check for retry */ |
| 1728 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1729 | /* ELS command is being retried */ |
| 1730 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1731 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1732 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1733 | spin_unlock_irq(shost->host_lock); |
| 1734 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1735 | } |
| 1736 | goto out; |
| 1737 | } |
| 1738 | /* ADISC failed */ |
| 1739 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1740 | if (!lpfc_error_lost_link(irsp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1741 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1742 | NLP_EVT_CMPL_ADISC); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1743 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1744 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1745 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1746 | NLP_EVT_CMPL_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1747 | |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 1748 | /* Check to see if there are more ADISCs to be sent */ |
| 1749 | if (disc && vport->num_disc_nodes) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1750 | lpfc_more_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1751 | out: |
| 1752 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1753 | return; |
| 1754 | } |
| 1755 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1756 | /** |
| 1757 | * lpfc_issue_els_adisc: Issue an address discover iocb to an node on a vport. |
| 1758 | * @vport: pointer to a virtual N_Port data structure. |
| 1759 | * @ndlp: pointer to a node-list data structure. |
| 1760 | * @retry: number of retries to the command IOCB. |
| 1761 | * |
| 1762 | * This routine issues an Address Discover (ADISC) for an @ndlp on a |
| 1763 | * @vport. It prepares the payload of the ADISC ELS command, updates the |
| 1764 | * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine |
| 1765 | * to issue the ADISC ELS command. |
| 1766 | * |
| 1767 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1768 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1769 | * will be stored into the context1 field of the IOCB for the completion |
| 1770 | * callback function to the ADISC ELS command. |
| 1771 | * |
| 1772 | * Return code |
| 1773 | * 0 - successfully issued adisc |
| 1774 | * 1 - failed to issue adisc |
| 1775 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1776 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1777 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1778 | uint8_t retry) |
| 1779 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1780 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1781 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1782 | ADISC *ap; |
| 1783 | IOCB_t *icmd; |
| 1784 | struct lpfc_iocbq *elsiocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1785 | struct lpfc_sli *psli = &phba->sli; |
| 1786 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1787 | uint8_t *pcmd; |
| 1788 | uint16_t cmdsize; |
| 1789 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1790 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1791 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1792 | ndlp->nlp_DID, ELS_CMD_ADISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1793 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1794 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1795 | |
| 1796 | icmd = &elsiocb->iocb; |
| 1797 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1798 | |
| 1799 | /* For ADISC request, remainder of payload is service parameters */ |
| 1800 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1801 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1802 | |
| 1803 | /* Fill in ADISC payload */ |
| 1804 | ap = (ADISC *) pcmd; |
| 1805 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1806 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 1807 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1808 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1809 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1810 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1811 | "Issue ADISC: did:x%x", |
| 1812 | ndlp->nlp_DID, 0, 0); |
| 1813 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1814 | phba->fc_stat.elsXmitADISC++; |
| 1815 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1816 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1817 | ndlp->nlp_flag |= NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1818 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1819 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1820 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1821 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1822 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1823 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1824 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1825 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1826 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1827 | } |
| 1828 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1829 | /** |
| 1830 | * lpfc_cmpl_els_logo: Completion callback function for logo. |
| 1831 | * @phba: pointer to lpfc hba data structure. |
| 1832 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1833 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1834 | * |
| 1835 | * This routine is the completion function for issuing the ELS Logout (LOGO) |
| 1836 | * command. If no error status was reported from the LOGO response, the |
| 1837 | * state machine of the associated ndlp shall be invoked for transition with |
| 1838 | * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported, |
| 1839 | * the lpfc_els_retry() routine will be invoked to retry the LOGO command. |
| 1840 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1841 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1842 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1843 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1844 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1845 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 1846 | struct lpfc_vport *vport = ndlp->vport; |
| 1847 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1848 | IOCB_t *irsp; |
| 1849 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1850 | |
| 1851 | psli = &phba->sli; |
| 1852 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1853 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1854 | |
| 1855 | irsp = &(rspiocb->iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1856 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1857 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1858 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1859 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1860 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1861 | "LOGO cmpl: status:x%x/x%x did:x%x", |
| 1862 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1863 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1864 | /* LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1865 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1866 | "0105 LOGO completes to NPort x%x " |
| 1867 | "Data: x%x x%x x%x x%x\n", |
| 1868 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1869 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1870 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1871 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1872 | goto out; |
| 1873 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1874 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
| 1875 | /* NLP_EVT_DEVICE_RM should unregister the RPI |
| 1876 | * which should abort all outstanding IOs. |
| 1877 | */ |
| 1878 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 1879 | NLP_EVT_DEVICE_RM); |
| 1880 | goto out; |
| 1881 | } |
| 1882 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1883 | if (irsp->ulpStatus) { |
| 1884 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1885 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1886 | /* ELS command is being retried */ |
| 1887 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1888 | /* LOGO failed */ |
| 1889 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1890 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1891 | goto out; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1892 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1893 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1894 | NLP_EVT_CMPL_LOGO); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1895 | } else |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 1896 | /* Good status, call state machine. |
| 1897 | * This will unregister the rpi if needed. |
| 1898 | */ |
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); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1901 | out: |
| 1902 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1903 | return; |
| 1904 | } |
| 1905 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1906 | /** |
| 1907 | * lpfc_issue_els_logo: Issue a logo to an node on a vport. |
| 1908 | * @vport: pointer to a virtual N_Port data structure. |
| 1909 | * @ndlp: pointer to a node-list data structure. |
| 1910 | * @retry: number of retries to the command IOCB. |
| 1911 | * |
| 1912 | * This routine constructs and issues an ELS Logout (LOGO) iocb command |
| 1913 | * to a remote node, referred by an @ndlp on a @vport. It constructs the |
| 1914 | * payload of the IOCB, properly sets up the @ndlp state, and invokes the |
| 1915 | * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. |
| 1916 | * |
| 1917 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1918 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1919 | * will be stored into the context1 field of the IOCB for the completion |
| 1920 | * callback function to the LOGO ELS command. |
| 1921 | * |
| 1922 | * Return code |
| 1923 | * 0 - successfully issued logo |
| 1924 | * 1 - failed to issue logo |
| 1925 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1926 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1927 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1928 | uint8_t retry) |
| 1929 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1930 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1931 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1932 | IOCB_t *icmd; |
| 1933 | struct lpfc_iocbq *elsiocb; |
| 1934 | struct lpfc_sli_ring *pring; |
| 1935 | struct lpfc_sli *psli; |
| 1936 | uint8_t *pcmd; |
| 1937 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1938 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1939 | |
| 1940 | psli = &phba->sli; |
| 1941 | pring = &psli->ring[LPFC_ELS_RING]; |
| 1942 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1943 | spin_lock_irq(shost->host_lock); |
| 1944 | if (ndlp->nlp_flag & NLP_LOGO_SND) { |
| 1945 | spin_unlock_irq(shost->host_lock); |
| 1946 | return 0; |
| 1947 | } |
| 1948 | spin_unlock_irq(shost->host_lock); |
| 1949 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1950 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1951 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1952 | ndlp->nlp_DID, ELS_CMD_LOGO); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1953 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1954 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1955 | |
| 1956 | icmd = &elsiocb->iocb; |
| 1957 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1958 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1959 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1960 | |
| 1961 | /* Fill in LOGO payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1962 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1963 | pcmd += sizeof(uint32_t); |
| 1964 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1965 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1966 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1967 | "Issue LOGO: did:x%x", |
| 1968 | ndlp->nlp_DID, 0, 0); |
| 1969 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1970 | phba->fc_stat.elsXmitLOGO++; |
| 1971 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1972 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1973 | ndlp->nlp_flag |= NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1974 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1975 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| 1976 | |
| 1977 | if (rc == IOCB_ERROR) { |
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); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1981 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1982 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1983 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1984 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1985 | } |
| 1986 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1987 | /** |
| 1988 | * lpfc_cmpl_els_cmd: Completion callback function for generic els command. |
| 1989 | * @phba: pointer to lpfc hba data structure. |
| 1990 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1991 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1992 | * |
| 1993 | * This routine is a generic completion callback function for ELS commands. |
| 1994 | * Specifically, it is the callback function which does not need to perform |
| 1995 | * any command specific operations. It is currently used by the ELS command |
| 1996 | * issuing routines for the ELS State Change Request (SCR), |
| 1997 | * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution |
| 1998 | * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than |
| 1999 | * certain debug loggings, this callback function simply invokes the |
| 2000 | * lpfc_els_chk_latt() routine to check whether link went down during the |
| 2001 | * discovery process. |
| 2002 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2003 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2004 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2005 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2006 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2007 | struct lpfc_vport *vport = cmdiocb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2008 | IOCB_t *irsp; |
| 2009 | |
| 2010 | irsp = &rspiocb->iocb; |
| 2011 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2012 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2013 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 2014 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2015 | irsp->un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2016 | /* ELS cmd tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2017 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2018 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", |
| 2019 | irsp->ulpIoTag, irsp->ulpStatus, |
| 2020 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2021 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2022 | lpfc_els_chk_latt(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2023 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2024 | return; |
| 2025 | } |
| 2026 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2027 | /** |
| 2028 | * lpfc_issue_els_scr: Issue a scr to an node on a vport. |
| 2029 | * @vport: pointer to a host virtual N_Port data structure. |
| 2030 | * @nportid: N_Port identifier to the remote node. |
| 2031 | * @retry: number of retries to the command IOCB. |
| 2032 | * |
| 2033 | * This routine issues a State Change Request (SCR) to a fabric node |
| 2034 | * on a @vport. The remote node @nportid is passed into the function. It |
| 2035 | * first search the @vport node list to find the matching ndlp. If no such |
| 2036 | * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An |
| 2037 | * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() |
| 2038 | * routine is invoked to send the SCR IOCB. |
| 2039 | * |
| 2040 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2041 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2042 | * will be stored into the context1 field of the IOCB for the completion |
| 2043 | * callback function to the SCR ELS command. |
| 2044 | * |
| 2045 | * Return code |
| 2046 | * 0 - Successfully issued scr command |
| 2047 | * 1 - Failed to issue scr command |
| 2048 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2049 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2050 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2051 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2052 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2053 | IOCB_t *icmd; |
| 2054 | struct lpfc_iocbq *elsiocb; |
| 2055 | struct lpfc_sli_ring *pring; |
| 2056 | struct lpfc_sli *psli; |
| 2057 | uint8_t *pcmd; |
| 2058 | uint16_t cmdsize; |
| 2059 | struct lpfc_nodelist *ndlp; |
| 2060 | |
| 2061 | psli = &phba->sli; |
| 2062 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2063 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2064 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2065 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2066 | if (!ndlp) { |
| 2067 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2068 | if (!ndlp) |
| 2069 | return 1; |
| 2070 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2071 | lpfc_enqueue_node(vport, ndlp); |
| 2072 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2073 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2074 | if (!ndlp) |
| 2075 | return 1; |
| 2076 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2077 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2078 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2079 | ndlp->nlp_DID, ELS_CMD_SCR); |
| 2080 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2081 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2082 | /* This will trigger the release of the node just |
| 2083 | * allocated |
| 2084 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2085 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2086 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2087 | } |
| 2088 | |
| 2089 | icmd = &elsiocb->iocb; |
| 2090 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2091 | |
| 2092 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2093 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2094 | |
| 2095 | /* For SCR, remainder of payload is SCR parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2096 | memset(pcmd, 0, sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2097 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
| 2098 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2099 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2100 | "Issue SCR: did:x%x", |
| 2101 | ndlp->nlp_DID, 0, 0); |
| 2102 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2103 | phba->fc_stat.elsXmitSCR++; |
| 2104 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2105 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2106 | /* The additional lpfc_nlp_put will cause the following |
| 2107 | * lpfc_els_free_iocb routine to trigger the rlease of |
| 2108 | * the node. |
| 2109 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2110 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2111 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2112 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2113 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2114 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2115 | * trigger the release of node. |
| 2116 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2117 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2118 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2119 | } |
| 2120 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2121 | /** |
| 2122 | * lpfc_issue_els_farpr: Issue a farp to an node on a vport. |
| 2123 | * @vport: pointer to a host virtual N_Port data structure. |
| 2124 | * @nportid: N_Port identifier to the remote node. |
| 2125 | * @retry: number of retries to the command IOCB. |
| 2126 | * |
| 2127 | * This routine issues a Fibre Channel Address Resolution Response |
| 2128 | * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) |
| 2129 | * is passed into the function. It first search the @vport node list to find |
| 2130 | * the matching ndlp. If no such ndlp is found, a new ndlp shall be created |
| 2131 | * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the |
| 2132 | * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. |
| 2133 | * |
| 2134 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2135 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2136 | * will be stored into the context1 field of the IOCB for the completion |
| 2137 | * callback function to the PARPR ELS command. |
| 2138 | * |
| 2139 | * Return code |
| 2140 | * 0 - Successfully issued farpr command |
| 2141 | * 1 - Failed to issue farpr command |
| 2142 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2143 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2144 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2145 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2146 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2147 | IOCB_t *icmd; |
| 2148 | struct lpfc_iocbq *elsiocb; |
| 2149 | struct lpfc_sli_ring *pring; |
| 2150 | struct lpfc_sli *psli; |
| 2151 | FARP *fp; |
| 2152 | uint8_t *pcmd; |
| 2153 | uint32_t *lp; |
| 2154 | uint16_t cmdsize; |
| 2155 | struct lpfc_nodelist *ondlp; |
| 2156 | struct lpfc_nodelist *ndlp; |
| 2157 | |
| 2158 | psli = &phba->sli; |
| 2159 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2160 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2161 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2162 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2163 | if (!ndlp) { |
| 2164 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2165 | if (!ndlp) |
| 2166 | return 1; |
| 2167 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2168 | lpfc_enqueue_node(vport, ndlp); |
| 2169 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2170 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2171 | if (!ndlp) |
| 2172 | return 1; |
| 2173 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2174 | |
| 2175 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2176 | ndlp->nlp_DID, ELS_CMD_RNID); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2177 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2178 | /* This will trigger the release of the node just |
| 2179 | * allocated |
| 2180 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2181 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2182 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2183 | } |
| 2184 | |
| 2185 | icmd = &elsiocb->iocb; |
| 2186 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2187 | |
| 2188 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2189 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2190 | |
| 2191 | /* Fill in FARPR payload */ |
| 2192 | fp = (FARP *) (pcmd); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2193 | memset(fp, 0, sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2194 | lp = (uint32_t *) pcmd; |
| 2195 | *lp++ = be32_to_cpu(nportid); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2196 | *lp++ = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2197 | fp->Rflags = 0; |
| 2198 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); |
| 2199 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2200 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2201 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2202 | ondlp = lpfc_findnode_did(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2203 | if (ondlp && NLP_CHK_NODE_ACT(ondlp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2204 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2205 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2206 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2207 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2208 | } |
| 2209 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2210 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2211 | "Issue FARPR: did:x%x", |
| 2212 | ndlp->nlp_DID, 0, 0); |
| 2213 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2214 | phba->fc_stat.elsXmitFARPR++; |
| 2215 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2216 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2217 | /* The additional lpfc_nlp_put will cause the following |
| 2218 | * lpfc_els_free_iocb routine to trigger the release of |
| 2219 | * the node. |
| 2220 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2221 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2222 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2223 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2224 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2225 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2226 | * trigger the release of the node. |
| 2227 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2228 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2229 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2230 | } |
| 2231 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2232 | /** |
| 2233 | * lpfc_cancel_retry_delay_tmo: Cancel the timer with delayed iocb-cmd retry. |
| 2234 | * @vport: pointer to a host virtual N_Port data structure. |
| 2235 | * @nlp: pointer to a node-list data structure. |
| 2236 | * |
| 2237 | * This routine cancels the timer with a delayed IOCB-command retry for |
| 2238 | * a @vport's @ndlp. It stops the timer for the delayed function retrial and |
| 2239 | * removes the ELS retry event if it presents. In addition, if the |
| 2240 | * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB |
| 2241 | * commands are sent for the @vport's nodes that require issuing discovery |
| 2242 | * ADISC. |
| 2243 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2244 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2245 | 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] | 2246 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2247 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2248 | struct lpfc_work_evt *evtp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2249 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2250 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) |
| 2251 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2252 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2253 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2254 | spin_unlock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2255 | del_timer_sync(&nlp->nlp_delayfunc); |
| 2256 | nlp->nlp_last_elscmd = 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2257 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2258 | list_del_init(&nlp->els_retry_evt.evt_listp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2259 | /* Decrement nlp reference count held for the delayed retry */ |
| 2260 | evtp = &nlp->els_retry_evt; |
| 2261 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); |
| 2262 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2263 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2264 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2265 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2266 | spin_unlock_irq(shost->host_lock); |
| 2267 | if (vport->num_disc_nodes) { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2268 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2269 | /* Check if there are more ADISCs to be sent */ |
| 2270 | lpfc_more_adisc(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2271 | } else { |
| 2272 | /* Check if there are more PLOGIs to be sent */ |
| 2273 | lpfc_more_plogi(vport); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 2274 | if (vport->num_disc_nodes == 0) { |
| 2275 | spin_lock_irq(shost->host_lock); |
| 2276 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2277 | spin_unlock_irq(shost->host_lock); |
| 2278 | lpfc_can_disctmo(vport); |
| 2279 | lpfc_end_rscn(vport); |
| 2280 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2281 | } |
| 2282 | } |
| 2283 | } |
| 2284 | return; |
| 2285 | } |
| 2286 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2287 | /** |
| 2288 | * lpfc_els_retry_delay: Timer function with a ndlp delayed function timer. |
| 2289 | * @ptr: holder for the pointer to the timer function associated data (ndlp). |
| 2290 | * |
| 2291 | * This routine is invoked by the ndlp delayed-function timer to check |
| 2292 | * whether there is any pending ELS retry event(s) with the node. If not, it |
| 2293 | * simply returns. Otherwise, if there is at least one ELS delayed event, it |
| 2294 | * adds the delayed events to the HBA work list and invokes the |
| 2295 | * lpfc_worker_wake_up() routine to wake up worker thread to process the |
| 2296 | * event. Note that lpfc_nlp_get() is called before posting the event to |
| 2297 | * the work list to hold reference count of ndlp so that it guarantees the |
| 2298 | * reference to ndlp will still be available when the worker thread gets |
| 2299 | * to the event associated with the ndlp. |
| 2300 | **/ |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2301 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2302 | lpfc_els_retry_delay(unsigned long ptr) |
| 2303 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2304 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr; |
| 2305 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2306 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2307 | unsigned long flags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2308 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2309 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2310 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2311 | if (!list_empty(&evtp->evt_listp)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2312 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2313 | return; |
| 2314 | } |
| 2315 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2316 | /* We need to hold the node by incrementing the reference |
| 2317 | * count until the queued work is done |
| 2318 | */ |
| 2319 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2320 | if (evtp->evt_arg1) { |
| 2321 | evtp->evt = LPFC_EVT_ELS_RETRY; |
| 2322 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2323 | lpfc_worker_wake_up(phba); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2324 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2325 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2326 | return; |
| 2327 | } |
| 2328 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2329 | /** |
| 2330 | * lpfc_els_retry_delay_handler: Work thread handler for ndlp delayed function. |
| 2331 | * @ndlp: pointer to a node-list data structure. |
| 2332 | * |
| 2333 | * This routine is the worker-thread handler for processing the @ndlp delayed |
| 2334 | * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves |
| 2335 | * the last ELS command from the associated ndlp and invokes the proper ELS |
| 2336 | * function according to the delayed ELS command to retry the command. |
| 2337 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2338 | void |
| 2339 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) |
| 2340 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2341 | struct lpfc_vport *vport = ndlp->vport; |
| 2342 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2343 | uint32_t cmd, did, retry; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2344 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2345 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2346 | did = ndlp->nlp_DID; |
| 2347 | cmd = ndlp->nlp_last_elscmd; |
| 2348 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2349 | |
| 2350 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2351 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2352 | return; |
| 2353 | } |
| 2354 | |
| 2355 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2356 | spin_unlock_irq(shost->host_lock); |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 2357 | /* |
| 2358 | * If a discovery event readded nlp_delayfunc after timer |
| 2359 | * firing and before processing the timer, cancel the |
| 2360 | * nlp_delayfunc. |
| 2361 | */ |
| 2362 | del_timer_sync(&ndlp->nlp_delayfunc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2363 | retry = ndlp->nlp_retry; |
| 2364 | |
| 2365 | switch (cmd) { |
| 2366 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2367 | lpfc_issue_els_flogi(vport, ndlp, retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2368 | break; |
| 2369 | case ELS_CMD_PLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2370 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2371 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2372 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2373 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2374 | break; |
| 2375 | case ELS_CMD_ADISC: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2376 | if (!lpfc_issue_els_adisc(vport, ndlp, 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_ADISC_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_PRLI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2382 | if (!lpfc_issue_els_prli(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_PRLI_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_LOGO: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2388 | if (!lpfc_issue_els_logo(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_NPR_NODE); |
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; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2393 | case ELS_CMD_FDISC: |
| 2394 | lpfc_issue_els_fdisc(vport, ndlp, retry); |
| 2395 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2396 | } |
| 2397 | return; |
| 2398 | } |
| 2399 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2400 | /** |
| 2401 | * lpfc_els_retry: Make retry decision on an els command iocb. |
| 2402 | * @phba: pointer to lpfc hba data structure. |
| 2403 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2404 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2405 | * |
| 2406 | * This routine makes a retry decision on an ELS command IOCB, which has |
| 2407 | * failed. The following ELS IOCBs use this function for retrying the command |
| 2408 | * when previously issued command responsed with error status: FLOGI, PLOGI, |
| 2409 | * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the |
| 2410 | * returned error status, it makes the decision whether a retry shall be |
| 2411 | * issued for the command, and whether a retry shall be made immediately or |
| 2412 | * delayed. In the former case, the corresponding ELS command issuing-function |
| 2413 | * is called to retry the command. In the later case, the ELS command shall |
| 2414 | * be posted to the ndlp delayed event and delayed function timer set to the |
| 2415 | * ndlp for the delayed command issusing. |
| 2416 | * |
| 2417 | * Return code |
| 2418 | * 0 - No retry of els command is made |
| 2419 | * 1 - Immediate or delayed retry of els command is made |
| 2420 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2421 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2422 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2423 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2424 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2425 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2426 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2427 | IOCB_t *irsp = &rspiocb->iocb; |
| 2428 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2429 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2430 | uint32_t *elscmd; |
| 2431 | struct ls_rjt stat; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2432 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2433 | int logerr = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2434 | uint32_t cmd = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2435 | uint32_t did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2436 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2437 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2438 | /* Note: context2 may be 0 for internal driver abort |
| 2439 | * of delays ELS command. |
| 2440 | */ |
| 2441 | |
| 2442 | if (pcmd && pcmd->virt) { |
| 2443 | elscmd = (uint32_t *) (pcmd->virt); |
| 2444 | cmd = *elscmd++; |
| 2445 | } |
| 2446 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2447 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2448 | did = ndlp->nlp_DID; |
| 2449 | else { |
| 2450 | /* We should only hit this case for retrying PLOGI */ |
| 2451 | did = irsp->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2452 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2453 | if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 2454 | && (cmd != ELS_CMD_PLOGI)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2455 | return 1; |
| 2456 | } |
| 2457 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2458 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2459 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", |
| 2460 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); |
| 2461 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2462 | switch (irsp->ulpStatus) { |
| 2463 | case IOSTAT_FCP_RSP_ERROR: |
| 2464 | case IOSTAT_REMOTE_STOP: |
| 2465 | break; |
| 2466 | |
| 2467 | case IOSTAT_LOCAL_REJECT: |
| 2468 | switch ((irsp->un.ulpWord[4] & 0xff)) { |
| 2469 | case IOERR_LOOP_OPEN_FAILURE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2470 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2471 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2472 | retry = 1; |
| 2473 | break; |
| 2474 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2475 | case IOERR_ILLEGAL_COMMAND: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2476 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2477 | "0124 Retry illegal cmd x%x " |
| 2478 | "retry:x%x delay:x%x\n", |
| 2479 | cmd, cmdiocb->retry, delay); |
| 2480 | retry = 1; |
| 2481 | /* All command's retry policy */ |
| 2482 | maxretry = 8; |
| 2483 | if (cmdiocb->retry > 2) |
| 2484 | delay = 1000; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2485 | break; |
| 2486 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2487 | case IOERR_NO_RESOURCES: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2488 | logerr = 1; /* HBA out of resources */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2489 | retry = 1; |
| 2490 | if (cmdiocb->retry > 100) |
| 2491 | delay = 100; |
| 2492 | maxretry = 250; |
| 2493 | break; |
| 2494 | |
| 2495 | case IOERR_ILLEGAL_FRAME: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2496 | delay = 100; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2497 | retry = 1; |
| 2498 | break; |
| 2499 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2500 | case IOERR_SEQUENCE_TIMEOUT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2501 | case IOERR_INVALID_RPI: |
| 2502 | retry = 1; |
| 2503 | break; |
| 2504 | } |
| 2505 | break; |
| 2506 | |
| 2507 | case IOSTAT_NPORT_RJT: |
| 2508 | case IOSTAT_FABRIC_RJT: |
| 2509 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 2510 | retry = 1; |
| 2511 | break; |
| 2512 | } |
| 2513 | break; |
| 2514 | |
| 2515 | case IOSTAT_NPORT_BSY: |
| 2516 | case IOSTAT_FABRIC_BSY: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2517 | logerr = 1; /* Fabric / Remote NPort out of resources */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2518 | retry = 1; |
| 2519 | break; |
| 2520 | |
| 2521 | case IOSTAT_LS_RJT: |
| 2522 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); |
| 2523 | /* Added for Vendor specifc support |
| 2524 | * Just keep retrying for these Rsn / Exp codes |
| 2525 | */ |
| 2526 | switch (stat.un.b.lsRjtRsnCode) { |
| 2527 | case LSRJT_UNABLE_TPC: |
| 2528 | if (stat.un.b.lsRjtRsnCodeExp == |
| 2529 | LSEXP_CMD_IN_PROGRESS) { |
| 2530 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2531 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2532 | maxretry = 48; |
| 2533 | } |
| 2534 | retry = 1; |
| 2535 | break; |
| 2536 | } |
| 2537 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2538 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2539 | maxretry = lpfc_max_els_tries + 1; |
| 2540 | retry = 1; |
| 2541 | break; |
| 2542 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2543 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2544 | (cmd == ELS_CMD_FDISC) && |
| 2545 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2546 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2547 | "0125 FDISC Failed (x%x). " |
| 2548 | "Fabric out of resources\n", |
| 2549 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2550 | lpfc_vport_set_state(vport, |
| 2551 | FC_VPORT_NO_FABRIC_RSCS); |
| 2552 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2553 | break; |
| 2554 | |
| 2555 | case LSRJT_LOGICAL_BSY: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2556 | if ((cmd == ELS_CMD_PLOGI) || |
| 2557 | (cmd == ELS_CMD_PRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2558 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2559 | maxretry = 48; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2560 | } else if (cmd == ELS_CMD_FDISC) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2561 | /* FDISC retry policy */ |
| 2562 | maxretry = 48; |
| 2563 | if (cmdiocb->retry >= 32) |
| 2564 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2565 | } |
| 2566 | retry = 1; |
| 2567 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2568 | |
| 2569 | case LSRJT_LOGICAL_ERR: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2570 | /* There are some cases where switches return this |
| 2571 | * error when they are not ready and should be returning |
| 2572 | * Logical Busy. We should delay every time. |
| 2573 | */ |
| 2574 | if (cmd == ELS_CMD_FDISC && |
| 2575 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { |
| 2576 | maxretry = 3; |
| 2577 | delay = 1000; |
| 2578 | retry = 1; |
| 2579 | break; |
| 2580 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2581 | case LSRJT_PROTOCOL_ERR: |
| 2582 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2583 | (cmd == ELS_CMD_FDISC) && |
| 2584 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || |
| 2585 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) |
| 2586 | ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2587 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame^] | 2588 | "0122 FDISC Failed (x%x). " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2589 | "Fabric Detected Bad WWN\n", |
| 2590 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2591 | lpfc_vport_set_state(vport, |
| 2592 | FC_VPORT_FABRIC_REJ_WWN); |
| 2593 | } |
| 2594 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2595 | } |
| 2596 | break; |
| 2597 | |
| 2598 | case IOSTAT_INTERMED_RSP: |
| 2599 | case IOSTAT_BA_RJT: |
| 2600 | break; |
| 2601 | |
| 2602 | default: |
| 2603 | break; |
| 2604 | } |
| 2605 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2606 | if (did == FDMI_DID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2607 | retry = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2608 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2609 | if ((cmd == ELS_CMD_FLOGI) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 2610 | (phba->fc_topology != TOPOLOGY_LOOP) && |
| 2611 | !lpfc_error_lost_link(irsp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2612 | /* FLOGI retry policy */ |
| 2613 | retry = 1; |
| 2614 | maxretry = 48; |
| 2615 | if (cmdiocb->retry >= 32) |
| 2616 | delay = 1000; |
| 2617 | } |
| 2618 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2619 | if ((++cmdiocb->retry) >= maxretry) { |
| 2620 | phba->fc_stat.elsRetryExceeded++; |
| 2621 | retry = 0; |
| 2622 | } |
| 2623 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2624 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 2625 | retry = 0; |
| 2626 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2627 | if (retry) { |
| 2628 | |
| 2629 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2630 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2631 | "0107 Retry ELS command x%x to remote " |
| 2632 | "NPORT x%x Data: x%x x%x\n", |
| 2633 | cmd, did, cmdiocb->retry, delay); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2634 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2635 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && |
| 2636 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 2637 | ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) { |
| 2638 | /* Don't reset timer for no resources */ |
| 2639 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2640 | /* If discovery / RSCN timer is running, reset it */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2641 | if (timer_pending(&vport->fc_disctmo) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2642 | (vport->fc_flag & FC_RSCN_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2643 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2644 | } |
| 2645 | |
| 2646 | phba->fc_stat.elsXmitRetry++; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2647 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2648 | phba->fc_stat.elsDelayRetry++; |
| 2649 | ndlp->nlp_retry = cmdiocb->retry; |
| 2650 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2651 | /* delay is specified in milliseconds */ |
| 2652 | mod_timer(&ndlp->nlp_delayfunc, |
| 2653 | jiffies + msecs_to_jiffies(delay)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2654 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2655 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2656 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2657 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2658 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2659 | if (cmd == ELS_CMD_PRLI) |
| 2660 | lpfc_nlp_set_state(vport, ndlp, |
| 2661 | NLP_STE_REG_LOGIN_ISSUE); |
| 2662 | else |
| 2663 | lpfc_nlp_set_state(vport, ndlp, |
| 2664 | NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2665 | ndlp->nlp_last_elscmd = cmd; |
| 2666 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2667 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2668 | } |
| 2669 | switch (cmd) { |
| 2670 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2671 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2672 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2673 | case ELS_CMD_FDISC: |
| 2674 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); |
| 2675 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2676 | case ELS_CMD_PLOGI: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2677 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2678 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2679 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2680 | NLP_STE_PLOGI_ISSUE); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2681 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2682 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2683 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2684 | case ELS_CMD_ADISC: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2685 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2686 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 2687 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2688 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2689 | case ELS_CMD_PRLI: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2690 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2691 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
| 2692 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2693 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2694 | case ELS_CMD_LOGO: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2695 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2696 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 2697 | lpfc_issue_els_logo(vport, ndlp, 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 | } |
| 2700 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2701 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2702 | if (logerr) { |
| 2703 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2704 | "0137 No retry ELS command x%x to remote " |
| 2705 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", |
| 2706 | cmd, did, irsp->ulpStatus, |
| 2707 | irsp->un.ulpWord[4]); |
| 2708 | } |
| 2709 | else { |
| 2710 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 2711 | "0108 No retry ELS command x%x to remote " |
| 2712 | "NPORT x%x Retried:%d Error:x%x/%x\n", |
| 2713 | cmd, did, cmdiocb->retry, irsp->ulpStatus, |
| 2714 | irsp->un.ulpWord[4]); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2715 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2716 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2717 | } |
| 2718 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2719 | /** |
| 2720 | * lpfc_els_free_data: Free lpfc dma buffer and data structure with an iocb. |
| 2721 | * @phba: pointer to lpfc hba data structure. |
| 2722 | * @buf_ptr1: pointer to the lpfc DMA buffer data structure. |
| 2723 | * |
| 2724 | * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) |
| 2725 | * associated with a command IOCB back to the lpfc DMA buffer pool. It first |
| 2726 | * checks to see whether there is a lpfc DMA buffer associated with the |
| 2727 | * response of the command IOCB. If so, it will be released before releasing |
| 2728 | * the lpfc DMA buffer associated with the IOCB itself. |
| 2729 | * |
| 2730 | * Return code |
| 2731 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 2732 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2733 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2734 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) |
| 2735 | { |
| 2736 | struct lpfc_dmabuf *buf_ptr; |
| 2737 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2738 | /* Free the response before processing the command. */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2739 | if (!list_empty(&buf_ptr1->list)) { |
| 2740 | list_remove_head(&buf_ptr1->list, buf_ptr, |
| 2741 | struct lpfc_dmabuf, |
| 2742 | list); |
| 2743 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 2744 | kfree(buf_ptr); |
| 2745 | } |
| 2746 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); |
| 2747 | kfree(buf_ptr1); |
| 2748 | return 0; |
| 2749 | } |
| 2750 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2751 | /** |
| 2752 | * lpfc_els_free_bpl: Free lpfc dma buffer and data structure with bpl. |
| 2753 | * @phba: pointer to lpfc hba data structure. |
| 2754 | * @buf_ptr: pointer to the lpfc dma buffer data structure. |
| 2755 | * |
| 2756 | * This routine releases the lpfc Direct Memory Access (DMA) buffer |
| 2757 | * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer |
| 2758 | * pool. |
| 2759 | * |
| 2760 | * Return code |
| 2761 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 2762 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2763 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2764 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) |
| 2765 | { |
| 2766 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 2767 | kfree(buf_ptr); |
| 2768 | return 0; |
| 2769 | } |
| 2770 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2771 | /** |
| 2772 | * lpfc_els_free_iocb: Free a command iocb and its associated resources. |
| 2773 | * @phba: pointer to lpfc hba data structure. |
| 2774 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 2775 | * |
| 2776 | * This routine frees a command IOCB and its associated resources. The |
| 2777 | * command IOCB data structure contains the reference to various associated |
| 2778 | * resources, these fields must be set to NULL if the associated reference |
| 2779 | * not present: |
| 2780 | * context1 - reference to ndlp |
| 2781 | * context2 - reference to cmd |
| 2782 | * context2->next - reference to rsp |
| 2783 | * context3 - reference to bpl |
| 2784 | * |
| 2785 | * It first properly decrements the reference count held on ndlp for the |
| 2786 | * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not |
| 2787 | * set, it invokes the lpfc_els_free_data() routine to release the Direct |
| 2788 | * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it |
| 2789 | * adds the DMA buffer the @phba data structure for the delayed release. |
| 2790 | * If reference to the Buffer Pointer List (BPL) is present, the |
| 2791 | * lpfc_els_free_bpl() routine is invoked to release the DMA memory |
| 2792 | * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is |
| 2793 | * invoked to release the IOCB data structure back to @phba IOCBQ list. |
| 2794 | * |
| 2795 | * Return code |
| 2796 | * 0 - Success (currently, always return 0) |
| 2797 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2798 | int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2799 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2800 | { |
| 2801 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2802 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2803 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2804 | ndlp = (struct lpfc_nodelist *)elsiocb->context1; |
| 2805 | if (ndlp) { |
| 2806 | if (ndlp->nlp_flag & NLP_DEFER_RM) { |
| 2807 | lpfc_nlp_put(ndlp); |
| 2808 | |
| 2809 | /* If the ndlp is not being used by another discovery |
| 2810 | * thread, free it. |
| 2811 | */ |
| 2812 | if (!lpfc_nlp_not_used(ndlp)) { |
| 2813 | /* If ndlp is being used by another discovery |
| 2814 | * thread, just clear NLP_DEFER_RM |
| 2815 | */ |
| 2816 | ndlp->nlp_flag &= ~NLP_DEFER_RM; |
| 2817 | } |
| 2818 | } |
| 2819 | else |
| 2820 | lpfc_nlp_put(ndlp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2821 | elsiocb->context1 = NULL; |
| 2822 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2823 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
| 2824 | if (elsiocb->context2) { |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2825 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { |
| 2826 | /* Firmware could still be in progress of DMAing |
| 2827 | * payload, so don't free data buffer till after |
| 2828 | * a hbeat. |
| 2829 | */ |
| 2830 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; |
| 2831 | buf_ptr = elsiocb->context2; |
| 2832 | elsiocb->context2 = NULL; |
| 2833 | if (buf_ptr) { |
| 2834 | buf_ptr1 = NULL; |
| 2835 | spin_lock_irq(&phba->hbalock); |
| 2836 | if (!list_empty(&buf_ptr->list)) { |
| 2837 | list_remove_head(&buf_ptr->list, |
| 2838 | buf_ptr1, struct lpfc_dmabuf, |
| 2839 | list); |
| 2840 | INIT_LIST_HEAD(&buf_ptr1->list); |
| 2841 | list_add_tail(&buf_ptr1->list, |
| 2842 | &phba->elsbuf); |
| 2843 | phba->elsbuf_cnt++; |
| 2844 | } |
| 2845 | INIT_LIST_HEAD(&buf_ptr->list); |
| 2846 | list_add_tail(&buf_ptr->list, &phba->elsbuf); |
| 2847 | phba->elsbuf_cnt++; |
| 2848 | spin_unlock_irq(&phba->hbalock); |
| 2849 | } |
| 2850 | } else { |
| 2851 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; |
| 2852 | lpfc_els_free_data(phba, buf_ptr1); |
| 2853 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2854 | } |
| 2855 | |
| 2856 | if (elsiocb->context3) { |
| 2857 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2858 | lpfc_els_free_bpl(phba, buf_ptr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2859 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2860 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2861 | return 0; |
| 2862 | } |
| 2863 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2864 | /** |
| 2865 | * lpfc_cmpl_els_logo_acc: Completion callback function to logo acc response. |
| 2866 | * @phba: pointer to lpfc hba data structure. |
| 2867 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2868 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2869 | * |
| 2870 | * This routine is the completion callback function to the Logout (LOGO) |
| 2871 | * Accept (ACC) Response ELS command. This routine is invoked to indicate |
| 2872 | * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to |
| 2873 | * release the ndlp if it has the last reference remaining (reference count |
| 2874 | * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1 |
| 2875 | * field to NULL to inform the following lpfc_els_free_iocb() routine no |
| 2876 | * ndlp reference count needs to be decremented. Otherwise, the ndlp |
| 2877 | * reference use-count shall be decremented by the lpfc_els_free_iocb() |
| 2878 | * routine. Finally, the lpfc_els_free_iocb() is invoked to release the |
| 2879 | * IOCB data structure. |
| 2880 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2881 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2882 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2883 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2884 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2885 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2886 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2887 | IOCB_t *irsp; |
| 2888 | |
| 2889 | irsp = &rspiocb->iocb; |
| 2890 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 2891 | "ACC LOGO cmpl: status:x%x/x%x did:x%x", |
| 2892 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2893 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2894 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2895 | "0109 ACC to LOGO completes to NPort x%x " |
| 2896 | "Data: x%x x%x x%x\n", |
| 2897 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 2898 | ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2899 | |
| 2900 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { |
| 2901 | /* NPort Recovery mode or node is just allocated */ |
| 2902 | if (!lpfc_nlp_not_used(ndlp)) { |
| 2903 | /* If the ndlp is being used by another discovery |
| 2904 | * thread, just unregister the RPI. |
| 2905 | */ |
| 2906 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2907 | } else { |
| 2908 | /* Indicate the node has already released, should |
| 2909 | * not reference to it from within lpfc_els_free_iocb. |
| 2910 | */ |
| 2911 | cmdiocb->context1 = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2912 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2913 | } |
| 2914 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2915 | return; |
| 2916 | } |
| 2917 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2918 | /** |
| 2919 | * lpfc_mbx_cmpl_dflt_rpi: Completion callbk func for unreg dflt rpi mbox cmd. |
| 2920 | * @phba: pointer to lpfc hba data structure. |
| 2921 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 2922 | * |
| 2923 | * This routine is the completion callback function for unregister default |
| 2924 | * RPI (Remote Port Index) mailbox command to the @phba. It simply releases |
| 2925 | * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and |
| 2926 | * decrements the ndlp reference count held for this completion callback |
| 2927 | * function. After that, it invokes the lpfc_nlp_not_used() to check |
| 2928 | * whether there is only one reference left on the ndlp. If so, it will |
| 2929 | * perform one more decrement and trigger the release of the ndlp. |
| 2930 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2931 | void |
| 2932 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 2933 | { |
| 2934 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 2935 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 2936 | |
| 2937 | pmb->context1 = NULL; |
| 2938 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2939 | kfree(mp); |
| 2940 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2941 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2942 | lpfc_nlp_put(ndlp); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2943 | /* This is the end of the default RPI cleanup logic for this |
| 2944 | * ndlp. If no other discovery threads are using this ndlp. |
| 2945 | * we should free all resources associated with it. |
| 2946 | */ |
| 2947 | lpfc_nlp_not_used(ndlp); |
| 2948 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2949 | return; |
| 2950 | } |
| 2951 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2952 | /** |
| 2953 | * lpfc_cmpl_els_rsp: Completion callback function for els response iocb cmd. |
| 2954 | * @phba: pointer to lpfc hba data structure. |
| 2955 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2956 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2957 | * |
| 2958 | * This routine is the completion callback function for ELS Response IOCB |
| 2959 | * command. In normal case, this callback function just properly sets the |
| 2960 | * nlp_flag bitmap in the ndlp data structure, if the mbox command reference |
| 2961 | * field in the command IOCB is not NULL, the referred mailbox command will |
| 2962 | * be send out, and then invokes the lpfc_els_free_iocb() routine to release |
| 2963 | * the IOCB. Under error conditions, such as when a LS_RJT is returned or a |
| 2964 | * link down event occurred during the discovery, the lpfc_nlp_not_used() |
| 2965 | * routine shall be invoked trying to release the ndlp if no other threads |
| 2966 | * are currently referring it. |
| 2967 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2968 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2969 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2970 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2971 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2972 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2973 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; |
| 2974 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2975 | IOCB_t *irsp; |
| 2976 | uint8_t *pcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2977 | LPFC_MBOXQ_t *mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2978 | struct lpfc_dmabuf *mp = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2979 | uint32_t ls_rjt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2980 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 2981 | irsp = &rspiocb->iocb; |
| 2982 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2983 | if (cmdiocb->context_un.mbox) |
| 2984 | mbox = cmdiocb->context_un.mbox; |
| 2985 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2986 | /* First determine if this is a LS_RJT cmpl. Note, this callback |
| 2987 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. |
| 2988 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2989 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2990 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 2991 | (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2992 | /* A LS_RJT associated with Default RPI cleanup has its own |
| 2993 | * seperate code path. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2994 | */ |
| 2995 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
| 2996 | ls_rjt = 1; |
| 2997 | } |
| 2998 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2999 | /* Check to see if link went down during discovery */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3000 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3001 | if (mbox) { |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3002 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3003 | if (mp) { |
| 3004 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3005 | kfree(mp); |
| 3006 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3007 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3008 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3009 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3010 | (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3011 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3012 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3013 | /* Indicate the node has already released, |
| 3014 | * should not reference to it from within |
| 3015 | * the routine lpfc_els_free_iocb. |
| 3016 | */ |
| 3017 | cmdiocb->context1 = NULL; |
| 3018 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3019 | goto out; |
| 3020 | } |
| 3021 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3022 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3023 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3024 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3025 | cmdiocb->iocb.un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3026 | /* ELS response tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3027 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3028 | "0110 ELS response tag x%x completes " |
| 3029 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", |
| 3030 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, |
| 3031 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, |
| 3032 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3033 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3034 | if (mbox) { |
| 3035 | if ((rspiocb->iocb.ulpStatus == 0) |
| 3036 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3037 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3038 | /* Increment reference count to ndlp to hold the |
| 3039 | * reference to ndlp for the callback function. |
| 3040 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3041 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3042 | mbox->vport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3043 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
| 3044 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 3045 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 3046 | } |
| 3047 | else { |
| 3048 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
| 3049 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 3050 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3051 | NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3052 | } |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3053 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3054 | != MBX_NOT_FINISHED) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3055 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3056 | else |
| 3057 | /* Decrement the ndlp reference count we |
| 3058 | * set for this failed mailbox command. |
| 3059 | */ |
| 3060 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3061 | |
| 3062 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ |
| 3063 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3064 | "0138 ELS rsp: Cannot issue reg_login for x%x " |
| 3065 | "Data: x%x x%x x%x\n", |
| 3066 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3067 | ndlp->nlp_rpi); |
| 3068 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3069 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3070 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3071 | /* Indicate node has already been released, |
| 3072 | * should not reference to it from within |
| 3073 | * the routine lpfc_els_free_iocb. |
| 3074 | */ |
| 3075 | cmdiocb->context1 = NULL; |
| 3076 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3077 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3078 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
| 3079 | if (!lpfc_error_lost_link(irsp) && |
| 3080 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3081 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3082 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3083 | /* Indicate node has already been |
| 3084 | * released, should not reference |
| 3085 | * to it from within the routine |
| 3086 | * lpfc_els_free_iocb. |
| 3087 | */ |
| 3088 | cmdiocb->context1 = NULL; |
| 3089 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3090 | } |
| 3091 | } |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3092 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3093 | if (mp) { |
| 3094 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3095 | kfree(mp); |
| 3096 | } |
| 3097 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3098 | } |
| 3099 | out: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3100 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3101 | spin_lock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3102 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3103 | spin_unlock_irq(shost->host_lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3104 | |
| 3105 | /* If the node is not being used by another discovery thread, |
| 3106 | * and we are sending a reject, we are done with it. |
| 3107 | * Release driver reference count here and free associated |
| 3108 | * resources. |
| 3109 | */ |
| 3110 | if (ls_rjt) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3111 | if (lpfc_nlp_not_used(ndlp)) |
| 3112 | /* Indicate node has already been released, |
| 3113 | * should not reference to it from within |
| 3114 | * the routine lpfc_els_free_iocb. |
| 3115 | */ |
| 3116 | cmdiocb->context1 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3117 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3118 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3119 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3120 | return; |
| 3121 | } |
| 3122 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3123 | /** |
| 3124 | * lpfc_els_rsp_acc: Prepare and issue an acc response iocb command. |
| 3125 | * @vport: pointer to a host virtual N_Port data structure. |
| 3126 | * @flag: the els command code to be accepted. |
| 3127 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3128 | * @ndlp: pointer to a node-list data structure. |
| 3129 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3130 | * |
| 3131 | * This routine prepares and issues an Accept (ACC) response IOCB |
| 3132 | * command. It uses the @flag to properly set up the IOCB field for the |
| 3133 | * specific ACC response command to be issued and invokes the |
| 3134 | * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a |
| 3135 | * @mbox pointer is passed in, it will be put into the context_un.mbox |
| 3136 | * field of the IOCB for the completion callback function to issue the |
| 3137 | * mailbox command to the HBA later when callback is invoked. |
| 3138 | * |
| 3139 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3140 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3141 | * will be stored into the context1 field of the IOCB for the completion |
| 3142 | * callback function to the corresponding response ELS IOCB command. |
| 3143 | * |
| 3144 | * Return code |
| 3145 | * 0 - Successfully issued acc response |
| 3146 | * 1 - Failed to issue acc response |
| 3147 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3148 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3149 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
| 3150 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3151 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3152 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3153 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3154 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3155 | IOCB_t *icmd; |
| 3156 | IOCB_t *oldcmd; |
| 3157 | struct lpfc_iocbq *elsiocb; |
| 3158 | struct lpfc_sli_ring *pring; |
| 3159 | struct lpfc_sli *psli; |
| 3160 | uint8_t *pcmd; |
| 3161 | uint16_t cmdsize; |
| 3162 | int rc; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3163 | ELS_PKT *els_pkt_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3164 | |
| 3165 | psli = &phba->sli; |
| 3166 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 3167 | oldcmd = &oldiocb->iocb; |
| 3168 | |
| 3169 | switch (flag) { |
| 3170 | case ELS_CMD_ACC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3171 | cmdsize = sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3172 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3173 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3174 | if (!elsiocb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3175 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3176 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3177 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3178 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3179 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3180 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3181 | icmd = &elsiocb->iocb; |
| 3182 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3183 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3184 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3185 | pcmd += sizeof(uint32_t); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3186 | |
| 3187 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3188 | "Issue ACC: did:x%x flg:x%x", |
| 3189 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3190 | break; |
| 3191 | case ELS_CMD_PLOGI: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3192 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3193 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3194 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3195 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3196 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3197 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3198 | icmd = &elsiocb->iocb; |
| 3199 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3200 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3201 | |
| 3202 | if (mbox) |
| 3203 | elsiocb->context_un.mbox = mbox; |
| 3204 | |
| 3205 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3206 | pcmd += sizeof(uint32_t); |
| 3207 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3208 | |
| 3209 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3210 | "Issue ACC PLOGI: did:x%x flg:x%x", |
| 3211 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3212 | break; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3213 | case ELS_CMD_PRLO: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3214 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3215 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3216 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
| 3217 | if (!elsiocb) |
| 3218 | return 1; |
| 3219 | |
| 3220 | icmd = &elsiocb->iocb; |
| 3221 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3222 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3223 | |
| 3224 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3225 | sizeof(uint32_t) + sizeof(PRLO)); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3226 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
| 3227 | els_pkt_ptr = (ELS_PKT *) pcmd; |
| 3228 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3229 | |
| 3230 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3231 | "Issue ACC PRLO: did:x%x flg:x%x", |
| 3232 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3233 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3234 | default: |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3235 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3236 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3237 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3238 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3239 | "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " |
| 3240 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n", |
| 3241 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3242 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3243 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3244 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3245 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3246 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3247 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3248 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
| 3249 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3250 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3251 | } |
| 3252 | |
| 3253 | phba->fc_stat.elsXmitACC++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3254 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3255 | if (rc == IOCB_ERROR) { |
| 3256 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3257 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3258 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3259 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3260 | } |
| 3261 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3262 | /** |
| 3263 | * lpfc_els_rsp_reject: Propare and issue a rjt response iocb command. |
| 3264 | * @vport: pointer to a virtual N_Port data structure. |
| 3265 | * @rejectError: |
| 3266 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3267 | * @ndlp: pointer to a node-list data structure. |
| 3268 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3269 | * |
| 3270 | * This routine prepares and issue an Reject (RJT) response IOCB |
| 3271 | * command. If a @mbox pointer is passed in, it will be put into the |
| 3272 | * context_un.mbox field of the IOCB for the completion callback function |
| 3273 | * to issue to the HBA later. |
| 3274 | * |
| 3275 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3276 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3277 | * will be stored into the context1 field of the IOCB for the completion |
| 3278 | * callback function to the reject response ELS IOCB command. |
| 3279 | * |
| 3280 | * Return code |
| 3281 | * 0 - Successfully issued reject response |
| 3282 | * 1 - Failed to issue reject response |
| 3283 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3284 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3285 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3286 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
| 3287 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3288 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3289 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3290 | IOCB_t *icmd; |
| 3291 | IOCB_t *oldcmd; |
| 3292 | struct lpfc_iocbq *elsiocb; |
| 3293 | struct lpfc_sli_ring *pring; |
| 3294 | struct lpfc_sli *psli; |
| 3295 | uint8_t *pcmd; |
| 3296 | uint16_t cmdsize; |
| 3297 | int rc; |
| 3298 | |
| 3299 | psli = &phba->sli; |
| 3300 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 3301 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3302 | cmdsize = 2 * sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3303 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3304 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3305 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3306 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3307 | |
| 3308 | icmd = &elsiocb->iocb; |
| 3309 | oldcmd = &oldiocb->iocb; |
| 3310 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3311 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3312 | |
| 3313 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3314 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3315 | *((uint32_t *) (pcmd)) = rejectError; |
| 3316 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3317 | if (mbox) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3318 | elsiocb->context_un.mbox = mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3319 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3320 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3321 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3322 | "0129 Xmit ELS RJT x%x response tag x%x " |
| 3323 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 3324 | "rpi x%x\n", |
| 3325 | rejectError, elsiocb->iotag, |
| 3326 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 3327 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3328 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3329 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", |
| 3330 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); |
| 3331 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3332 | phba->fc_stat.elsXmitLSRJT++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3333 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3334 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3335 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3336 | if (rc == IOCB_ERROR) { |
| 3337 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3338 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3339 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3340 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3341 | } |
| 3342 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3343 | /** |
| 3344 | * lpfc_els_rsp_adisc_acc: Prepare and issue acc response to adisc iocb cmd. |
| 3345 | * @vport: pointer to a virtual N_Port data structure. |
| 3346 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3347 | * @ndlp: pointer to a node-list data structure. |
| 3348 | * |
| 3349 | * This routine prepares and issues an Accept (ACC) response to Address |
| 3350 | * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB |
| 3351 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3352 | * |
| 3353 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3354 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3355 | * will be stored into the context1 field of the IOCB for the completion |
| 3356 | * callback function to the ADISC Accept response ELS IOCB command. |
| 3357 | * |
| 3358 | * Return code |
| 3359 | * 0 - Successfully issued acc adisc response |
| 3360 | * 1 - Failed to issue adisc acc response |
| 3361 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3362 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3363 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
| 3364 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3365 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3366 | struct lpfc_hba *phba = vport->phba; |
| 3367 | struct lpfc_sli *psli = &phba->sli; |
| 3368 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3369 | ADISC *ap; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3370 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3371 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3372 | uint8_t *pcmd; |
| 3373 | uint16_t cmdsize; |
| 3374 | int rc; |
| 3375 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3376 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3377 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3378 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3379 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3380 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3381 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3382 | icmd = &elsiocb->iocb; |
| 3383 | oldcmd = &oldiocb->iocb; |
| 3384 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3385 | |
| 3386 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3387 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3388 | "0130 Xmit ADISC ACC response iotag x%x xri: " |
| 3389 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", |
| 3390 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3391 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3392 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3393 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3394 | |
| 3395 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3396 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3397 | |
| 3398 | ap = (ADISC *) (pcmd); |
| 3399 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3400 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3401 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3402 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3403 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3404 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3405 | "Issue ACC ADISC: did:x%x flg:x%x", |
| 3406 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3407 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3408 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3409 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3410 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3411 | if (rc == IOCB_ERROR) { |
| 3412 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3413 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3414 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3415 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3416 | } |
| 3417 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3418 | /** |
| 3419 | * lpfc_els_rsp_prli_acc: Prepare and issue acc response to prli iocb cmd. |
| 3420 | * @vport: pointer to a virtual N_Port data structure. |
| 3421 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3422 | * @ndlp: pointer to a node-list data structure. |
| 3423 | * |
| 3424 | * This routine prepares and issues an Accept (ACC) response to Process |
| 3425 | * Login (PRLI) ELS command. It simply prepares the payload of the IOCB |
| 3426 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3427 | * |
| 3428 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3429 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3430 | * will be stored into the context1 field of the IOCB for the completion |
| 3431 | * callback function to the PRLI Accept response ELS IOCB command. |
| 3432 | * |
| 3433 | * Return code |
| 3434 | * 0 - Successfully issued acc prli response |
| 3435 | * 1 - Failed to issue acc prli response |
| 3436 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3437 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3438 | 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] | 3439 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3440 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3441 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3442 | PRLI *npr; |
| 3443 | lpfc_vpd_t *vpd; |
| 3444 | IOCB_t *icmd; |
| 3445 | IOCB_t *oldcmd; |
| 3446 | struct lpfc_iocbq *elsiocb; |
| 3447 | struct lpfc_sli_ring *pring; |
| 3448 | struct lpfc_sli *psli; |
| 3449 | uint8_t *pcmd; |
| 3450 | uint16_t cmdsize; |
| 3451 | int rc; |
| 3452 | |
| 3453 | psli = &phba->sli; |
| 3454 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 3455 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3456 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3457 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3458 | ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK))); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3459 | if (!elsiocb) |
| 3460 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3461 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3462 | icmd = &elsiocb->iocb; |
| 3463 | oldcmd = &oldiocb->iocb; |
| 3464 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3465 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3466 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3467 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " |
| 3468 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 3469 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3470 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3471 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3472 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3473 | |
| 3474 | *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3475 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3476 | |
| 3477 | /* For PRLI, remainder of payload is PRLI parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3478 | memset(pcmd, 0, sizeof(PRLI)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3479 | |
| 3480 | npr = (PRLI *) pcmd; |
| 3481 | vpd = &phba->vpd; |
| 3482 | /* |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3483 | * If the remote port is a target and our firmware version is 3.20 or |
| 3484 | * later, set the following bits for FC-TAPE support. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3485 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3486 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
| 3487 | (vpd->rev.feaLevelHigh >= 0x02)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3488 | npr->ConfmComplAllowed = 1; |
| 3489 | npr->Retry = 1; |
| 3490 | npr->TaskRetryIdReq = 1; |
| 3491 | } |
| 3492 | |
| 3493 | npr->acceptRspCode = PRLI_REQ_EXECUTED; |
| 3494 | npr->estabImagePair = 1; |
| 3495 | npr->readXferRdyDis = 1; |
| 3496 | npr->ConfmComplAllowed = 1; |
| 3497 | |
| 3498 | npr->prliType = PRLI_FCP_TYPE; |
| 3499 | npr->initiatorFunc = 1; |
| 3500 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3501 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3502 | "Issue ACC PRLI: did:x%x flg:x%x", |
| 3503 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3504 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3505 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3506 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3507 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3508 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3509 | if (rc == IOCB_ERROR) { |
| 3510 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3511 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3512 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3513 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3514 | } |
| 3515 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3516 | /** |
| 3517 | * lpfc_els_rsp_rnid_acc: Issue rnid acc response iocb command. |
| 3518 | * @vport: pointer to a virtual N_Port data structure. |
| 3519 | * @format: rnid command format. |
| 3520 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3521 | * @ndlp: pointer to a node-list data structure. |
| 3522 | * |
| 3523 | * This routine issues a Request Node Identification Data (RNID) Accept |
| 3524 | * (ACC) response. It constructs the RNID ACC response command according to |
| 3525 | * the proper @format and then calls the lpfc_sli_issue_iocb() routine to |
| 3526 | * issue the response. Note that this command does not need to hold the ndlp |
| 3527 | * reference count for the callback. So, the ndlp reference count taken by |
| 3528 | * the lpfc_prep_els_iocb() routine is put back and the context1 field of |
| 3529 | * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that |
| 3530 | * there is no ndlp reference available. |
| 3531 | * |
| 3532 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3533 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3534 | * will be stored into the context1 field of the IOCB for the completion |
| 3535 | * callback function. However, for the RNID Accept Response ELS command, |
| 3536 | * this is undone later by this routine after the IOCB is allocated. |
| 3537 | * |
| 3538 | * Return code |
| 3539 | * 0 - Successfully issued acc rnid response |
| 3540 | * 1 - Failed to issue acc rnid response |
| 3541 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3542 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3543 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3544 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3545 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3546 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3547 | RNID *rn; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3548 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3549 | struct lpfc_iocbq *elsiocb; |
| 3550 | struct lpfc_sli_ring *pring; |
| 3551 | struct lpfc_sli *psli; |
| 3552 | uint8_t *pcmd; |
| 3553 | uint16_t cmdsize; |
| 3554 | int rc; |
| 3555 | |
| 3556 | psli = &phba->sli; |
| 3557 | pring = &psli->ring[LPFC_ELS_RING]; |
| 3558 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3559 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
| 3560 | + (2 * sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3561 | if (format) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3562 | cmdsize += sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3563 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3564 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3565 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3566 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3567 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3568 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3569 | icmd = &elsiocb->iocb; |
| 3570 | oldcmd = &oldiocb->iocb; |
| 3571 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3572 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3573 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3574 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", |
| 3575 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3576 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3577 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3578 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3579 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3580 | memset(pcmd, 0, sizeof(RNID)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3581 | rn = (RNID *) (pcmd); |
| 3582 | rn->Format = format; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3583 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
| 3584 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3585 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3586 | switch (format) { |
| 3587 | case 0: |
| 3588 | rn->SpecificLen = 0; |
| 3589 | break; |
| 3590 | case RNID_TOPOLOGY_DISC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3591 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3592 | memcpy(&rn->un.topologyDisc.portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3593 | &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3594 | rn->un.topologyDisc.unitType = RNID_HBA; |
| 3595 | rn->un.topologyDisc.physPort = 0; |
| 3596 | rn->un.topologyDisc.attachedNodes = 0; |
| 3597 | break; |
| 3598 | default: |
| 3599 | rn->CommonLen = 0; |
| 3600 | rn->SpecificLen = 0; |
| 3601 | break; |
| 3602 | } |
| 3603 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3604 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3605 | "Issue ACC RNID: did:x%x flg:x%x", |
| 3606 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3607 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3608 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3609 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3610 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3611 | elsiocb->context1 = NULL; /* Don't need ndlp for cmpl, |
| 3612 | * it could be freed */ |
| 3613 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3614 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3615 | if (rc == IOCB_ERROR) { |
| 3616 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3617 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3618 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3619 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3620 | } |
| 3621 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3622 | /** |
| 3623 | * lpfc_els_disc_adisc: Issue remaining adisc iocbs to npr nodes of a vport. |
| 3624 | * @vport: pointer to a host virtual N_Port data structure. |
| 3625 | * |
| 3626 | * This routine issues Address Discover (ADISC) ELS commands to those |
| 3627 | * N_Ports which are in node port recovery state and ADISC has not been issued |
| 3628 | * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the |
| 3629 | * lpfc_issue_els_adisc() routine, the per @vport number of discover count |
| 3630 | * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a |
| 3631 | * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will |
| 3632 | * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC |
| 3633 | * IOCBs quit for later pick up. On the other hand, after walking through |
| 3634 | * all the ndlps with the @vport and there is none ADISC IOCB issued, the |
| 3635 | * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is |
| 3636 | * no more ADISC need to be sent. |
| 3637 | * |
| 3638 | * Return code |
| 3639 | * The number of N_Ports with adisc issued. |
| 3640 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3641 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3642 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3643 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3644 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3645 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3646 | int sentadisc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3647 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3648 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3649 | 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] | 3650 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3651 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3652 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 3653 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 3654 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3655 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3656 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3657 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3658 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3659 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 3660 | lpfc_issue_els_adisc(vport, ndlp, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3661 | sentadisc++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3662 | vport->num_disc_nodes++; |
| 3663 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3664 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3665 | spin_lock_irq(shost->host_lock); |
| 3666 | vport->fc_flag |= FC_NLP_MORE; |
| 3667 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3668 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3669 | } |
| 3670 | } |
| 3671 | } |
| 3672 | if (sentadisc == 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3673 | spin_lock_irq(shost->host_lock); |
| 3674 | vport->fc_flag &= ~FC_NLP_MORE; |
| 3675 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3676 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3677 | return sentadisc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3678 | } |
| 3679 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3680 | /** |
| 3681 | * lpfc_els_disc_plogi: Issue plogi for all npr nodes of a vport before adisc. |
| 3682 | * @vport: pointer to a host virtual N_Port data structure. |
| 3683 | * |
| 3684 | * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports |
| 3685 | * which are in node port recovery state, with a @vport. Each time an ELS |
| 3686 | * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, |
| 3687 | * the per @vport number of discover count (num_disc_nodes) shall be |
| 3688 | * incremented. If the num_disc_nodes reaches a pre-configured threshold |
| 3689 | * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE |
| 3690 | * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for |
| 3691 | * later pick up. On the other hand, after walking through all the ndlps with |
| 3692 | * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag |
| 3693 | * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC |
| 3694 | * PLOGI need to be sent. |
| 3695 | * |
| 3696 | * Return code |
| 3697 | * The number of N_Ports with plogi issued. |
| 3698 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3699 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3700 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3701 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3702 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3703 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3704 | int sentplogi = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3705 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3706 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 3707 | 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] | 3708 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3709 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3710 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 3711 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 3712 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && |
| 3713 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { |
| 3714 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3715 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 3716 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3717 | sentplogi++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3718 | vport->num_disc_nodes++; |
| 3719 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3720 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3721 | spin_lock_irq(shost->host_lock); |
| 3722 | vport->fc_flag |= FC_NLP_MORE; |
| 3723 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3724 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3725 | } |
| 3726 | } |
| 3727 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3728 | if (sentplogi) { |
| 3729 | lpfc_set_disctmo(vport); |
| 3730 | } |
| 3731 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3732 | spin_lock_irq(shost->host_lock); |
| 3733 | vport->fc_flag &= ~FC_NLP_MORE; |
| 3734 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3735 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3736 | return sentplogi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3737 | } |
| 3738 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3739 | /** |
| 3740 | * lpfc_els_flush_rscn: Clean up any rscn activities with a vport. |
| 3741 | * @vport: pointer to a host virtual N_Port data structure. |
| 3742 | * |
| 3743 | * This routine cleans up any Registration State Change Notification |
| 3744 | * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the |
| 3745 | * @vport together with the host_lock is used to prevent multiple thread |
| 3746 | * trying to access the RSCN array on a same @vport at the same time. |
| 3747 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3748 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3749 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3750 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3751 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3752 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3753 | int i; |
| 3754 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3755 | spin_lock_irq(shost->host_lock); |
| 3756 | if (vport->fc_rscn_flush) { |
| 3757 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 3758 | spin_unlock_irq(shost->host_lock); |
| 3759 | return; |
| 3760 | } |
| 3761 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ |
| 3762 | vport->fc_rscn_flush = 1; |
| 3763 | spin_unlock_irq(shost->host_lock); |
| 3764 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3765 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3766 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3767 | vport->fc_rscn_id_list[i] = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3768 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3769 | spin_lock_irq(shost->host_lock); |
| 3770 | vport->fc_rscn_id_cnt = 0; |
| 3771 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); |
| 3772 | spin_unlock_irq(shost->host_lock); |
| 3773 | lpfc_can_disctmo(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3774 | /* Indicate we are done walking this fc_rscn_id_list */ |
| 3775 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3776 | } |
| 3777 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3778 | /** |
| 3779 | * lpfc_rscn_payload_check: Check whether there is a pending rscn to a did. |
| 3780 | * @vport: pointer to a host virtual N_Port data structure. |
| 3781 | * @did: remote destination port identifier. |
| 3782 | * |
| 3783 | * This routine checks whether there is any pending Registration State |
| 3784 | * Configuration Notification (RSCN) to a @did on @vport. |
| 3785 | * |
| 3786 | * Return code |
| 3787 | * None zero - The @did matched with a pending rscn |
| 3788 | * 0 - not able to match @did with a pending rscn |
| 3789 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3790 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3791 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3792 | { |
| 3793 | D_ID ns_did; |
| 3794 | D_ID rscn_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3795 | uint32_t *lp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3796 | uint32_t payload_len, i; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3797 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3798 | |
| 3799 | ns_did.un.word = did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3800 | |
| 3801 | /* Never match fabric nodes for RSCNs */ |
| 3802 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3803 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3804 | |
| 3805 | /* If we are doing a FULL RSCN rediscovery, match everything */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3806 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3807 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3808 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3809 | spin_lock_irq(shost->host_lock); |
| 3810 | if (vport->fc_rscn_flush) { |
| 3811 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 3812 | spin_unlock_irq(shost->host_lock); |
| 3813 | return 0; |
| 3814 | } |
| 3815 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 3816 | vport->fc_rscn_flush = 1; |
| 3817 | spin_unlock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3818 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3819 | lp = vport->fc_rscn_id_list[i]->virt; |
| 3820 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 3821 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3822 | while (payload_len) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3823 | rscn_did.un.word = be32_to_cpu(*lp++); |
| 3824 | payload_len -= sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3825 | switch (rscn_did.un.b.resv) { |
| 3826 | case 0: /* Single N_Port ID effected */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3827 | if (ns_did.un.word == rscn_did.un.word) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3828 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3829 | break; |
| 3830 | case 1: /* Whole N_Port Area effected */ |
| 3831 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 3832 | && (ns_did.un.b.area == rscn_did.un.b.area)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3833 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3834 | break; |
| 3835 | case 2: /* Whole N_Port Domain effected */ |
| 3836 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3837 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3838 | break; |
| 3839 | default: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3840 | /* Unknown Identifier in RSCN node */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3841 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 3842 | "0217 Unknown Identifier in " |
| 3843 | "RSCN payload Data: x%x\n", |
| 3844 | rscn_did.un.word); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3845 | case 3: /* Whole Fabric effected */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3846 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3847 | } |
| 3848 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3849 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3850 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 3851 | vport->fc_rscn_flush = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3852 | return 0; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3853 | return_did_out: |
| 3854 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 3855 | vport->fc_rscn_flush = 0; |
| 3856 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3857 | } |
| 3858 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3859 | /** |
| 3860 | * lpfc_rscn_recovery_check: Send recovery event to vport nodes matching rscn |
| 3861 | * @vport: pointer to a host virtual N_Port data structure. |
| 3862 | * |
| 3863 | * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the |
| 3864 | * state machine for a @vport's nodes that are with pending RSCN (Registration |
| 3865 | * State Change Notification). |
| 3866 | * |
| 3867 | * Return code |
| 3868 | * 0 - Successful (currently alway return 0) |
| 3869 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3870 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3871 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3872 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3873 | struct lpfc_nodelist *ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3874 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3875 | /* Move all affected nodes by pending RSCNs to NPR state. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3876 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3877 | if (!NLP_CHK_NODE_ACT(ndlp) || |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3878 | (ndlp->nlp_state == NLP_STE_UNUSED_NODE) || |
| 3879 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3880 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3881 | lpfc_disc_state_machine(vport, ndlp, NULL, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3882 | NLP_EVT_DEVICE_RECOVERY); |
| 3883 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3884 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3885 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3886 | } |
| 3887 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3888 | /** |
| 3889 | * lpfc_els_rcv_rscn: Process an unsolicited rscn iocb. |
| 3890 | * @vport: pointer to a host virtual N_Port data structure. |
| 3891 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3892 | * @ndlp: pointer to a node-list data structure. |
| 3893 | * |
| 3894 | * This routine processes an unsolicited RSCN (Registration State Change |
| 3895 | * Notification) IOCB. First, the payload of the unsolicited RSCN is walked |
| 3896 | * to invoke fc_host_post_event() routine to the FC transport layer. If the |
| 3897 | * discover state machine is about to begin discovery, it just accepts the |
| 3898 | * RSCN and the discovery process will satisfy the RSCN. If this RSCN only |
| 3899 | * contains N_Port IDs for other vports on this HBA, it just accepts the |
| 3900 | * RSCN and ignore processing it. If the state machine is in the recovery |
| 3901 | * state, the fc_rscn_id_list of this @vport is walked and the |
| 3902 | * lpfc_rscn_recovery_check() routine is invoked to send recovery event for |
| 3903 | * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() |
| 3904 | * routine is invoked to handle the RSCN event. |
| 3905 | * |
| 3906 | * Return code |
| 3907 | * 0 - Just sent the acc response |
| 3908 | * 1 - Sent the acc response and waited for name server completion |
| 3909 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3910 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3911 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3912 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3913 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3914 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3915 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3916 | struct lpfc_dmabuf *pcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3917 | uint32_t *lp, *datap; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3918 | IOCB_t *icmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3919 | uint32_t payload_len, length, nportid, *cmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3920 | int rscn_cnt; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3921 | int rscn_id = 0, hba_id = 0; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 3922 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3923 | |
| 3924 | icmd = &cmdiocb->iocb; |
| 3925 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 3926 | lp = (uint32_t *) pcmd->virt; |
| 3927 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3928 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 3929 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3930 | /* RSCN received */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3931 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 3932 | "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] | 3933 | vport->fc_flag, payload_len, *lp, |
| 3934 | vport->fc_rscn_id_cnt); |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 3935 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3936 | fc_host_post_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 3937 | FCH_EVT_RSCN, lp[i]); |
| 3938 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3939 | /* If we are about to begin discovery, just ACC the RSCN. |
| 3940 | * Discovery processing will satisfy it. |
| 3941 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3942 | if (vport->port_state <= LPFC_NS_QRY) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3943 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 3944 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", |
| 3945 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 3946 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3947 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3948 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3949 | } |
| 3950 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3951 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
| 3952 | * just ACC and ignore it. |
| 3953 | */ |
| 3954 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3955 | !(vport->cfg_peer_port_login)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3956 | i = payload_len; |
| 3957 | datap = lp; |
| 3958 | while (i > 0) { |
| 3959 | nportid = *datap++; |
| 3960 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); |
| 3961 | i -= sizeof(uint32_t); |
| 3962 | rscn_id++; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3963 | if (lpfc_find_vport_by_did(phba, nportid)) |
| 3964 | hba_id++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3965 | } |
| 3966 | if (rscn_id == hba_id) { |
| 3967 | /* ALL NPortIDs in RSCN are on HBA */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3968 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame^] | 3969 | "0219 Ignore RSCN " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3970 | "Data: x%x x%x x%x x%x\n", |
| 3971 | vport->fc_flag, payload_len, |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3972 | *lp, vport->fc_rscn_id_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3973 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 3974 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", |
| 3975 | ndlp->nlp_DID, vport->port_state, |
| 3976 | ndlp->nlp_flag); |
| 3977 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3978 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3979 | ndlp, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3980 | return 0; |
| 3981 | } |
| 3982 | } |
| 3983 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3984 | spin_lock_irq(shost->host_lock); |
| 3985 | if (vport->fc_rscn_flush) { |
| 3986 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 3987 | spin_unlock_irq(shost->host_lock); |
| 3988 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3989 | /* Send back ACC */ |
| 3990 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3991 | return 0; |
| 3992 | } |
| 3993 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 3994 | vport->fc_rscn_flush = 1; |
| 3995 | spin_unlock_irq(shost->host_lock); |
| 3996 | /* Get the array count after sucessfully have the token */ |
| 3997 | rscn_cnt = vport->fc_rscn_id_cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3998 | /* If we are already processing an RSCN, save the received |
| 3999 | * RSCN payload buffer, cmdiocb->context2 to process later. |
| 4000 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4001 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4002 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4003 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", |
| 4004 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4005 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4006 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4007 | vport->fc_flag |= FC_RSCN_DEFERRED; |
| 4008 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4009 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4010 | vport->fc_flag |= FC_RSCN_MODE; |
| 4011 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4012 | if (rscn_cnt) { |
| 4013 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; |
| 4014 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); |
| 4015 | } |
| 4016 | if ((rscn_cnt) && |
| 4017 | (payload_len + length <= LPFC_BPL_SIZE)) { |
| 4018 | *cmd &= ELS_CMD_MASK; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4019 | *cmd |= cpu_to_be32(payload_len + length); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4020 | memcpy(((uint8_t *)cmd) + length, lp, |
| 4021 | payload_len); |
| 4022 | } else { |
| 4023 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; |
| 4024 | vport->fc_rscn_id_cnt++; |
| 4025 | /* If we zero, cmdiocb->context2, the calling |
| 4026 | * routine will not try to free it. |
| 4027 | */ |
| 4028 | cmdiocb->context2 = NULL; |
| 4029 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4030 | /* Deferred RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4031 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4032 | "0235 Deferred RSCN " |
| 4033 | "Data: x%x x%x x%x\n", |
| 4034 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4035 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4036 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4037 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
| 4038 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4039 | /* ReDiscovery RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4040 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4041 | "0234 ReDiscovery RSCN " |
| 4042 | "Data: x%x x%x x%x\n", |
| 4043 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4044 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4045 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4046 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4047 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4048 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4049 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4050 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4051 | lpfc_rscn_recovery_check(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4052 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4053 | vport->fc_flag &= ~FC_RSCN_DEFERRED; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4054 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4055 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4056 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4057 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4058 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", |
| 4059 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4060 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4061 | spin_lock_irq(shost->host_lock); |
| 4062 | vport->fc_flag |= FC_RSCN_MODE; |
| 4063 | spin_unlock_irq(shost->host_lock); |
| 4064 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4065 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4066 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4067 | /* |
| 4068 | * If we zero, cmdiocb->context2, the calling routine will |
| 4069 | * not try to free it. |
| 4070 | */ |
| 4071 | cmdiocb->context2 = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4072 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4073 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4074 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4075 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4076 | lpfc_rscn_recovery_check(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4077 | return lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4078 | } |
| 4079 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4080 | /** |
| 4081 | * lpfc_els_handle_rscn: Handle rscn for a vport. |
| 4082 | * @vport: pointer to a host virtual N_Port data structure. |
| 4083 | * |
| 4084 | * This routine handles the Registration State Configuration Notification |
| 4085 | * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall |
| 4086 | * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, |
| 4087 | * if the ndlp to NameServer exists, a Common Transport (CT) command to the |
| 4088 | * NameServer shall be issued. If CT command to the NameServer fails to be |
| 4089 | * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any |
| 4090 | * RSCN activities with the @vport. |
| 4091 | * |
| 4092 | * Return code |
| 4093 | * 0 - Cleaned up rscn on the @vport |
| 4094 | * 1 - Wait for plogi to name server before proceed |
| 4095 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4096 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4097 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4098 | { |
| 4099 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4100 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4101 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4102 | /* Ignore RSCN if the port is being torn down. */ |
| 4103 | if (vport->load_flag & FC_UNLOADING) { |
| 4104 | lpfc_els_flush_rscn(vport); |
| 4105 | return 0; |
| 4106 | } |
| 4107 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4108 | /* Start timer for RSCN processing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4109 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4110 | |
| 4111 | /* RSCN processed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4112 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4113 | "0215 RSCN processed Data: x%x x%x x%x x%x\n", |
| 4114 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, |
| 4115 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4116 | |
| 4117 | /* To process RSCN, first compare RSCN data with NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4118 | vport->fc_ns_retry = 0; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4119 | vport->num_disc_nodes = 0; |
| 4120 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4121 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4122 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) |
| 4123 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4124 | /* Good ndlp, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4125 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4126 | /* Wait for NameServer query cmpl before we can |
| 4127 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4128 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4129 | } else { |
| 4130 | /* If login to NameServer does not exist, issue one */ |
| 4131 | /* Good status, issue PLOGI to NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4132 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4133 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4134 | /* Wait for NameServer login cmpl before we can |
| 4135 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4136 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4137 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4138 | if (ndlp) { |
| 4139 | ndlp = lpfc_enable_node(vport, ndlp, |
| 4140 | NLP_STE_PLOGI_ISSUE); |
| 4141 | if (!ndlp) { |
| 4142 | lpfc_els_flush_rscn(vport); |
| 4143 | return 0; |
| 4144 | } |
| 4145 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4146 | } else { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4147 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 4148 | if (!ndlp) { |
| 4149 | lpfc_els_flush_rscn(vport); |
| 4150 | return 0; |
| 4151 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4152 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4153 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4154 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4155 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4156 | ndlp->nlp_type |= NLP_FABRIC; |
| 4157 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); |
| 4158 | /* Wait for NameServer login cmpl before we can |
| 4159 | * continue |
| 4160 | */ |
| 4161 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4162 | } |
| 4163 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4164 | lpfc_els_flush_rscn(vport); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4165 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4166 | } |
| 4167 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4168 | /** |
| 4169 | * lpfc_els_rcv_flogi: Process an unsolicited flogi iocb. |
| 4170 | * @vport: pointer to a host virtual N_Port data structure. |
| 4171 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4172 | * @ndlp: pointer to a node-list data structure. |
| 4173 | * |
| 4174 | * This routine processes Fabric Login (FLOGI) IOCB received as an ELS |
| 4175 | * unsolicited event. An unsolicited FLOGI can be received in a point-to- |
| 4176 | * point topology. As an unsolicited FLOGI should not be received in a loop |
| 4177 | * mode, any unsolicited FLOGI received in loop mode shall be ignored. The |
| 4178 | * lpfc_check_sparm() routine is invoked to check the parameters in the |
| 4179 | * unsolicited FLOGI. If parameters validation failed, the routine |
| 4180 | * lpfc_els_rsp_reject() shall be called with reject reason code set to |
| 4181 | * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the |
| 4182 | * FLOGI shall be compared with the Port WWN of the @vport to determine who |
| 4183 | * will initiate PLOGI. The higher lexicographical value party shall has |
| 4184 | * higher priority (as the winning port) and will initiate PLOGI and |
| 4185 | * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result |
| 4186 | * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI |
| 4187 | * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. |
| 4188 | * |
| 4189 | * Return code |
| 4190 | * 0 - Successfully processed the unsolicited flogi |
| 4191 | * 1 - Failed to process the unsolicited flogi |
| 4192 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4193 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4194 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4195 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4196 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4197 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4198 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4199 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4200 | uint32_t *lp = (uint32_t *) pcmd->virt; |
| 4201 | IOCB_t *icmd = &cmdiocb->iocb; |
| 4202 | struct serv_parm *sp; |
| 4203 | LPFC_MBOXQ_t *mbox; |
| 4204 | struct ls_rjt stat; |
| 4205 | uint32_t cmd, did; |
| 4206 | int rc; |
| 4207 | |
| 4208 | cmd = *lp++; |
| 4209 | sp = (struct serv_parm *) lp; |
| 4210 | |
| 4211 | /* FLOGI received */ |
| 4212 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4213 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4214 | |
| 4215 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 4216 | /* We should never receive a FLOGI in loop mode, ignore it */ |
| 4217 | did = icmd->un.elsreq64.remoteID; |
| 4218 | |
| 4219 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in |
| 4220 | Loop Mode */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4221 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4222 | "0113 An FLOGI ELS command x%x was " |
| 4223 | "received from DID x%x in Loop Mode\n", |
| 4224 | cmd, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4225 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4226 | } |
| 4227 | |
| 4228 | did = Fabric_DID; |
| 4229 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4230 | if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4231 | /* For a FLOGI we accept, then if our portname is greater |
| 4232 | * then the remote portname we initiate Nport login. |
| 4233 | */ |
| 4234 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4235 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4236 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4237 | |
| 4238 | if (!rc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4239 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4240 | if (!mbox) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4241 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4242 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4243 | lpfc_linkdown(phba); |
| 4244 | lpfc_init_link(phba, mbox, |
| 4245 | phba->cfg_topology, |
| 4246 | phba->cfg_link_speed); |
| 4247 | mbox->mb.un.varInitLnk.lipsr_AL_PA = 0; |
| 4248 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4249 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4250 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4251 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4252 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4253 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4254 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4255 | return 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4256 | } else if (rc > 0) { /* greater than */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4257 | spin_lock_irq(shost->host_lock); |
| 4258 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 4259 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4260 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4261 | spin_lock_irq(shost->host_lock); |
| 4262 | vport->fc_flag |= FC_PT2PT; |
| 4263 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 4264 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4265 | } else { |
| 4266 | /* Reject this request because invalid parameters */ |
| 4267 | stat.un.b.lsRjtRsvd0 = 0; |
| 4268 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4269 | stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; |
| 4270 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4271 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4272 | NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4273 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4274 | } |
| 4275 | |
| 4276 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4277 | lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4278 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4279 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4280 | } |
| 4281 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4282 | /** |
| 4283 | * lpfc_els_rcv_rnid: Process an unsolicited rnid iocb. |
| 4284 | * @vport: pointer to a host virtual N_Port data structure. |
| 4285 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4286 | * @ndlp: pointer to a node-list data structure. |
| 4287 | * |
| 4288 | * This routine processes Request Node Identification Data (RNID) IOCB |
| 4289 | * received as an ELS unsolicited event. Only when the RNID specified format |
| 4290 | * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) |
| 4291 | * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to |
| 4292 | * Accept (ACC) the RNID ELS command. All the other RNID formats are |
| 4293 | * rejected by invoking the lpfc_els_rsp_reject() routine. |
| 4294 | * |
| 4295 | * Return code |
| 4296 | * 0 - Successfully processed rnid iocb (currently always return 0) |
| 4297 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4298 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4299 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4300 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4301 | { |
| 4302 | struct lpfc_dmabuf *pcmd; |
| 4303 | uint32_t *lp; |
| 4304 | IOCB_t *icmd; |
| 4305 | RNID *rn; |
| 4306 | struct ls_rjt stat; |
| 4307 | uint32_t cmd, did; |
| 4308 | |
| 4309 | icmd = &cmdiocb->iocb; |
| 4310 | did = icmd->un.elsreq64.remoteID; |
| 4311 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4312 | lp = (uint32_t *) pcmd->virt; |
| 4313 | |
| 4314 | cmd = *lp++; |
| 4315 | rn = (RNID *) lp; |
| 4316 | |
| 4317 | /* RNID received */ |
| 4318 | |
| 4319 | switch (rn->Format) { |
| 4320 | case 0: |
| 4321 | case RNID_TOPOLOGY_DISC: |
| 4322 | /* Send back ACC */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4323 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4324 | break; |
| 4325 | default: |
| 4326 | /* Reject this request because format not supported */ |
| 4327 | stat.un.b.lsRjtRsvd0 = 0; |
| 4328 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4329 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4330 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4331 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4332 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4333 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4334 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4335 | } |
| 4336 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4337 | /** |
| 4338 | * lpfc_els_rcv_lirr: Process an unsolicited lirr iocb. |
| 4339 | * @vport: pointer to a host virtual N_Port data structure. |
| 4340 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4341 | * @ndlp: pointer to a node-list data structure. |
| 4342 | * |
| 4343 | * This routine processes a Link Incident Report Registration(LIRR) IOCB |
| 4344 | * received as an ELS unsolicited event. Currently, this function just invokes |
| 4345 | * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. |
| 4346 | * |
| 4347 | * Return code |
| 4348 | * 0 - Successfully processed lirr iocb (currently always return 0) |
| 4349 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4350 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4351 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4352 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4353 | { |
| 4354 | struct ls_rjt stat; |
| 4355 | |
| 4356 | /* For now, unconditionally reject this command */ |
| 4357 | stat.un.b.lsRjtRsvd0 = 0; |
| 4358 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4359 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4360 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4361 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4362 | return 0; |
| 4363 | } |
| 4364 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4365 | /** |
| 4366 | * lpfc_els_rsp_rps_acc: Completion callbk func for MBX_READ_LNK_STAT mbox cmd. |
| 4367 | * @phba: pointer to lpfc hba data structure. |
| 4368 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 4369 | * |
| 4370 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 4371 | * mailbox command. This callback function is to actually send the Accept |
| 4372 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 4373 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 4374 | * mailbox command, constructs the RPS response with the link statistics |
| 4375 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 4376 | * response to the RPS. |
| 4377 | * |
| 4378 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4379 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4380 | * will be stored into the context1 field of the IOCB for the completion |
| 4381 | * callback function to the RPS Accept Response ELS IOCB command. |
| 4382 | * |
| 4383 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 4384 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4385 | 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] | 4386 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4387 | struct lpfc_sli *psli = &phba->sli; |
| 4388 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4389 | MAILBOX_t *mb; |
| 4390 | IOCB_t *icmd; |
| 4391 | RPS_RSP *rps_rsp; |
| 4392 | uint8_t *pcmd; |
| 4393 | struct lpfc_iocbq *elsiocb; |
| 4394 | struct lpfc_nodelist *ndlp; |
| 4395 | uint16_t xri, status; |
| 4396 | uint32_t cmdsize; |
| 4397 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4398 | mb = &pmb->mb; |
| 4399 | |
| 4400 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 4401 | xri = (uint16_t) ((unsigned long)(pmb->context1)); |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 4402 | pmb->context1 = NULL; |
| 4403 | pmb->context2 = NULL; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4404 | |
| 4405 | if (mb->mbxStatus) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4406 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4407 | return; |
| 4408 | } |
| 4409 | |
| 4410 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4411 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4412 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 4413 | lpfc_max_els_tries, ndlp, |
| 4414 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4415 | |
| 4416 | /* Decrement the ndlp reference count from previous mbox command */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4417 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4418 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4419 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4420 | return; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4421 | |
| 4422 | icmd = &elsiocb->iocb; |
| 4423 | icmd->ulpContext = xri; |
| 4424 | |
| 4425 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4426 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4427 | pcmd += sizeof(uint32_t); /* Skip past command */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4428 | rps_rsp = (RPS_RSP *)pcmd; |
| 4429 | |
| 4430 | if (phba->fc_topology != TOPOLOGY_LOOP) |
| 4431 | status = 0x10; |
| 4432 | else |
| 4433 | status = 0x8; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4434 | if (phba->pport->fc_flag & FC_FABRIC) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4435 | status |= 0x4; |
| 4436 | |
| 4437 | rps_rsp->rsvd1 = 0; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4438 | rps_rsp->portStatus = cpu_to_be16(status); |
| 4439 | rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 4440 | rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 4441 | rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 4442 | rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 4443 | rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 4444 | rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4445 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4446 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 4447 | "0118 Xmit ELS RPS ACC response tag x%x xri x%x, " |
| 4448 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 4449 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4450 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4451 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4452 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4453 | phba->fc_stat.elsXmitACC++; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4454 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4455 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4456 | return; |
| 4457 | } |
| 4458 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4459 | /** |
| 4460 | * lpfc_els_rcv_rps: Process an unsolicited rps iocb. |
| 4461 | * @vport: pointer to a host virtual N_Port data structure. |
| 4462 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4463 | * @ndlp: pointer to a node-list data structure. |
| 4464 | * |
| 4465 | * This routine processes Read Port Status (RPS) IOCB received as an |
| 4466 | * ELS unsolicited event. It first checks the remote port state. If the |
| 4467 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 4468 | * state, it invokes the lpfc_els_rsp_reject() routine to send the reject |
| 4469 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 4470 | * for reading the HBA link statistics. It is for the callback function, |
| 4471 | * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 4472 | * to actually sending out RPS Accept (ACC) response. |
| 4473 | * |
| 4474 | * Return codes |
| 4475 | * 0 - Successfully processed rps iocb (currently always return 0) |
| 4476 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4477 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4478 | lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4479 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4480 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4481 | struct lpfc_hba *phba = vport->phba; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4482 | uint32_t *lp; |
| 4483 | uint8_t flag; |
| 4484 | LPFC_MBOXQ_t *mbox; |
| 4485 | struct lpfc_dmabuf *pcmd; |
| 4486 | RPS *rps; |
| 4487 | struct ls_rjt stat; |
| 4488 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4489 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4490 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
| 4491 | /* reject the unsolicited RPS request and done with it */ |
| 4492 | goto reject_out; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4493 | |
| 4494 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4495 | lp = (uint32_t *) pcmd->virt; |
| 4496 | flag = (be32_to_cpu(*lp++) & 0xf); |
| 4497 | rps = (RPS *) lp; |
| 4498 | |
| 4499 | if ((flag == 0) || |
| 4500 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4501 | ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4502 | sizeof(struct lpfc_name)) == 0))) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4503 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4504 | printk("Fix me....\n"); |
| 4505 | dump_stack(); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4506 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 4507 | if (mbox) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4508 | lpfc_read_lnk_stat(phba, mbox); |
| 4509 | mbox->context1 = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4510 | (void *)((unsigned long) cmdiocb->iocb.ulpContext); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4511 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4512 | mbox->vport = vport; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4513 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4514 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4515 | != MBX_NOT_FINISHED) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4516 | /* Mbox completion will send ELS Response */ |
| 4517 | return 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4518 | /* Decrement reference count used for the failed mbox |
| 4519 | * command. |
| 4520 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4521 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4522 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4523 | } |
| 4524 | } |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4525 | |
| 4526 | reject_out: |
| 4527 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4528 | stat.un.b.lsRjtRsvd0 = 0; |
| 4529 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4530 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4531 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4532 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4533 | return 0; |
| 4534 | } |
| 4535 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4536 | /** |
| 4537 | * lpfc_els_rsp_rpl_acc: Issue an accept rpl els command. |
| 4538 | * @vport: pointer to a host virtual N_Port data structure. |
| 4539 | * @cmdsize: size of the ELS command. |
| 4540 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4541 | * @ndlp: pointer to a node-list data structure. |
| 4542 | * |
| 4543 | * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. |
| 4544 | * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. |
| 4545 | * |
| 4546 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4547 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4548 | * will be stored into the context1 field of the IOCB for the completion |
| 4549 | * callback function to the RPL Accept Response ELS command. |
| 4550 | * |
| 4551 | * Return code |
| 4552 | * 0 - Successfully issued ACC RPL ELS command |
| 4553 | * 1 - Failed to issue ACC RPL ELS command |
| 4554 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 4555 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4556 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
| 4557 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4558 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4559 | struct lpfc_hba *phba = vport->phba; |
| 4560 | IOCB_t *icmd, *oldcmd; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4561 | RPL_RSP rpl_rsp; |
| 4562 | struct lpfc_iocbq *elsiocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4563 | struct lpfc_sli *psli = &phba->sli; |
| 4564 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4565 | uint8_t *pcmd; |
| 4566 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4567 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4568 | ndlp->nlp_DID, ELS_CMD_ACC); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4569 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4570 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4571 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4572 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4573 | icmd = &elsiocb->iocb; |
| 4574 | oldcmd = &oldiocb->iocb; |
| 4575 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 4576 | |
| 4577 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4578 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4579 | pcmd += sizeof(uint16_t); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4580 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
| 4581 | pcmd += sizeof(uint16_t); |
| 4582 | |
| 4583 | /* Setup the RPL ACC payload */ |
| 4584 | rpl_rsp.listLen = be32_to_cpu(1); |
| 4585 | rpl_rsp.index = 0; |
| 4586 | rpl_rsp.port_num_blk.portNum = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4587 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
| 4588 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4589 | sizeof(struct lpfc_name)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4590 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4591 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4592 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4593 | "0120 Xmit ELS RPL ACC response tag x%x " |
| 4594 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 4595 | "rpi x%x\n", |
| 4596 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4597 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4598 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4599 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4600 | phba->fc_stat.elsXmitACC++; |
| 4601 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
| 4602 | lpfc_els_free_iocb(phba, elsiocb); |
| 4603 | return 1; |
| 4604 | } |
| 4605 | return 0; |
| 4606 | } |
| 4607 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4608 | /** |
| 4609 | * lpfc_els_rcv_rpl: Process an unsolicited rpl iocb. |
| 4610 | * @vport: pointer to a host virtual N_Port data structure. |
| 4611 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4612 | * @ndlp: pointer to a node-list data structure. |
| 4613 | * |
| 4614 | * This routine processes Read Port List (RPL) IOCB received as an ELS |
| 4615 | * unsolicited event. It first checks the remote port state. If the remote |
| 4616 | * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it |
| 4617 | * invokes the lpfc_els_rsp_reject() routine to send reject response. |
| 4618 | * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine |
| 4619 | * to accept the RPL. |
| 4620 | * |
| 4621 | * Return code |
| 4622 | * 0 - Successfully processed rpl iocb (currently always return 0) |
| 4623 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4624 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4625 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4626 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4627 | { |
| 4628 | struct lpfc_dmabuf *pcmd; |
| 4629 | uint32_t *lp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4630 | uint32_t maxsize; |
| 4631 | uint16_t cmdsize; |
| 4632 | RPL *rpl; |
| 4633 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4634 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4635 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 4636 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4637 | /* issue rejection response */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4638 | stat.un.b.lsRjtRsvd0 = 0; |
| 4639 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4640 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4641 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4642 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4643 | NULL); |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 4644 | /* rejected the unsolicited RPL request and done with it */ |
| 4645 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4646 | } |
| 4647 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4648 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4649 | lp = (uint32_t *) pcmd->virt; |
| 4650 | rpl = (RPL *) (lp + 1); |
| 4651 | |
| 4652 | maxsize = be32_to_cpu(rpl->maxsize); |
| 4653 | |
| 4654 | /* We support only one port */ |
| 4655 | if ((rpl->index == 0) && |
| 4656 | ((maxsize == 0) || |
| 4657 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { |
| 4658 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4659 | } else { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4660 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
| 4661 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4662 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4663 | |
| 4664 | return 0; |
| 4665 | } |
| 4666 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4667 | /** |
| 4668 | * lpfc_els_rcv_farp: Process an unsolicited farp request els command. |
| 4669 | * @vport: pointer to a virtual N_Port data structure. |
| 4670 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4671 | * @ndlp: pointer to a node-list data structure. |
| 4672 | * |
| 4673 | * This routine processes Fibre Channel Address Resolution Protocol |
| 4674 | * (FARP) Request IOCB received as an ELS unsolicited event. Currently, |
| 4675 | * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, |
| 4676 | * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the |
| 4677 | * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the |
| 4678 | * remote PortName is compared against the FC PortName stored in the @vport |
| 4679 | * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is |
| 4680 | * compared against the FC NodeName stored in the @vport data structure. |
| 4681 | * If any of these matches and the FARP_REQUEST_FARPR flag is set in the |
| 4682 | * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is |
| 4683 | * invoked to send out FARP Response to the remote node. Before sending the |
| 4684 | * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP |
| 4685 | * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() |
| 4686 | * routine is invoked to log into the remote port first. |
| 4687 | * |
| 4688 | * Return code |
| 4689 | * 0 - Either the FARP Match Mode not supported or successfully processed |
| 4690 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4691 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4692 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4693 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4694 | { |
| 4695 | struct lpfc_dmabuf *pcmd; |
| 4696 | uint32_t *lp; |
| 4697 | IOCB_t *icmd; |
| 4698 | FARP *fp; |
| 4699 | uint32_t cmd, cnt, did; |
| 4700 | |
| 4701 | icmd = &cmdiocb->iocb; |
| 4702 | did = icmd->un.elsreq64.remoteID; |
| 4703 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4704 | lp = (uint32_t *) pcmd->virt; |
| 4705 | |
| 4706 | cmd = *lp++; |
| 4707 | fp = (FARP *) lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4708 | /* FARP-REQ received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4709 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4710 | "0601 FARP-REQ received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4711 | /* We will only support match on WWPN or WWNN */ |
| 4712 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4713 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4714 | } |
| 4715 | |
| 4716 | cnt = 0; |
| 4717 | /* If this FARP command is searching for my portname */ |
| 4718 | if (fp->Mflags & FARP_MATCH_PORT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4719 | if (memcmp(&fp->RportName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4720 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4721 | cnt = 1; |
| 4722 | } |
| 4723 | |
| 4724 | /* If this FARP command is searching for my nodename */ |
| 4725 | if (fp->Mflags & FARP_MATCH_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4726 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4727 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4728 | cnt = 1; |
| 4729 | } |
| 4730 | |
| 4731 | if (cnt) { |
| 4732 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 4733 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { |
| 4734 | /* Log back into the node before sending the FARP. */ |
| 4735 | if (fp->Rflags & FARP_REQUEST_PLOGI) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4736 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4737 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4738 | NLP_STE_PLOGI_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4739 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4740 | } |
| 4741 | |
| 4742 | /* Send a FARP response to that node */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4743 | if (fp->Rflags & FARP_REQUEST_FARPR) |
| 4744 | lpfc_issue_els_farpr(vport, did, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4745 | } |
| 4746 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4747 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4748 | } |
| 4749 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4750 | /** |
| 4751 | * lpfc_els_rcv_farpr: Process an unsolicited farp response iocb. |
| 4752 | * @vport: pointer to a host virtual N_Port data structure. |
| 4753 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4754 | * @ndlp: pointer to a node-list data structure. |
| 4755 | * |
| 4756 | * This routine processes Fibre Channel Address Resolution Protocol |
| 4757 | * Response (FARPR) IOCB received as an ELS unsolicited event. It simply |
| 4758 | * invokes the lpfc_els_rsp_acc() routine to the remote node to accept |
| 4759 | * the FARP response request. |
| 4760 | * |
| 4761 | * Return code |
| 4762 | * 0 - Successfully processed FARPR IOCB (currently always return 0) |
| 4763 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4764 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4765 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4766 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4767 | { |
| 4768 | struct lpfc_dmabuf *pcmd; |
| 4769 | uint32_t *lp; |
| 4770 | IOCB_t *icmd; |
| 4771 | uint32_t cmd, did; |
| 4772 | |
| 4773 | icmd = &cmdiocb->iocb; |
| 4774 | did = icmd->un.elsreq64.remoteID; |
| 4775 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4776 | lp = (uint32_t *) pcmd->virt; |
| 4777 | |
| 4778 | cmd = *lp++; |
| 4779 | /* FARP-RSP received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4780 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4781 | "0600 FARP-RSP received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4782 | /* ACCEPT the Farp resp request */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4783 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4784 | |
| 4785 | return 0; |
| 4786 | } |
| 4787 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4788 | /** |
| 4789 | * lpfc_els_rcv_fan: Process an unsolicited fan iocb command. |
| 4790 | * @vport: pointer to a host virtual N_Port data structure. |
| 4791 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4792 | * @fan_ndlp: pointer to a node-list data structure. |
| 4793 | * |
| 4794 | * This routine processes a Fabric Address Notification (FAN) IOCB |
| 4795 | * command received as an ELS unsolicited event. The FAN ELS command will |
| 4796 | * only be processed on a physical port (i.e., the @vport represents the |
| 4797 | * physical port). The fabric NodeName and PortName from the FAN IOCB are |
| 4798 | * compared against those in the phba data structure. If any of those is |
| 4799 | * different, the lpfc_initial_flogi() routine is invoked to initialize |
| 4800 | * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, |
| 4801 | * if both of those are identical, the lpfc_issue_fabric_reglogin() routine |
| 4802 | * is invoked to register login to the fabric. |
| 4803 | * |
| 4804 | * Return code |
| 4805 | * 0 - Successfully processed fan iocb (currently always return 0). |
| 4806 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4807 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4808 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4809 | struct lpfc_nodelist *fan_ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4810 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4811 | struct lpfc_hba *phba = vport->phba; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4812 | uint32_t *lp; |
| 4813 | FAN *fp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4814 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4815 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); |
| 4816 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; |
| 4817 | fp = (FAN *) ++lp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4818 | /* FAN received; Fan does not have a reply sequence */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4819 | if ((vport == phba->pport) && |
| 4820 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4821 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4822 | sizeof(struct lpfc_name))) || |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4823 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4824 | sizeof(struct lpfc_name)))) { |
| 4825 | /* This port has switched fabrics. FLOGI is required */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4826 | lpfc_initial_flogi(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4827 | } else { |
| 4828 | /* FAN verified - skip FLOGI */ |
| 4829 | vport->fc_myDID = vport->fc_prevDID; |
| 4830 | lpfc_issue_fabric_reglogin(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4831 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4832 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4833 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4834 | } |
| 4835 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4836 | /** |
| 4837 | * lpfc_els_timeout: Handler funciton to the els timer. |
| 4838 | * @ptr: holder for the timer function associated data. |
| 4839 | * |
| 4840 | * This routine is invoked by the ELS timer after timeout. It posts the ELS |
| 4841 | * timer timeout event by setting the WORKER_ELS_TMO bit to the work port |
| 4842 | * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake |
| 4843 | * up the worker thread. It is for the worker thread to invoke the routine |
| 4844 | * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. |
| 4845 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4846 | void |
| 4847 | lpfc_els_timeout(unsigned long ptr) |
| 4848 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4849 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 4850 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4851 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4852 | unsigned long iflag; |
| 4853 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4854 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4855 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; |
| 4856 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4857 | vport->work_port_events |= WORKER_ELS_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4858 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4859 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4860 | if (!tmo_posted) |
| 4861 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4862 | return; |
| 4863 | } |
| 4864 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4865 | /** |
| 4866 | * lpfc_els_timeout_handler: Process an els timeout event. |
| 4867 | * @vport: pointer to a virtual N_Port data structure. |
| 4868 | * |
| 4869 | * This routine is the actual handler function that processes an ELS timeout |
| 4870 | * event. It walks the ELS ring to get and abort all the IOCBs (except the |
| 4871 | * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by |
| 4872 | * invoking the lpfc_sli_issue_abort_iotag() routine. |
| 4873 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4874 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4875 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4876 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4877 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4878 | struct lpfc_sli_ring *pring; |
| 4879 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 4880 | IOCB_t *cmd = NULL; |
| 4881 | struct lpfc_dmabuf *pcmd; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4882 | uint32_t els_command = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4883 | uint32_t timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4884 | uint32_t remote_ID = 0xffffffff; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4885 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4886 | /* If the timer is already canceled do nothing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4887 | if ((vport->work_port_events & WORKER_ELS_TMO) == 0) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4888 | return; |
| 4889 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4890 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4891 | timeout = (uint32_t)(phba->fc_ratov << 1); |
| 4892 | |
| 4893 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4894 | |
| 4895 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 4896 | cmd = &piocb->iocb; |
| 4897 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4898 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
| 4899 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 4900 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4901 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4902 | |
| 4903 | if (piocb->vport != vport) |
| 4904 | continue; |
| 4905 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4906 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4907 | if (pcmd) |
| 4908 | els_command = *(uint32_t *) (pcmd->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4909 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4910 | if (els_command == ELS_CMD_FARP || |
| 4911 | els_command == ELS_CMD_FARPR || |
| 4912 | els_command == ELS_CMD_FDISC) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4913 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4914 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4915 | if (piocb->drvrTimeout > 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4916 | if (piocb->drvrTimeout >= timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4917 | piocb->drvrTimeout -= timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4918 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4919 | piocb->drvrTimeout = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4920 | continue; |
| 4921 | } |
| 4922 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4923 | remote_ID = 0xffffffff; |
| 4924 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4925 | remote_ID = cmd->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4926 | else { |
| 4927 | struct lpfc_nodelist *ndlp; |
| 4928 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4929 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4930 | remote_ID = ndlp->nlp_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4931 | } |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4932 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4933 | "0127 ELS timeout Data: x%x x%x x%x " |
| 4934 | "x%x\n", els_command, |
| 4935 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4936 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4937 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4938 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 4939 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4940 | if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) |
| 4941 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4942 | } |
| 4943 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4944 | /** |
| 4945 | * lpfc_els_flush_cmd: Clean up the outstanding els commands to a vport. |
| 4946 | * @vport: pointer to a host virtual N_Port data structure. |
| 4947 | * |
| 4948 | * This routine is used to clean up all the outstanding ELS commands on a |
| 4949 | * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() |
| 4950 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 4951 | * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 4952 | * the IOCBs with a non-NULL completion callback function, the callback |
| 4953 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 4954 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion |
| 4955 | * callback function, the IOCB will simply be released. Finally, it walks |
| 4956 | * the ELS transmit completion queue to issue an abort IOCB to any transmit |
| 4957 | * completion queue IOCB that is associated with the @vport and is not |
| 4958 | * an IOCB from libdfc (i.e., the management plane IOCBs that are not |
| 4959 | * part of the discovery state machine) out to HBA by invoking the |
| 4960 | * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the |
| 4961 | * abort IOCB to any transmit completion queueed IOCB, it does not guarantee |
| 4962 | * the IOCBs are aborted when this function returns. |
| 4963 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4964 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4965 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4966 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4967 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4968 | struct lpfc_hba *phba = vport->phba; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4969 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4970 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 4971 | IOCB_t *cmd = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4972 | |
| 4973 | lpfc_fabric_abort_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4974 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4975 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4976 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 4977 | cmd = &piocb->iocb; |
| 4978 | |
| 4979 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 4980 | continue; |
| 4981 | } |
| 4982 | |
| 4983 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4984 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 4985 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 4986 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 4987 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4988 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4989 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4990 | if (piocb->vport != vport) |
| 4991 | continue; |
| 4992 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4993 | list_move_tail(&piocb->list, &completions); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 4994 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4995 | } |
| 4996 | |
| 4997 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4998 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 4999 | continue; |
| 5000 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5001 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5002 | if (piocb->vport != vport) |
| 5003 | continue; |
| 5004 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 5005 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5006 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5007 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5008 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5009 | while (!list_empty(&completions)) { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5010 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| 5011 | cmd = &piocb->iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5012 | list_del_init(&piocb->list); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5013 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5014 | if (!piocb->iocb_cmpl) |
| 5015 | lpfc_sli_release_iocbq(phba, piocb); |
| 5016 | else { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5017 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 5018 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 5019 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5020 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5021 | } |
| 5022 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5023 | return; |
| 5024 | } |
| 5025 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5026 | /** |
| 5027 | * lpfc_els_flush_all_cmd: Clean up all the outstanding els commands to a HBA. |
| 5028 | * @phba: pointer to lpfc hba data structure. |
| 5029 | * |
| 5030 | * This routine is used to clean up all the outstanding ELS commands on a |
| 5031 | * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() |
| 5032 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 5033 | * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5034 | * the IOCBs with the completion callback function associated, the callback |
| 5035 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5036 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion |
| 5037 | * callback function associated, the IOCB will simply be released. Finally, |
| 5038 | * it walks the ELS transmit completion queue to issue an abort IOCB to any |
| 5039 | * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the |
| 5040 | * management plane IOCBs that are not part of the discovery state machine) |
| 5041 | * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. |
| 5042 | **/ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5043 | void |
| 5044 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) |
| 5045 | { |
| 5046 | LIST_HEAD(completions); |
| 5047 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 5048 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5049 | IOCB_t *cmd = NULL; |
| 5050 | |
| 5051 | lpfc_fabric_abort_hba(phba); |
| 5052 | spin_lock_irq(&phba->hbalock); |
| 5053 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5054 | cmd = &piocb->iocb; |
| 5055 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5056 | continue; |
| 5057 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
| 5058 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5059 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5060 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5061 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| 5062 | continue; |
| 5063 | list_move_tail(&piocb->list, &completions); |
| 5064 | pring->txq_cnt--; |
| 5065 | } |
| 5066 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 5067 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5068 | continue; |
| 5069 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 5070 | } |
| 5071 | spin_unlock_irq(&phba->hbalock); |
| 5072 | while (!list_empty(&completions)) { |
| 5073 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| 5074 | cmd = &piocb->iocb; |
| 5075 | list_del_init(&piocb->list); |
| 5076 | if (!piocb->iocb_cmpl) |
| 5077 | lpfc_sli_release_iocbq(phba, piocb); |
| 5078 | else { |
| 5079 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 5080 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 5081 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 5082 | } |
| 5083 | } |
| 5084 | return; |
| 5085 | } |
| 5086 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5087 | /** |
| 5088 | * lpfc_els_unsol_buffer: Process an unsolicited event data buffer. |
| 5089 | * @phba: pointer to lpfc hba data structure. |
| 5090 | * @pring: pointer to a SLI ring. |
| 5091 | * @vport: pointer to a host virtual N_Port data structure. |
| 5092 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 5093 | * |
| 5094 | * This routine is used for processing the IOCB associated with a unsolicited |
| 5095 | * event. It first determines whether there is an existing ndlp that matches |
| 5096 | * the DID from the unsolicited IOCB. If not, it will create a new one with |
| 5097 | * the DID from the unsolicited IOCB. The ELS command from the unsolicited |
| 5098 | * IOCB is then used to invoke the proper routine and to set up proper state |
| 5099 | * of the discovery state machine. |
| 5100 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5101 | static void |
| 5102 | 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] | 5103 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5104 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5105 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5106 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5107 | struct ls_rjt stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5108 | uint32_t *payload; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5109 | uint32_t cmd, did, newnode, rjt_err = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5110 | IOCB_t *icmd = &elsiocb->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5111 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5112 | if (!vport || !(elsiocb->context2)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5113 | goto dropit; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5114 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5115 | newnode = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5116 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
| 5117 | cmd = *payload; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5118 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5119 | lpfc_post_buffer(phba, pring, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5120 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5121 | did = icmd->un.rcvels.remoteID; |
| 5122 | if (icmd->ulpStatus) { |
| 5123 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5124 | "RCV Unsol ELS: status:x%x/x%x did:x%x", |
| 5125 | icmd->ulpStatus, icmd->un.ulpWord[4], did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5126 | goto dropit; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5127 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5128 | |
| 5129 | /* Check to see if link went down during discovery */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5130 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5131 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5132 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5133 | /* Ignore traffic recevied during vport shutdown. */ |
| 5134 | if (vport->load_flag & FC_UNLOADING) |
| 5135 | goto dropit; |
| 5136 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5137 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5138 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5139 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5140 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5141 | if (!ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5142 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5143 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5144 | lpfc_nlp_init(vport, ndlp, did); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5145 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5146 | newnode = 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5147 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5148 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5149 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5150 | ndlp = lpfc_enable_node(vport, ndlp, |
| 5151 | NLP_STE_UNUSED_NODE); |
| 5152 | if (!ndlp) |
| 5153 | goto dropit; |
| 5154 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5155 | newnode = 1; |
| 5156 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| 5157 | ndlp->nlp_type |= NLP_FABRIC; |
| 5158 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 5159 | /* This is similar to the new node path */ |
| 5160 | ndlp = lpfc_nlp_get(ndlp); |
| 5161 | if (!ndlp) |
| 5162 | goto dropit; |
| 5163 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5164 | newnode = 1; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5165 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5166 | |
| 5167 | phba->fc_stat.elsRcvFrame++; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5168 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5169 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5170 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5171 | |
| 5172 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { |
| 5173 | cmd &= ELS_CMD_MASK; |
| 5174 | } |
| 5175 | /* ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5176 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5177 | "0112 ELS command x%x received from NPORT x%x " |
| 5178 | "Data: x%x\n", cmd, did, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5179 | switch (cmd) { |
| 5180 | case ELS_CMD_PLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5181 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5182 | "RCV PLOGI: did:x%x/ste:x%x flg:x%x", |
| 5183 | did, vport->port_state, ndlp->nlp_flag); |
| 5184 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5185 | phba->fc_stat.elsRcvPLOGI++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5186 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
| 5187 | |
| 5188 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 5189 | if (!(phba->pport->fc_flag & FC_PT2PT) || |
| 5190 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { |
| 5191 | rjt_err = LSRJT_UNABLE_TPC; |
| 5192 | break; |
| 5193 | } |
| 5194 | /* We get here, and drop thru, if we are PT2PT with |
| 5195 | * another NPort and the other side has initiated |
| 5196 | * the PLOGI before responding to our FLOGI. |
| 5197 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5198 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5199 | |
| 5200 | shost = lpfc_shost_from_vport(vport); |
| 5201 | spin_lock_irq(shost->host_lock); |
| 5202 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; |
| 5203 | spin_unlock_irq(shost->host_lock); |
| 5204 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5205 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5206 | NLP_EVT_RCV_PLOGI); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5207 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5208 | break; |
| 5209 | case ELS_CMD_FLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5210 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5211 | "RCV FLOGI: did:x%x/ste:x%x flg:x%x", |
| 5212 | did, vport->port_state, ndlp->nlp_flag); |
| 5213 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5214 | phba->fc_stat.elsRcvFLOGI++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5215 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5216 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5217 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5218 | break; |
| 5219 | case ELS_CMD_LOGO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5220 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5221 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", |
| 5222 | did, vport->port_state, ndlp->nlp_flag); |
| 5223 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5224 | phba->fc_stat.elsRcvLOGO++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5225 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5226 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5227 | break; |
| 5228 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5229 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5230 | break; |
| 5231 | case ELS_CMD_PRLO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5232 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5233 | "RCV PRLO: did:x%x/ste:x%x flg:x%x", |
| 5234 | did, vport->port_state, ndlp->nlp_flag); |
| 5235 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5236 | phba->fc_stat.elsRcvPRLO++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5237 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5238 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5239 | break; |
| 5240 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5241 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5242 | break; |
| 5243 | case ELS_CMD_RSCN: |
| 5244 | phba->fc_stat.elsRcvRSCN++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5245 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5246 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5247 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5248 | break; |
| 5249 | case ELS_CMD_ADISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5250 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5251 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", |
| 5252 | did, vport->port_state, ndlp->nlp_flag); |
| 5253 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5254 | phba->fc_stat.elsRcvADISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5255 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5256 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5257 | break; |
| 5258 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5259 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5260 | NLP_EVT_RCV_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5261 | break; |
| 5262 | case ELS_CMD_PDISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5263 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5264 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", |
| 5265 | did, vport->port_state, ndlp->nlp_flag); |
| 5266 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5267 | phba->fc_stat.elsRcvPDISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5268 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5269 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5270 | break; |
| 5271 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5272 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5273 | NLP_EVT_RCV_PDISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5274 | break; |
| 5275 | case ELS_CMD_FARPR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5276 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5277 | "RCV FARPR: did:x%x/ste:x%x flg:x%x", |
| 5278 | did, vport->port_state, ndlp->nlp_flag); |
| 5279 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5280 | phba->fc_stat.elsRcvFARPR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5281 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5282 | break; |
| 5283 | case ELS_CMD_FARP: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5284 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5285 | "RCV FARP: did:x%x/ste:x%x flg:x%x", |
| 5286 | did, vport->port_state, ndlp->nlp_flag); |
| 5287 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5288 | phba->fc_stat.elsRcvFARP++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5289 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5290 | break; |
| 5291 | case ELS_CMD_FAN: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5292 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5293 | "RCV FAN: did:x%x/ste:x%x flg:x%x", |
| 5294 | did, vport->port_state, ndlp->nlp_flag); |
| 5295 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5296 | phba->fc_stat.elsRcvFAN++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5297 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5298 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5299 | case ELS_CMD_PRLI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5300 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5301 | "RCV PRLI: did:x%x/ste:x%x flg:x%x", |
| 5302 | did, vport->port_state, ndlp->nlp_flag); |
| 5303 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5304 | phba->fc_stat.elsRcvPRLI++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5305 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5306 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5307 | break; |
| 5308 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5309 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5310 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5311 | case ELS_CMD_LIRR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5312 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5313 | "RCV LIRR: did:x%x/ste:x%x flg:x%x", |
| 5314 | did, vport->port_state, ndlp->nlp_flag); |
| 5315 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5316 | phba->fc_stat.elsRcvLIRR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5317 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5318 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5319 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5320 | break; |
| 5321 | case ELS_CMD_RPS: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5322 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5323 | "RCV RPS: did:x%x/ste:x%x flg:x%x", |
| 5324 | did, vport->port_state, ndlp->nlp_flag); |
| 5325 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5326 | phba->fc_stat.elsRcvRPS++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5327 | lpfc_els_rcv_rps(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5328 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5329 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5330 | break; |
| 5331 | case ELS_CMD_RPL: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5332 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5333 | "RCV RPL: did:x%x/ste:x%x flg:x%x", |
| 5334 | did, vport->port_state, ndlp->nlp_flag); |
| 5335 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5336 | phba->fc_stat.elsRcvRPL++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5337 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5338 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5339 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5340 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5341 | case ELS_CMD_RNID: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5342 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5343 | "RCV RNID: did:x%x/ste:x%x flg:x%x", |
| 5344 | did, vport->port_state, ndlp->nlp_flag); |
| 5345 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5346 | phba->fc_stat.elsRcvRNID++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5347 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5348 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5349 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5350 | break; |
| 5351 | default: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5352 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5353 | "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", |
| 5354 | cmd, did, vport->port_state); |
| 5355 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5356 | /* Unsupported ELS command, reject */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5357 | rjt_err = LSRJT_INVALID_CMD; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5358 | |
| 5359 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5360 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5361 | "0115 Unknown ELS command x%x " |
| 5362 | "received from NPORT x%x\n", cmd, did); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5363 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5364 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5365 | break; |
| 5366 | } |
| 5367 | |
| 5368 | /* check if need to LS_RJT received ELS cmd */ |
| 5369 | if (rjt_err) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5370 | memset(&stat, 0, sizeof(stat)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5371 | stat.un.b.lsRjtRsnCode = rjt_err; |
James.Smart@Emulex.Com | 1f679ca | 2005-06-25 10:34:27 -0400 | [diff] [blame] | 5372 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5373 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
| 5374 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5375 | } |
| 5376 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame^] | 5377 | lpfc_nlp_put(elsiocb->context1); |
| 5378 | elsiocb->context1 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5379 | return; |
| 5380 | |
| 5381 | dropit: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5382 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
| 5383 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5384 | "(%d):0111 Dropping received ELS cmd " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5385 | "Data: x%x x%x x%x\n", |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5386 | vport->vpi, icmd->ulpStatus, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5387 | icmd->un.ulpWord[4], icmd->ulpTimeout); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5388 | phba->fc_stat.elsRcvDrop++; |
| 5389 | } |
| 5390 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5391 | /** |
| 5392 | * lpfc_find_vport_by_vpid: Find a vport on a HBA through vport identifier. |
| 5393 | * @phba: pointer to lpfc hba data structure. |
| 5394 | * @vpi: host virtual N_Port identifier. |
| 5395 | * |
| 5396 | * This routine finds a vport on a HBA (referred by @phba) through a |
| 5397 | * @vpi. The function walks the HBA's vport list and returns the address |
| 5398 | * of the vport with the matching @vpi. |
| 5399 | * |
| 5400 | * Return code |
| 5401 | * NULL - No vport with the matching @vpi found |
| 5402 | * Otherwise - Address to the vport with the matching @vpi. |
| 5403 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5404 | static struct lpfc_vport * |
| 5405 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) |
| 5406 | { |
| 5407 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5408 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5409 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5410 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5411 | list_for_each_entry(vport, &phba->port_list, listentry) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5412 | if (vport->vpi == vpi) { |
| 5413 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5414 | return vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5415 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5416 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5417 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5418 | return NULL; |
| 5419 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5420 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5421 | /** |
| 5422 | * lpfc_els_unsol_event: Process an unsolicited event from an els sli ring. |
| 5423 | * @phba: pointer to lpfc hba data structure. |
| 5424 | * @pring: pointer to a SLI ring. |
| 5425 | * @elsiocb: pointer to lpfc els iocb data structure. |
| 5426 | * |
| 5427 | * This routine is used to process an unsolicited event received from a SLI |
| 5428 | * (Service Level Interface) ring. The actual processing of the data buffer |
| 5429 | * associated with the unsolicited event is done by invoking the routine |
| 5430 | * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the |
| 5431 | * SLI ring on which the unsolicited event was received. |
| 5432 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5433 | void |
| 5434 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 5435 | struct lpfc_iocbq *elsiocb) |
| 5436 | { |
| 5437 | struct lpfc_vport *vport = phba->pport; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5438 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5439 | dma_addr_t paddr; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5440 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
| 5441 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5442 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame^] | 5443 | elsiocb->context1 = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5444 | elsiocb->context2 = NULL; |
| 5445 | elsiocb->context3 = NULL; |
| 5446 | |
| 5447 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
| 5448 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 5449 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 5450 | (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5451 | phba->fc_stat.NoRcvBuf++; |
| 5452 | /* Not enough posted buffers; Try posting more buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5453 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5454 | lpfc_post_buffer(phba, pring, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5455 | return; |
| 5456 | } |
| 5457 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5458 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 5459 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || |
| 5460 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 5461 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) |
| 5462 | vport = phba->pport; |
| 5463 | else { |
| 5464 | uint16_t vpi = icmd->unsli3.rcvsli3.vpi; |
| 5465 | vport = lpfc_find_vport_by_vpid(phba, vpi); |
| 5466 | } |
| 5467 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5468 | /* If there are no BDEs associated |
| 5469 | * with this IOCB, there is nothing to do. |
| 5470 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5471 | if (icmd->ulpBdeCount == 0) |
| 5472 | return; |
| 5473 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5474 | /* type of ELS cmd is first 32bit word |
| 5475 | * in packet |
| 5476 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5477 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5478 | elsiocb->context2 = bdeBuf1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5479 | } else { |
| 5480 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, |
| 5481 | icmd->un.cont64[0].addrLow); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5482 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
| 5483 | paddr); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5484 | } |
| 5485 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5486 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
| 5487 | /* |
| 5488 | * The different unsolicited event handlers would tell us |
| 5489 | * if they are done with "mp" by setting context2 to NULL. |
| 5490 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5491 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5492 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
| 5493 | elsiocb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5494 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5495 | |
| 5496 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5497 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5498 | icmd->ulpBdeCount == 2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5499 | elsiocb->context2 = bdeBuf2; |
| 5500 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5501 | /* free mp if we are done with it */ |
| 5502 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5503 | lpfc_in_buf_free(phba, elsiocb->context2); |
| 5504 | elsiocb->context2 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5505 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5506 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5507 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5508 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5509 | /** |
| 5510 | * lpfc_do_scr_ns_plogi: Issue a plogi to the name server for scr. |
| 5511 | * @phba: pointer to lpfc hba data structure. |
| 5512 | * @vport: pointer to a virtual N_Port data structure. |
| 5513 | * |
| 5514 | * This routine issues a Port Login (PLOGI) to the Name Server with |
| 5515 | * State Change Request (SCR) for a @vport. This routine will create an |
| 5516 | * ndlp for the Name Server associated to the @vport if such node does |
| 5517 | * not already exist. The PLOGI to Name Server is issued by invoking the |
| 5518 | * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface |
| 5519 | * (FDMI) is configured to the @vport, a FDMI node will be created and |
| 5520 | * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. |
| 5521 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5522 | void |
| 5523 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 5524 | { |
| 5525 | struct lpfc_nodelist *ndlp, *ndlp_fdmi; |
| 5526 | |
| 5527 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 5528 | if (!ndlp) { |
| 5529 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 5530 | if (!ndlp) { |
| 5531 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 5532 | lpfc_disc_start(vport); |
| 5533 | return; |
| 5534 | } |
| 5535 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5536 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5537 | "0251 NameServer login: no memory\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5538 | return; |
| 5539 | } |
| 5540 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5541 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5542 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 5543 | if (!ndlp) { |
| 5544 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 5545 | lpfc_disc_start(vport); |
| 5546 | return; |
| 5547 | } |
| 5548 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 5549 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5550 | "0348 NameServer login: node freed\n"); |
| 5551 | return; |
| 5552 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5553 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5554 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5555 | |
| 5556 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 5557 | |
| 5558 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { |
| 5559 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5560 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5561 | "0252 Cannot issue NameServer login\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5562 | return; |
| 5563 | } |
| 5564 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5565 | if (vport->cfg_fdmi_on) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5566 | ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool, |
| 5567 | GFP_KERNEL); |
| 5568 | if (ndlp_fdmi) { |
| 5569 | lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID); |
| 5570 | ndlp_fdmi->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5571 | lpfc_nlp_set_state(vport, ndlp_fdmi, |
| 5572 | NLP_STE_PLOGI_ISSUE); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5573 | lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, |
| 5574 | 0); |
| 5575 | } |
| 5576 | } |
| 5577 | return; |
| 5578 | } |
| 5579 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5580 | /** |
| 5581 | * lpfc_cmpl_reg_new_vport: Completion callback function to register new vport. |
| 5582 | * @phba: pointer to lpfc hba data structure. |
| 5583 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 5584 | * |
| 5585 | * This routine is the completion callback function to register new vport |
| 5586 | * mailbox command. If the new vport mailbox command completes successfully, |
| 5587 | * the fabric registration login shall be performed on physical port (the |
| 5588 | * new vport created is actually a physical port, with VPI 0) or the port |
| 5589 | * login to Name Server for State Change Request (SCR) will be performed |
| 5590 | * on virtual port (real virtual port, with VPI greater than 0). |
| 5591 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5592 | static void |
| 5593 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 5594 | { |
| 5595 | struct lpfc_vport *vport = pmb->vport; |
| 5596 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5597 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 5598 | MAILBOX_t *mb = &pmb->mb; |
| 5599 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5600 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5601 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5602 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5603 | |
| 5604 | if (mb->mbxStatus) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5605 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 5606 | "0915 Register VPI failed: 0x%x\n", |
| 5607 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5608 | |
| 5609 | switch (mb->mbxStatus) { |
| 5610 | case 0x11: /* unsupported feature */ |
| 5611 | case 0x9603: /* max_vpi exceeded */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5612 | case 0x9602: /* Link event since CLEAR_LA */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5613 | /* giving up on vport registration */ |
| 5614 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 5615 | spin_lock_irq(shost->host_lock); |
| 5616 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 5617 | spin_unlock_irq(shost->host_lock); |
| 5618 | lpfc_can_disctmo(vport); |
| 5619 | break; |
| 5620 | default: |
| 5621 | /* Try to recover from this error */ |
| 5622 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5623 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5624 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5625 | spin_unlock_irq(shost->host_lock); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5626 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 5627 | lpfc_initial_flogi(vport); |
| 5628 | else |
| 5629 | lpfc_initial_fdisc(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5630 | break; |
| 5631 | } |
| 5632 | |
| 5633 | } else { |
| 5634 | if (vport == phba->pport) |
| 5635 | lpfc_issue_fabric_reglogin(vport); |
| 5636 | else |
| 5637 | lpfc_do_scr_ns_plogi(phba, vport); |
| 5638 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5639 | |
| 5640 | /* Now, we decrement the ndlp reference count held for this |
| 5641 | * callback function |
| 5642 | */ |
| 5643 | lpfc_nlp_put(ndlp); |
| 5644 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5645 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5646 | return; |
| 5647 | } |
| 5648 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5649 | /** |
| 5650 | * lpfc_register_new_vport: Register a new vport with a HBA. |
| 5651 | * @phba: pointer to lpfc hba data structure. |
| 5652 | * @vport: pointer to a host virtual N_Port data structure. |
| 5653 | * @ndlp: pointer to a node-list data structure. |
| 5654 | * |
| 5655 | * This routine registers the @vport as a new virtual port with a HBA. |
| 5656 | * It is done through a registering vpi mailbox command. |
| 5657 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 5658 | static void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5659 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 5660 | struct lpfc_nodelist *ndlp) |
| 5661 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5662 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5663 | LPFC_MBOXQ_t *mbox; |
| 5664 | |
| 5665 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5666 | if (mbox) { |
| 5667 | lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, mbox); |
| 5668 | mbox->vport = vport; |
| 5669 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 5670 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5671 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5672 | == MBX_NOT_FINISHED) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5673 | /* mailbox command not success, decrement ndlp |
| 5674 | * reference count for this command |
| 5675 | */ |
| 5676 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5677 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5678 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5679 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 5680 | "0253 Register VPI: Can't send mbox\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5681 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5682 | } |
| 5683 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5684 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 5685 | "0254 Register VPI: no memory\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5686 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5687 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5688 | return; |
| 5689 | |
| 5690 | mbox_err_exit: |
| 5691 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 5692 | spin_lock_irq(shost->host_lock); |
| 5693 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 5694 | spin_unlock_irq(shost->host_lock); |
| 5695 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5696 | } |
| 5697 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5698 | /** |
| 5699 | * lpfc_cmpl_els_fdisc: Completion function for fdisc iocb command. |
| 5700 | * @phba: pointer to lpfc hba data structure. |
| 5701 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5702 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 5703 | * |
| 5704 | * This routine is the completion callback function to a Fabric Discover |
| 5705 | * (FDISC) ELS command. Since all the FDISC ELS commands are issued |
| 5706 | * single threaded, each FDISC completion callback function will reset |
| 5707 | * the discovery timer for all vports such that the timers will not get |
| 5708 | * unnecessary timeout. The function checks the FDISC IOCB status. If error |
| 5709 | * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the |
| 5710 | * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID |
| 5711 | * assigned to the vport has been changed with the completion of the FDISC |
| 5712 | * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) |
| 5713 | * are unregistered from the HBA, and then the lpfc_register_new_vport() |
| 5714 | * routine is invoked to register new vport with the HBA. Otherwise, the |
| 5715 | * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name |
| 5716 | * Server for State Change Request (SCR). |
| 5717 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5718 | static void |
| 5719 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 5720 | struct lpfc_iocbq *rspiocb) |
| 5721 | { |
| 5722 | struct lpfc_vport *vport = cmdiocb->vport; |
| 5723 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5724 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 5725 | struct lpfc_nodelist *np; |
| 5726 | struct lpfc_nodelist *next_np; |
| 5727 | IOCB_t *irsp = &rspiocb->iocb; |
| 5728 | struct lpfc_iocbq *piocb; |
| 5729 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5730 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5731 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", |
| 5732 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 5733 | vport->fc_prevDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5734 | /* Since all FDISCs are being single threaded, we |
| 5735 | * must reset the discovery timer for ALL vports |
| 5736 | * waiting to send FDISC when one completes. |
| 5737 | */ |
| 5738 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { |
| 5739 | lpfc_set_disctmo(piocb->vport); |
| 5740 | } |
| 5741 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5742 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 5743 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", |
| 5744 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); |
| 5745 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5746 | if (irsp->ulpStatus) { |
| 5747 | /* Check for retry */ |
| 5748 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| 5749 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5750 | /* FDISC failed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5751 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame^] | 5752 | "0126 FDISC failed. (%d/%d)\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5753 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame^] | 5754 | goto fdisc_failed; |
| 5755 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5756 | if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING) |
| 5757 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5758 | lpfc_nlp_put(ndlp); |
| 5759 | /* giving up on FDISC. Cancel discovery timer */ |
| 5760 | lpfc_can_disctmo(vport); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame^] | 5761 | spin_lock_irq(shost->host_lock); |
| 5762 | vport->fc_flag |= FC_FABRIC; |
| 5763 | if (vport->phba->fc_topology == TOPOLOGY_LOOP) |
| 5764 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 5765 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5766 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame^] | 5767 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| 5768 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); |
| 5769 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 5770 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 5771 | /* If our NportID changed, we need to ensure all |
| 5772 | * remaining NPORTs get unreg_login'ed so we can |
| 5773 | * issue unreg_vpi. |
| 5774 | */ |
| 5775 | list_for_each_entry_safe(np, next_np, |
| 5776 | &vport->fc_nodes, nlp_listp) { |
| 5777 | if (!NLP_CHK_NODE_ACT(ndlp) || |
| 5778 | (np->nlp_state != NLP_STE_NPR_NODE) || |
| 5779 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 5780 | continue; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5781 | spin_lock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame^] | 5782 | np->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5783 | spin_unlock_irq(shost->host_lock); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame^] | 5784 | lpfc_unreg_rpi(vport, np); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5785 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame^] | 5786 | lpfc_mbx_unreg_vpi(vport); |
| 5787 | spin_lock_irq(shost->host_lock); |
| 5788 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 5789 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5790 | } |
| 5791 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame^] | 5792 | if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
| 5793 | lpfc_register_new_vport(phba, vport, ndlp); |
| 5794 | else |
| 5795 | lpfc_do_scr_ns_plogi(phba, vport); |
| 5796 | goto out; |
| 5797 | fdisc_failed: |
| 5798 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 5799 | /* Cancel discovery timer */ |
| 5800 | lpfc_can_disctmo(vport); |
| 5801 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5802 | out: |
| 5803 | lpfc_els_free_iocb(phba, cmdiocb); |
| 5804 | } |
| 5805 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5806 | /** |
| 5807 | * lpfc_issue_els_fdisc: Issue a fdisc iocb command. |
| 5808 | * @vport: pointer to a virtual N_Port data structure. |
| 5809 | * @ndlp: pointer to a node-list data structure. |
| 5810 | * @retry: number of retries to the command IOCB. |
| 5811 | * |
| 5812 | * This routine prepares and issues a Fabric Discover (FDISC) IOCB to |
| 5813 | * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() |
| 5814 | * routine to issue the IOCB, which makes sure only one outstanding fabric |
| 5815 | * IOCB will be sent off HBA at any given time. |
| 5816 | * |
| 5817 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 5818 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 5819 | * will be stored into the context1 field of the IOCB for the completion |
| 5820 | * callback function to the FDISC ELS command. |
| 5821 | * |
| 5822 | * Return code |
| 5823 | * 0 - Successfully issued fdisc iocb command |
| 5824 | * 1 - Failed to issue fdisc iocb command |
| 5825 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 5826 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5827 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 5828 | uint8_t retry) |
| 5829 | { |
| 5830 | struct lpfc_hba *phba = vport->phba; |
| 5831 | IOCB_t *icmd; |
| 5832 | struct lpfc_iocbq *elsiocb; |
| 5833 | struct serv_parm *sp; |
| 5834 | uint8_t *pcmd; |
| 5835 | uint16_t cmdsize; |
| 5836 | int did = ndlp->nlp_DID; |
| 5837 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5838 | |
| 5839 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
| 5840 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
| 5841 | ELS_CMD_FDISC); |
| 5842 | if (!elsiocb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5843 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5844 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5845 | "0255 Issue FDISC: no IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5846 | return 1; |
| 5847 | } |
| 5848 | |
| 5849 | icmd = &elsiocb->iocb; |
| 5850 | icmd->un.elsreq64.myID = 0; |
| 5851 | icmd->un.elsreq64.fl = 1; |
| 5852 | |
| 5853 | /* For FDISC, Let FDISC rsp set the NPortID for this VPI */ |
| 5854 | icmd->ulpCt_h = 1; |
| 5855 | icmd->ulpCt_l = 0; |
| 5856 | |
| 5857 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5858 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; |
| 5859 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ |
| 5860 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); |
| 5861 | sp = (struct serv_parm *) pcmd; |
| 5862 | /* Setup CSPs accordingly for Fabric */ |
| 5863 | sp->cmn.e_d_tov = 0; |
| 5864 | sp->cmn.w2.r_a_tov = 0; |
| 5865 | sp->cls1.classValid = 0; |
| 5866 | sp->cls2.seqDelivery = 1; |
| 5867 | sp->cls3.seqDelivery = 1; |
| 5868 | |
| 5869 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ |
| 5870 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ |
| 5871 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ |
| 5872 | pcmd += sizeof(uint32_t); /* Port Name */ |
| 5873 | memcpy(pcmd, &vport->fc_portname, 8); |
| 5874 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 5875 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 5876 | memcpy(pcmd, &vport->fc_nodename, 8); |
| 5877 | |
| 5878 | lpfc_set_disctmo(vport); |
| 5879 | |
| 5880 | phba->fc_stat.elsXmitFDISC++; |
| 5881 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; |
| 5882 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5883 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 5884 | "Issue FDISC: did:x%x", |
| 5885 | did, 0, 0); |
| 5886 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5887 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| 5888 | if (rc == IOCB_ERROR) { |
| 5889 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5890 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5891 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5892 | "0256 Issue FDISC: Cannot send IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5893 | return 1; |
| 5894 | } |
| 5895 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); |
| 5896 | vport->port_state = LPFC_FDISC; |
| 5897 | return 0; |
| 5898 | } |
| 5899 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5900 | /** |
| 5901 | * lpfc_cmpl_els_npiv_logo: Completion function with vport logo. |
| 5902 | * @phba: pointer to lpfc hba data structure. |
| 5903 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5904 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 5905 | * |
| 5906 | * This routine is the completion callback function to the issuing of a LOGO |
| 5907 | * ELS command off a vport. It frees the command IOCB and then decrement the |
| 5908 | * reference count held on ndlp for this completion function, indicating that |
| 5909 | * the reference to the ndlp is no long needed. Note that the |
| 5910 | * lpfc_els_free_iocb() routine decrements the ndlp reference held for this |
| 5911 | * callback function and an additional explicit ndlp reference decrementation |
| 5912 | * will trigger the actual release of the ndlp. |
| 5913 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5914 | static void |
| 5915 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 5916 | struct lpfc_iocbq *rspiocb) |
| 5917 | { |
| 5918 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5919 | IOCB_t *irsp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5920 | struct lpfc_nodelist *ndlp; |
| 5921 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5922 | |
| 5923 | irsp = &rspiocb->iocb; |
| 5924 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 5925 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", |
| 5926 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5927 | |
| 5928 | lpfc_els_free_iocb(phba, cmdiocb); |
| 5929 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5930 | |
| 5931 | /* Trigger the release of the ndlp after logo */ |
| 5932 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5933 | } |
| 5934 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5935 | /** |
| 5936 | * lpfc_issue_els_npiv_logo: Issue a logo off a vport. |
| 5937 | * @vport: pointer to a virtual N_Port data structure. |
| 5938 | * @ndlp: pointer to a node-list data structure. |
| 5939 | * |
| 5940 | * This routine issues a LOGO ELS command to an @ndlp off a @vport. |
| 5941 | * |
| 5942 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 5943 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 5944 | * will be stored into the context1 field of the IOCB for the completion |
| 5945 | * callback function to the LOGO ELS command. |
| 5946 | * |
| 5947 | * Return codes |
| 5948 | * 0 - Successfully issued logo off the @vport |
| 5949 | * 1 - Failed to issue logo off the @vport |
| 5950 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5951 | int |
| 5952 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 5953 | { |
| 5954 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5955 | struct lpfc_hba *phba = vport->phba; |
| 5956 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 5957 | IOCB_t *icmd; |
| 5958 | struct lpfc_iocbq *elsiocb; |
| 5959 | uint8_t *pcmd; |
| 5960 | uint16_t cmdsize; |
| 5961 | |
| 5962 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); |
| 5963 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, |
| 5964 | ELS_CMD_LOGO); |
| 5965 | if (!elsiocb) |
| 5966 | return 1; |
| 5967 | |
| 5968 | icmd = &elsiocb->iocb; |
| 5969 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5970 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
| 5971 | pcmd += sizeof(uint32_t); |
| 5972 | |
| 5973 | /* Fill in LOGO payload */ |
| 5974 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
| 5975 | pcmd += sizeof(uint32_t); |
| 5976 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 5977 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5978 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 5979 | "Issue LOGO npiv did:x%x flg:x%x", |
| 5980 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 5981 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5982 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
| 5983 | spin_lock_irq(shost->host_lock); |
| 5984 | ndlp->nlp_flag |= NLP_LOGO_SND; |
| 5985 | spin_unlock_irq(shost->host_lock); |
| 5986 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
| 5987 | spin_lock_irq(shost->host_lock); |
| 5988 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
| 5989 | spin_unlock_irq(shost->host_lock); |
| 5990 | lpfc_els_free_iocb(phba, elsiocb); |
| 5991 | return 1; |
| 5992 | } |
| 5993 | return 0; |
| 5994 | } |
| 5995 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5996 | /** |
| 5997 | * lpfc_fabric_block_timeout: Handler function to the fabric block timer. |
| 5998 | * @ptr: holder for the timer function associated data. |
| 5999 | * |
| 6000 | * This routine is invoked by the fabric iocb block timer after |
| 6001 | * timeout. It posts the fabric iocb block timeout event by setting the |
| 6002 | * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes |
| 6003 | * lpfc_worker_wake_up() routine to wake up the worker thread. It is for |
| 6004 | * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the |
| 6005 | * posted event WORKER_FABRIC_BLOCK_TMO. |
| 6006 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6007 | void |
| 6008 | lpfc_fabric_block_timeout(unsigned long ptr) |
| 6009 | { |
| 6010 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| 6011 | unsigned long iflags; |
| 6012 | uint32_t tmo_posted; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6013 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6014 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 6015 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; |
| 6016 | if (!tmo_posted) |
| 6017 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; |
| 6018 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 6019 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6020 | if (!tmo_posted) |
| 6021 | lpfc_worker_wake_up(phba); |
| 6022 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6023 | } |
| 6024 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6025 | /** |
| 6026 | * lpfc_resume_fabric_iocbs: Issue a fabric iocb from driver internal list. |
| 6027 | * @phba: pointer to lpfc hba data structure. |
| 6028 | * |
| 6029 | * This routine issues one fabric iocb from the driver internal list to |
| 6030 | * the HBA. It first checks whether it's ready to issue one fabric iocb to |
| 6031 | * the HBA (whether there is no outstanding fabric iocb). If so, it shall |
| 6032 | * remove one pending fabric iocb from the driver internal list and invokes |
| 6033 | * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. |
| 6034 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6035 | static void |
| 6036 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) |
| 6037 | { |
| 6038 | struct lpfc_iocbq *iocb; |
| 6039 | unsigned long iflags; |
| 6040 | int ret; |
| 6041 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 6042 | IOCB_t *cmd; |
| 6043 | |
| 6044 | repeat: |
| 6045 | iocb = NULL; |
| 6046 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6047 | /* Post any pending iocb to the SLI layer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6048 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
| 6049 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), |
| 6050 | list); |
| 6051 | if (iocb) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6052 | /* Increment fabric iocb count to hold the position */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6053 | atomic_inc(&phba->fabric_iocb_count); |
| 6054 | } |
| 6055 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6056 | if (iocb) { |
| 6057 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 6058 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 6059 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 6060 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6061 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 6062 | "Fabric sched1: ste:x%x", |
| 6063 | iocb->vport->port_state, 0, 0); |
| 6064 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6065 | ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0); |
| 6066 | |
| 6067 | if (ret == IOCB_ERROR) { |
| 6068 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 6069 | iocb->fabric_iocb_cmpl = NULL; |
| 6070 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6071 | cmd = &iocb->iocb; |
| 6072 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 6073 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 6074 | iocb->iocb_cmpl(phba, iocb, iocb); |
| 6075 | |
| 6076 | atomic_dec(&phba->fabric_iocb_count); |
| 6077 | goto repeat; |
| 6078 | } |
| 6079 | } |
| 6080 | |
| 6081 | return; |
| 6082 | } |
| 6083 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6084 | /** |
| 6085 | * lpfc_unblock_fabric_iocbs: Unblock issuing fabric iocb command. |
| 6086 | * @phba: pointer to lpfc hba data structure. |
| 6087 | * |
| 6088 | * This routine unblocks the issuing fabric iocb command. The function |
| 6089 | * will clear the fabric iocb block bit and then invoke the routine |
| 6090 | * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb |
| 6091 | * from the driver internal fabric iocb list. |
| 6092 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6093 | void |
| 6094 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) |
| 6095 | { |
| 6096 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 6097 | |
| 6098 | lpfc_resume_fabric_iocbs(phba); |
| 6099 | return; |
| 6100 | } |
| 6101 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6102 | /** |
| 6103 | * lpfc_block_fabric_iocbs: Block issuing fabric iocb command. |
| 6104 | * @phba: pointer to lpfc hba data structure. |
| 6105 | * |
| 6106 | * This routine blocks the issuing fabric iocb for a specified amount of |
| 6107 | * time (currently 100 ms). This is done by set the fabric iocb block bit |
| 6108 | * and set up a timeout timer for 100ms. When the block bit is set, no more |
| 6109 | * fabric iocb will be issued out of the HBA. |
| 6110 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6111 | static void |
| 6112 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) |
| 6113 | { |
| 6114 | int blocked; |
| 6115 | |
| 6116 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6117 | /* Start a timer to unblock fabric iocbs after 100ms */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6118 | if (!blocked) |
| 6119 | mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 ); |
| 6120 | |
| 6121 | return; |
| 6122 | } |
| 6123 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6124 | /** |
| 6125 | * lpfc_cmpl_fabric_iocb: Completion callback function for fabric iocb. |
| 6126 | * @phba: pointer to lpfc hba data structure. |
| 6127 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6128 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6129 | * |
| 6130 | * This routine is the callback function that is put to the fabric iocb's |
| 6131 | * callback function pointer (iocb->iocb_cmpl). The original iocb's callback |
| 6132 | * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback |
| 6133 | * function first restores and invokes the original iocb's callback function |
| 6134 | * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next |
| 6135 | * fabric bound iocb from the driver internal fabric iocb list onto the wire. |
| 6136 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6137 | static void |
| 6138 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6139 | struct lpfc_iocbq *rspiocb) |
| 6140 | { |
| 6141 | struct ls_rjt stat; |
| 6142 | |
| 6143 | if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC) |
| 6144 | BUG(); |
| 6145 | |
| 6146 | switch (rspiocb->iocb.ulpStatus) { |
| 6147 | case IOSTAT_NPORT_RJT: |
| 6148 | case IOSTAT_FABRIC_RJT: |
| 6149 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 6150 | lpfc_block_fabric_iocbs(phba); |
| 6151 | } |
| 6152 | break; |
| 6153 | |
| 6154 | case IOSTAT_NPORT_BSY: |
| 6155 | case IOSTAT_FABRIC_BSY: |
| 6156 | lpfc_block_fabric_iocbs(phba); |
| 6157 | break; |
| 6158 | |
| 6159 | case IOSTAT_LS_RJT: |
| 6160 | stat.un.lsRjtError = |
| 6161 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); |
| 6162 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || |
| 6163 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) |
| 6164 | lpfc_block_fabric_iocbs(phba); |
| 6165 | break; |
| 6166 | } |
| 6167 | |
| 6168 | if (atomic_read(&phba->fabric_iocb_count) == 0) |
| 6169 | BUG(); |
| 6170 | |
| 6171 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; |
| 6172 | cmdiocb->fabric_iocb_cmpl = NULL; |
| 6173 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6174 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); |
| 6175 | |
| 6176 | atomic_dec(&phba->fabric_iocb_count); |
| 6177 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6178 | /* Post any pending iocbs to HBA */ |
| 6179 | lpfc_resume_fabric_iocbs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6180 | } |
| 6181 | } |
| 6182 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6183 | /** |
| 6184 | * lpfc_issue_fabric_iocb: Issue a fabric iocb command. |
| 6185 | * @phba: pointer to lpfc hba data structure. |
| 6186 | * @iocb: pointer to lpfc command iocb data structure. |
| 6187 | * |
| 6188 | * This routine is used as the top-level API for issuing a fabric iocb command |
| 6189 | * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver |
| 6190 | * function makes sure that only one fabric bound iocb will be outstanding at |
| 6191 | * any given time. As such, this function will first check to see whether there |
| 6192 | * is already an outstanding fabric iocb on the wire. If so, it will put the |
| 6193 | * newly issued iocb onto the driver internal fabric iocb list, waiting to be |
| 6194 | * issued later. Otherwise, it will issue the iocb on the wire and update the |
| 6195 | * fabric iocb count it indicate that there is one fabric iocb on the wire. |
| 6196 | * |
| 6197 | * Note, this implementation has a potential sending out fabric IOCBs out of |
| 6198 | * order. The problem is caused by the construction of the "ready" boolen does |
| 6199 | * not include the condition that the internal fabric IOCB list is empty. As |
| 6200 | * such, it is possible a fabric IOCB issued by this routine might be "jump" |
| 6201 | * ahead of the fabric IOCBs in the internal list. |
| 6202 | * |
| 6203 | * Return code |
| 6204 | * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully |
| 6205 | * IOCB_ERROR - failed to issue fabric iocb |
| 6206 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6207 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6208 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
| 6209 | { |
| 6210 | unsigned long iflags; |
| 6211 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 6212 | int ready; |
| 6213 | int ret; |
| 6214 | |
| 6215 | if (atomic_read(&phba->fabric_iocb_count) > 1) |
| 6216 | BUG(); |
| 6217 | |
| 6218 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 6219 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && |
| 6220 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 6221 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6222 | if (ready) |
| 6223 | /* Increment fabric iocb count to hold the position */ |
| 6224 | atomic_inc(&phba->fabric_iocb_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6225 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6226 | if (ready) { |
| 6227 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 6228 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 6229 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 6230 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6231 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 6232 | "Fabric sched2: ste:x%x", |
| 6233 | iocb->vport->port_state, 0, 0); |
| 6234 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6235 | ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0); |
| 6236 | |
| 6237 | if (ret == IOCB_ERROR) { |
| 6238 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 6239 | iocb->fabric_iocb_cmpl = NULL; |
| 6240 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6241 | atomic_dec(&phba->fabric_iocb_count); |
| 6242 | } |
| 6243 | } else { |
| 6244 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 6245 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); |
| 6246 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6247 | ret = IOCB_SUCCESS; |
| 6248 | } |
| 6249 | return ret; |
| 6250 | } |
| 6251 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6252 | /** |
| 6253 | * lpfc_fabric_abort_vport: Abort a vport's iocbs from driver fabric iocb list. |
| 6254 | * @vport: pointer to a virtual N_Port data structure. |
| 6255 | * |
| 6256 | * This routine aborts all the IOCBs associated with a @vport from the |
| 6257 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 6258 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 6259 | * list, removes each IOCB associated with the @vport off the list, set the |
| 6260 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 6261 | * associated with the IOCB. |
| 6262 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6263 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6264 | { |
| 6265 | LIST_HEAD(completions); |
| 6266 | struct lpfc_hba *phba = vport->phba; |
| 6267 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 6268 | IOCB_t *cmd; |
| 6269 | |
| 6270 | spin_lock_irq(&phba->hbalock); |
| 6271 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 6272 | list) { |
| 6273 | |
| 6274 | if (piocb->vport != vport) |
| 6275 | continue; |
| 6276 | |
| 6277 | list_move_tail(&piocb->list, &completions); |
| 6278 | } |
| 6279 | spin_unlock_irq(&phba->hbalock); |
| 6280 | |
| 6281 | while (!list_empty(&completions)) { |
| 6282 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| 6283 | list_del_init(&piocb->list); |
| 6284 | |
| 6285 | cmd = &piocb->iocb; |
| 6286 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 6287 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 6288 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 6289 | } |
| 6290 | } |
| 6291 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6292 | /** |
| 6293 | * lpfc_fabric_abort_nport: Abort a ndlp's iocbs from driver fabric iocb list. |
| 6294 | * @ndlp: pointer to a node-list data structure. |
| 6295 | * |
| 6296 | * This routine aborts all the IOCBs associated with an @ndlp from the |
| 6297 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 6298 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 6299 | * list, removes each IOCB associated with the @ndlp off the list, set the |
| 6300 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 6301 | * associated with the IOCB. |
| 6302 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6303 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) |
| 6304 | { |
| 6305 | LIST_HEAD(completions); |
| 6306 | struct lpfc_hba *phba = ndlp->vport->phba; |
| 6307 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 6308 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 6309 | IOCB_t *cmd; |
| 6310 | |
| 6311 | spin_lock_irq(&phba->hbalock); |
| 6312 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 6313 | list) { |
| 6314 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { |
| 6315 | |
| 6316 | list_move_tail(&piocb->list, &completions); |
| 6317 | } |
| 6318 | } |
| 6319 | spin_unlock_irq(&phba->hbalock); |
| 6320 | |
| 6321 | while (!list_empty(&completions)) { |
| 6322 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| 6323 | list_del_init(&piocb->list); |
| 6324 | |
| 6325 | cmd = &piocb->iocb; |
| 6326 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 6327 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 6328 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 6329 | } |
| 6330 | } |
| 6331 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6332 | /** |
| 6333 | * lpfc_fabric_abort_hba: Abort all iocbs on driver fabric iocb list. |
| 6334 | * @phba: pointer to lpfc hba data structure. |
| 6335 | * |
| 6336 | * This routine aborts all the IOCBs currently on the driver internal |
| 6337 | * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS |
| 6338 | * IOCB ring. This function takes the entire IOCB list off the fabric IOCB |
| 6339 | * list, removes IOCBs off the list, set the status feild to |
| 6340 | * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with |
| 6341 | * the IOCB. |
| 6342 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6343 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) |
| 6344 | { |
| 6345 | LIST_HEAD(completions); |
| 6346 | struct lpfc_iocbq *piocb; |
| 6347 | IOCB_t *cmd; |
| 6348 | |
| 6349 | spin_lock_irq(&phba->hbalock); |
| 6350 | list_splice_init(&phba->fabric_iocb_list, &completions); |
| 6351 | spin_unlock_irq(&phba->hbalock); |
| 6352 | |
| 6353 | while (!list_empty(&completions)) { |
| 6354 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| 6355 | list_del_init(&piocb->list); |
| 6356 | |
| 6357 | cmd = &piocb->iocb; |
| 6358 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 6359 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 6360 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 6361 | } |
| 6362 | } |