| 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); |
| 203 | icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BDL; |
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; |
| 238 | bpl->tus.f.bdeFlags = BUFF_USE_RCV; |
| 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 | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 476 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 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 | /** |
| 1559 | * lpfc_more_adisc: Issue more adisc as needed. |
| 1560 | * @vport: pointer to a host virtual N_Port data structure. |
| 1561 | * |
| 1562 | * This routine determines whether there are more ndlps on a @vport |
| 1563 | * node list need to have Address Discover (ADISC) issued. If so, it will |
| 1564 | * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's |
| 1565 | * remaining nodes which need to have ADISC sent. |
| 1566 | **/ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1567 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1568 | lpfc_more_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1569 | { |
| 1570 | int sentadisc; |
| 1571 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1572 | if (vport->num_disc_nodes) |
| 1573 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1574 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1575 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1576 | "0210 Continue discovery with %d ADISCs to go " |
| 1577 | "Data: x%x x%x x%x\n", |
| 1578 | vport->num_disc_nodes, vport->fc_adisc_cnt, |
| 1579 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1580 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1581 | if (vport->fc_flag & FC_NLP_MORE) { |
| 1582 | lpfc_set_disctmo(vport); |
| 1583 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
| 1584 | sentadisc = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1585 | } |
| 1586 | return; |
| 1587 | } |
| 1588 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 1589 | /** |
| 1590 | * lpfc_rscn_disc: Perform rscn discovery for a vport. |
| 1591 | * @vport: pointer to a host virtual N_Port data structure. |
| 1592 | * |
| 1593 | * This routine performs Registration State Change Notification (RSCN) |
| 1594 | * discovery for a @vport. If the @vport's node port recovery count is not |
| 1595 | * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all |
| 1596 | * the nodes that need recovery. If none of the PLOGI were needed through |
| 1597 | * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be |
| 1598 | * invoked to check and handle possible more RSCN came in during the period |
| 1599 | * of processing the current ones. |
| 1600 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1601 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1602 | lpfc_rscn_disc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1603 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1604 | lpfc_can_disctmo(vport); |
| 1605 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1606 | /* RSCN discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1607 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 1608 | if (vport->fc_npr_cnt) |
| 1609 | if (lpfc_els_disc_plogi(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1610 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1611 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1612 | lpfc_end_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1613 | } |
| 1614 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 1615 | /** |
| 1616 | * lpfc_cmpl_els_adisc: Completion callback function for adisc. |
| 1617 | * @phba: pointer to lpfc hba data structure. |
| 1618 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1619 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1620 | * |
| 1621 | * This routine is the completion function for issuing the Address Discover |
| 1622 | * (ADISC) command. It first checks to see whether link went down during |
| 1623 | * the discovery process. If so, the node will be marked as node port |
| 1624 | * recovery for issuing discover IOCB by the link attention handler and |
| 1625 | * exit. Otherwise, the response status is checked. If error was reported |
| 1626 | * in the response status, the ADISC command shall be retried by invoking |
| 1627 | * the lpfc_els_retry() routine. Otherwise, if no error was reported in |
| 1628 | * the response status, the state machine is invoked to set transition |
| 1629 | * with respect to NLP_EVT_CMPL_ADISC event. |
| 1630 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1631 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1632 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1633 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1634 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1635 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1636 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1637 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1638 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1639 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1640 | |
| 1641 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1642 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1643 | |
| 1644 | irsp = &(rspiocb->iocb); |
| 1645 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1646 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1647 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1648 | "ADISC cmpl: status:x%x/x%x did:x%x", |
| 1649 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1650 | ndlp->nlp_DID); |
| 1651 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1652 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1653 | * is being used during discovery. |
| 1654 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1655 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1656 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1657 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1658 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1659 | /* ADISC completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1660 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1661 | "0104 ADISC completes to NPort x%x " |
| 1662 | "Data: x%x x%x x%x x%x x%x\n", |
| 1663 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1664 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1665 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1666 | if (lpfc_els_chk_latt(vport)) { |
| 1667 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1668 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1669 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1670 | goto out; |
| 1671 | } |
| 1672 | |
| 1673 | if (irsp->ulpStatus) { |
| 1674 | /* Check for retry */ |
| 1675 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1676 | /* ELS command is being retried */ |
| 1677 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1678 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1679 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1680 | spin_unlock_irq(shost->host_lock); |
| 1681 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1682 | } |
| 1683 | goto out; |
| 1684 | } |
| 1685 | /* ADISC failed */ |
| 1686 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1687 | if (!lpfc_error_lost_link(irsp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1688 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1689 | NLP_EVT_CMPL_ADISC); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1690 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1691 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1692 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1693 | NLP_EVT_CMPL_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1694 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1695 | if (disc && vport->num_disc_nodes) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1696 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1697 | lpfc_more_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1698 | |
| 1699 | /* Check to see if we are done with ADISC authentication */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1700 | if (vport->num_disc_nodes == 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1701 | /* If we get here, there is nothing left to ADISC */ |
| 1702 | /* |
| 1703 | * For NPIV, cmpl_reg_vpi will set port_state to READY, |
| 1704 | * and continue discovery. |
| 1705 | */ |
| 1706 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 1707 | !(vport->fc_flag & FC_RSCN_MODE)) { |
| 1708 | lpfc_issue_reg_vpi(phba, vport); |
| 1709 | goto out; |
| 1710 | } |
| 1711 | /* |
| 1712 | * For SLI2, we need to set port_state to READY |
| 1713 | * and continue discovery. |
| 1714 | */ |
| 1715 | if (vport->port_state < LPFC_VPORT_READY) { |
| 1716 | /* If we get here, there is nothing to ADISC */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1717 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1718 | lpfc_issue_clear_la(phba, vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1719 | |
| 1720 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
| 1721 | vport->num_disc_nodes = 0; |
| 1722 | /* go thru NPR list, issue ELS PLOGIs */ |
| 1723 | if (vport->fc_npr_cnt) |
| 1724 | lpfc_els_disc_plogi(vport); |
| 1725 | |
| 1726 | if (!vport->num_disc_nodes) { |
| 1727 | spin_lock_irq(shost->host_lock); |
| 1728 | vport->fc_flag &= |
| 1729 | ~FC_NDISC_ACTIVE; |
| 1730 | spin_unlock_irq( |
| 1731 | shost->host_lock); |
| 1732 | lpfc_can_disctmo(vport); |
| 1733 | } |
| 1734 | } |
| 1735 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1736 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1737 | lpfc_rscn_disc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1738 | } |
| 1739 | } |
| 1740 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1741 | out: |
| 1742 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1743 | return; |
| 1744 | } |
| 1745 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 1746 | /** |
| 1747 | * lpfc_issue_els_adisc: Issue an address discover iocb to an node on a vport. |
| 1748 | * @vport: pointer to a virtual N_Port data structure. |
| 1749 | * @ndlp: pointer to a node-list data structure. |
| 1750 | * @retry: number of retries to the command IOCB. |
| 1751 | * |
| 1752 | * This routine issues an Address Discover (ADISC) for an @ndlp on a |
| 1753 | * @vport. It prepares the payload of the ADISC ELS command, updates the |
| 1754 | * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine |
| 1755 | * to issue the ADISC ELS command. |
| 1756 | * |
| 1757 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1758 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1759 | * will be stored into the context1 field of the IOCB for the completion |
| 1760 | * callback function to the ADISC ELS command. |
| 1761 | * |
| 1762 | * Return code |
| 1763 | * 0 - successfully issued adisc |
| 1764 | * 1 - failed to issue adisc |
| 1765 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1766 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1767 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1768 | uint8_t retry) |
| 1769 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1770 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1771 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1772 | ADISC *ap; |
| 1773 | IOCB_t *icmd; |
| 1774 | struct lpfc_iocbq *elsiocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1775 | struct lpfc_sli *psli = &phba->sli; |
| 1776 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1777 | uint8_t *pcmd; |
| 1778 | uint16_t cmdsize; |
| 1779 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1780 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1781 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1782 | ndlp->nlp_DID, ELS_CMD_ADISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1783 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1784 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1785 | |
| 1786 | icmd = &elsiocb->iocb; |
| 1787 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1788 | |
| 1789 | /* For ADISC request, remainder of payload is service parameters */ |
| 1790 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1791 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1792 | |
| 1793 | /* Fill in ADISC payload */ |
| 1794 | ap = (ADISC *) pcmd; |
| 1795 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1796 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 1797 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1798 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1799 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1800 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1801 | "Issue ADISC: did:x%x", |
| 1802 | ndlp->nlp_DID, 0, 0); |
| 1803 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1804 | phba->fc_stat.elsXmitADISC++; |
| 1805 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1806 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1807 | ndlp->nlp_flag |= NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1808 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1809 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1810 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1811 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1812 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1813 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1814 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1815 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1816 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1817 | } |
| 1818 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 1819 | /** |
| 1820 | * lpfc_cmpl_els_logo: Completion callback function for logo. |
| 1821 | * @phba: pointer to lpfc hba data structure. |
| 1822 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1823 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1824 | * |
| 1825 | * This routine is the completion function for issuing the ELS Logout (LOGO) |
| 1826 | * command. If no error status was reported from the LOGO response, the |
| 1827 | * state machine of the associated ndlp shall be invoked for transition with |
| 1828 | * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported, |
| 1829 | * the lpfc_els_retry() routine will be invoked to retry the LOGO command. |
| 1830 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1831 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1832 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1833 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1834 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1835 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 1836 | struct lpfc_vport *vport = ndlp->vport; |
| 1837 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1838 | IOCB_t *irsp; |
| 1839 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1840 | |
| 1841 | psli = &phba->sli; |
| 1842 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1843 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1844 | |
| 1845 | irsp = &(rspiocb->iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1846 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1847 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1848 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1849 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1850 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1851 | "LOGO cmpl: status:x%x/x%x did:x%x", |
| 1852 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1853 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1854 | /* LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1855 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1856 | "0105 LOGO completes to NPort x%x " |
| 1857 | "Data: x%x x%x x%x x%x\n", |
| 1858 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1859 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1860 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1861 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1862 | goto out; |
| 1863 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1864 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
| 1865 | /* NLP_EVT_DEVICE_RM should unregister the RPI |
| 1866 | * which should abort all outstanding IOs. |
| 1867 | */ |
| 1868 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 1869 | NLP_EVT_DEVICE_RM); |
| 1870 | goto out; |
| 1871 | } |
| 1872 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1873 | if (irsp->ulpStatus) { |
| 1874 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1875 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1876 | /* ELS command is being retried */ |
| 1877 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1878 | /* LOGO failed */ |
| 1879 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1880 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1881 | goto out; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1882 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1883 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1884 | NLP_EVT_CMPL_LOGO); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1885 | } else |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 1886 | /* Good status, call state machine. |
| 1887 | * This will unregister the rpi if needed. |
| 1888 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1889 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1890 | NLP_EVT_CMPL_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1891 | out: |
| 1892 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1893 | return; |
| 1894 | } |
| 1895 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 1896 | /** |
| 1897 | * lpfc_issue_els_logo: Issue a logo to an node on a vport. |
| 1898 | * @vport: pointer to a virtual N_Port data structure. |
| 1899 | * @ndlp: pointer to a node-list data structure. |
| 1900 | * @retry: number of retries to the command IOCB. |
| 1901 | * |
| 1902 | * This routine constructs and issues an ELS Logout (LOGO) iocb command |
| 1903 | * to a remote node, referred by an @ndlp on a @vport. It constructs the |
| 1904 | * payload of the IOCB, properly sets up the @ndlp state, and invokes the |
| 1905 | * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. |
| 1906 | * |
| 1907 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 1908 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 1909 | * will be stored into the context1 field of the IOCB for the completion |
| 1910 | * callback function to the LOGO ELS command. |
| 1911 | * |
| 1912 | * Return code |
| 1913 | * 0 - successfully issued logo |
| 1914 | * 1 - failed to issue logo |
| 1915 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1916 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1917 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1918 | uint8_t retry) |
| 1919 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1920 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1921 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1922 | IOCB_t *icmd; |
| 1923 | struct lpfc_iocbq *elsiocb; |
| 1924 | struct lpfc_sli_ring *pring; |
| 1925 | struct lpfc_sli *psli; |
| 1926 | uint8_t *pcmd; |
| 1927 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1928 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1929 | |
| 1930 | psli = &phba->sli; |
| 1931 | pring = &psli->ring[LPFC_ELS_RING]; |
| 1932 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1933 | spin_lock_irq(shost->host_lock); |
| 1934 | if (ndlp->nlp_flag & NLP_LOGO_SND) { |
| 1935 | spin_unlock_irq(shost->host_lock); |
| 1936 | return 0; |
| 1937 | } |
| 1938 | spin_unlock_irq(shost->host_lock); |
| 1939 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1940 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1941 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1942 | ndlp->nlp_DID, ELS_CMD_LOGO); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1943 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1944 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1945 | |
| 1946 | icmd = &elsiocb->iocb; |
| 1947 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1948 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1949 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1950 | |
| 1951 | /* Fill in LOGO payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1952 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1953 | pcmd += sizeof(uint32_t); |
| 1954 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1955 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1956 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1957 | "Issue LOGO: did:x%x", |
| 1958 | ndlp->nlp_DID, 0, 0); |
| 1959 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1960 | phba->fc_stat.elsXmitLOGO++; |
| 1961 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1962 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1963 | ndlp->nlp_flag |= NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1964 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1965 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| 1966 | |
| 1967 | if (rc == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1968 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1969 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1970 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1971 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1972 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1973 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1974 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1975 | } |
| 1976 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 1977 | /** |
| 1978 | * lpfc_cmpl_els_cmd: Completion callback function for generic els command. |
| 1979 | * @phba: pointer to lpfc hba data structure. |
| 1980 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 1981 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 1982 | * |
| 1983 | * This routine is a generic completion callback function for ELS commands. |
| 1984 | * Specifically, it is the callback function which does not need to perform |
| 1985 | * any command specific operations. It is currently used by the ELS command |
| 1986 | * issuing routines for the ELS State Change Request (SCR), |
| 1987 | * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution |
| 1988 | * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than |
| 1989 | * certain debug loggings, this callback function simply invokes the |
| 1990 | * lpfc_els_chk_latt() routine to check whether link went down during the |
| 1991 | * discovery process. |
| 1992 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1993 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1994 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1995 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1996 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1997 | struct lpfc_vport *vport = cmdiocb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1998 | IOCB_t *irsp; |
| 1999 | |
| 2000 | irsp = &rspiocb->iocb; |
| 2001 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2002 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2003 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 2004 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 2005 | irsp->un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2006 | /* ELS cmd tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2007 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2008 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", |
| 2009 | irsp->ulpIoTag, irsp->ulpStatus, |
| 2010 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2011 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2012 | lpfc_els_chk_latt(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2013 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2014 | return; |
| 2015 | } |
| 2016 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 2017 | /** |
| 2018 | * lpfc_issue_els_scr: Issue a scr to an node on a vport. |
| 2019 | * @vport: pointer to a host virtual N_Port data structure. |
| 2020 | * @nportid: N_Port identifier to the remote node. |
| 2021 | * @retry: number of retries to the command IOCB. |
| 2022 | * |
| 2023 | * This routine issues a State Change Request (SCR) to a fabric node |
| 2024 | * on a @vport. The remote node @nportid is passed into the function. It |
| 2025 | * first search the @vport node list to find the matching ndlp. If no such |
| 2026 | * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An |
| 2027 | * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() |
| 2028 | * routine is invoked to send the SCR IOCB. |
| 2029 | * |
| 2030 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2031 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2032 | * will be stored into the context1 field of the IOCB for the completion |
| 2033 | * callback function to the SCR ELS command. |
| 2034 | * |
| 2035 | * Return code |
| 2036 | * 0 - Successfully issued scr command |
| 2037 | * 1 - Failed to issue scr command |
| 2038 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2039 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2040 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2041 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2042 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2043 | IOCB_t *icmd; |
| 2044 | struct lpfc_iocbq *elsiocb; |
| 2045 | struct lpfc_sli_ring *pring; |
| 2046 | struct lpfc_sli *psli; |
| 2047 | uint8_t *pcmd; |
| 2048 | uint16_t cmdsize; |
| 2049 | struct lpfc_nodelist *ndlp; |
| 2050 | |
| 2051 | psli = &phba->sli; |
| 2052 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2053 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2054 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2055 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2056 | if (!ndlp) { |
| 2057 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2058 | if (!ndlp) |
| 2059 | return 1; |
| 2060 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2061 | lpfc_enqueue_node(vport, ndlp); |
| 2062 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2063 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2064 | if (!ndlp) |
| 2065 | return 1; |
| 2066 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2067 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2068 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2069 | ndlp->nlp_DID, ELS_CMD_SCR); |
| 2070 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2071 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2072 | /* This will trigger the release of the node just |
| 2073 | * allocated |
| 2074 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2075 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2076 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2077 | } |
| 2078 | |
| 2079 | icmd = &elsiocb->iocb; |
| 2080 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2081 | |
| 2082 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2083 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2084 | |
| 2085 | /* For SCR, remainder of payload is SCR parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2086 | memset(pcmd, 0, sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2087 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
| 2088 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2089 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2090 | "Issue SCR: did:x%x", |
| 2091 | ndlp->nlp_DID, 0, 0); |
| 2092 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2093 | phba->fc_stat.elsXmitSCR++; |
| 2094 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2095 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2096 | /* The additional lpfc_nlp_put will cause the following |
| 2097 | * lpfc_els_free_iocb routine to trigger the rlease of |
| 2098 | * the node. |
| 2099 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2100 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2101 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2102 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2103 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2104 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2105 | * trigger the release of node. |
| 2106 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2107 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2108 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2109 | } |
| 2110 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 2111 | /** |
| 2112 | * lpfc_issue_els_farpr: Issue a farp to an node on a vport. |
| 2113 | * @vport: pointer to a host virtual N_Port data structure. |
| 2114 | * @nportid: N_Port identifier to the remote node. |
| 2115 | * @retry: number of retries to the command IOCB. |
| 2116 | * |
| 2117 | * This routine issues a Fibre Channel Address Resolution Response |
| 2118 | * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) |
| 2119 | * is passed into the function. It first search the @vport node list to find |
| 2120 | * the matching ndlp. If no such ndlp is found, a new ndlp shall be created |
| 2121 | * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the |
| 2122 | * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. |
| 2123 | * |
| 2124 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 2125 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 2126 | * will be stored into the context1 field of the IOCB for the completion |
| 2127 | * callback function to the PARPR ELS command. |
| 2128 | * |
| 2129 | * Return code |
| 2130 | * 0 - Successfully issued farpr command |
| 2131 | * 1 - Failed to issue farpr command |
| 2132 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2133 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2134 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2135 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2136 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2137 | IOCB_t *icmd; |
| 2138 | struct lpfc_iocbq *elsiocb; |
| 2139 | struct lpfc_sli_ring *pring; |
| 2140 | struct lpfc_sli *psli; |
| 2141 | FARP *fp; |
| 2142 | uint8_t *pcmd; |
| 2143 | uint32_t *lp; |
| 2144 | uint16_t cmdsize; |
| 2145 | struct lpfc_nodelist *ondlp; |
| 2146 | struct lpfc_nodelist *ndlp; |
| 2147 | |
| 2148 | psli = &phba->sli; |
| 2149 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2150 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2151 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2152 | ndlp = lpfc_findnode_did(vport, nportid); |
| 2153 | if (!ndlp) { |
| 2154 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2155 | if (!ndlp) |
| 2156 | return 1; |
| 2157 | lpfc_nlp_init(vport, ndlp, nportid); |
| 2158 | lpfc_enqueue_node(vport, ndlp); |
| 2159 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2160 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 2161 | if (!ndlp) |
| 2162 | return 1; |
| 2163 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2164 | |
| 2165 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 2166 | ndlp->nlp_DID, ELS_CMD_RNID); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2167 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2168 | /* This will trigger the release of the node just |
| 2169 | * allocated |
| 2170 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2171 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2172 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2173 | } |
| 2174 | |
| 2175 | icmd = &elsiocb->iocb; |
| 2176 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2177 | |
| 2178 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2179 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2180 | |
| 2181 | /* Fill in FARPR payload */ |
| 2182 | fp = (FARP *) (pcmd); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2183 | memset(fp, 0, sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2184 | lp = (uint32_t *) pcmd; |
| 2185 | *lp++ = be32_to_cpu(nportid); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2186 | *lp++ = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2187 | fp->Rflags = 0; |
| 2188 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); |
| 2189 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2190 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2191 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2192 | ondlp = lpfc_findnode_did(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2193 | if (ondlp && NLP_CHK_NODE_ACT(ondlp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2194 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2195 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2196 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2197 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2198 | } |
| 2199 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2200 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2201 | "Issue FARPR: did:x%x", |
| 2202 | ndlp->nlp_DID, 0, 0); |
| 2203 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2204 | phba->fc_stat.elsXmitFARPR++; |
| 2205 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2206 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2207 | /* The additional lpfc_nlp_put will cause the following |
| 2208 | * lpfc_els_free_iocb routine to trigger the release of |
| 2209 | * the node. |
| 2210 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2211 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2212 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2213 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2214 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2215 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 2216 | * trigger the release of the node. |
| 2217 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2218 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2219 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2220 | } |
| 2221 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 2222 | /** |
| 2223 | * lpfc_cancel_retry_delay_tmo: Cancel the timer with delayed iocb-cmd retry. |
| 2224 | * @vport: pointer to a host virtual N_Port data structure. |
| 2225 | * @nlp: pointer to a node-list data structure. |
| 2226 | * |
| 2227 | * This routine cancels the timer with a delayed IOCB-command retry for |
| 2228 | * a @vport's @ndlp. It stops the timer for the delayed function retrial and |
| 2229 | * removes the ELS retry event if it presents. In addition, if the |
| 2230 | * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB |
| 2231 | * commands are sent for the @vport's nodes that require issuing discovery |
| 2232 | * ADISC. |
| 2233 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2234 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2235 | 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] | 2236 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2237 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2238 | struct lpfc_work_evt *evtp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2239 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2240 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) |
| 2241 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2242 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2243 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2244 | spin_unlock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2245 | del_timer_sync(&nlp->nlp_delayfunc); |
| 2246 | nlp->nlp_last_elscmd = 0; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2247 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2248 | list_del_init(&nlp->els_retry_evt.evt_listp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2249 | /* Decrement nlp reference count held for the delayed retry */ |
| 2250 | evtp = &nlp->els_retry_evt; |
| 2251 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); |
| 2252 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2253 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2254 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2255 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2256 | spin_unlock_irq(shost->host_lock); |
| 2257 | if (vport->num_disc_nodes) { |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2258 | if (vport->port_state < LPFC_VPORT_READY) { |
| 2259 | /* Check if there are more ADISCs to be sent */ |
| 2260 | lpfc_more_adisc(vport); |
| 2261 | if ((vport->num_disc_nodes == 0) && |
| 2262 | (vport->fc_npr_cnt)) |
| 2263 | lpfc_els_disc_plogi(vport); |
| 2264 | } else { |
| 2265 | /* Check if there are more PLOGIs to be sent */ |
| 2266 | lpfc_more_plogi(vport); |
| 2267 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2268 | if (vport->num_disc_nodes == 0) { |
| 2269 | spin_lock_irq(shost->host_lock); |
| 2270 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 2271 | spin_unlock_irq(shost->host_lock); |
| 2272 | lpfc_can_disctmo(vport); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2273 | lpfc_end_rscn(vport); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2274 | } |
| 2275 | } |
| 2276 | } |
| 2277 | return; |
| 2278 | } |
| 2279 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 2280 | /** |
| 2281 | * lpfc_els_retry_delay: Timer function with a ndlp delayed function timer. |
| 2282 | * @ptr: holder for the pointer to the timer function associated data (ndlp). |
| 2283 | * |
| 2284 | * This routine is invoked by the ndlp delayed-function timer to check |
| 2285 | * whether there is any pending ELS retry event(s) with the node. If not, it |
| 2286 | * simply returns. Otherwise, if there is at least one ELS delayed event, it |
| 2287 | * adds the delayed events to the HBA work list and invokes the |
| 2288 | * lpfc_worker_wake_up() routine to wake up worker thread to process the |
| 2289 | * event. Note that lpfc_nlp_get() is called before posting the event to |
| 2290 | * the work list to hold reference count of ndlp so that it guarantees the |
| 2291 | * reference to ndlp will still be available when the worker thread gets |
| 2292 | * to the event associated with the ndlp. |
| 2293 | **/ |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 2294 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2295 | lpfc_els_retry_delay(unsigned long ptr) |
| 2296 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2297 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr; |
| 2298 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2299 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2300 | unsigned long flags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2301 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2302 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2303 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2304 | if (!list_empty(&evtp->evt_listp)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2305 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2306 | return; |
| 2307 | } |
| 2308 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2309 | /* We need to hold the node by incrementing the reference |
| 2310 | * count until the queued work is done |
| 2311 | */ |
| 2312 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2313 | if (evtp->evt_arg1) { |
| 2314 | evtp->evt = LPFC_EVT_ELS_RETRY; |
| 2315 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2316 | lpfc_worker_wake_up(phba); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2317 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2318 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2319 | return; |
| 2320 | } |
| 2321 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 2322 | /** |
| 2323 | * lpfc_els_retry_delay_handler: Work thread handler for ndlp delayed function. |
| 2324 | * @ndlp: pointer to a node-list data structure. |
| 2325 | * |
| 2326 | * This routine is the worker-thread handler for processing the @ndlp delayed |
| 2327 | * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves |
| 2328 | * the last ELS command from the associated ndlp and invokes the proper ELS |
| 2329 | * function according to the delayed ELS command to retry the command. |
| 2330 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2331 | void |
| 2332 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) |
| 2333 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2334 | struct lpfc_vport *vport = ndlp->vport; |
| 2335 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2336 | uint32_t cmd, did, retry; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2337 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2338 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2339 | did = ndlp->nlp_DID; |
| 2340 | cmd = ndlp->nlp_last_elscmd; |
| 2341 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2342 | |
| 2343 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2344 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2345 | return; |
| 2346 | } |
| 2347 | |
| 2348 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2349 | spin_unlock_irq(shost->host_lock); |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 2350 | /* |
| 2351 | * If a discovery event readded nlp_delayfunc after timer |
| 2352 | * firing and before processing the timer, cancel the |
| 2353 | * nlp_delayfunc. |
| 2354 | */ |
| 2355 | del_timer_sync(&ndlp->nlp_delayfunc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2356 | retry = ndlp->nlp_retry; |
| 2357 | |
| 2358 | switch (cmd) { |
| 2359 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2360 | lpfc_issue_els_flogi(vport, ndlp, retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2361 | break; |
| 2362 | case ELS_CMD_PLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2363 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2364 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2365 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2366 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2367 | break; |
| 2368 | case ELS_CMD_ADISC: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2369 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2370 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2371 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2372 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2373 | break; |
| 2374 | case ELS_CMD_PRLI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2375 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2376 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2377 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2378 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2379 | break; |
| 2380 | case ELS_CMD_LOGO: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2381 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2382 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2383 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 2384 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2385 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2386 | case ELS_CMD_FDISC: |
| 2387 | lpfc_issue_els_fdisc(vport, ndlp, retry); |
| 2388 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2389 | } |
| 2390 | return; |
| 2391 | } |
| 2392 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 2393 | /** |
| 2394 | * lpfc_els_retry: Make retry decision on an els command iocb. |
| 2395 | * @phba: pointer to lpfc hba data structure. |
| 2396 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2397 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2398 | * |
| 2399 | * This routine makes a retry decision on an ELS command IOCB, which has |
| 2400 | * failed. The following ELS IOCBs use this function for retrying the command |
| 2401 | * when previously issued command responsed with error status: FLOGI, PLOGI, |
| 2402 | * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the |
| 2403 | * returned error status, it makes the decision whether a retry shall be |
| 2404 | * issued for the command, and whether a retry shall be made immediately or |
| 2405 | * delayed. In the former case, the corresponding ELS command issuing-function |
| 2406 | * is called to retry the command. In the later case, the ELS command shall |
| 2407 | * be posted to the ndlp delayed event and delayed function timer set to the |
| 2408 | * ndlp for the delayed command issusing. |
| 2409 | * |
| 2410 | * Return code |
| 2411 | * 0 - No retry of els command is made |
| 2412 | * 1 - Immediate or delayed retry of els command is made |
| 2413 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2414 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2415 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2416 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2417 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2418 | struct lpfc_vport *vport = cmdiocb->vport; |
| 2419 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2420 | IOCB_t *irsp = &rspiocb->iocb; |
| 2421 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2422 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2423 | uint32_t *elscmd; |
| 2424 | struct ls_rjt stat; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2425 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2426 | int logerr = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2427 | uint32_t cmd = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2428 | uint32_t did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2429 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2430 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2431 | /* Note: context2 may be 0 for internal driver abort |
| 2432 | * of delays ELS command. |
| 2433 | */ |
| 2434 | |
| 2435 | if (pcmd && pcmd->virt) { |
| 2436 | elscmd = (uint32_t *) (pcmd->virt); |
| 2437 | cmd = *elscmd++; |
| 2438 | } |
| 2439 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2440 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2441 | did = ndlp->nlp_DID; |
| 2442 | else { |
| 2443 | /* We should only hit this case for retrying PLOGI */ |
| 2444 | did = irsp->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2445 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2446 | if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 2447 | && (cmd != ELS_CMD_PLOGI)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2448 | return 1; |
| 2449 | } |
| 2450 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2451 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 2452 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", |
| 2453 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); |
| 2454 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2455 | switch (irsp->ulpStatus) { |
| 2456 | case IOSTAT_FCP_RSP_ERROR: |
| 2457 | case IOSTAT_REMOTE_STOP: |
| 2458 | break; |
| 2459 | |
| 2460 | case IOSTAT_LOCAL_REJECT: |
| 2461 | switch ((irsp->un.ulpWord[4] & 0xff)) { |
| 2462 | case IOERR_LOOP_OPEN_FAILURE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2463 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2464 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2465 | retry = 1; |
| 2466 | break; |
| 2467 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2468 | case IOERR_ILLEGAL_COMMAND: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2469 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2470 | "0124 Retry illegal cmd x%x " |
| 2471 | "retry:x%x delay:x%x\n", |
| 2472 | cmd, cmdiocb->retry, delay); |
| 2473 | retry = 1; |
| 2474 | /* All command's retry policy */ |
| 2475 | maxretry = 8; |
| 2476 | if (cmdiocb->retry > 2) |
| 2477 | delay = 1000; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2478 | break; |
| 2479 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2480 | case IOERR_NO_RESOURCES: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2481 | logerr = 1; /* HBA out of resources */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2482 | retry = 1; |
| 2483 | if (cmdiocb->retry > 100) |
| 2484 | delay = 100; |
| 2485 | maxretry = 250; |
| 2486 | break; |
| 2487 | |
| 2488 | case IOERR_ILLEGAL_FRAME: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2489 | delay = 100; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2490 | retry = 1; |
| 2491 | break; |
| 2492 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2493 | case IOERR_SEQUENCE_TIMEOUT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2494 | case IOERR_INVALID_RPI: |
| 2495 | retry = 1; |
| 2496 | break; |
| 2497 | } |
| 2498 | break; |
| 2499 | |
| 2500 | case IOSTAT_NPORT_RJT: |
| 2501 | case IOSTAT_FABRIC_RJT: |
| 2502 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 2503 | retry = 1; |
| 2504 | break; |
| 2505 | } |
| 2506 | break; |
| 2507 | |
| 2508 | case IOSTAT_NPORT_BSY: |
| 2509 | case IOSTAT_FABRIC_BSY: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2510 | logerr = 1; /* Fabric / Remote NPort out of resources */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2511 | retry = 1; |
| 2512 | break; |
| 2513 | |
| 2514 | case IOSTAT_LS_RJT: |
| 2515 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); |
| 2516 | /* Added for Vendor specifc support |
| 2517 | * Just keep retrying for these Rsn / Exp codes |
| 2518 | */ |
| 2519 | switch (stat.un.b.lsRjtRsnCode) { |
| 2520 | case LSRJT_UNABLE_TPC: |
| 2521 | if (stat.un.b.lsRjtRsnCodeExp == |
| 2522 | LSEXP_CMD_IN_PROGRESS) { |
| 2523 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2524 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2525 | maxretry = 48; |
| 2526 | } |
| 2527 | retry = 1; |
| 2528 | break; |
| 2529 | } |
| 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 = lpfc_max_els_tries + 1; |
| 2533 | retry = 1; |
| 2534 | break; |
| 2535 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2536 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2537 | (cmd == ELS_CMD_FDISC) && |
| 2538 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2539 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2540 | "0125 FDISC Failed (x%x). " |
| 2541 | "Fabric out of resources\n", |
| 2542 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2543 | lpfc_vport_set_state(vport, |
| 2544 | FC_VPORT_NO_FABRIC_RSCS); |
| 2545 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2546 | break; |
| 2547 | |
| 2548 | case LSRJT_LOGICAL_BSY: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2549 | if ((cmd == ELS_CMD_PLOGI) || |
| 2550 | (cmd == ELS_CMD_PRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2551 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2552 | maxretry = 48; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2553 | } else if (cmd == ELS_CMD_FDISC) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2554 | /* FDISC retry policy */ |
| 2555 | maxretry = 48; |
| 2556 | if (cmdiocb->retry >= 32) |
| 2557 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2558 | } |
| 2559 | retry = 1; |
| 2560 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2561 | |
| 2562 | case LSRJT_LOGICAL_ERR: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2563 | /* There are some cases where switches return this |
| 2564 | * error when they are not ready and should be returning |
| 2565 | * Logical Busy. We should delay every time. |
| 2566 | */ |
| 2567 | if (cmd == ELS_CMD_FDISC && |
| 2568 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { |
| 2569 | maxretry = 3; |
| 2570 | delay = 1000; |
| 2571 | retry = 1; |
| 2572 | break; |
| 2573 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2574 | case LSRJT_PROTOCOL_ERR: |
| 2575 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2576 | (cmd == ELS_CMD_FDISC) && |
| 2577 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || |
| 2578 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) |
| 2579 | ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2580 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2581 | "0123 FDISC Failed (x%x). " |
| 2582 | "Fabric Detected Bad WWN\n", |
| 2583 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2584 | lpfc_vport_set_state(vport, |
| 2585 | FC_VPORT_FABRIC_REJ_WWN); |
| 2586 | } |
| 2587 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2588 | } |
| 2589 | break; |
| 2590 | |
| 2591 | case IOSTAT_INTERMED_RSP: |
| 2592 | case IOSTAT_BA_RJT: |
| 2593 | break; |
| 2594 | |
| 2595 | default: |
| 2596 | break; |
| 2597 | } |
| 2598 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2599 | if (did == FDMI_DID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2600 | retry = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2601 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2602 | if ((cmd == ELS_CMD_FLOGI) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 2603 | (phba->fc_topology != TOPOLOGY_LOOP) && |
| 2604 | !lpfc_error_lost_link(irsp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2605 | /* FLOGI retry policy */ |
| 2606 | retry = 1; |
| 2607 | maxretry = 48; |
| 2608 | if (cmdiocb->retry >= 32) |
| 2609 | delay = 1000; |
| 2610 | } |
| 2611 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2612 | if ((++cmdiocb->retry) >= maxretry) { |
| 2613 | phba->fc_stat.elsRetryExceeded++; |
| 2614 | retry = 0; |
| 2615 | } |
| 2616 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2617 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 2618 | retry = 0; |
| 2619 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2620 | if (retry) { |
| 2621 | |
| 2622 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2623 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2624 | "0107 Retry ELS command x%x to remote " |
| 2625 | "NPORT x%x Data: x%x x%x\n", |
| 2626 | cmd, did, cmdiocb->retry, delay); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2627 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2628 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && |
| 2629 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 2630 | ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) { |
| 2631 | /* Don't reset timer for no resources */ |
| 2632 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2633 | /* If discovery / RSCN timer is running, reset it */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2634 | if (timer_pending(&vport->fc_disctmo) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2635 | (vport->fc_flag & FC_RSCN_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2636 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2637 | } |
| 2638 | |
| 2639 | phba->fc_stat.elsXmitRetry++; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2640 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2641 | phba->fc_stat.elsDelayRetry++; |
| 2642 | ndlp->nlp_retry = cmdiocb->retry; |
| 2643 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2644 | /* delay is specified in milliseconds */ |
| 2645 | mod_timer(&ndlp->nlp_delayfunc, |
| 2646 | jiffies + msecs_to_jiffies(delay)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2647 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2648 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2649 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2650 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2651 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2652 | if (cmd == ELS_CMD_PRLI) |
| 2653 | lpfc_nlp_set_state(vport, ndlp, |
| 2654 | NLP_STE_REG_LOGIN_ISSUE); |
| 2655 | else |
| 2656 | lpfc_nlp_set_state(vport, ndlp, |
| 2657 | NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2658 | ndlp->nlp_last_elscmd = cmd; |
| 2659 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2660 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2661 | } |
| 2662 | switch (cmd) { |
| 2663 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2664 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2665 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2666 | case ELS_CMD_FDISC: |
| 2667 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); |
| 2668 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2669 | case ELS_CMD_PLOGI: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2670 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2671 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2672 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2673 | NLP_STE_PLOGI_ISSUE); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2674 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2675 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2676 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2677 | case ELS_CMD_ADISC: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -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, NLP_STE_ADISC_ISSUE); |
| 2680 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2681 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2682 | case ELS_CMD_PRLI: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2683 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2684 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
| 2685 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2686 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2687 | case ELS_CMD_LOGO: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2688 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2689 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 2690 | lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2691 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2692 | } |
| 2693 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2694 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2695 | if (logerr) { |
| 2696 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2697 | "0137 No retry ELS command x%x to remote " |
| 2698 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", |
| 2699 | cmd, did, irsp->ulpStatus, |
| 2700 | irsp->un.ulpWord[4]); |
| 2701 | } |
| 2702 | else { |
| 2703 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 2704 | "0108 No retry ELS command x%x to remote " |
| 2705 | "NPORT x%x Retried:%d Error:x%x/%x\n", |
| 2706 | cmd, did, cmdiocb->retry, irsp->ulpStatus, |
| 2707 | irsp->un.ulpWord[4]); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2708 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2709 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2710 | } |
| 2711 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 2712 | /** |
| 2713 | * lpfc_els_free_data: Free lpfc dma buffer and data structure with an iocb. |
| 2714 | * @phba: pointer to lpfc hba data structure. |
| 2715 | * @buf_ptr1: pointer to the lpfc DMA buffer data structure. |
| 2716 | * |
| 2717 | * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) |
| 2718 | * associated with a command IOCB back to the lpfc DMA buffer pool. It first |
| 2719 | * checks to see whether there is a lpfc DMA buffer associated with the |
| 2720 | * response of the command IOCB. If so, it will be released before releasing |
| 2721 | * the lpfc DMA buffer associated with the IOCB itself. |
| 2722 | * |
| 2723 | * Return code |
| 2724 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 2725 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2726 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2727 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) |
| 2728 | { |
| 2729 | struct lpfc_dmabuf *buf_ptr; |
| 2730 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 2731 | /* Free the response before processing the command. */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2732 | if (!list_empty(&buf_ptr1->list)) { |
| 2733 | list_remove_head(&buf_ptr1->list, buf_ptr, |
| 2734 | struct lpfc_dmabuf, |
| 2735 | list); |
| 2736 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 2737 | kfree(buf_ptr); |
| 2738 | } |
| 2739 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); |
| 2740 | kfree(buf_ptr1); |
| 2741 | return 0; |
| 2742 | } |
| 2743 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 2744 | /** |
| 2745 | * lpfc_els_free_bpl: Free lpfc dma buffer and data structure with bpl. |
| 2746 | * @phba: pointer to lpfc hba data structure. |
| 2747 | * @buf_ptr: pointer to the lpfc dma buffer data structure. |
| 2748 | * |
| 2749 | * This routine releases the lpfc Direct Memory Access (DMA) buffer |
| 2750 | * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer |
| 2751 | * pool. |
| 2752 | * |
| 2753 | * Return code |
| 2754 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) |
| 2755 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2756 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2757 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) |
| 2758 | { |
| 2759 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 2760 | kfree(buf_ptr); |
| 2761 | return 0; |
| 2762 | } |
| 2763 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 2764 | /** |
| 2765 | * lpfc_els_free_iocb: Free a command iocb and its associated resources. |
| 2766 | * @phba: pointer to lpfc hba data structure. |
| 2767 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 2768 | * |
| 2769 | * This routine frees a command IOCB and its associated resources. The |
| 2770 | * command IOCB data structure contains the reference to various associated |
| 2771 | * resources, these fields must be set to NULL if the associated reference |
| 2772 | * not present: |
| 2773 | * context1 - reference to ndlp |
| 2774 | * context2 - reference to cmd |
| 2775 | * context2->next - reference to rsp |
| 2776 | * context3 - reference to bpl |
| 2777 | * |
| 2778 | * It first properly decrements the reference count held on ndlp for the |
| 2779 | * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not |
| 2780 | * set, it invokes the lpfc_els_free_data() routine to release the Direct |
| 2781 | * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it |
| 2782 | * adds the DMA buffer the @phba data structure for the delayed release. |
| 2783 | * If reference to the Buffer Pointer List (BPL) is present, the |
| 2784 | * lpfc_els_free_bpl() routine is invoked to release the DMA memory |
| 2785 | * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is |
| 2786 | * invoked to release the IOCB data structure back to @phba IOCBQ list. |
| 2787 | * |
| 2788 | * Return code |
| 2789 | * 0 - Success (currently, always return 0) |
| 2790 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2791 | int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2792 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2793 | { |
| 2794 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2795 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2796 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2797 | ndlp = (struct lpfc_nodelist *)elsiocb->context1; |
| 2798 | if (ndlp) { |
| 2799 | if (ndlp->nlp_flag & NLP_DEFER_RM) { |
| 2800 | lpfc_nlp_put(ndlp); |
| 2801 | |
| 2802 | /* If the ndlp is not being used by another discovery |
| 2803 | * thread, free it. |
| 2804 | */ |
| 2805 | if (!lpfc_nlp_not_used(ndlp)) { |
| 2806 | /* If ndlp is being used by another discovery |
| 2807 | * thread, just clear NLP_DEFER_RM |
| 2808 | */ |
| 2809 | ndlp->nlp_flag &= ~NLP_DEFER_RM; |
| 2810 | } |
| 2811 | } |
| 2812 | else |
| 2813 | lpfc_nlp_put(ndlp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2814 | elsiocb->context1 = NULL; |
| 2815 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2816 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
| 2817 | if (elsiocb->context2) { |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2818 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { |
| 2819 | /* Firmware could still be in progress of DMAing |
| 2820 | * payload, so don't free data buffer till after |
| 2821 | * a hbeat. |
| 2822 | */ |
| 2823 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; |
| 2824 | buf_ptr = elsiocb->context2; |
| 2825 | elsiocb->context2 = NULL; |
| 2826 | if (buf_ptr) { |
| 2827 | buf_ptr1 = NULL; |
| 2828 | spin_lock_irq(&phba->hbalock); |
| 2829 | if (!list_empty(&buf_ptr->list)) { |
| 2830 | list_remove_head(&buf_ptr->list, |
| 2831 | buf_ptr1, struct lpfc_dmabuf, |
| 2832 | list); |
| 2833 | INIT_LIST_HEAD(&buf_ptr1->list); |
| 2834 | list_add_tail(&buf_ptr1->list, |
| 2835 | &phba->elsbuf); |
| 2836 | phba->elsbuf_cnt++; |
| 2837 | } |
| 2838 | INIT_LIST_HEAD(&buf_ptr->list); |
| 2839 | list_add_tail(&buf_ptr->list, &phba->elsbuf); |
| 2840 | phba->elsbuf_cnt++; |
| 2841 | spin_unlock_irq(&phba->hbalock); |
| 2842 | } |
| 2843 | } else { |
| 2844 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; |
| 2845 | lpfc_els_free_data(phba, buf_ptr1); |
| 2846 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2847 | } |
| 2848 | |
| 2849 | if (elsiocb->context3) { |
| 2850 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2851 | lpfc_els_free_bpl(phba, buf_ptr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2852 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2853 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2854 | return 0; |
| 2855 | } |
| 2856 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 2857 | /** |
| 2858 | * lpfc_cmpl_els_logo_acc: Completion callback function to logo acc response. |
| 2859 | * @phba: pointer to lpfc hba data structure. |
| 2860 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2861 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2862 | * |
| 2863 | * This routine is the completion callback function to the Logout (LOGO) |
| 2864 | * Accept (ACC) Response ELS command. This routine is invoked to indicate |
| 2865 | * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to |
| 2866 | * release the ndlp if it has the last reference remaining (reference count |
| 2867 | * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1 |
| 2868 | * field to NULL to inform the following lpfc_els_free_iocb() routine no |
| 2869 | * ndlp reference count needs to be decremented. Otherwise, the ndlp |
| 2870 | * reference use-count shall be decremented by the lpfc_els_free_iocb() |
| 2871 | * routine. Finally, the lpfc_els_free_iocb() is invoked to release the |
| 2872 | * IOCB data structure. |
| 2873 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2874 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2875 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2876 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2877 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2878 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2879 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2880 | IOCB_t *irsp; |
| 2881 | |
| 2882 | irsp = &rspiocb->iocb; |
| 2883 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 2884 | "ACC LOGO cmpl: status:x%x/x%x did:x%x", |
| 2885 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2886 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2887 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2888 | "0109 ACC to LOGO completes to NPort x%x " |
| 2889 | "Data: x%x x%x x%x\n", |
| 2890 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 2891 | ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2892 | |
| 2893 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { |
| 2894 | /* NPort Recovery mode or node is just allocated */ |
| 2895 | if (!lpfc_nlp_not_used(ndlp)) { |
| 2896 | /* If the ndlp is being used by another discovery |
| 2897 | * thread, just unregister the RPI. |
| 2898 | */ |
| 2899 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2900 | } else { |
| 2901 | /* Indicate the node has already released, should |
| 2902 | * not reference to it from within lpfc_els_free_iocb. |
| 2903 | */ |
| 2904 | cmdiocb->context1 = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2905 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2906 | } |
| 2907 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2908 | return; |
| 2909 | } |
| 2910 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 2911 | /** |
| 2912 | * lpfc_mbx_cmpl_dflt_rpi: Completion callbk func for unreg dflt rpi mbox cmd. |
| 2913 | * @phba: pointer to lpfc hba data structure. |
| 2914 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 2915 | * |
| 2916 | * This routine is the completion callback function for unregister default |
| 2917 | * RPI (Remote Port Index) mailbox command to the @phba. It simply releases |
| 2918 | * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and |
| 2919 | * decrements the ndlp reference count held for this completion callback |
| 2920 | * function. After that, it invokes the lpfc_nlp_not_used() to check |
| 2921 | * whether there is only one reference left on the ndlp. If so, it will |
| 2922 | * perform one more decrement and trigger the release of the ndlp. |
| 2923 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2924 | void |
| 2925 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 2926 | { |
| 2927 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 2928 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 2929 | |
| 2930 | pmb->context1 = NULL; |
| 2931 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2932 | kfree(mp); |
| 2933 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2934 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2935 | lpfc_nlp_put(ndlp); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2936 | /* This is the end of the default RPI cleanup logic for this |
| 2937 | * ndlp. If no other discovery threads are using this ndlp. |
| 2938 | * we should free all resources associated with it. |
| 2939 | */ |
| 2940 | lpfc_nlp_not_used(ndlp); |
| 2941 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2942 | return; |
| 2943 | } |
| 2944 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 2945 | /** |
| 2946 | * lpfc_cmpl_els_rsp: Completion callback function for els response iocb cmd. |
| 2947 | * @phba: pointer to lpfc hba data structure. |
| 2948 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 2949 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 2950 | * |
| 2951 | * This routine is the completion callback function for ELS Response IOCB |
| 2952 | * command. In normal case, this callback function just properly sets the |
| 2953 | * nlp_flag bitmap in the ndlp data structure, if the mbox command reference |
| 2954 | * field in the command IOCB is not NULL, the referred mailbox command will |
| 2955 | * be send out, and then invokes the lpfc_els_free_iocb() routine to release |
| 2956 | * the IOCB. Under error conditions, such as when a LS_RJT is returned or a |
| 2957 | * link down event occurred during the discovery, the lpfc_nlp_not_used() |
| 2958 | * routine shall be invoked trying to release the ndlp if no other threads |
| 2959 | * are currently referring it. |
| 2960 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2961 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2962 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2963 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2964 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2965 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2966 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; |
| 2967 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2968 | IOCB_t *irsp; |
| 2969 | uint8_t *pcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2970 | LPFC_MBOXQ_t *mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2971 | struct lpfc_dmabuf *mp = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2972 | uint32_t ls_rjt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2973 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 2974 | irsp = &rspiocb->iocb; |
| 2975 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2976 | if (cmdiocb->context_un.mbox) |
| 2977 | mbox = cmdiocb->context_un.mbox; |
| 2978 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2979 | /* First determine if this is a LS_RJT cmpl. Note, this callback |
| 2980 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. |
| 2981 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2982 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2983 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 2984 | (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2985 | /* A LS_RJT associated with Default RPI cleanup has its own |
| 2986 | * seperate code path. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2987 | */ |
| 2988 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
| 2989 | ls_rjt = 1; |
| 2990 | } |
| 2991 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2992 | /* Check to see if link went down during discovery */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2993 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2994 | if (mbox) { |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2995 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 2996 | if (mp) { |
| 2997 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2998 | kfree(mp); |
| 2999 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3000 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3001 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3002 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 3003 | (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3004 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3005 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3006 | /* Indicate the node has already released, |
| 3007 | * should not reference to it from within |
| 3008 | * the routine lpfc_els_free_iocb. |
| 3009 | */ |
| 3010 | cmdiocb->context1 = NULL; |
| 3011 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3012 | goto out; |
| 3013 | } |
| 3014 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3015 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3016 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3017 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3018 | cmdiocb->iocb.un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3019 | /* ELS response tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3020 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3021 | "0110 ELS response tag x%x completes " |
| 3022 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", |
| 3023 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, |
| 3024 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, |
| 3025 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3026 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3027 | if (mbox) { |
| 3028 | if ((rspiocb->iocb.ulpStatus == 0) |
| 3029 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3030 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3031 | /* Increment reference count to ndlp to hold the |
| 3032 | * reference to ndlp for the callback function. |
| 3033 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3034 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3035 | mbox->vport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3036 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
| 3037 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 3038 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 3039 | } |
| 3040 | else { |
| 3041 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
| 3042 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 3043 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3044 | NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3045 | } |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3046 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3047 | != MBX_NOT_FINISHED) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3048 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3049 | else |
| 3050 | /* Decrement the ndlp reference count we |
| 3051 | * set for this failed mailbox command. |
| 3052 | */ |
| 3053 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3054 | |
| 3055 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ |
| 3056 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3057 | "0138 ELS rsp: Cannot issue reg_login for x%x " |
| 3058 | "Data: x%x x%x x%x\n", |
| 3059 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3060 | ndlp->nlp_rpi); |
| 3061 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3062 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3063 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3064 | /* Indicate node has already been released, |
| 3065 | * should not reference to it from within |
| 3066 | * the routine lpfc_els_free_iocb. |
| 3067 | */ |
| 3068 | cmdiocb->context1 = NULL; |
| 3069 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3070 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3071 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
| 3072 | if (!lpfc_error_lost_link(irsp) && |
| 3073 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3074 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3075 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3076 | /* Indicate node has already been |
| 3077 | * released, should not reference |
| 3078 | * to it from within the routine |
| 3079 | * lpfc_els_free_iocb. |
| 3080 | */ |
| 3081 | cmdiocb->context1 = NULL; |
| 3082 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3083 | } |
| 3084 | } |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 3085 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 3086 | if (mp) { |
| 3087 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3088 | kfree(mp); |
| 3089 | } |
| 3090 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3091 | } |
| 3092 | out: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3093 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3094 | spin_lock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3095 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3096 | spin_unlock_irq(shost->host_lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3097 | |
| 3098 | /* If the node is not being used by another discovery thread, |
| 3099 | * and we are sending a reject, we are done with it. |
| 3100 | * Release driver reference count here and free associated |
| 3101 | * resources. |
| 3102 | */ |
| 3103 | if (ls_rjt) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3104 | if (lpfc_nlp_not_used(ndlp)) |
| 3105 | /* Indicate node has already been released, |
| 3106 | * should not reference to it from within |
| 3107 | * the routine lpfc_els_free_iocb. |
| 3108 | */ |
| 3109 | cmdiocb->context1 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3110 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3111 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3112 | lpfc_els_free_iocb(phba, cmdiocb); |
| 3113 | return; |
| 3114 | } |
| 3115 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 3116 | /** |
| 3117 | * lpfc_els_rsp_acc: Prepare and issue an acc response iocb command. |
| 3118 | * @vport: pointer to a host virtual N_Port data structure. |
| 3119 | * @flag: the els command code to be accepted. |
| 3120 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3121 | * @ndlp: pointer to a node-list data structure. |
| 3122 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3123 | * |
| 3124 | * This routine prepares and issues an Accept (ACC) response IOCB |
| 3125 | * command. It uses the @flag to properly set up the IOCB field for the |
| 3126 | * specific ACC response command to be issued and invokes the |
| 3127 | * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a |
| 3128 | * @mbox pointer is passed in, it will be put into the context_un.mbox |
| 3129 | * field of the IOCB for the completion callback function to issue the |
| 3130 | * mailbox command to the HBA later when callback is invoked. |
| 3131 | * |
| 3132 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3133 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3134 | * will be stored into the context1 field of the IOCB for the completion |
| 3135 | * callback function to the corresponding response ELS IOCB command. |
| 3136 | * |
| 3137 | * Return code |
| 3138 | * 0 - Successfully issued acc response |
| 3139 | * 1 - Failed to issue acc response |
| 3140 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3141 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3142 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
| 3143 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3144 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3145 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3146 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3147 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3148 | IOCB_t *icmd; |
| 3149 | IOCB_t *oldcmd; |
| 3150 | struct lpfc_iocbq *elsiocb; |
| 3151 | struct lpfc_sli_ring *pring; |
| 3152 | struct lpfc_sli *psli; |
| 3153 | uint8_t *pcmd; |
| 3154 | uint16_t cmdsize; |
| 3155 | int rc; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3156 | ELS_PKT *els_pkt_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3157 | |
| 3158 | psli = &phba->sli; |
| 3159 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 3160 | oldcmd = &oldiocb->iocb; |
| 3161 | |
| 3162 | switch (flag) { |
| 3163 | case ELS_CMD_ACC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3164 | cmdsize = sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3165 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3166 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3167 | if (!elsiocb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3168 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3169 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3170 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3171 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3172 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3173 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3174 | icmd = &elsiocb->iocb; |
| 3175 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3176 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3177 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3178 | pcmd += sizeof(uint32_t); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3179 | |
| 3180 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3181 | "Issue ACC: did:x%x flg:x%x", |
| 3182 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3183 | break; |
| 3184 | case ELS_CMD_PLOGI: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3185 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3186 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 3187 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3188 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3189 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3190 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3191 | icmd = &elsiocb->iocb; |
| 3192 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3193 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3194 | |
| 3195 | if (mbox) |
| 3196 | elsiocb->context_un.mbox = mbox; |
| 3197 | |
| 3198 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3199 | pcmd += sizeof(uint32_t); |
| 3200 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3201 | |
| 3202 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3203 | "Issue ACC PLOGI: did:x%x flg:x%x", |
| 3204 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3205 | break; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3206 | case ELS_CMD_PRLO: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3207 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3208 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3209 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
| 3210 | if (!elsiocb) |
| 3211 | return 1; |
| 3212 | |
| 3213 | icmd = &elsiocb->iocb; |
| 3214 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3215 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3216 | |
| 3217 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3218 | sizeof(uint32_t) + sizeof(PRLO)); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3219 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
| 3220 | els_pkt_ptr = (ELS_PKT *) pcmd; |
| 3221 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3222 | |
| 3223 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3224 | "Issue ACC PRLO: did:x%x flg:x%x", |
| 3225 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 3226 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3227 | default: |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3228 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3229 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3230 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3231 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3232 | "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " |
| 3233 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n", |
| 3234 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3235 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3236 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3237 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3238 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3239 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3240 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3241 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
| 3242 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3243 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3244 | } |
| 3245 | |
| 3246 | phba->fc_stat.elsXmitACC++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3247 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3248 | if (rc == IOCB_ERROR) { |
| 3249 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3250 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3251 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3252 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3253 | } |
| 3254 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 3255 | /** |
| 3256 | * lpfc_els_rsp_reject: Propare and issue a rjt response iocb command. |
| 3257 | * @vport: pointer to a virtual N_Port data structure. |
| 3258 | * @rejectError: |
| 3259 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3260 | * @ndlp: pointer to a node-list data structure. |
| 3261 | * @mbox: pointer to the driver internal queue element for mailbox command. |
| 3262 | * |
| 3263 | * This routine prepares and issue an Reject (RJT) response IOCB |
| 3264 | * command. If a @mbox pointer is passed in, it will be put into the |
| 3265 | * context_un.mbox field of the IOCB for the completion callback function |
| 3266 | * to issue to the HBA later. |
| 3267 | * |
| 3268 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3269 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3270 | * will be stored into the context1 field of the IOCB for the completion |
| 3271 | * callback function to the reject response ELS IOCB command. |
| 3272 | * |
| 3273 | * Return code |
| 3274 | * 0 - Successfully issued reject response |
| 3275 | * 1 - Failed to issue reject response |
| 3276 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3277 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3278 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3279 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
| 3280 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3281 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3282 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3283 | IOCB_t *icmd; |
| 3284 | IOCB_t *oldcmd; |
| 3285 | struct lpfc_iocbq *elsiocb; |
| 3286 | struct lpfc_sli_ring *pring; |
| 3287 | struct lpfc_sli *psli; |
| 3288 | uint8_t *pcmd; |
| 3289 | uint16_t cmdsize; |
| 3290 | int rc; |
| 3291 | |
| 3292 | psli = &phba->sli; |
| 3293 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 3294 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3295 | cmdsize = 2 * sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3296 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3297 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3298 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3299 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3300 | |
| 3301 | icmd = &elsiocb->iocb; |
| 3302 | oldcmd = &oldiocb->iocb; |
| 3303 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3304 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3305 | |
| 3306 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3307 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3308 | *((uint32_t *) (pcmd)) = rejectError; |
| 3309 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3310 | if (mbox) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3311 | elsiocb->context_un.mbox = mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3312 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3313 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3314 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3315 | "0129 Xmit ELS RJT x%x response tag x%x " |
| 3316 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 3317 | "rpi x%x\n", |
| 3318 | rejectError, elsiocb->iotag, |
| 3319 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 3320 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3321 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3322 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", |
| 3323 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); |
| 3324 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3325 | phba->fc_stat.elsXmitLSRJT++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3326 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3327 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3328 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3329 | if (rc == IOCB_ERROR) { |
| 3330 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3331 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3332 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3333 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3334 | } |
| 3335 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 3336 | /** |
| 3337 | * lpfc_els_rsp_adisc_acc: Prepare and issue acc response to adisc iocb cmd. |
| 3338 | * @vport: pointer to a virtual N_Port data structure. |
| 3339 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3340 | * @ndlp: pointer to a node-list data structure. |
| 3341 | * |
| 3342 | * This routine prepares and issues an Accept (ACC) response to Address |
| 3343 | * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB |
| 3344 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3345 | * |
| 3346 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3347 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3348 | * will be stored into the context1 field of the IOCB for the completion |
| 3349 | * callback function to the ADISC Accept response ELS IOCB command. |
| 3350 | * |
| 3351 | * Return code |
| 3352 | * 0 - Successfully issued acc adisc response |
| 3353 | * 1 - Failed to issue adisc acc response |
| 3354 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3355 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3356 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
| 3357 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3358 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3359 | struct lpfc_hba *phba = vport->phba; |
| 3360 | struct lpfc_sli *psli = &phba->sli; |
| 3361 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3362 | ADISC *ap; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3363 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3364 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3365 | uint8_t *pcmd; |
| 3366 | uint16_t cmdsize; |
| 3367 | int rc; |
| 3368 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3369 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3370 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3371 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3372 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3373 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3374 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3375 | icmd = &elsiocb->iocb; |
| 3376 | oldcmd = &oldiocb->iocb; |
| 3377 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3378 | |
| 3379 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3380 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3381 | "0130 Xmit ADISC ACC response iotag x%x xri: " |
| 3382 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", |
| 3383 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3384 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3385 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3386 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3387 | |
| 3388 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3389 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3390 | |
| 3391 | ap = (ADISC *) (pcmd); |
| 3392 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3393 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3394 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3395 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3396 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3397 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3398 | "Issue ACC ADISC: did:x%x flg:x%x", |
| 3399 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3400 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3401 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3402 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3403 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3404 | if (rc == IOCB_ERROR) { |
| 3405 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3406 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3407 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3408 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3409 | } |
| 3410 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 3411 | /** |
| 3412 | * lpfc_els_rsp_prli_acc: Prepare and issue acc response to prli iocb cmd. |
| 3413 | * @vport: pointer to a virtual N_Port data structure. |
| 3414 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3415 | * @ndlp: pointer to a node-list data structure. |
| 3416 | * |
| 3417 | * This routine prepares and issues an Accept (ACC) response to Process |
| 3418 | * Login (PRLI) ELS command. It simply prepares the payload of the IOCB |
| 3419 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. |
| 3420 | * |
| 3421 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3422 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3423 | * will be stored into the context1 field of the IOCB for the completion |
| 3424 | * callback function to the PRLI Accept response ELS IOCB command. |
| 3425 | * |
| 3426 | * Return code |
| 3427 | * 0 - Successfully issued acc prli response |
| 3428 | * 1 - Failed to issue acc prli response |
| 3429 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3430 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3431 | 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] | 3432 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3433 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3434 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3435 | PRLI *npr; |
| 3436 | lpfc_vpd_t *vpd; |
| 3437 | IOCB_t *icmd; |
| 3438 | IOCB_t *oldcmd; |
| 3439 | struct lpfc_iocbq *elsiocb; |
| 3440 | struct lpfc_sli_ring *pring; |
| 3441 | struct lpfc_sli *psli; |
| 3442 | uint8_t *pcmd; |
| 3443 | uint16_t cmdsize; |
| 3444 | int rc; |
| 3445 | |
| 3446 | psli = &phba->sli; |
| 3447 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 3448 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3449 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3450 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3451 | ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK))); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3452 | if (!elsiocb) |
| 3453 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3454 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3455 | icmd = &elsiocb->iocb; |
| 3456 | oldcmd = &oldiocb->iocb; |
| 3457 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3458 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3459 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3460 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " |
| 3461 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 3462 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3463 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3464 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3465 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3466 | |
| 3467 | *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3468 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3469 | |
| 3470 | /* For PRLI, remainder of payload is PRLI parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3471 | memset(pcmd, 0, sizeof(PRLI)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3472 | |
| 3473 | npr = (PRLI *) pcmd; |
| 3474 | vpd = &phba->vpd; |
| 3475 | /* |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3476 | * If the remote port is a target and our firmware version is 3.20 or |
| 3477 | * later, set the following bits for FC-TAPE support. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3478 | */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3479 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
| 3480 | (vpd->rev.feaLevelHigh >= 0x02)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3481 | npr->ConfmComplAllowed = 1; |
| 3482 | npr->Retry = 1; |
| 3483 | npr->TaskRetryIdReq = 1; |
| 3484 | } |
| 3485 | |
| 3486 | npr->acceptRspCode = PRLI_REQ_EXECUTED; |
| 3487 | npr->estabImagePair = 1; |
| 3488 | npr->readXferRdyDis = 1; |
| 3489 | npr->ConfmComplAllowed = 1; |
| 3490 | |
| 3491 | npr->prliType = PRLI_FCP_TYPE; |
| 3492 | npr->initiatorFunc = 1; |
| 3493 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3494 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3495 | "Issue ACC PRLI: did:x%x flg:x%x", |
| 3496 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3497 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3498 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3499 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3500 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3501 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3502 | if (rc == IOCB_ERROR) { |
| 3503 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3504 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3505 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3506 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3507 | } |
| 3508 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 3509 | /** |
| 3510 | * lpfc_els_rsp_rnid_acc: Issue rnid acc response iocb command. |
| 3511 | * @vport: pointer to a virtual N_Port data structure. |
| 3512 | * @format: rnid command format. |
| 3513 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 3514 | * @ndlp: pointer to a node-list data structure. |
| 3515 | * |
| 3516 | * This routine issues a Request Node Identification Data (RNID) Accept |
| 3517 | * (ACC) response. It constructs the RNID ACC response command according to |
| 3518 | * the proper @format and then calls the lpfc_sli_issue_iocb() routine to |
| 3519 | * issue the response. Note that this command does not need to hold the ndlp |
| 3520 | * reference count for the callback. So, the ndlp reference count taken by |
| 3521 | * the lpfc_prep_els_iocb() routine is put back and the context1 field of |
| 3522 | * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that |
| 3523 | * there is no ndlp reference available. |
| 3524 | * |
| 3525 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 3526 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 3527 | * will be stored into the context1 field of the IOCB for the completion |
| 3528 | * callback function. However, for the RNID Accept Response ELS command, |
| 3529 | * this is undone later by this routine after the IOCB is allocated. |
| 3530 | * |
| 3531 | * Return code |
| 3532 | * 0 - Successfully issued acc rnid response |
| 3533 | * 1 - Failed to issue acc rnid response |
| 3534 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3535 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3536 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3537 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3538 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3539 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3540 | RNID *rn; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3541 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3542 | struct lpfc_iocbq *elsiocb; |
| 3543 | struct lpfc_sli_ring *pring; |
| 3544 | struct lpfc_sli *psli; |
| 3545 | uint8_t *pcmd; |
| 3546 | uint16_t cmdsize; |
| 3547 | int rc; |
| 3548 | |
| 3549 | psli = &phba->sli; |
| 3550 | pring = &psli->ring[LPFC_ELS_RING]; |
| 3551 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3552 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
| 3553 | + (2 * sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3554 | if (format) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3555 | cmdsize += sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3556 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3557 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3558 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3559 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3560 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3561 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3562 | icmd = &elsiocb->iocb; |
| 3563 | oldcmd = &oldiocb->iocb; |
| 3564 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3565 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3566 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3567 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", |
| 3568 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3569 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3570 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3571 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3572 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3573 | memset(pcmd, 0, sizeof(RNID)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3574 | rn = (RNID *) (pcmd); |
| 3575 | rn->Format = format; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3576 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
| 3577 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 3578 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3579 | switch (format) { |
| 3580 | case 0: |
| 3581 | rn->SpecificLen = 0; |
| 3582 | break; |
| 3583 | case RNID_TOPOLOGY_DISC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3584 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3585 | memcpy(&rn->un.topologyDisc.portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3586 | &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3587 | rn->un.topologyDisc.unitType = RNID_HBA; |
| 3588 | rn->un.topologyDisc.physPort = 0; |
| 3589 | rn->un.topologyDisc.attachedNodes = 0; |
| 3590 | break; |
| 3591 | default: |
| 3592 | rn->CommonLen = 0; |
| 3593 | rn->SpecificLen = 0; |
| 3594 | break; |
| 3595 | } |
| 3596 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3597 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 3598 | "Issue ACC RNID: did:x%x flg:x%x", |
| 3599 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 3600 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3601 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3602 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3603 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3604 | elsiocb->context1 = NULL; /* Don't need ndlp for cmpl, |
| 3605 | * it could be freed */ |
| 3606 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3607 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3608 | if (rc == IOCB_ERROR) { |
| 3609 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3610 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3611 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3612 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3613 | } |
| 3614 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 3615 | /** |
| 3616 | * lpfc_els_disc_adisc: Issue remaining adisc iocbs to npr nodes of a vport. |
| 3617 | * @vport: pointer to a host virtual N_Port data structure. |
| 3618 | * |
| 3619 | * This routine issues Address Discover (ADISC) ELS commands to those |
| 3620 | * N_Ports which are in node port recovery state and ADISC has not been issued |
| 3621 | * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the |
| 3622 | * lpfc_issue_els_adisc() routine, the per @vport number of discover count |
| 3623 | * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a |
| 3624 | * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will |
| 3625 | * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC |
| 3626 | * IOCBs quit for later pick up. On the other hand, after walking through |
| 3627 | * all the ndlps with the @vport and there is none ADISC IOCB issued, the |
| 3628 | * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is |
| 3629 | * no more ADISC need to be sent. |
| 3630 | * |
| 3631 | * Return code |
| 3632 | * The number of N_Ports with adisc issued. |
| 3633 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3634 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3635 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3636 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3637 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3638 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3639 | int sentadisc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3640 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3641 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3642 | 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] | 3643 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3644 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3645 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 3646 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 3647 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3648 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3649 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3650 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3651 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3652 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 3653 | lpfc_issue_els_adisc(vport, ndlp, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3654 | sentadisc++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3655 | vport->num_disc_nodes++; |
| 3656 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3657 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3658 | spin_lock_irq(shost->host_lock); |
| 3659 | vport->fc_flag |= FC_NLP_MORE; |
| 3660 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3661 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3662 | } |
| 3663 | } |
| 3664 | } |
| 3665 | if (sentadisc == 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3666 | spin_lock_irq(shost->host_lock); |
| 3667 | vport->fc_flag &= ~FC_NLP_MORE; |
| 3668 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3669 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3670 | return sentadisc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3671 | } |
| 3672 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 3673 | /** |
| 3674 | * lpfc_els_disc_plogi: Issue plogi for all npr nodes of a vport before adisc. |
| 3675 | * @vport: pointer to a host virtual N_Port data structure. |
| 3676 | * |
| 3677 | * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports |
| 3678 | * which are in node port recovery state, with a @vport. Each time an ELS |
| 3679 | * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, |
| 3680 | * the per @vport number of discover count (num_disc_nodes) shall be |
| 3681 | * incremented. If the num_disc_nodes reaches a pre-configured threshold |
| 3682 | * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE |
| 3683 | * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for |
| 3684 | * later pick up. On the other hand, after walking through all the ndlps with |
| 3685 | * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag |
| 3686 | * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC |
| 3687 | * PLOGI need to be sent. |
| 3688 | * |
| 3689 | * Return code |
| 3690 | * The number of N_Ports with plogi issued. |
| 3691 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3692 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3693 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3694 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3695 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3696 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3697 | int sentplogi = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3698 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3699 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 3700 | 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] | 3701 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3702 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3703 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 3704 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 3705 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && |
| 3706 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { |
| 3707 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3708 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 3709 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3710 | sentplogi++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3711 | vport->num_disc_nodes++; |
| 3712 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3713 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3714 | spin_lock_irq(shost->host_lock); |
| 3715 | vport->fc_flag |= FC_NLP_MORE; |
| 3716 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3717 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3718 | } |
| 3719 | } |
| 3720 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3721 | if (sentplogi) { |
| 3722 | lpfc_set_disctmo(vport); |
| 3723 | } |
| 3724 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3725 | spin_lock_irq(shost->host_lock); |
| 3726 | vport->fc_flag &= ~FC_NLP_MORE; |
| 3727 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3728 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3729 | return sentplogi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3730 | } |
| 3731 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 3732 | /** |
| 3733 | * lpfc_els_flush_rscn: Clean up any rscn activities with a vport. |
| 3734 | * @vport: pointer to a host virtual N_Port data structure. |
| 3735 | * |
| 3736 | * This routine cleans up any Registration State Change Notification |
| 3737 | * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the |
| 3738 | * @vport together with the host_lock is used to prevent multiple thread |
| 3739 | * trying to access the RSCN array on a same @vport at the same time. |
| 3740 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3741 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3742 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3743 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3744 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3745 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3746 | int i; |
| 3747 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3748 | spin_lock_irq(shost->host_lock); |
| 3749 | if (vport->fc_rscn_flush) { |
| 3750 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 3751 | spin_unlock_irq(shost->host_lock); |
| 3752 | return; |
| 3753 | } |
| 3754 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ |
| 3755 | vport->fc_rscn_flush = 1; |
| 3756 | spin_unlock_irq(shost->host_lock); |
| 3757 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3758 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3759 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3760 | vport->fc_rscn_id_list[i] = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3761 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3762 | spin_lock_irq(shost->host_lock); |
| 3763 | vport->fc_rscn_id_cnt = 0; |
| 3764 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); |
| 3765 | spin_unlock_irq(shost->host_lock); |
| 3766 | lpfc_can_disctmo(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3767 | /* Indicate we are done walking this fc_rscn_id_list */ |
| 3768 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3769 | } |
| 3770 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 3771 | /** |
| 3772 | * lpfc_rscn_payload_check: Check whether there is a pending rscn to a did. |
| 3773 | * @vport: pointer to a host virtual N_Port data structure. |
| 3774 | * @did: remote destination port identifier. |
| 3775 | * |
| 3776 | * This routine checks whether there is any pending Registration State |
| 3777 | * Configuration Notification (RSCN) to a @did on @vport. |
| 3778 | * |
| 3779 | * Return code |
| 3780 | * None zero - The @did matched with a pending rscn |
| 3781 | * 0 - not able to match @did with a pending rscn |
| 3782 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3783 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3784 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3785 | { |
| 3786 | D_ID ns_did; |
| 3787 | D_ID rscn_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3788 | uint32_t *lp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3789 | uint32_t payload_len, i; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3790 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3791 | |
| 3792 | ns_did.un.word = did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3793 | |
| 3794 | /* Never match fabric nodes for RSCNs */ |
| 3795 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3796 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3797 | |
| 3798 | /* If we are doing a FULL RSCN rediscovery, match everything */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3799 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3800 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3801 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3802 | spin_lock_irq(shost->host_lock); |
| 3803 | if (vport->fc_rscn_flush) { |
| 3804 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 3805 | spin_unlock_irq(shost->host_lock); |
| 3806 | return 0; |
| 3807 | } |
| 3808 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 3809 | vport->fc_rscn_flush = 1; |
| 3810 | spin_unlock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3811 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3812 | lp = vport->fc_rscn_id_list[i]->virt; |
| 3813 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 3814 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3815 | while (payload_len) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3816 | rscn_did.un.word = be32_to_cpu(*lp++); |
| 3817 | payload_len -= sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3818 | switch (rscn_did.un.b.resv) { |
| 3819 | case 0: /* Single N_Port ID effected */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3820 | if (ns_did.un.word == rscn_did.un.word) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3821 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3822 | break; |
| 3823 | case 1: /* Whole N_Port Area effected */ |
| 3824 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 3825 | && (ns_did.un.b.area == rscn_did.un.b.area)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3826 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3827 | break; |
| 3828 | case 2: /* Whole N_Port Domain effected */ |
| 3829 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3830 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3831 | break; |
| 3832 | default: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3833 | /* Unknown Identifier in RSCN node */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3834 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 3835 | "0217 Unknown Identifier in " |
| 3836 | "RSCN payload Data: x%x\n", |
| 3837 | rscn_did.un.word); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3838 | case 3: /* Whole Fabric effected */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3839 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3840 | } |
| 3841 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3842 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3843 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 3844 | vport->fc_rscn_flush = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3845 | return 0; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3846 | return_did_out: |
| 3847 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 3848 | vport->fc_rscn_flush = 0; |
| 3849 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3850 | } |
| 3851 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 3852 | /** |
| 3853 | * lpfc_rscn_recovery_check: Send recovery event to vport nodes matching rscn |
| 3854 | * @vport: pointer to a host virtual N_Port data structure. |
| 3855 | * |
| 3856 | * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the |
| 3857 | * state machine for a @vport's nodes that are with pending RSCN (Registration |
| 3858 | * State Change Notification). |
| 3859 | * |
| 3860 | * Return code |
| 3861 | * 0 - Successful (currently alway return 0) |
| 3862 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3863 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3864 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3865 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3866 | struct lpfc_nodelist *ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3867 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3868 | /* Move all affected nodes by pending RSCNs to NPR state. */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3869 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3870 | if (!NLP_CHK_NODE_ACT(ndlp) || |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3871 | (ndlp->nlp_state == NLP_STE_UNUSED_NODE) || |
| 3872 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3873 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3874 | lpfc_disc_state_machine(vport, ndlp, NULL, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 3875 | NLP_EVT_DEVICE_RECOVERY); |
| 3876 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3877 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3878 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3879 | } |
| 3880 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 3881 | /** |
| 3882 | * lpfc_els_rcv_rscn: Process an unsolicited rscn iocb. |
| 3883 | * @vport: pointer to a host virtual N_Port data structure. |
| 3884 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 3885 | * @ndlp: pointer to a node-list data structure. |
| 3886 | * |
| 3887 | * This routine processes an unsolicited RSCN (Registration State Change |
| 3888 | * Notification) IOCB. First, the payload of the unsolicited RSCN is walked |
| 3889 | * to invoke fc_host_post_event() routine to the FC transport layer. If the |
| 3890 | * discover state machine is about to begin discovery, it just accepts the |
| 3891 | * RSCN and the discovery process will satisfy the RSCN. If this RSCN only |
| 3892 | * contains N_Port IDs for other vports on this HBA, it just accepts the |
| 3893 | * RSCN and ignore processing it. If the state machine is in the recovery |
| 3894 | * state, the fc_rscn_id_list of this @vport is walked and the |
| 3895 | * lpfc_rscn_recovery_check() routine is invoked to send recovery event for |
| 3896 | * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() |
| 3897 | * routine is invoked to handle the RSCN event. |
| 3898 | * |
| 3899 | * Return code |
| 3900 | * 0 - Just sent the acc response |
| 3901 | * 1 - Sent the acc response and waited for name server completion |
| 3902 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3903 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3904 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3905 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3906 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3907 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3908 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3909 | struct lpfc_dmabuf *pcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3910 | uint32_t *lp, *datap; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3911 | IOCB_t *icmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3912 | uint32_t payload_len, length, nportid, *cmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3913 | int rscn_cnt; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3914 | int rscn_id = 0, hba_id = 0; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 3915 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3916 | |
| 3917 | icmd = &cmdiocb->iocb; |
| 3918 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 3919 | lp = (uint32_t *) pcmd->virt; |
| 3920 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3921 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 3922 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3923 | /* RSCN received */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3924 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 3925 | "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] | 3926 | vport->fc_flag, payload_len, *lp, |
| 3927 | vport->fc_rscn_id_cnt); |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 3928 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3929 | fc_host_post_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 3930 | FCH_EVT_RSCN, lp[i]); |
| 3931 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3932 | /* If we are about to begin discovery, just ACC the RSCN. |
| 3933 | * Discovery processing will satisfy it. |
| 3934 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3935 | if (vport->port_state <= LPFC_NS_QRY) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3936 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 3937 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", |
| 3938 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 3939 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3940 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3941 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3942 | } |
| 3943 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3944 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
| 3945 | * just ACC and ignore it. |
| 3946 | */ |
| 3947 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3948 | !(vport->cfg_peer_port_login)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3949 | i = payload_len; |
| 3950 | datap = lp; |
| 3951 | while (i > 0) { |
| 3952 | nportid = *datap++; |
| 3953 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); |
| 3954 | i -= sizeof(uint32_t); |
| 3955 | rscn_id++; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3956 | if (lpfc_find_vport_by_did(phba, nportid)) |
| 3957 | hba_id++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3958 | } |
| 3959 | if (rscn_id == hba_id) { |
| 3960 | /* ALL NPortIDs in RSCN are on HBA */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3961 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 3962 | "0214 Ignore RSCN " |
| 3963 | "Data: x%x x%x x%x x%x\n", |
| 3964 | vport->fc_flag, payload_len, |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3965 | *lp, vport->fc_rscn_id_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3966 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 3967 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", |
| 3968 | ndlp->nlp_DID, vport->port_state, |
| 3969 | ndlp->nlp_flag); |
| 3970 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3971 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3972 | ndlp, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3973 | return 0; |
| 3974 | } |
| 3975 | } |
| 3976 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3977 | spin_lock_irq(shost->host_lock); |
| 3978 | if (vport->fc_rscn_flush) { |
| 3979 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 3980 | spin_unlock_irq(shost->host_lock); |
| 3981 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3982 | /* Send back ACC */ |
| 3983 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3984 | return 0; |
| 3985 | } |
| 3986 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 3987 | vport->fc_rscn_flush = 1; |
| 3988 | spin_unlock_irq(shost->host_lock); |
| 3989 | /* Get the array count after sucessfully have the token */ |
| 3990 | rscn_cnt = vport->fc_rscn_id_cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3991 | /* If we are already processing an RSCN, save the received |
| 3992 | * RSCN payload buffer, cmdiocb->context2 to process later. |
| 3993 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3994 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3995 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 3996 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", |
| 3997 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 3998 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3999 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4000 | vport->fc_flag |= FC_RSCN_DEFERRED; |
| 4001 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4002 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4003 | vport->fc_flag |= FC_RSCN_MODE; |
| 4004 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4005 | if (rscn_cnt) { |
| 4006 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; |
| 4007 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); |
| 4008 | } |
| 4009 | if ((rscn_cnt) && |
| 4010 | (payload_len + length <= LPFC_BPL_SIZE)) { |
| 4011 | *cmd &= ELS_CMD_MASK; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4012 | *cmd |= cpu_to_be32(payload_len + length); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4013 | memcpy(((uint8_t *)cmd) + length, lp, |
| 4014 | payload_len); |
| 4015 | } else { |
| 4016 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; |
| 4017 | vport->fc_rscn_id_cnt++; |
| 4018 | /* If we zero, cmdiocb->context2, the calling |
| 4019 | * routine will not try to free it. |
| 4020 | */ |
| 4021 | cmdiocb->context2 = NULL; |
| 4022 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4023 | /* Deferred RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4024 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4025 | "0235 Deferred RSCN " |
| 4026 | "Data: x%x x%x x%x\n", |
| 4027 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4028 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4029 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4030 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
| 4031 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4032 | /* ReDiscovery RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4033 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4034 | "0234 ReDiscovery RSCN " |
| 4035 | "Data: x%x x%x x%x\n", |
| 4036 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 4037 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4038 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4039 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4040 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4041 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4042 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4043 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4044 | lpfc_rscn_recovery_check(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4045 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4046 | vport->fc_flag &= ~FC_RSCN_DEFERRED; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4047 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4048 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4049 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4050 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4051 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", |
| 4052 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 4053 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4054 | spin_lock_irq(shost->host_lock); |
| 4055 | vport->fc_flag |= FC_RSCN_MODE; |
| 4056 | spin_unlock_irq(shost->host_lock); |
| 4057 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4058 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 4059 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4060 | /* |
| 4061 | * If we zero, cmdiocb->context2, the calling routine will |
| 4062 | * not try to free it. |
| 4063 | */ |
| 4064 | cmdiocb->context2 = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4065 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4066 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4067 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4068 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4069 | lpfc_rscn_recovery_check(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4070 | return lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4071 | } |
| 4072 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 4073 | /** |
| 4074 | * lpfc_els_handle_rscn: Handle rscn for a vport. |
| 4075 | * @vport: pointer to a host virtual N_Port data structure. |
| 4076 | * |
| 4077 | * This routine handles the Registration State Configuration Notification |
| 4078 | * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall |
| 4079 | * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, |
| 4080 | * if the ndlp to NameServer exists, a Common Transport (CT) command to the |
| 4081 | * NameServer shall be issued. If CT command to the NameServer fails to be |
| 4082 | * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any |
| 4083 | * RSCN activities with the @vport. |
| 4084 | * |
| 4085 | * Return code |
| 4086 | * 0 - Cleaned up rscn on the @vport |
| 4087 | * 1 - Wait for plogi to name server before proceed |
| 4088 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4089 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4090 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4091 | { |
| 4092 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4093 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4094 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4095 | /* Ignore RSCN if the port is being torn down. */ |
| 4096 | if (vport->load_flag & FC_UNLOADING) { |
| 4097 | lpfc_els_flush_rscn(vport); |
| 4098 | return 0; |
| 4099 | } |
| 4100 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4101 | /* Start timer for RSCN processing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4102 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4103 | |
| 4104 | /* RSCN processed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4105 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 4106 | "0215 RSCN processed Data: x%x x%x x%x x%x\n", |
| 4107 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, |
| 4108 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4109 | |
| 4110 | /* To process RSCN, first compare RSCN data with NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4111 | vport->fc_ns_retry = 0; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 4112 | vport->num_disc_nodes = 0; |
| 4113 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4114 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4115 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) |
| 4116 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4117 | /* Good ndlp, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4118 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4119 | /* Wait for NameServer query cmpl before we can |
| 4120 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4121 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4122 | } else { |
| 4123 | /* If login to NameServer does not exist, issue one */ |
| 4124 | /* Good status, issue PLOGI to NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4125 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4126 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4127 | /* Wait for NameServer login cmpl before we can |
| 4128 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4129 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4130 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4131 | if (ndlp) { |
| 4132 | ndlp = lpfc_enable_node(vport, ndlp, |
| 4133 | NLP_STE_PLOGI_ISSUE); |
| 4134 | if (!ndlp) { |
| 4135 | lpfc_els_flush_rscn(vport); |
| 4136 | return 0; |
| 4137 | } |
| 4138 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4139 | } else { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4140 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 4141 | if (!ndlp) { |
| 4142 | lpfc_els_flush_rscn(vport); |
| 4143 | return 0; |
| 4144 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4145 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4146 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4147 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4148 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4149 | ndlp->nlp_type |= NLP_FABRIC; |
| 4150 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); |
| 4151 | /* Wait for NameServer login cmpl before we can |
| 4152 | * continue |
| 4153 | */ |
| 4154 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4155 | } |
| 4156 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4157 | lpfc_els_flush_rscn(vport); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4158 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4159 | } |
| 4160 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 4161 | /** |
| 4162 | * lpfc_els_rcv_flogi: Process an unsolicited flogi iocb. |
| 4163 | * @vport: pointer to a host virtual N_Port data structure. |
| 4164 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4165 | * @ndlp: pointer to a node-list data structure. |
| 4166 | * |
| 4167 | * This routine processes Fabric Login (FLOGI) IOCB received as an ELS |
| 4168 | * unsolicited event. An unsolicited FLOGI can be received in a point-to- |
| 4169 | * point topology. As an unsolicited FLOGI should not be received in a loop |
| 4170 | * mode, any unsolicited FLOGI received in loop mode shall be ignored. The |
| 4171 | * lpfc_check_sparm() routine is invoked to check the parameters in the |
| 4172 | * unsolicited FLOGI. If parameters validation failed, the routine |
| 4173 | * lpfc_els_rsp_reject() shall be called with reject reason code set to |
| 4174 | * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the |
| 4175 | * FLOGI shall be compared with the Port WWN of the @vport to determine who |
| 4176 | * will initiate PLOGI. The higher lexicographical value party shall has |
| 4177 | * higher priority (as the winning port) and will initiate PLOGI and |
| 4178 | * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result |
| 4179 | * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI |
| 4180 | * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. |
| 4181 | * |
| 4182 | * Return code |
| 4183 | * 0 - Successfully processed the unsolicited flogi |
| 4184 | * 1 - Failed to process the unsolicited flogi |
| 4185 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4186 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4187 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4188 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4189 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4190 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4191 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4192 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4193 | uint32_t *lp = (uint32_t *) pcmd->virt; |
| 4194 | IOCB_t *icmd = &cmdiocb->iocb; |
| 4195 | struct serv_parm *sp; |
| 4196 | LPFC_MBOXQ_t *mbox; |
| 4197 | struct ls_rjt stat; |
| 4198 | uint32_t cmd, did; |
| 4199 | int rc; |
| 4200 | |
| 4201 | cmd = *lp++; |
| 4202 | sp = (struct serv_parm *) lp; |
| 4203 | |
| 4204 | /* FLOGI received */ |
| 4205 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4206 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4207 | |
| 4208 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 4209 | /* We should never receive a FLOGI in loop mode, ignore it */ |
| 4210 | did = icmd->un.elsreq64.remoteID; |
| 4211 | |
| 4212 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in |
| 4213 | Loop Mode */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4214 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4215 | "0113 An FLOGI ELS command x%x was " |
| 4216 | "received from DID x%x in Loop Mode\n", |
| 4217 | cmd, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4218 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4219 | } |
| 4220 | |
| 4221 | did = Fabric_DID; |
| 4222 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4223 | if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4224 | /* For a FLOGI we accept, then if our portname is greater |
| 4225 | * then the remote portname we initiate Nport login. |
| 4226 | */ |
| 4227 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4228 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4229 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4230 | |
| 4231 | if (!rc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4232 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4233 | if (!mbox) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4234 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4235 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4236 | lpfc_linkdown(phba); |
| 4237 | lpfc_init_link(phba, mbox, |
| 4238 | phba->cfg_topology, |
| 4239 | phba->cfg_link_speed); |
| 4240 | mbox->mb.un.varInitLnk.lipsr_AL_PA = 0; |
| 4241 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4242 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4243 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 4244 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4245 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4246 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4247 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4248 | return 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4249 | } else if (rc > 0) { /* greater than */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4250 | spin_lock_irq(shost->host_lock); |
| 4251 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 4252 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4253 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4254 | spin_lock_irq(shost->host_lock); |
| 4255 | vport->fc_flag |= FC_PT2PT; |
| 4256 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 4257 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4258 | } else { |
| 4259 | /* Reject this request because invalid parameters */ |
| 4260 | stat.un.b.lsRjtRsvd0 = 0; |
| 4261 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4262 | stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; |
| 4263 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4264 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4265 | NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4266 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4267 | } |
| 4268 | |
| 4269 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4270 | lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4271 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4272 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4273 | } |
| 4274 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 4275 | /** |
| 4276 | * lpfc_els_rcv_rnid: Process an unsolicited rnid iocb. |
| 4277 | * @vport: pointer to a host virtual N_Port data structure. |
| 4278 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4279 | * @ndlp: pointer to a node-list data structure. |
| 4280 | * |
| 4281 | * This routine processes Request Node Identification Data (RNID) IOCB |
| 4282 | * received as an ELS unsolicited event. Only when the RNID specified format |
| 4283 | * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) |
| 4284 | * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to |
| 4285 | * Accept (ACC) the RNID ELS command. All the other RNID formats are |
| 4286 | * rejected by invoking the lpfc_els_rsp_reject() routine. |
| 4287 | * |
| 4288 | * Return code |
| 4289 | * 0 - Successfully processed rnid iocb (currently always return 0) |
| 4290 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4291 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4292 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4293 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4294 | { |
| 4295 | struct lpfc_dmabuf *pcmd; |
| 4296 | uint32_t *lp; |
| 4297 | IOCB_t *icmd; |
| 4298 | RNID *rn; |
| 4299 | struct ls_rjt stat; |
| 4300 | uint32_t cmd, did; |
| 4301 | |
| 4302 | icmd = &cmdiocb->iocb; |
| 4303 | did = icmd->un.elsreq64.remoteID; |
| 4304 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4305 | lp = (uint32_t *) pcmd->virt; |
| 4306 | |
| 4307 | cmd = *lp++; |
| 4308 | rn = (RNID *) lp; |
| 4309 | |
| 4310 | /* RNID received */ |
| 4311 | |
| 4312 | switch (rn->Format) { |
| 4313 | case 0: |
| 4314 | case RNID_TOPOLOGY_DISC: |
| 4315 | /* Send back ACC */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4316 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4317 | break; |
| 4318 | default: |
| 4319 | /* Reject this request because format not supported */ |
| 4320 | stat.un.b.lsRjtRsvd0 = 0; |
| 4321 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4322 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4323 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4324 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4325 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4326 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4327 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4328 | } |
| 4329 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 4330 | /** |
| 4331 | * lpfc_els_rcv_lirr: Process an unsolicited lirr iocb. |
| 4332 | * @vport: pointer to a host virtual N_Port data structure. |
| 4333 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4334 | * @ndlp: pointer to a node-list data structure. |
| 4335 | * |
| 4336 | * This routine processes a Link Incident Report Registration(LIRR) IOCB |
| 4337 | * received as an ELS unsolicited event. Currently, this function just invokes |
| 4338 | * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. |
| 4339 | * |
| 4340 | * Return code |
| 4341 | * 0 - Successfully processed lirr iocb (currently always return 0) |
| 4342 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4343 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4344 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4345 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4346 | { |
| 4347 | struct ls_rjt stat; |
| 4348 | |
| 4349 | /* For now, unconditionally reject this command */ |
| 4350 | stat.un.b.lsRjtRsvd0 = 0; |
| 4351 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4352 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4353 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4354 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4355 | return 0; |
| 4356 | } |
| 4357 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 4358 | /** |
| 4359 | * lpfc_els_rsp_rps_acc: Completion callbk func for MBX_READ_LNK_STAT mbox cmd. |
| 4360 | * @phba: pointer to lpfc hba data structure. |
| 4361 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 4362 | * |
| 4363 | * This routine is the completion callback function for the MBX_READ_LNK_STAT |
| 4364 | * mailbox command. This callback function is to actually send the Accept |
| 4365 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It |
| 4366 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT |
| 4367 | * mailbox command, constructs the RPS response with the link statistics |
| 4368 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC |
| 4369 | * response to the RPS. |
| 4370 | * |
| 4371 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4372 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4373 | * will be stored into the context1 field of the IOCB for the completion |
| 4374 | * callback function to the RPS Accept Response ELS IOCB command. |
| 4375 | * |
| 4376 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 4377 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4378 | 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] | 4379 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4380 | struct lpfc_sli *psli = &phba->sli; |
| 4381 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4382 | MAILBOX_t *mb; |
| 4383 | IOCB_t *icmd; |
| 4384 | RPS_RSP *rps_rsp; |
| 4385 | uint8_t *pcmd; |
| 4386 | struct lpfc_iocbq *elsiocb; |
| 4387 | struct lpfc_nodelist *ndlp; |
| 4388 | uint16_t xri, status; |
| 4389 | uint32_t cmdsize; |
| 4390 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4391 | mb = &pmb->mb; |
| 4392 | |
| 4393 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 4394 | xri = (uint16_t) ((unsigned long)(pmb->context1)); |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 4395 | pmb->context1 = NULL; |
| 4396 | pmb->context2 = NULL; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4397 | |
| 4398 | if (mb->mbxStatus) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4399 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4400 | return; |
| 4401 | } |
| 4402 | |
| 4403 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4404 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4405 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 4406 | lpfc_max_els_tries, ndlp, |
| 4407 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4408 | |
| 4409 | /* Decrement the ndlp reference count from previous mbox command */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4410 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4411 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4412 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4413 | return; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4414 | |
| 4415 | icmd = &elsiocb->iocb; |
| 4416 | icmd->ulpContext = xri; |
| 4417 | |
| 4418 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4419 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4420 | pcmd += sizeof(uint32_t); /* Skip past command */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4421 | rps_rsp = (RPS_RSP *)pcmd; |
| 4422 | |
| 4423 | if (phba->fc_topology != TOPOLOGY_LOOP) |
| 4424 | status = 0x10; |
| 4425 | else |
| 4426 | status = 0x8; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4427 | if (phba->pport->fc_flag & FC_FABRIC) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4428 | status |= 0x4; |
| 4429 | |
| 4430 | rps_rsp->rsvd1 = 0; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4431 | rps_rsp->portStatus = cpu_to_be16(status); |
| 4432 | rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 4433 | rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 4434 | rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 4435 | rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 4436 | rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 4437 | rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4438 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4439 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 4440 | "0118 Xmit ELS RPS ACC response tag x%x xri x%x, " |
| 4441 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 4442 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4443 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4444 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4445 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4446 | phba->fc_stat.elsXmitACC++; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4447 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4448 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4449 | return; |
| 4450 | } |
| 4451 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 4452 | /** |
| 4453 | * lpfc_els_rcv_rps: Process an unsolicited rps iocb. |
| 4454 | * @vport: pointer to a host virtual N_Port data structure. |
| 4455 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4456 | * @ndlp: pointer to a node-list data structure. |
| 4457 | * |
| 4458 | * This routine processes Read Port Status (RPS) IOCB received as an |
| 4459 | * ELS unsolicited event. It first checks the remote port state. If the |
| 4460 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE |
| 4461 | * state, it invokes the lpfc_els_rsp_reject() routine to send the reject |
| 4462 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command |
| 4463 | * for reading the HBA link statistics. It is for the callback function, |
| 4464 | * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command |
| 4465 | * to actually sending out RPS Accept (ACC) response. |
| 4466 | * |
| 4467 | * Return codes |
| 4468 | * 0 - Successfully processed rps iocb (currently always return 0) |
| 4469 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4470 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4471 | lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4472 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4473 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4474 | struct lpfc_hba *phba = vport->phba; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4475 | uint32_t *lp; |
| 4476 | uint8_t flag; |
| 4477 | LPFC_MBOXQ_t *mbox; |
| 4478 | struct lpfc_dmabuf *pcmd; |
| 4479 | RPS *rps; |
| 4480 | struct ls_rjt stat; |
| 4481 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4482 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 4483 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4484 | stat.un.b.lsRjtRsvd0 = 0; |
| 4485 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4486 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4487 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4488 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4489 | NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4490 | } |
| 4491 | |
| 4492 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4493 | lp = (uint32_t *) pcmd->virt; |
| 4494 | flag = (be32_to_cpu(*lp++) & 0xf); |
| 4495 | rps = (RPS *) lp; |
| 4496 | |
| 4497 | if ((flag == 0) || |
| 4498 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4499 | ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4500 | sizeof(struct lpfc_name)) == 0))) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4501 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4502 | printk("Fix me....\n"); |
| 4503 | dump_stack(); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4504 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 4505 | if (mbox) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4506 | lpfc_read_lnk_stat(phba, mbox); |
| 4507 | mbox->context1 = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4508 | (void *)((unsigned long) cmdiocb->iocb.ulpContext); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4509 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4510 | mbox->vport = vport; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4511 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4512 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4513 | != MBX_NOT_FINISHED) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4514 | /* Mbox completion will send ELS Response */ |
| 4515 | return 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4516 | /* Decrement reference count used for the failed mbox |
| 4517 | * command. |
| 4518 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4519 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4520 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4521 | } |
| 4522 | } |
| 4523 | stat.un.b.lsRjtRsvd0 = 0; |
| 4524 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4525 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4526 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4527 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4528 | return 0; |
| 4529 | } |
| 4530 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 4531 | /** |
| 4532 | * lpfc_els_rsp_rpl_acc: Issue an accept rpl els command. |
| 4533 | * @vport: pointer to a host virtual N_Port data structure. |
| 4534 | * @cmdsize: size of the ELS command. |
| 4535 | * @oldiocb: pointer to the original lpfc command iocb data structure. |
| 4536 | * @ndlp: pointer to a node-list data structure. |
| 4537 | * |
| 4538 | * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. |
| 4539 | * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. |
| 4540 | * |
| 4541 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 4542 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 4543 | * will be stored into the context1 field of the IOCB for the completion |
| 4544 | * callback function to the RPL Accept Response ELS command. |
| 4545 | * |
| 4546 | * Return code |
| 4547 | * 0 - Successfully issued ACC RPL ELS command |
| 4548 | * 1 - Failed to issue ACC RPL ELS command |
| 4549 | **/ |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 4550 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4551 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
| 4552 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4553 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4554 | struct lpfc_hba *phba = vport->phba; |
| 4555 | IOCB_t *icmd, *oldcmd; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4556 | RPL_RSP rpl_rsp; |
| 4557 | struct lpfc_iocbq *elsiocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4558 | struct lpfc_sli *psli = &phba->sli; |
| 4559 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4560 | uint8_t *pcmd; |
| 4561 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4562 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 4563 | ndlp->nlp_DID, ELS_CMD_ACC); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4564 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4565 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4566 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 4567 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4568 | icmd = &elsiocb->iocb; |
| 4569 | oldcmd = &oldiocb->iocb; |
| 4570 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 4571 | |
| 4572 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4573 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4574 | pcmd += sizeof(uint16_t); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4575 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
| 4576 | pcmd += sizeof(uint16_t); |
| 4577 | |
| 4578 | /* Setup the RPL ACC payload */ |
| 4579 | rpl_rsp.listLen = be32_to_cpu(1); |
| 4580 | rpl_rsp.index = 0; |
| 4581 | rpl_rsp.port_num_blk.portNum = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4582 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
| 4583 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4584 | sizeof(struct lpfc_name)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4585 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4586 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4587 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4588 | "0120 Xmit ELS RPL ACC response tag x%x " |
| 4589 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 4590 | "rpi x%x\n", |
| 4591 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 4592 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 4593 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4594 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4595 | phba->fc_stat.elsXmitACC++; |
| 4596 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
| 4597 | lpfc_els_free_iocb(phba, elsiocb); |
| 4598 | return 1; |
| 4599 | } |
| 4600 | return 0; |
| 4601 | } |
| 4602 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 4603 | /** |
| 4604 | * lpfc_els_rcv_rpl: Process an unsolicited rpl iocb. |
| 4605 | * @vport: pointer to a host virtual N_Port data structure. |
| 4606 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4607 | * @ndlp: pointer to a node-list data structure. |
| 4608 | * |
| 4609 | * This routine processes Read Port List (RPL) IOCB received as an ELS |
| 4610 | * unsolicited event. It first checks the remote port state. If the remote |
| 4611 | * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it |
| 4612 | * invokes the lpfc_els_rsp_reject() routine to send reject response. |
| 4613 | * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine |
| 4614 | * to accept the RPL. |
| 4615 | * |
| 4616 | * Return code |
| 4617 | * 0 - Successfully processed rpl iocb (currently always return 0) |
| 4618 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4619 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4620 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4621 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4622 | { |
| 4623 | struct lpfc_dmabuf *pcmd; |
| 4624 | uint32_t *lp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4625 | uint32_t maxsize; |
| 4626 | uint16_t cmdsize; |
| 4627 | RPL *rpl; |
| 4628 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4629 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4630 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 4631 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4632 | stat.un.b.lsRjtRsvd0 = 0; |
| 4633 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 4634 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 4635 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4636 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 4637 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4638 | } |
| 4639 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4640 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4641 | lp = (uint32_t *) pcmd->virt; |
| 4642 | rpl = (RPL *) (lp + 1); |
| 4643 | |
| 4644 | maxsize = be32_to_cpu(rpl->maxsize); |
| 4645 | |
| 4646 | /* We support only one port */ |
| 4647 | if ((rpl->index == 0) && |
| 4648 | ((maxsize == 0) || |
| 4649 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { |
| 4650 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4651 | } else { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4652 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
| 4653 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4654 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4655 | |
| 4656 | return 0; |
| 4657 | } |
| 4658 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 4659 | /** |
| 4660 | * lpfc_els_rcv_farp: Process an unsolicited farp request els command. |
| 4661 | * @vport: pointer to a virtual N_Port data structure. |
| 4662 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4663 | * @ndlp: pointer to a node-list data structure. |
| 4664 | * |
| 4665 | * This routine processes Fibre Channel Address Resolution Protocol |
| 4666 | * (FARP) Request IOCB received as an ELS unsolicited event. Currently, |
| 4667 | * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, |
| 4668 | * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the |
| 4669 | * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the |
| 4670 | * remote PortName is compared against the FC PortName stored in the @vport |
| 4671 | * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is |
| 4672 | * compared against the FC NodeName stored in the @vport data structure. |
| 4673 | * If any of these matches and the FARP_REQUEST_FARPR flag is set in the |
| 4674 | * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is |
| 4675 | * invoked to send out FARP Response to the remote node. Before sending the |
| 4676 | * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP |
| 4677 | * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() |
| 4678 | * routine is invoked to log into the remote port first. |
| 4679 | * |
| 4680 | * Return code |
| 4681 | * 0 - Either the FARP Match Mode not supported or successfully processed |
| 4682 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4683 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4684 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4685 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4686 | { |
| 4687 | struct lpfc_dmabuf *pcmd; |
| 4688 | uint32_t *lp; |
| 4689 | IOCB_t *icmd; |
| 4690 | FARP *fp; |
| 4691 | uint32_t cmd, cnt, did; |
| 4692 | |
| 4693 | icmd = &cmdiocb->iocb; |
| 4694 | did = icmd->un.elsreq64.remoteID; |
| 4695 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4696 | lp = (uint32_t *) pcmd->virt; |
| 4697 | |
| 4698 | cmd = *lp++; |
| 4699 | fp = (FARP *) lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4700 | /* FARP-REQ received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4701 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4702 | "0601 FARP-REQ received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4703 | /* We will only support match on WWPN or WWNN */ |
| 4704 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4705 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4706 | } |
| 4707 | |
| 4708 | cnt = 0; |
| 4709 | /* If this FARP command is searching for my portname */ |
| 4710 | if (fp->Mflags & FARP_MATCH_PORT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4711 | if (memcmp(&fp->RportName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4712 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4713 | cnt = 1; |
| 4714 | } |
| 4715 | |
| 4716 | /* If this FARP command is searching for my nodename */ |
| 4717 | if (fp->Mflags & FARP_MATCH_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4718 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4719 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4720 | cnt = 1; |
| 4721 | } |
| 4722 | |
| 4723 | if (cnt) { |
| 4724 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 4725 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { |
| 4726 | /* Log back into the node before sending the FARP. */ |
| 4727 | if (fp->Rflags & FARP_REQUEST_PLOGI) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4728 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4729 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 4730 | NLP_STE_PLOGI_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4731 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4732 | } |
| 4733 | |
| 4734 | /* Send a FARP response to that node */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4735 | if (fp->Rflags & FARP_REQUEST_FARPR) |
| 4736 | lpfc_issue_els_farpr(vport, did, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4737 | } |
| 4738 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4739 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4740 | } |
| 4741 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 4742 | /** |
| 4743 | * lpfc_els_rcv_farpr: Process an unsolicited farp response iocb. |
| 4744 | * @vport: pointer to a host virtual N_Port data structure. |
| 4745 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4746 | * @ndlp: pointer to a node-list data structure. |
| 4747 | * |
| 4748 | * This routine processes Fibre Channel Address Resolution Protocol |
| 4749 | * Response (FARPR) IOCB received as an ELS unsolicited event. It simply |
| 4750 | * invokes the lpfc_els_rsp_acc() routine to the remote node to accept |
| 4751 | * the FARP response request. |
| 4752 | * |
| 4753 | * Return code |
| 4754 | * 0 - Successfully processed FARPR IOCB (currently always return 0) |
| 4755 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4756 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4757 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4758 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4759 | { |
| 4760 | struct lpfc_dmabuf *pcmd; |
| 4761 | uint32_t *lp; |
| 4762 | IOCB_t *icmd; |
| 4763 | uint32_t cmd, did; |
| 4764 | |
| 4765 | icmd = &cmdiocb->iocb; |
| 4766 | did = icmd->un.elsreq64.remoteID; |
| 4767 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 4768 | lp = (uint32_t *) pcmd->virt; |
| 4769 | |
| 4770 | cmd = *lp++; |
| 4771 | /* FARP-RSP received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4772 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4773 | "0600 FARP-RSP received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4774 | /* ACCEPT the Farp resp request */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4775 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4776 | |
| 4777 | return 0; |
| 4778 | } |
| 4779 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 4780 | /** |
| 4781 | * lpfc_els_rcv_fan: Process an unsolicited fan iocb command. |
| 4782 | * @vport: pointer to a host virtual N_Port data structure. |
| 4783 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 4784 | * @fan_ndlp: pointer to a node-list data structure. |
| 4785 | * |
| 4786 | * This routine processes a Fabric Address Notification (FAN) IOCB |
| 4787 | * command received as an ELS unsolicited event. The FAN ELS command will |
| 4788 | * only be processed on a physical port (i.e., the @vport represents the |
| 4789 | * physical port). The fabric NodeName and PortName from the FAN IOCB are |
| 4790 | * compared against those in the phba data structure. If any of those is |
| 4791 | * different, the lpfc_initial_flogi() routine is invoked to initialize |
| 4792 | * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, |
| 4793 | * if both of those are identical, the lpfc_issue_fabric_reglogin() routine |
| 4794 | * is invoked to register login to the fabric. |
| 4795 | * |
| 4796 | * Return code |
| 4797 | * 0 - Successfully processed fan iocb (currently always return 0). |
| 4798 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4799 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4800 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 4801 | struct lpfc_nodelist *fan_ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4802 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4803 | struct lpfc_hba *phba = vport->phba; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4804 | uint32_t *lp; |
| 4805 | FAN *fp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4806 | |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4807 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); |
| 4808 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; |
| 4809 | fp = (FAN *) ++lp; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4810 | /* FAN received; Fan does not have a reply sequence */ |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4811 | if ((vport == phba->pport) && |
| 4812 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4813 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4814 | sizeof(struct lpfc_name))) || |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 4815 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4816 | sizeof(struct lpfc_name)))) { |
| 4817 | /* This port has switched fabrics. FLOGI is required */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4818 | lpfc_initial_flogi(vport); |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 4819 | } else { |
| 4820 | /* FAN verified - skip FLOGI */ |
| 4821 | vport->fc_myDID = vport->fc_prevDID; |
| 4822 | lpfc_issue_fabric_reglogin(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4823 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4824 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4825 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4826 | } |
| 4827 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 4828 | /** |
| 4829 | * lpfc_els_timeout: Handler funciton to the els timer. |
| 4830 | * @ptr: holder for the timer function associated data. |
| 4831 | * |
| 4832 | * This routine is invoked by the ELS timer after timeout. It posts the ELS |
| 4833 | * timer timeout event by setting the WORKER_ELS_TMO bit to the work port |
| 4834 | * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake |
| 4835 | * up the worker thread. It is for the worker thread to invoke the routine |
| 4836 | * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. |
| 4837 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4838 | void |
| 4839 | lpfc_els_timeout(unsigned long ptr) |
| 4840 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4841 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 4842 | struct lpfc_hba *phba = vport->phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4843 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4844 | unsigned long iflag; |
| 4845 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4846 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4847 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; |
| 4848 | if (!tmo_posted) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4849 | vport->work_port_events |= WORKER_ELS_TMO; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4850 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4851 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 4852 | if (!tmo_posted) |
| 4853 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4854 | return; |
| 4855 | } |
| 4856 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 4857 | /** |
| 4858 | * lpfc_els_timeout_handler: Process an els timeout event. |
| 4859 | * @vport: pointer to a virtual N_Port data structure. |
| 4860 | * |
| 4861 | * This routine is the actual handler function that processes an ELS timeout |
| 4862 | * event. It walks the ELS ring to get and abort all the IOCBs (except the |
| 4863 | * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by |
| 4864 | * invoking the lpfc_sli_issue_abort_iotag() routine. |
| 4865 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4866 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4867 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4868 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4869 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4870 | struct lpfc_sli_ring *pring; |
| 4871 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 4872 | IOCB_t *cmd = NULL; |
| 4873 | struct lpfc_dmabuf *pcmd; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4874 | uint32_t els_command = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4875 | uint32_t timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4876 | uint32_t remote_ID = 0xffffffff; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4877 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4878 | /* If the timer is already canceled do nothing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4879 | if ((vport->work_port_events & WORKER_ELS_TMO) == 0) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4880 | return; |
| 4881 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4882 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4883 | timeout = (uint32_t)(phba->fc_ratov << 1); |
| 4884 | |
| 4885 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4886 | |
| 4887 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 4888 | cmd = &piocb->iocb; |
| 4889 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4890 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
| 4891 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 4892 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4893 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4894 | |
| 4895 | if (piocb->vport != vport) |
| 4896 | continue; |
| 4897 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4898 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4899 | if (pcmd) |
| 4900 | els_command = *(uint32_t *) (pcmd->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4901 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4902 | if (els_command == ELS_CMD_FARP || |
| 4903 | els_command == ELS_CMD_FARPR || |
| 4904 | els_command == ELS_CMD_FDISC) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4905 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4906 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4907 | if (piocb->drvrTimeout > 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4908 | if (piocb->drvrTimeout >= timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4909 | piocb->drvrTimeout -= timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4910 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4911 | piocb->drvrTimeout = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4912 | continue; |
| 4913 | } |
| 4914 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4915 | remote_ID = 0xffffffff; |
| 4916 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4917 | remote_ID = cmd->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4918 | else { |
| 4919 | struct lpfc_nodelist *ndlp; |
| 4920 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 4921 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4922 | remote_ID = ndlp->nlp_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4923 | } |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4924 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4925 | "0127 ELS timeout Data: x%x x%x x%x " |
| 4926 | "x%x\n", els_command, |
| 4927 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4928 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4929 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4930 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 4931 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4932 | if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) |
| 4933 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4934 | } |
| 4935 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 4936 | /** |
| 4937 | * lpfc_els_flush_cmd: Clean up the outstanding els commands to a vport. |
| 4938 | * @vport: pointer to a host virtual N_Port data structure. |
| 4939 | * |
| 4940 | * This routine is used to clean up all the outstanding ELS commands on a |
| 4941 | * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() |
| 4942 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 4943 | * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 4944 | * the IOCBs with a non-NULL completion callback function, the callback |
| 4945 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 4946 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion |
| 4947 | * callback function, the IOCB will simply be released. Finally, it walks |
| 4948 | * the ELS transmit completion queue to issue an abort IOCB to any transmit |
| 4949 | * completion queue IOCB that is associated with the @vport and is not |
| 4950 | * an IOCB from libdfc (i.e., the management plane IOCBs that are not |
| 4951 | * part of the discovery state machine) out to HBA by invoking the |
| 4952 | * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the |
| 4953 | * abort IOCB to any transmit completion queueed IOCB, it does not guarantee |
| 4954 | * the IOCBs are aborted when this function returns. |
| 4955 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4956 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4957 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4958 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4959 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4960 | struct lpfc_hba *phba = vport->phba; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4961 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4962 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 4963 | IOCB_t *cmd = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4964 | |
| 4965 | lpfc_fabric_abort_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4966 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4967 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4968 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 4969 | cmd = &piocb->iocb; |
| 4970 | |
| 4971 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 4972 | continue; |
| 4973 | } |
| 4974 | |
| 4975 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4976 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 4977 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 4978 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 4979 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4980 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4981 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4982 | if (piocb->vport != vport) |
| 4983 | continue; |
| 4984 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4985 | list_move_tail(&piocb->list, &completions); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 4986 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4987 | } |
| 4988 | |
| 4989 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4990 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 4991 | continue; |
| 4992 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4993 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4994 | if (piocb->vport != vport) |
| 4995 | continue; |
| 4996 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4997 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4998 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4999 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5000 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5001 | while (!list_empty(&completions)) { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5002 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| 5003 | cmd = &piocb->iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5004 | list_del_init(&piocb->list); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5005 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5006 | if (!piocb->iocb_cmpl) |
| 5007 | lpfc_sli_release_iocbq(phba, piocb); |
| 5008 | else { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5009 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 5010 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 5011 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5012 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 5013 | } |
| 5014 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5015 | return; |
| 5016 | } |
| 5017 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 5018 | /** |
| 5019 | * lpfc_els_flush_all_cmd: Clean up all the outstanding els commands to a HBA. |
| 5020 | * @phba: pointer to lpfc hba data structure. |
| 5021 | * |
| 5022 | * This routine is used to clean up all the outstanding ELS commands on a |
| 5023 | * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() |
| 5024 | * routine. After that, it walks the ELS transmit queue to remove all the |
| 5025 | * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For |
| 5026 | * the IOCBs with the completion callback function associated, the callback |
| 5027 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and |
| 5028 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion |
| 5029 | * callback function associated, the IOCB will simply be released. Finally, |
| 5030 | * it walks the ELS transmit completion queue to issue an abort IOCB to any |
| 5031 | * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the |
| 5032 | * management plane IOCBs that are not part of the discovery state machine) |
| 5033 | * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. |
| 5034 | **/ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5035 | void |
| 5036 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) |
| 5037 | { |
| 5038 | LIST_HEAD(completions); |
| 5039 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 5040 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5041 | IOCB_t *cmd = NULL; |
| 5042 | |
| 5043 | lpfc_fabric_abort_hba(phba); |
| 5044 | spin_lock_irq(&phba->hbalock); |
| 5045 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 5046 | cmd = &piocb->iocb; |
| 5047 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5048 | continue; |
| 5049 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
| 5050 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 5051 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 5052 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 5053 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| 5054 | continue; |
| 5055 | list_move_tail(&piocb->list, &completions); |
| 5056 | pring->txq_cnt--; |
| 5057 | } |
| 5058 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 5059 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 5060 | continue; |
| 5061 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 5062 | } |
| 5063 | spin_unlock_irq(&phba->hbalock); |
| 5064 | while (!list_empty(&completions)) { |
| 5065 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| 5066 | cmd = &piocb->iocb; |
| 5067 | list_del_init(&piocb->list); |
| 5068 | if (!piocb->iocb_cmpl) |
| 5069 | lpfc_sli_release_iocbq(phba, piocb); |
| 5070 | else { |
| 5071 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 5072 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 5073 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 5074 | } |
| 5075 | } |
| 5076 | return; |
| 5077 | } |
| 5078 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 5079 | /** |
| 5080 | * lpfc_els_unsol_buffer: Process an unsolicited event data buffer. |
| 5081 | * @phba: pointer to lpfc hba data structure. |
| 5082 | * @pring: pointer to a SLI ring. |
| 5083 | * @vport: pointer to a host virtual N_Port data structure. |
| 5084 | * @elsiocb: pointer to lpfc els command iocb data structure. |
| 5085 | * |
| 5086 | * This routine is used for processing the IOCB associated with a unsolicited |
| 5087 | * event. It first determines whether there is an existing ndlp that matches |
| 5088 | * the DID from the unsolicited IOCB. If not, it will create a new one with |
| 5089 | * the DID from the unsolicited IOCB. The ELS command from the unsolicited |
| 5090 | * IOCB is then used to invoke the proper routine and to set up proper state |
| 5091 | * of the discovery state machine. |
| 5092 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5093 | static void |
| 5094 | 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] | 5095 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5096 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5097 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5098 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5099 | struct ls_rjt stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5100 | uint32_t *payload; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5101 | uint32_t cmd, did, newnode, rjt_err = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5102 | IOCB_t *icmd = &elsiocb->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5103 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5104 | if (!vport || !(elsiocb->context2)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5105 | goto dropit; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5106 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5107 | newnode = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5108 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
| 5109 | cmd = *payload; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5110 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5111 | lpfc_post_buffer(phba, pring, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5112 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5113 | did = icmd->un.rcvels.remoteID; |
| 5114 | if (icmd->ulpStatus) { |
| 5115 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5116 | "RCV Unsol ELS: status:x%x/x%x did:x%x", |
| 5117 | icmd->ulpStatus, icmd->un.ulpWord[4], did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5118 | goto dropit; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5119 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5120 | |
| 5121 | /* Check to see if link went down during discovery */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5122 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5123 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5124 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5125 | /* Ignore traffic recevied during vport shutdown. */ |
| 5126 | if (vport->load_flag & FC_UNLOADING) |
| 5127 | goto dropit; |
| 5128 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5129 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5130 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5131 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 5132 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5133 | if (!ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5134 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5135 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5136 | lpfc_nlp_init(vport, ndlp, did); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5137 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5138 | newnode = 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5139 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5140 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5141 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5142 | ndlp = lpfc_enable_node(vport, ndlp, |
| 5143 | NLP_STE_UNUSED_NODE); |
| 5144 | if (!ndlp) |
| 5145 | goto dropit; |
| 5146 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5147 | newnode = 1; |
| 5148 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| 5149 | ndlp->nlp_type |= NLP_FABRIC; |
| 5150 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 5151 | /* This is similar to the new node path */ |
| 5152 | ndlp = lpfc_nlp_get(ndlp); |
| 5153 | if (!ndlp) |
| 5154 | goto dropit; |
| 5155 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 5156 | newnode = 1; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5157 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5158 | |
| 5159 | phba->fc_stat.elsRcvFrame++; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5160 | if (elsiocb->context1) |
| 5161 | lpfc_nlp_put(elsiocb->context1); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5162 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5163 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5164 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5165 | |
| 5166 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { |
| 5167 | cmd &= ELS_CMD_MASK; |
| 5168 | } |
| 5169 | /* ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5170 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5171 | "0112 ELS command x%x received from NPORT x%x " |
| 5172 | "Data: x%x\n", cmd, did, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5173 | switch (cmd) { |
| 5174 | case ELS_CMD_PLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5175 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5176 | "RCV PLOGI: did:x%x/ste:x%x flg:x%x", |
| 5177 | did, vport->port_state, ndlp->nlp_flag); |
| 5178 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5179 | phba->fc_stat.elsRcvPLOGI++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5180 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
| 5181 | |
| 5182 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 5183 | if (!(phba->pport->fc_flag & FC_PT2PT) || |
| 5184 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { |
| 5185 | rjt_err = LSRJT_UNABLE_TPC; |
| 5186 | break; |
| 5187 | } |
| 5188 | /* We get here, and drop thru, if we are PT2PT with |
| 5189 | * another NPort and the other side has initiated |
| 5190 | * the PLOGI before responding to our FLOGI. |
| 5191 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5192 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5193 | |
| 5194 | shost = lpfc_shost_from_vport(vport); |
| 5195 | spin_lock_irq(shost->host_lock); |
| 5196 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; |
| 5197 | spin_unlock_irq(shost->host_lock); |
| 5198 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5199 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5200 | NLP_EVT_RCV_PLOGI); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5201 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5202 | break; |
| 5203 | case ELS_CMD_FLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5204 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5205 | "RCV FLOGI: did:x%x/ste:x%x flg:x%x", |
| 5206 | did, vport->port_state, ndlp->nlp_flag); |
| 5207 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5208 | phba->fc_stat.elsRcvFLOGI++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5209 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5210 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5211 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5212 | break; |
| 5213 | case ELS_CMD_LOGO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5214 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5215 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", |
| 5216 | did, vport->port_state, ndlp->nlp_flag); |
| 5217 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5218 | phba->fc_stat.elsRcvLOGO++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5219 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5220 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5221 | break; |
| 5222 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5223 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5224 | break; |
| 5225 | case ELS_CMD_PRLO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5226 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5227 | "RCV PRLO: did:x%x/ste:x%x flg:x%x", |
| 5228 | did, vport->port_state, ndlp->nlp_flag); |
| 5229 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5230 | phba->fc_stat.elsRcvPRLO++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5231 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5232 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5233 | break; |
| 5234 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5235 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5236 | break; |
| 5237 | case ELS_CMD_RSCN: |
| 5238 | phba->fc_stat.elsRcvRSCN++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 5239 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5240 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5241 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5242 | break; |
| 5243 | case ELS_CMD_ADISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5244 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5245 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", |
| 5246 | did, vport->port_state, ndlp->nlp_flag); |
| 5247 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5248 | phba->fc_stat.elsRcvADISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5249 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5250 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5251 | break; |
| 5252 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5253 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5254 | NLP_EVT_RCV_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5255 | break; |
| 5256 | case ELS_CMD_PDISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5257 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5258 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", |
| 5259 | did, vport->port_state, ndlp->nlp_flag); |
| 5260 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5261 | phba->fc_stat.elsRcvPDISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5262 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5263 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5264 | break; |
| 5265 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5266 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 5267 | NLP_EVT_RCV_PDISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5268 | break; |
| 5269 | case ELS_CMD_FARPR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5270 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5271 | "RCV FARPR: did:x%x/ste:x%x flg:x%x", |
| 5272 | did, vport->port_state, ndlp->nlp_flag); |
| 5273 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5274 | phba->fc_stat.elsRcvFARPR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5275 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5276 | break; |
| 5277 | case ELS_CMD_FARP: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5278 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5279 | "RCV FARP: did:x%x/ste:x%x flg:x%x", |
| 5280 | did, vport->port_state, ndlp->nlp_flag); |
| 5281 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5282 | phba->fc_stat.elsRcvFARP++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5283 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5284 | break; |
| 5285 | case ELS_CMD_FAN: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5286 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5287 | "RCV FAN: did:x%x/ste:x%x flg:x%x", |
| 5288 | did, vport->port_state, ndlp->nlp_flag); |
| 5289 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5290 | phba->fc_stat.elsRcvFAN++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5291 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5292 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5293 | case ELS_CMD_PRLI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5294 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5295 | "RCV PRLI: did:x%x/ste:x%x flg:x%x", |
| 5296 | did, vport->port_state, ndlp->nlp_flag); |
| 5297 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5298 | phba->fc_stat.elsRcvPRLI++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5299 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5300 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5301 | break; |
| 5302 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5303 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5304 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5305 | case ELS_CMD_LIRR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5306 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5307 | "RCV LIRR: did:x%x/ste:x%x flg:x%x", |
| 5308 | did, vport->port_state, ndlp->nlp_flag); |
| 5309 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5310 | phba->fc_stat.elsRcvLIRR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5311 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5312 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5313 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5314 | break; |
| 5315 | case ELS_CMD_RPS: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5316 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5317 | "RCV RPS: did:x%x/ste:x%x flg:x%x", |
| 5318 | did, vport->port_state, ndlp->nlp_flag); |
| 5319 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5320 | phba->fc_stat.elsRcvRPS++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5321 | lpfc_els_rcv_rps(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5322 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5323 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5324 | break; |
| 5325 | case ELS_CMD_RPL: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5326 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5327 | "RCV RPL: did:x%x/ste:x%x flg:x%x", |
| 5328 | did, vport->port_state, ndlp->nlp_flag); |
| 5329 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5330 | phba->fc_stat.elsRcvRPL++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5331 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5332 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5333 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 5334 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5335 | case ELS_CMD_RNID: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5336 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5337 | "RCV RNID: did:x%x/ste:x%x flg:x%x", |
| 5338 | did, vport->port_state, ndlp->nlp_flag); |
| 5339 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5340 | phba->fc_stat.elsRcvRNID++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5341 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5342 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5343 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5344 | break; |
| 5345 | default: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5346 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 5347 | "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", |
| 5348 | cmd, did, vport->port_state); |
| 5349 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5350 | /* Unsupported ELS command, reject */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5351 | rjt_err = LSRJT_INVALID_CMD; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5352 | |
| 5353 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5354 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5355 | "0115 Unknown ELS command x%x " |
| 5356 | "received from NPORT x%x\n", cmd, did); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 5357 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5358 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5359 | break; |
| 5360 | } |
| 5361 | |
| 5362 | /* check if need to LS_RJT received ELS cmd */ |
| 5363 | if (rjt_err) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5364 | memset(&stat, 0, sizeof(stat)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5365 | stat.un.b.lsRjtRsnCode = rjt_err; |
James.Smart@Emulex.Com | 1f679ca | 2005-06-25 10:34:27 -0400 | [diff] [blame] | 5366 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5367 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
| 5368 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5369 | } |
| 5370 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5371 | return; |
| 5372 | |
| 5373 | dropit: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5374 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
| 5375 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5376 | "(%d):0111 Dropping received ELS cmd " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5377 | "Data: x%x x%x x%x\n", |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5378 | vport->vpi, icmd->ulpStatus, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5379 | icmd->un.ulpWord[4], icmd->ulpTimeout); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5380 | phba->fc_stat.elsRcvDrop++; |
| 5381 | } |
| 5382 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 5383 | /** |
| 5384 | * lpfc_find_vport_by_vpid: Find a vport on a HBA through vport identifier. |
| 5385 | * @phba: pointer to lpfc hba data structure. |
| 5386 | * @vpi: host virtual N_Port identifier. |
| 5387 | * |
| 5388 | * This routine finds a vport on a HBA (referred by @phba) through a |
| 5389 | * @vpi. The function walks the HBA's vport list and returns the address |
| 5390 | * of the vport with the matching @vpi. |
| 5391 | * |
| 5392 | * Return code |
| 5393 | * NULL - No vport with the matching @vpi found |
| 5394 | * Otherwise - Address to the vport with the matching @vpi. |
| 5395 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5396 | static struct lpfc_vport * |
| 5397 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) |
| 5398 | { |
| 5399 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5400 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5401 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5402 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5403 | list_for_each_entry(vport, &phba->port_list, listentry) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5404 | if (vport->vpi == vpi) { |
| 5405 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5406 | return vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5407 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5408 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 5409 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5410 | return NULL; |
| 5411 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5412 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 5413 | /** |
| 5414 | * lpfc_els_unsol_event: Process an unsolicited event from an els sli ring. |
| 5415 | * @phba: pointer to lpfc hba data structure. |
| 5416 | * @pring: pointer to a SLI ring. |
| 5417 | * @elsiocb: pointer to lpfc els iocb data structure. |
| 5418 | * |
| 5419 | * This routine is used to process an unsolicited event received from a SLI |
| 5420 | * (Service Level Interface) ring. The actual processing of the data buffer |
| 5421 | * associated with the unsolicited event is done by invoking the routine |
| 5422 | * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the |
| 5423 | * SLI ring on which the unsolicited event was received. |
| 5424 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5425 | void |
| 5426 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 5427 | struct lpfc_iocbq *elsiocb) |
| 5428 | { |
| 5429 | struct lpfc_vport *vport = phba->pport; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5430 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5431 | dma_addr_t paddr; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5432 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
| 5433 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5434 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5435 | elsiocb->context2 = NULL; |
| 5436 | elsiocb->context3 = NULL; |
| 5437 | |
| 5438 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
| 5439 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 5440 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 5441 | (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5442 | phba->fc_stat.NoRcvBuf++; |
| 5443 | /* Not enough posted buffers; Try posting more buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5444 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 5445 | lpfc_post_buffer(phba, pring, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5446 | return; |
| 5447 | } |
| 5448 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5449 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 5450 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || |
| 5451 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 5452 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) |
| 5453 | vport = phba->pport; |
| 5454 | else { |
| 5455 | uint16_t vpi = icmd->unsli3.rcvsli3.vpi; |
| 5456 | vport = lpfc_find_vport_by_vpid(phba, vpi); |
| 5457 | } |
| 5458 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5459 | /* If there are no BDEs associated |
| 5460 | * with this IOCB, there is nothing to do. |
| 5461 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5462 | if (icmd->ulpBdeCount == 0) |
| 5463 | return; |
| 5464 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5465 | /* type of ELS cmd is first 32bit word |
| 5466 | * in packet |
| 5467 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5468 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5469 | elsiocb->context2 = bdeBuf1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5470 | } else { |
| 5471 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, |
| 5472 | icmd->un.cont64[0].addrLow); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5473 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
| 5474 | paddr); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5475 | } |
| 5476 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5477 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
| 5478 | /* |
| 5479 | * The different unsolicited event handlers would tell us |
| 5480 | * if they are done with "mp" by setting context2 to NULL. |
| 5481 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 5482 | lpfc_nlp_put(elsiocb->context1); |
| 5483 | elsiocb->context1 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5484 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5485 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
| 5486 | elsiocb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5487 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5488 | |
| 5489 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5490 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5491 | icmd->ulpBdeCount == 2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5492 | elsiocb->context2 = bdeBuf2; |
| 5493 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5494 | /* free mp if we are done with it */ |
| 5495 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5496 | lpfc_in_buf_free(phba, elsiocb->context2); |
| 5497 | elsiocb->context2 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5498 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5499 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5500 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5501 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 5502 | /** |
| 5503 | * lpfc_do_scr_ns_plogi: Issue a plogi to the name server for scr. |
| 5504 | * @phba: pointer to lpfc hba data structure. |
| 5505 | * @vport: pointer to a virtual N_Port data structure. |
| 5506 | * |
| 5507 | * This routine issues a Port Login (PLOGI) to the Name Server with |
| 5508 | * State Change Request (SCR) for a @vport. This routine will create an |
| 5509 | * ndlp for the Name Server associated to the @vport if such node does |
| 5510 | * not already exist. The PLOGI to Name Server is issued by invoking the |
| 5511 | * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface |
| 5512 | * (FDMI) is configured to the @vport, a FDMI node will be created and |
| 5513 | * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. |
| 5514 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5515 | void |
| 5516 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 5517 | { |
| 5518 | struct lpfc_nodelist *ndlp, *ndlp_fdmi; |
| 5519 | |
| 5520 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 5521 | if (!ndlp) { |
| 5522 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 5523 | if (!ndlp) { |
| 5524 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 5525 | lpfc_disc_start(vport); |
| 5526 | return; |
| 5527 | } |
| 5528 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5529 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5530 | "0251 NameServer login: no memory\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5531 | return; |
| 5532 | } |
| 5533 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5534 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5535 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 5536 | if (!ndlp) { |
| 5537 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 5538 | lpfc_disc_start(vport); |
| 5539 | return; |
| 5540 | } |
| 5541 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 5542 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5543 | "0348 NameServer login: node freed\n"); |
| 5544 | return; |
| 5545 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5546 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5547 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5548 | |
| 5549 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 5550 | |
| 5551 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { |
| 5552 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5553 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5554 | "0252 Cannot issue NameServer login\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5555 | return; |
| 5556 | } |
| 5557 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5558 | if (vport->cfg_fdmi_on) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5559 | ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool, |
| 5560 | GFP_KERNEL); |
| 5561 | if (ndlp_fdmi) { |
| 5562 | lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID); |
| 5563 | ndlp_fdmi->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 5564 | lpfc_nlp_set_state(vport, ndlp_fdmi, |
| 5565 | NLP_STE_PLOGI_ISSUE); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5566 | lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, |
| 5567 | 0); |
| 5568 | } |
| 5569 | } |
| 5570 | return; |
| 5571 | } |
| 5572 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 5573 | /** |
| 5574 | * lpfc_cmpl_reg_new_vport: Completion callback function to register new vport. |
| 5575 | * @phba: pointer to lpfc hba data structure. |
| 5576 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 5577 | * |
| 5578 | * This routine is the completion callback function to register new vport |
| 5579 | * mailbox command. If the new vport mailbox command completes successfully, |
| 5580 | * the fabric registration login shall be performed on physical port (the |
| 5581 | * new vport created is actually a physical port, with VPI 0) or the port |
| 5582 | * login to Name Server for State Change Request (SCR) will be performed |
| 5583 | * on virtual port (real virtual port, with VPI greater than 0). |
| 5584 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5585 | static void |
| 5586 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 5587 | { |
| 5588 | struct lpfc_vport *vport = pmb->vport; |
| 5589 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5590 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 5591 | MAILBOX_t *mb = &pmb->mb; |
| 5592 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5593 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5594 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5595 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5596 | |
| 5597 | if (mb->mbxStatus) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5598 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 5599 | "0915 Register VPI failed: 0x%x\n", |
| 5600 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5601 | |
| 5602 | switch (mb->mbxStatus) { |
| 5603 | case 0x11: /* unsupported feature */ |
| 5604 | case 0x9603: /* max_vpi exceeded */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5605 | case 0x9602: /* Link event since CLEAR_LA */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5606 | /* giving up on vport registration */ |
| 5607 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 5608 | spin_lock_irq(shost->host_lock); |
| 5609 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 5610 | spin_unlock_irq(shost->host_lock); |
| 5611 | lpfc_can_disctmo(vport); |
| 5612 | break; |
| 5613 | default: |
| 5614 | /* Try to recover from this error */ |
| 5615 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5616 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5617 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5618 | spin_unlock_irq(shost->host_lock); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 5619 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 5620 | lpfc_initial_flogi(vport); |
| 5621 | else |
| 5622 | lpfc_initial_fdisc(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5623 | break; |
| 5624 | } |
| 5625 | |
| 5626 | } else { |
| 5627 | if (vport == phba->pport) |
| 5628 | lpfc_issue_fabric_reglogin(vport); |
| 5629 | else |
| 5630 | lpfc_do_scr_ns_plogi(phba, vport); |
| 5631 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5632 | |
| 5633 | /* Now, we decrement the ndlp reference count held for this |
| 5634 | * callback function |
| 5635 | */ |
| 5636 | lpfc_nlp_put(ndlp); |
| 5637 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5638 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5639 | return; |
| 5640 | } |
| 5641 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 5642 | /** |
| 5643 | * lpfc_register_new_vport: Register a new vport with a HBA. |
| 5644 | * @phba: pointer to lpfc hba data structure. |
| 5645 | * @vport: pointer to a host virtual N_Port data structure. |
| 5646 | * @ndlp: pointer to a node-list data structure. |
| 5647 | * |
| 5648 | * This routine registers the @vport as a new virtual port with a HBA. |
| 5649 | * It is done through a registering vpi mailbox command. |
| 5650 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 5651 | static void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5652 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 5653 | struct lpfc_nodelist *ndlp) |
| 5654 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5655 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5656 | LPFC_MBOXQ_t *mbox; |
| 5657 | |
| 5658 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5659 | if (mbox) { |
| 5660 | lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, mbox); |
| 5661 | mbox->vport = vport; |
| 5662 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 5663 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 5664 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5665 | == MBX_NOT_FINISHED) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5666 | /* mailbox command not success, decrement ndlp |
| 5667 | * reference count for this command |
| 5668 | */ |
| 5669 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5670 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5671 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5672 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 5673 | "0253 Register VPI: Can't send mbox\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5674 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5675 | } |
| 5676 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5677 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 5678 | "0254 Register VPI: no memory\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5679 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5680 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5681 | return; |
| 5682 | |
| 5683 | mbox_err_exit: |
| 5684 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 5685 | spin_lock_irq(shost->host_lock); |
| 5686 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 5687 | spin_unlock_irq(shost->host_lock); |
| 5688 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5689 | } |
| 5690 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 5691 | /** |
| 5692 | * lpfc_cmpl_els_fdisc: Completion function for fdisc iocb command. |
| 5693 | * @phba: pointer to lpfc hba data structure. |
| 5694 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5695 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 5696 | * |
| 5697 | * This routine is the completion callback function to a Fabric Discover |
| 5698 | * (FDISC) ELS command. Since all the FDISC ELS commands are issued |
| 5699 | * single threaded, each FDISC completion callback function will reset |
| 5700 | * the discovery timer for all vports such that the timers will not get |
| 5701 | * unnecessary timeout. The function checks the FDISC IOCB status. If error |
| 5702 | * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the |
| 5703 | * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID |
| 5704 | * assigned to the vport has been changed with the completion of the FDISC |
| 5705 | * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) |
| 5706 | * are unregistered from the HBA, and then the lpfc_register_new_vport() |
| 5707 | * routine is invoked to register new vport with the HBA. Otherwise, the |
| 5708 | * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name |
| 5709 | * Server for State Change Request (SCR). |
| 5710 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5711 | static void |
| 5712 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 5713 | struct lpfc_iocbq *rspiocb) |
| 5714 | { |
| 5715 | struct lpfc_vport *vport = cmdiocb->vport; |
| 5716 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5717 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 5718 | struct lpfc_nodelist *np; |
| 5719 | struct lpfc_nodelist *next_np; |
| 5720 | IOCB_t *irsp = &rspiocb->iocb; |
| 5721 | struct lpfc_iocbq *piocb; |
| 5722 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5723 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 5724 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", |
| 5725 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 5726 | vport->fc_prevDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5727 | /* Since all FDISCs are being single threaded, we |
| 5728 | * must reset the discovery timer for ALL vports |
| 5729 | * waiting to send FDISC when one completes. |
| 5730 | */ |
| 5731 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { |
| 5732 | lpfc_set_disctmo(piocb->vport); |
| 5733 | } |
| 5734 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5735 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 5736 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", |
| 5737 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); |
| 5738 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5739 | if (irsp->ulpStatus) { |
| 5740 | /* Check for retry */ |
| 5741 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| 5742 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5743 | /* FDISC failed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5744 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5745 | "0124 FDISC failed. (%d/%d)\n", |
| 5746 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5747 | if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING) |
| 5748 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5749 | lpfc_nlp_put(ndlp); |
| 5750 | /* giving up on FDISC. Cancel discovery timer */ |
| 5751 | lpfc_can_disctmo(vport); |
| 5752 | } else { |
| 5753 | spin_lock_irq(shost->host_lock); |
| 5754 | vport->fc_flag |= FC_FABRIC; |
| 5755 | if (vport->phba->fc_topology == TOPOLOGY_LOOP) |
| 5756 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 5757 | spin_unlock_irq(shost->host_lock); |
| 5758 | |
| 5759 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| 5760 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); |
| 5761 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 5762 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 5763 | /* If our NportID changed, we need to ensure all |
| 5764 | * remaining NPORTs get unreg_login'ed so we can |
| 5765 | * issue unreg_vpi. |
| 5766 | */ |
| 5767 | list_for_each_entry_safe(np, next_np, |
| 5768 | &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5769 | if (!NLP_CHK_NODE_ACT(ndlp) || |
| 5770 | (np->nlp_state != NLP_STE_NPR_NODE) || |
| 5771 | !(np->nlp_flag & NLP_NPR_ADISC)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5772 | continue; |
| 5773 | spin_lock_irq(shost->host_lock); |
| 5774 | np->nlp_flag &= ~NLP_NPR_ADISC; |
| 5775 | spin_unlock_irq(shost->host_lock); |
| 5776 | lpfc_unreg_rpi(vport, np); |
| 5777 | } |
| 5778 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5779 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5780 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 5781 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5782 | } |
| 5783 | |
| 5784 | if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
| 5785 | lpfc_register_new_vport(phba, vport, ndlp); |
| 5786 | else |
| 5787 | lpfc_do_scr_ns_plogi(phba, vport); |
| 5788 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 5789 | /* Unconditionaly kick off releasing fabric node for vports */ |
| 5790 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5791 | } |
| 5792 | |
| 5793 | out: |
| 5794 | lpfc_els_free_iocb(phba, cmdiocb); |
| 5795 | } |
| 5796 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 5797 | /** |
| 5798 | * lpfc_issue_els_fdisc: Issue a fdisc iocb command. |
| 5799 | * @vport: pointer to a virtual N_Port data structure. |
| 5800 | * @ndlp: pointer to a node-list data structure. |
| 5801 | * @retry: number of retries to the command IOCB. |
| 5802 | * |
| 5803 | * This routine prepares and issues a Fabric Discover (FDISC) IOCB to |
| 5804 | * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() |
| 5805 | * routine to issue the IOCB, which makes sure only one outstanding fabric |
| 5806 | * IOCB will be sent off HBA at any given time. |
| 5807 | * |
| 5808 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 5809 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 5810 | * will be stored into the context1 field of the IOCB for the completion |
| 5811 | * callback function to the FDISC ELS command. |
| 5812 | * |
| 5813 | * Return code |
| 5814 | * 0 - Successfully issued fdisc iocb command |
| 5815 | * 1 - Failed to issue fdisc iocb command |
| 5816 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 5817 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5818 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 5819 | uint8_t retry) |
| 5820 | { |
| 5821 | struct lpfc_hba *phba = vport->phba; |
| 5822 | IOCB_t *icmd; |
| 5823 | struct lpfc_iocbq *elsiocb; |
| 5824 | struct serv_parm *sp; |
| 5825 | uint8_t *pcmd; |
| 5826 | uint16_t cmdsize; |
| 5827 | int did = ndlp->nlp_DID; |
| 5828 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5829 | |
| 5830 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
| 5831 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
| 5832 | ELS_CMD_FDISC); |
| 5833 | if (!elsiocb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5834 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5835 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5836 | "0255 Issue FDISC: no IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5837 | return 1; |
| 5838 | } |
| 5839 | |
| 5840 | icmd = &elsiocb->iocb; |
| 5841 | icmd->un.elsreq64.myID = 0; |
| 5842 | icmd->un.elsreq64.fl = 1; |
| 5843 | |
| 5844 | /* For FDISC, Let FDISC rsp set the NPortID for this VPI */ |
| 5845 | icmd->ulpCt_h = 1; |
| 5846 | icmd->ulpCt_l = 0; |
| 5847 | |
| 5848 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5849 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; |
| 5850 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ |
| 5851 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); |
| 5852 | sp = (struct serv_parm *) pcmd; |
| 5853 | /* Setup CSPs accordingly for Fabric */ |
| 5854 | sp->cmn.e_d_tov = 0; |
| 5855 | sp->cmn.w2.r_a_tov = 0; |
| 5856 | sp->cls1.classValid = 0; |
| 5857 | sp->cls2.seqDelivery = 1; |
| 5858 | sp->cls3.seqDelivery = 1; |
| 5859 | |
| 5860 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ |
| 5861 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ |
| 5862 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ |
| 5863 | pcmd += sizeof(uint32_t); /* Port Name */ |
| 5864 | memcpy(pcmd, &vport->fc_portname, 8); |
| 5865 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 5866 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 5867 | memcpy(pcmd, &vport->fc_nodename, 8); |
| 5868 | |
| 5869 | lpfc_set_disctmo(vport); |
| 5870 | |
| 5871 | phba->fc_stat.elsXmitFDISC++; |
| 5872 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; |
| 5873 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5874 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 5875 | "Issue FDISC: did:x%x", |
| 5876 | did, 0, 0); |
| 5877 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5878 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| 5879 | if (rc == IOCB_ERROR) { |
| 5880 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5881 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5882 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 5883 | "0256 Issue FDISC: Cannot send IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5884 | return 1; |
| 5885 | } |
| 5886 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); |
| 5887 | vport->port_state = LPFC_FDISC; |
| 5888 | return 0; |
| 5889 | } |
| 5890 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 5891 | /** |
| 5892 | * lpfc_cmpl_els_npiv_logo: Completion function with vport logo. |
| 5893 | * @phba: pointer to lpfc hba data structure. |
| 5894 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 5895 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 5896 | * |
| 5897 | * This routine is the completion callback function to the issuing of a LOGO |
| 5898 | * ELS command off a vport. It frees the command IOCB and then decrement the |
| 5899 | * reference count held on ndlp for this completion function, indicating that |
| 5900 | * the reference to the ndlp is no long needed. Note that the |
| 5901 | * lpfc_els_free_iocb() routine decrements the ndlp reference held for this |
| 5902 | * callback function and an additional explicit ndlp reference decrementation |
| 5903 | * will trigger the actual release of the ndlp. |
| 5904 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5905 | static void |
| 5906 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 5907 | struct lpfc_iocbq *rspiocb) |
| 5908 | { |
| 5909 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5910 | IOCB_t *irsp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5911 | struct lpfc_nodelist *ndlp; |
| 5912 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5913 | |
| 5914 | irsp = &rspiocb->iocb; |
| 5915 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 5916 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", |
| 5917 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5918 | |
| 5919 | lpfc_els_free_iocb(phba, cmdiocb); |
| 5920 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5921 | |
| 5922 | /* Trigger the release of the ndlp after logo */ |
| 5923 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5924 | } |
| 5925 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 5926 | /** |
| 5927 | * lpfc_issue_els_npiv_logo: Issue a logo off a vport. |
| 5928 | * @vport: pointer to a virtual N_Port data structure. |
| 5929 | * @ndlp: pointer to a node-list data structure. |
| 5930 | * |
| 5931 | * This routine issues a LOGO ELS command to an @ndlp off a @vport. |
| 5932 | * |
| 5933 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp |
| 5934 | * will be incremented by 1 for holding the ndlp and the reference to ndlp |
| 5935 | * will be stored into the context1 field of the IOCB for the completion |
| 5936 | * callback function to the LOGO ELS command. |
| 5937 | * |
| 5938 | * Return codes |
| 5939 | * 0 - Successfully issued logo off the @vport |
| 5940 | * 1 - Failed to issue logo off the @vport |
| 5941 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5942 | int |
| 5943 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 5944 | { |
| 5945 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 5946 | struct lpfc_hba *phba = vport->phba; |
| 5947 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 5948 | IOCB_t *icmd; |
| 5949 | struct lpfc_iocbq *elsiocb; |
| 5950 | uint8_t *pcmd; |
| 5951 | uint16_t cmdsize; |
| 5952 | |
| 5953 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); |
| 5954 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, |
| 5955 | ELS_CMD_LOGO); |
| 5956 | if (!elsiocb) |
| 5957 | return 1; |
| 5958 | |
| 5959 | icmd = &elsiocb->iocb; |
| 5960 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 5961 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
| 5962 | pcmd += sizeof(uint32_t); |
| 5963 | |
| 5964 | /* Fill in LOGO payload */ |
| 5965 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
| 5966 | pcmd += sizeof(uint32_t); |
| 5967 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 5968 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5969 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 5970 | "Issue LOGO npiv did:x%x flg:x%x", |
| 5971 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 5972 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5973 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
| 5974 | spin_lock_irq(shost->host_lock); |
| 5975 | ndlp->nlp_flag |= NLP_LOGO_SND; |
| 5976 | spin_unlock_irq(shost->host_lock); |
| 5977 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
| 5978 | spin_lock_irq(shost->host_lock); |
| 5979 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
| 5980 | spin_unlock_irq(shost->host_lock); |
| 5981 | lpfc_els_free_iocb(phba, elsiocb); |
| 5982 | return 1; |
| 5983 | } |
| 5984 | return 0; |
| 5985 | } |
| 5986 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 5987 | /** |
| 5988 | * lpfc_fabric_block_timeout: Handler function to the fabric block timer. |
| 5989 | * @ptr: holder for the timer function associated data. |
| 5990 | * |
| 5991 | * This routine is invoked by the fabric iocb block timer after |
| 5992 | * timeout. It posts the fabric iocb block timeout event by setting the |
| 5993 | * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes |
| 5994 | * lpfc_worker_wake_up() routine to wake up the worker thread. It is for |
| 5995 | * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the |
| 5996 | * posted event WORKER_FABRIC_BLOCK_TMO. |
| 5997 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5998 | void |
| 5999 | lpfc_fabric_block_timeout(unsigned long ptr) |
| 6000 | { |
| 6001 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| 6002 | unsigned long iflags; |
| 6003 | uint32_t tmo_posted; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6004 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6005 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 6006 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; |
| 6007 | if (!tmo_posted) |
| 6008 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; |
| 6009 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 6010 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 6011 | if (!tmo_posted) |
| 6012 | lpfc_worker_wake_up(phba); |
| 6013 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6014 | } |
| 6015 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 6016 | /** |
| 6017 | * lpfc_resume_fabric_iocbs: Issue a fabric iocb from driver internal list. |
| 6018 | * @phba: pointer to lpfc hba data structure. |
| 6019 | * |
| 6020 | * This routine issues one fabric iocb from the driver internal list to |
| 6021 | * the HBA. It first checks whether it's ready to issue one fabric iocb to |
| 6022 | * the HBA (whether there is no outstanding fabric iocb). If so, it shall |
| 6023 | * remove one pending fabric iocb from the driver internal list and invokes |
| 6024 | * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. |
| 6025 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6026 | static void |
| 6027 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) |
| 6028 | { |
| 6029 | struct lpfc_iocbq *iocb; |
| 6030 | unsigned long iflags; |
| 6031 | int ret; |
| 6032 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 6033 | IOCB_t *cmd; |
| 6034 | |
| 6035 | repeat: |
| 6036 | iocb = NULL; |
| 6037 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6038 | /* Post any pending iocb to the SLI layer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6039 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
| 6040 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), |
| 6041 | list); |
| 6042 | if (iocb) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6043 | /* Increment fabric iocb count to hold the position */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6044 | atomic_inc(&phba->fabric_iocb_count); |
| 6045 | } |
| 6046 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6047 | if (iocb) { |
| 6048 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 6049 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 6050 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 6051 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6052 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 6053 | "Fabric sched1: ste:x%x", |
| 6054 | iocb->vport->port_state, 0, 0); |
| 6055 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6056 | ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0); |
| 6057 | |
| 6058 | if (ret == IOCB_ERROR) { |
| 6059 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 6060 | iocb->fabric_iocb_cmpl = NULL; |
| 6061 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6062 | cmd = &iocb->iocb; |
| 6063 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 6064 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 6065 | iocb->iocb_cmpl(phba, iocb, iocb); |
| 6066 | |
| 6067 | atomic_dec(&phba->fabric_iocb_count); |
| 6068 | goto repeat; |
| 6069 | } |
| 6070 | } |
| 6071 | |
| 6072 | return; |
| 6073 | } |
| 6074 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 6075 | /** |
| 6076 | * lpfc_unblock_fabric_iocbs: Unblock issuing fabric iocb command. |
| 6077 | * @phba: pointer to lpfc hba data structure. |
| 6078 | * |
| 6079 | * This routine unblocks the issuing fabric iocb command. The function |
| 6080 | * will clear the fabric iocb block bit and then invoke the routine |
| 6081 | * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb |
| 6082 | * from the driver internal fabric iocb list. |
| 6083 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6084 | void |
| 6085 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) |
| 6086 | { |
| 6087 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 6088 | |
| 6089 | lpfc_resume_fabric_iocbs(phba); |
| 6090 | return; |
| 6091 | } |
| 6092 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 6093 | /** |
| 6094 | * lpfc_block_fabric_iocbs: Block issuing fabric iocb command. |
| 6095 | * @phba: pointer to lpfc hba data structure. |
| 6096 | * |
| 6097 | * This routine blocks the issuing fabric iocb for a specified amount of |
| 6098 | * time (currently 100 ms). This is done by set the fabric iocb block bit |
| 6099 | * and set up a timeout timer for 100ms. When the block bit is set, no more |
| 6100 | * fabric iocb will be issued out of the HBA. |
| 6101 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6102 | static void |
| 6103 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) |
| 6104 | { |
| 6105 | int blocked; |
| 6106 | |
| 6107 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6108 | /* Start a timer to unblock fabric iocbs after 100ms */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6109 | if (!blocked) |
| 6110 | mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 ); |
| 6111 | |
| 6112 | return; |
| 6113 | } |
| 6114 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 6115 | /** |
| 6116 | * lpfc_cmpl_fabric_iocb: Completion callback function for fabric iocb. |
| 6117 | * @phba: pointer to lpfc hba data structure. |
| 6118 | * @cmdiocb: pointer to lpfc command iocb data structure. |
| 6119 | * @rspiocb: pointer to lpfc response iocb data structure. |
| 6120 | * |
| 6121 | * This routine is the callback function that is put to the fabric iocb's |
| 6122 | * callback function pointer (iocb->iocb_cmpl). The original iocb's callback |
| 6123 | * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback |
| 6124 | * function first restores and invokes the original iocb's callback function |
| 6125 | * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next |
| 6126 | * fabric bound iocb from the driver internal fabric iocb list onto the wire. |
| 6127 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6128 | static void |
| 6129 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 6130 | struct lpfc_iocbq *rspiocb) |
| 6131 | { |
| 6132 | struct ls_rjt stat; |
| 6133 | |
| 6134 | if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC) |
| 6135 | BUG(); |
| 6136 | |
| 6137 | switch (rspiocb->iocb.ulpStatus) { |
| 6138 | case IOSTAT_NPORT_RJT: |
| 6139 | case IOSTAT_FABRIC_RJT: |
| 6140 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 6141 | lpfc_block_fabric_iocbs(phba); |
| 6142 | } |
| 6143 | break; |
| 6144 | |
| 6145 | case IOSTAT_NPORT_BSY: |
| 6146 | case IOSTAT_FABRIC_BSY: |
| 6147 | lpfc_block_fabric_iocbs(phba); |
| 6148 | break; |
| 6149 | |
| 6150 | case IOSTAT_LS_RJT: |
| 6151 | stat.un.lsRjtError = |
| 6152 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); |
| 6153 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || |
| 6154 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) |
| 6155 | lpfc_block_fabric_iocbs(phba); |
| 6156 | break; |
| 6157 | } |
| 6158 | |
| 6159 | if (atomic_read(&phba->fabric_iocb_count) == 0) |
| 6160 | BUG(); |
| 6161 | |
| 6162 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; |
| 6163 | cmdiocb->fabric_iocb_cmpl = NULL; |
| 6164 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6165 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); |
| 6166 | |
| 6167 | atomic_dec(&phba->fabric_iocb_count); |
| 6168 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6169 | /* Post any pending iocbs to HBA */ |
| 6170 | lpfc_resume_fabric_iocbs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6171 | } |
| 6172 | } |
| 6173 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 6174 | /** |
| 6175 | * lpfc_issue_fabric_iocb: Issue a fabric iocb command. |
| 6176 | * @phba: pointer to lpfc hba data structure. |
| 6177 | * @iocb: pointer to lpfc command iocb data structure. |
| 6178 | * |
| 6179 | * This routine is used as the top-level API for issuing a fabric iocb command |
| 6180 | * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver |
| 6181 | * function makes sure that only one fabric bound iocb will be outstanding at |
| 6182 | * any given time. As such, this function will first check to see whether there |
| 6183 | * is already an outstanding fabric iocb on the wire. If so, it will put the |
| 6184 | * newly issued iocb onto the driver internal fabric iocb list, waiting to be |
| 6185 | * issued later. Otherwise, it will issue the iocb on the wire and update the |
| 6186 | * fabric iocb count it indicate that there is one fabric iocb on the wire. |
| 6187 | * |
| 6188 | * Note, this implementation has a potential sending out fabric IOCBs out of |
| 6189 | * order. The problem is caused by the construction of the "ready" boolen does |
| 6190 | * not include the condition that the internal fabric IOCB list is empty. As |
| 6191 | * such, it is possible a fabric IOCB issued by this routine might be "jump" |
| 6192 | * ahead of the fabric IOCBs in the internal list. |
| 6193 | * |
| 6194 | * Return code |
| 6195 | * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully |
| 6196 | * IOCB_ERROR - failed to issue fabric iocb |
| 6197 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6198 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6199 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
| 6200 | { |
| 6201 | unsigned long iflags; |
| 6202 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 6203 | int ready; |
| 6204 | int ret; |
| 6205 | |
| 6206 | if (atomic_read(&phba->fabric_iocb_count) > 1) |
| 6207 | BUG(); |
| 6208 | |
| 6209 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 6210 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && |
| 6211 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 6212 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 6213 | if (ready) |
| 6214 | /* Increment fabric iocb count to hold the position */ |
| 6215 | atomic_inc(&phba->fabric_iocb_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6216 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6217 | if (ready) { |
| 6218 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 6219 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 6220 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 6221 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6222 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 6223 | "Fabric sched2: ste:x%x", |
| 6224 | iocb->vport->port_state, 0, 0); |
| 6225 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6226 | ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0); |
| 6227 | |
| 6228 | if (ret == IOCB_ERROR) { |
| 6229 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 6230 | iocb->fabric_iocb_cmpl = NULL; |
| 6231 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 6232 | atomic_dec(&phba->fabric_iocb_count); |
| 6233 | } |
| 6234 | } else { |
| 6235 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 6236 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); |
| 6237 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6238 | ret = IOCB_SUCCESS; |
| 6239 | } |
| 6240 | return ret; |
| 6241 | } |
| 6242 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 6243 | /** |
| 6244 | * lpfc_fabric_abort_vport: Abort a vport's iocbs from driver fabric iocb list. |
| 6245 | * @vport: pointer to a virtual N_Port data structure. |
| 6246 | * |
| 6247 | * This routine aborts all the IOCBs associated with a @vport from the |
| 6248 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 6249 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 6250 | * list, removes each IOCB associated with the @vport off the list, set the |
| 6251 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 6252 | * associated with the IOCB. |
| 6253 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 6254 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6255 | { |
| 6256 | LIST_HEAD(completions); |
| 6257 | struct lpfc_hba *phba = vport->phba; |
| 6258 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 6259 | IOCB_t *cmd; |
| 6260 | |
| 6261 | spin_lock_irq(&phba->hbalock); |
| 6262 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 6263 | list) { |
| 6264 | |
| 6265 | if (piocb->vport != vport) |
| 6266 | continue; |
| 6267 | |
| 6268 | list_move_tail(&piocb->list, &completions); |
| 6269 | } |
| 6270 | spin_unlock_irq(&phba->hbalock); |
| 6271 | |
| 6272 | while (!list_empty(&completions)) { |
| 6273 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| 6274 | list_del_init(&piocb->list); |
| 6275 | |
| 6276 | cmd = &piocb->iocb; |
| 6277 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 6278 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 6279 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 6280 | } |
| 6281 | } |
| 6282 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 6283 | /** |
| 6284 | * lpfc_fabric_abort_nport: Abort a ndlp's iocbs from driver fabric iocb list. |
| 6285 | * @ndlp: pointer to a node-list data structure. |
| 6286 | * |
| 6287 | * This routine aborts all the IOCBs associated with an @ndlp from the |
| 6288 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be |
| 6289 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB |
| 6290 | * list, removes each IOCB associated with the @ndlp off the list, set the |
| 6291 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function |
| 6292 | * associated with the IOCB. |
| 6293 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6294 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) |
| 6295 | { |
| 6296 | LIST_HEAD(completions); |
| 6297 | struct lpfc_hba *phba = ndlp->vport->phba; |
| 6298 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 6299 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 6300 | IOCB_t *cmd; |
| 6301 | |
| 6302 | spin_lock_irq(&phba->hbalock); |
| 6303 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 6304 | list) { |
| 6305 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { |
| 6306 | |
| 6307 | list_move_tail(&piocb->list, &completions); |
| 6308 | } |
| 6309 | } |
| 6310 | spin_unlock_irq(&phba->hbalock); |
| 6311 | |
| 6312 | while (!list_empty(&completions)) { |
| 6313 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| 6314 | list_del_init(&piocb->list); |
| 6315 | |
| 6316 | cmd = &piocb->iocb; |
| 6317 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 6318 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 6319 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 6320 | } |
| 6321 | } |
| 6322 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame^] | 6323 | /** |
| 6324 | * lpfc_fabric_abort_hba: Abort all iocbs on driver fabric iocb list. |
| 6325 | * @phba: pointer to lpfc hba data structure. |
| 6326 | * |
| 6327 | * This routine aborts all the IOCBs currently on the driver internal |
| 6328 | * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS |
| 6329 | * IOCB ring. This function takes the entire IOCB list off the fabric IOCB |
| 6330 | * list, removes IOCBs off the list, set the status feild to |
| 6331 | * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with |
| 6332 | * the IOCB. |
| 6333 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 6334 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) |
| 6335 | { |
| 6336 | LIST_HEAD(completions); |
| 6337 | struct lpfc_iocbq *piocb; |
| 6338 | IOCB_t *cmd; |
| 6339 | |
| 6340 | spin_lock_irq(&phba->hbalock); |
| 6341 | list_splice_init(&phba->fabric_iocb_list, &completions); |
| 6342 | spin_unlock_irq(&phba->hbalock); |
| 6343 | |
| 6344 | while (!list_empty(&completions)) { |
| 6345 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| 6346 | list_del_init(&piocb->list); |
| 6347 | |
| 6348 | cmd = &piocb->iocb; |
| 6349 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 6350 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 6351 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 6352 | } |
| 6353 | } |