| 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. * |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 4 | * Copyright (C) 2004-2006 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 | *******************************************************************/ |
| 21 | |
| 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" |
| 38 | |
| 39 | static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *, |
| 40 | struct lpfc_iocbq *); |
| 41 | static int lpfc_max_els_tries = 3; |
| 42 | |
| 43 | static int |
| 44 | lpfc_els_chk_latt(struct lpfc_hba * phba) |
| 45 | { |
| 46 | struct lpfc_sli *psli; |
| 47 | LPFC_MBOXQ_t *mbox; |
| 48 | uint32_t ha_copy; |
| 49 | int rc; |
| 50 | |
| 51 | psli = &phba->sli; |
| 52 | |
| 53 | if ((phba->hba_state >= LPFC_HBA_READY) || |
| 54 | (phba->hba_state == LPFC_LINK_DOWN)) |
| 55 | return 0; |
| 56 | |
| 57 | /* Read the HBA Host Attention Register */ |
| 58 | spin_lock_irq(phba->host->host_lock); |
| 59 | ha_copy = readl(phba->HAregaddr); |
| 60 | spin_unlock_irq(phba->host->host_lock); |
| 61 | |
| 62 | if (!(ha_copy & HA_LATT)) |
| 63 | return 0; |
| 64 | |
| 65 | /* Pending Link Event during Discovery */ |
| 66 | lpfc_printf_log(phba, KERN_WARNING, LOG_DISCOVERY, |
| 67 | "%d:0237 Pending Link Event during " |
| 68 | "Discovery: State x%x\n", |
| 69 | phba->brd_no, phba->hba_state); |
| 70 | |
| 71 | /* CLEAR_LA should re-enable link attention events and |
| 72 | * we should then imediately take a LATT event. The |
| 73 | * LATT processing should call lpfc_linkdown() which |
| 74 | * will cleanup any left over in-progress discovery |
| 75 | * events. |
| 76 | */ |
| 77 | spin_lock_irq(phba->host->host_lock); |
| 78 | phba->fc_flag |= FC_ABORT_DISCOVERY; |
| 79 | spin_unlock_irq(phba->host->host_lock); |
| 80 | |
| 81 | if (phba->hba_state != LPFC_CLEAR_LA) { |
| 82 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) { |
| 83 | phba->hba_state = LPFC_CLEAR_LA; |
| 84 | lpfc_clear_la(phba, mbox); |
| 85 | mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la; |
| 86 | rc = lpfc_sli_issue_mbox (phba, mbox, |
| 87 | (MBX_NOWAIT | MBX_STOP_IOCB)); |
| 88 | if (rc == MBX_NOT_FINISHED) { |
| 89 | mempool_free(mbox, phba->mbox_mem_pool); |
| 90 | phba->hba_state = LPFC_HBA_ERROR; |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 95 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 96 | |
| 97 | } |
| 98 | |
| 99 | static struct lpfc_iocbq * |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 100 | lpfc_prep_els_iocb(struct lpfc_hba * phba, uint8_t expectRsp, |
| 101 | uint16_t cmdSize, uint8_t retry, struct lpfc_nodelist * ndlp, |
| 102 | uint32_t did, uint32_t elscmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 103 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 104 | struct lpfc_sli_ring *pring; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 105 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 106 | struct lpfc_dmabuf *pcmd, *prsp, *pbuflist; |
| 107 | struct ulp_bde64 *bpl; |
| 108 | IOCB_t *icmd; |
| 109 | |
| 110 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 111 | |
| 112 | if (phba->hba_state < LPFC_LINK_UP) |
| 113 | return NULL; |
| 114 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 115 | /* Allocate buffer for command iocb */ |
| 116 | spin_lock_irq(phba->host->host_lock); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 117 | elsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 118 | spin_unlock_irq(phba->host->host_lock); |
| 119 | |
| 120 | if (elsiocb == NULL) |
| 121 | return NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 122 | icmd = &elsiocb->iocb; |
| 123 | |
| 124 | /* fill in BDEs for command */ |
| 125 | /* Allocate buffer for command payload */ |
| 126 | if (((pcmd = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL)) == 0) || |
| 127 | ((pcmd->virt = lpfc_mbuf_alloc(phba, |
| 128 | MEM_PRI, &(pcmd->phys))) == 0)) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 129 | kfree(pcmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 130 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 131 | spin_lock_irq(phba->host->host_lock); |
| 132 | lpfc_sli_release_iocbq(phba, elsiocb); |
| 133 | spin_unlock_irq(phba->host->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 134 | return NULL; |
| 135 | } |
| 136 | |
| 137 | INIT_LIST_HEAD(&pcmd->list); |
| 138 | |
| 139 | /* Allocate buffer for response payload */ |
| 140 | if (expectRsp) { |
| 141 | prsp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 142 | if (prsp) |
| 143 | prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 144 | &prsp->phys); |
| 145 | if (prsp == 0 || prsp->virt == 0) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 146 | kfree(prsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 147 | lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); |
| 148 | kfree(pcmd); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 149 | spin_lock_irq(phba->host->host_lock); |
| 150 | lpfc_sli_release_iocbq(phba, elsiocb); |
| 151 | spin_unlock_irq(phba->host->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 152 | return NULL; |
| 153 | } |
| 154 | INIT_LIST_HEAD(&prsp->list); |
| 155 | } else { |
| 156 | prsp = NULL; |
| 157 | } |
| 158 | |
| 159 | /* Allocate buffer for Buffer ptr list */ |
| 160 | pbuflist = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 161 | if (pbuflist) |
| 162 | pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 163 | &pbuflist->phys); |
| 164 | if (pbuflist == 0 || pbuflist->virt == 0) { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 165 | spin_lock_irq(phba->host->host_lock); |
| 166 | lpfc_sli_release_iocbq(phba, elsiocb); |
| 167 | spin_unlock_irq(phba->host->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 168 | lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); |
| 169 | lpfc_mbuf_free(phba, prsp->virt, prsp->phys); |
| 170 | kfree(pcmd); |
| 171 | kfree(prsp); |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 172 | kfree(pbuflist); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 173 | return NULL; |
| 174 | } |
| 175 | |
| 176 | INIT_LIST_HEAD(&pbuflist->list); |
| 177 | |
| 178 | icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); |
| 179 | icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys); |
| 180 | icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BDL; |
| 181 | if (expectRsp) { |
| 182 | icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof (struct ulp_bde64)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 183 | icmd->un.elsreq64.remoteID = did; /* DID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 184 | icmd->ulpCommand = CMD_ELS_REQUEST64_CR; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 185 | icmd->ulpTimeout = phba->fc_ratov * 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 186 | } else { |
| 187 | icmd->un.elsreq64.bdl.bdeSize = sizeof (struct ulp_bde64); |
| 188 | icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX; |
| 189 | } |
| 190 | |
| 191 | icmd->ulpBdeCount = 1; |
| 192 | icmd->ulpLe = 1; |
| 193 | icmd->ulpClass = CLASS3; |
| 194 | |
| 195 | bpl = (struct ulp_bde64 *) pbuflist->virt; |
| 196 | bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys)); |
| 197 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys)); |
| 198 | bpl->tus.f.bdeSize = cmdSize; |
| 199 | bpl->tus.f.bdeFlags = 0; |
| 200 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 201 | |
| 202 | if (expectRsp) { |
| 203 | bpl++; |
| 204 | bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys)); |
| 205 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys)); |
| 206 | bpl->tus.f.bdeSize = FCELSSIZE; |
| 207 | bpl->tus.f.bdeFlags = BUFF_USE_RCV; |
| 208 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 209 | } |
| 210 | |
| 211 | /* Save for completion so we can release these resources */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 212 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| 213 | elsiocb->context2 = pcmd; |
| 214 | elsiocb->context3 = pbuflist; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 215 | elsiocb->retry = retry; |
| 216 | elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT; |
| 217 | |
| 218 | if (prsp) { |
| 219 | list_add(&prsp->list, &pcmd->list); |
| 220 | } |
| 221 | |
| 222 | if (expectRsp) { |
| 223 | /* Xmit ELS command <elsCmd> to remote NPORT <did> */ |
| 224 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 225 | "%d:0116 Xmit ELS command x%x to remote " |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 226 | "NPORT x%x I/O tag: x%x, HBA state: x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 227 | phba->brd_no, elscmd, |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 228 | did, elsiocb->iotag, phba->hba_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 229 | } else { |
| 230 | /* Xmit ELS response <elsCmd> to remote NPORT <did> */ |
| 231 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 232 | "%d:0117 Xmit ELS response x%x to remote " |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 233 | "NPORT x%x I/O tag: x%x, size: x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 234 | phba->brd_no, elscmd, |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 235 | ndlp->nlp_DID, elsiocb->iotag, cmdSize); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 236 | } |
| 237 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 238 | return elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | |
| 242 | static int |
| 243 | lpfc_cmpl_els_flogi_fabric(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
| 244 | struct serv_parm *sp, IOCB_t *irsp) |
| 245 | { |
| 246 | LPFC_MBOXQ_t *mbox; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 247 | struct lpfc_dmabuf *mp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 248 | int rc; |
| 249 | |
| 250 | spin_lock_irq(phba->host->host_lock); |
| 251 | phba->fc_flag |= FC_FABRIC; |
| 252 | spin_unlock_irq(phba->host->host_lock); |
| 253 | |
| 254 | phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov); |
| 255 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ |
| 256 | phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000; |
| 257 | |
| 258 | phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; |
| 259 | |
| 260 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 261 | spin_lock_irq(phba->host->host_lock); |
| 262 | phba->fc_flag |= FC_PUBLIC_LOOP; |
| 263 | spin_unlock_irq(phba->host->host_lock); |
| 264 | } else { |
| 265 | /* |
| 266 | * If we are a N-port connected to a Fabric, fixup sparam's so |
| 267 | * logins to devices on remote loops work. |
| 268 | */ |
| 269 | phba->fc_sparam.cmn.altBbCredit = 1; |
| 270 | } |
| 271 | |
| 272 | phba->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| 273 | memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); |
| 274 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name)); |
| 275 | ndlp->nlp_class_sup = 0; |
| 276 | if (sp->cls1.classValid) |
| 277 | ndlp->nlp_class_sup |= FC_COS_CLASS1; |
| 278 | if (sp->cls2.classValid) |
| 279 | ndlp->nlp_class_sup |= FC_COS_CLASS2; |
| 280 | if (sp->cls3.classValid) |
| 281 | ndlp->nlp_class_sup |= FC_COS_CLASS3; |
| 282 | if (sp->cls4.classValid) |
| 283 | ndlp->nlp_class_sup |= FC_COS_CLASS4; |
| 284 | ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 285 | sp->cmn.bbRcvSizeLsb; |
| 286 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
| 287 | |
| 288 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 289 | if (!mbox) |
| 290 | goto fail; |
| 291 | |
| 292 | phba->hba_state = LPFC_FABRIC_CFG_LINK; |
| 293 | lpfc_config_link(phba, mbox); |
| 294 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 295 | |
| 296 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB); |
| 297 | if (rc == MBX_NOT_FINISHED) |
| 298 | goto fail_free_mbox; |
| 299 | |
| 300 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 301 | if (!mbox) |
| 302 | goto fail; |
| 303 | |
| 304 | if (lpfc_reg_login(phba, Fabric_DID, (uint8_t *) sp, mbox, 0)) |
| 305 | goto fail_free_mbox; |
| 306 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 307 | mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 308 | mbox->context2 = lpfc_nlp_get(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 309 | |
| 310 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB); |
| 311 | if (rc == MBX_NOT_FINISHED) |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 312 | goto fail_issue_reg_login; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 313 | |
| 314 | return 0; |
| 315 | |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 316 | fail_issue_reg_login: |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 317 | lpfc_nlp_put(ndlp); |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 318 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 319 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 320 | kfree(mp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 321 | fail_free_mbox: |
| 322 | mempool_free(mbox, phba->mbox_mem_pool); |
| 323 | fail: |
| 324 | return -ENXIO; |
| 325 | } |
| 326 | |
| 327 | /* |
| 328 | * We FLOGIed into an NPort, initiate pt2pt protocol |
| 329 | */ |
| 330 | static int |
| 331 | lpfc_cmpl_els_flogi_nport(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
| 332 | struct serv_parm *sp) |
| 333 | { |
| 334 | LPFC_MBOXQ_t *mbox; |
| 335 | int rc; |
| 336 | |
| 337 | spin_lock_irq(phba->host->host_lock); |
| 338 | phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 339 | spin_unlock_irq(phba->host->host_lock); |
| 340 | |
| 341 | phba->fc_edtov = FF_DEF_EDTOV; |
| 342 | phba->fc_ratov = FF_DEF_RATOV; |
| 343 | rc = memcmp(&phba->fc_portname, &sp->portName, |
| 344 | sizeof(struct lpfc_name)); |
| 345 | if (rc >= 0) { |
| 346 | /* This side will initiate the PLOGI */ |
| 347 | spin_lock_irq(phba->host->host_lock); |
| 348 | phba->fc_flag |= FC_PT2PT_PLOGI; |
| 349 | spin_unlock_irq(phba->host->host_lock); |
| 350 | |
| 351 | /* |
| 352 | * N_Port ID cannot be 0, set our to LocalID the other |
| 353 | * side will be RemoteID. |
| 354 | */ |
| 355 | |
| 356 | /* not equal */ |
| 357 | if (rc) |
| 358 | phba->fc_myDID = PT2PT_LocalID; |
| 359 | |
| 360 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 361 | if (!mbox) |
| 362 | goto fail; |
| 363 | |
| 364 | lpfc_config_link(phba, mbox); |
| 365 | |
| 366 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 367 | rc = lpfc_sli_issue_mbox(phba, mbox, |
| 368 | MBX_NOWAIT | MBX_STOP_IOCB); |
| 369 | if (rc == MBX_NOT_FINISHED) { |
| 370 | mempool_free(mbox, phba->mbox_mem_pool); |
| 371 | goto fail; |
| 372 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 373 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 374 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame^] | 375 | ndlp = lpfc_findnode_did(phba, PT2PT_RemoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 376 | if (!ndlp) { |
| 377 | /* |
| 378 | * Cannot find existing Fabric ndlp, so allocate a |
| 379 | * new one |
| 380 | */ |
| 381 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 382 | if (!ndlp) |
| 383 | goto fail; |
| 384 | |
| 385 | lpfc_nlp_init(phba, ndlp, PT2PT_RemoteID); |
| 386 | } |
| 387 | |
| 388 | memcpy(&ndlp->nlp_portname, &sp->portName, |
| 389 | sizeof(struct lpfc_name)); |
| 390 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, |
| 391 | sizeof(struct lpfc_name)); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 392 | lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 393 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 394 | } else { |
| 395 | /* This side will wait for the PLOGI */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 396 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | spin_lock_irq(phba->host->host_lock); |
| 400 | phba->fc_flag |= FC_PT2PT; |
| 401 | spin_unlock_irq(phba->host->host_lock); |
| 402 | |
| 403 | /* Start discovery - this should just do CLEAR_LA */ |
| 404 | lpfc_disc_start(phba); |
| 405 | return 0; |
| 406 | fail: |
| 407 | return -ENXIO; |
| 408 | } |
| 409 | |
| 410 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 411 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 412 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 413 | { |
| 414 | IOCB_t *irsp = &rspiocb->iocb; |
| 415 | struct lpfc_nodelist *ndlp = cmdiocb->context1; |
| 416 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 417 | struct serv_parm *sp; |
| 418 | int rc; |
| 419 | |
| 420 | /* Check to see if link went down during discovery */ |
| 421 | if (lpfc_els_chk_latt(phba)) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 422 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 423 | goto out; |
| 424 | } |
| 425 | |
| 426 | if (irsp->ulpStatus) { |
| 427 | /* Check for retry */ |
| 428 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 429 | /* ELS command is being retried */ |
| 430 | goto out; |
| 431 | } |
| 432 | /* FLOGI failed, so there is no fabric */ |
| 433 | spin_lock_irq(phba->host->host_lock); |
| 434 | phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 435 | spin_unlock_irq(phba->host->host_lock); |
| 436 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 437 | /* If private loop, then allow max outstanding els to be |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 438 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no |
| 439 | * alpa map would take too long otherwise. |
| 440 | */ |
| 441 | if (phba->alpa_map[0] == 0) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 442 | phba->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | /* FLOGI failure */ |
| 446 | lpfc_printf_log(phba, |
| 447 | KERN_INFO, |
| 448 | LOG_ELS, |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 449 | "%d:0100 FLOGI failure Data: x%x x%x x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 450 | phba->brd_no, |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 451 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 452 | irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 453 | goto flogifail; |
| 454 | } |
| 455 | |
| 456 | /* |
| 457 | * The FLogI succeeded. Sync the data for the CPU before |
| 458 | * accessing it. |
| 459 | */ |
| 460 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
| 461 | |
| 462 | sp = prsp->virt + sizeof(uint32_t); |
| 463 | |
| 464 | /* FLOGI completes successfully */ |
| 465 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 466 | "%d:0101 FLOGI completes sucessfully " |
| 467 | "Data: x%x x%x x%x x%x\n", |
| 468 | phba->brd_no, |
| 469 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, |
| 470 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution); |
| 471 | |
| 472 | if (phba->hba_state == LPFC_FLOGI) { |
| 473 | /* |
| 474 | * If Common Service Parameters indicate Nport |
| 475 | * we are point to point, if Fport we are Fabric. |
| 476 | */ |
| 477 | if (sp->cmn.fPort) |
| 478 | rc = lpfc_cmpl_els_flogi_fabric(phba, ndlp, sp, irsp); |
| 479 | else |
| 480 | rc = lpfc_cmpl_els_flogi_nport(phba, ndlp, sp); |
| 481 | |
| 482 | if (!rc) |
| 483 | goto out; |
| 484 | } |
| 485 | |
| 486 | flogifail: |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 487 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 488 | |
| 489 | if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT || |
| 490 | (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED && |
| 491 | irsp->un.ulpWord[4] != IOERR_SLI_DOWN)) { |
| 492 | /* FLOGI failed, so just use loop map to make discovery list */ |
| 493 | lpfc_disc_list_loopmap(phba); |
| 494 | |
| 495 | /* Start discovery */ |
| 496 | lpfc_disc_start(phba); |
| 497 | } |
| 498 | |
| 499 | out: |
| 500 | lpfc_els_free_iocb(phba, cmdiocb); |
| 501 | } |
| 502 | |
| 503 | static int |
| 504 | lpfc_issue_els_flogi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, |
| 505 | uint8_t retry) |
| 506 | { |
| 507 | struct serv_parm *sp; |
| 508 | IOCB_t *icmd; |
| 509 | struct lpfc_iocbq *elsiocb; |
| 510 | struct lpfc_sli_ring *pring; |
| 511 | uint8_t *pcmd; |
| 512 | uint16_t cmdsize; |
| 513 | uint32_t tmo; |
| 514 | int rc; |
| 515 | |
| 516 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 517 | |
| 518 | cmdsize = (sizeof (uint32_t) + sizeof (struct serv_parm)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 519 | elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp, |
| 520 | ndlp->nlp_DID, ELS_CMD_FLOGI); |
| 521 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 522 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 523 | |
| 524 | icmd = &elsiocb->iocb; |
| 525 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 526 | |
| 527 | /* For FLOGI request, remainder of payload is service parameters */ |
| 528 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; |
| 529 | pcmd += sizeof (uint32_t); |
| 530 | memcpy(pcmd, &phba->fc_sparam, sizeof (struct serv_parm)); |
| 531 | sp = (struct serv_parm *) pcmd; |
| 532 | |
| 533 | /* Setup CSPs accordingly for Fabric */ |
| 534 | sp->cmn.e_d_tov = 0; |
| 535 | sp->cmn.w2.r_a_tov = 0; |
| 536 | sp->cls1.classValid = 0; |
| 537 | sp->cls2.seqDelivery = 1; |
| 538 | sp->cls3.seqDelivery = 1; |
| 539 | if (sp->cmn.fcphLow < FC_PH3) |
| 540 | sp->cmn.fcphLow = FC_PH3; |
| 541 | if (sp->cmn.fcphHigh < FC_PH3) |
| 542 | sp->cmn.fcphHigh = FC_PH3; |
| 543 | |
| 544 | tmo = phba->fc_ratov; |
| 545 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; |
| 546 | lpfc_set_disctmo(phba); |
| 547 | phba->fc_ratov = tmo; |
| 548 | |
| 549 | phba->fc_stat.elsXmitFLOGI++; |
| 550 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; |
| 551 | spin_lock_irq(phba->host->host_lock); |
| 552 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| 553 | spin_unlock_irq(phba->host->host_lock); |
| 554 | if (rc == IOCB_ERROR) { |
| 555 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 556 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 557 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 558 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | int |
| 562 | lpfc_els_abort_flogi(struct lpfc_hba * phba) |
| 563 | { |
| 564 | struct lpfc_sli_ring *pring; |
| 565 | struct lpfc_iocbq *iocb, *next_iocb; |
| 566 | struct lpfc_nodelist *ndlp; |
| 567 | IOCB_t *icmd; |
| 568 | |
| 569 | /* Abort outstanding I/O on NPort <nlp_DID> */ |
| 570 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
| 571 | "%d:0201 Abort outstanding I/O on NPort x%x\n", |
| 572 | phba->brd_no, Fabric_DID); |
| 573 | |
| 574 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 575 | |
| 576 | /* |
| 577 | * Check the txcmplq for an iocb that matches the nport the driver is |
| 578 | * searching for. |
| 579 | */ |
| 580 | spin_lock_irq(phba->host->host_lock); |
| 581 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 582 | icmd = &iocb->iocb; |
| 583 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) { |
| 584 | ndlp = (struct lpfc_nodelist *)(iocb->context1); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 585 | if (ndlp && (ndlp->nlp_DID == Fabric_DID)) |
| 586 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 587 | } |
| 588 | } |
| 589 | spin_unlock_irq(phba->host->host_lock); |
| 590 | |
| 591 | return 0; |
| 592 | } |
| 593 | |
| 594 | int |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame^] | 595 | lpfc_initial_flogi(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 596 | { |
| 597 | struct lpfc_nodelist *ndlp; |
| 598 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 599 | /* First look for the Fabric ndlp */ |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame^] | 600 | ndlp = lpfc_findnode_did(phba, Fabric_DID); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 601 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 602 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 603 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 604 | if (!ndlp) |
| 605 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 606 | lpfc_nlp_init(phba, ndlp, Fabric_DID); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 607 | } else { |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 608 | lpfc_dequeue_node(phba, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 609 | } |
| 610 | if (lpfc_issue_els_flogi(phba, ndlp, 0)) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 611 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 612 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 613 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | static void |
| 617 | lpfc_more_plogi(struct lpfc_hba * phba) |
| 618 | { |
| 619 | int sentplogi; |
| 620 | |
| 621 | if (phba->num_disc_nodes) |
| 622 | phba->num_disc_nodes--; |
| 623 | |
| 624 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ |
| 625 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
| 626 | "%d:0232 Continue discovery with %d PLOGIs to go " |
| 627 | "Data: x%x x%x x%x\n", |
| 628 | phba->brd_no, phba->num_disc_nodes, phba->fc_plogi_cnt, |
| 629 | phba->fc_flag, phba->hba_state); |
| 630 | |
| 631 | /* Check to see if there are more PLOGIs to be sent */ |
| 632 | if (phba->fc_flag & FC_NLP_MORE) { |
| 633 | /* go thru NPR list and issue any remaining ELS PLOGIs */ |
| 634 | sentplogi = lpfc_els_disc_plogi(phba); |
| 635 | } |
| 636 | return; |
| 637 | } |
| 638 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 639 | static struct lpfc_nodelist * |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame^] | 640 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, struct lpfc_dmabuf *prsp, |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 641 | struct lpfc_nodelist *ndlp) |
| 642 | { |
| 643 | struct lpfc_nodelist *new_ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 644 | uint32_t *lp; |
| 645 | struct serv_parm *sp; |
| 646 | uint8_t name[sizeof (struct lpfc_name)]; |
| 647 | uint32_t rc; |
| 648 | |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 649 | /* Fabric nodes can have the same WWPN so we don't bother searching |
| 650 | * by WWPN. Just return the ndlp that was given to us. |
| 651 | */ |
| 652 | if (ndlp->nlp_type & NLP_FABRIC) |
| 653 | return ndlp; |
| 654 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 655 | lp = (uint32_t *) prsp->virt; |
| 656 | sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t)); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame^] | 657 | memset(name, 0, sizeof(struct lpfc_name)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 658 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame^] | 659 | /* 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] | 660 | * we have for that ndlp. If not, we have some work to do. |
| 661 | */ |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame^] | 662 | new_ndlp = lpfc_findnode_wwpn(phba, &sp->portName); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 663 | |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 664 | if (new_ndlp == ndlp) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 665 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 666 | |
| 667 | if (!new_ndlp) { |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 668 | rc = |
| 669 | memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)); |
| 670 | if (!rc) |
| 671 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 672 | new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC); |
| 673 | if (!new_ndlp) |
| 674 | return ndlp; |
| 675 | |
| 676 | lpfc_nlp_init(phba, new_ndlp, ndlp->nlp_DID); |
| 677 | } |
| 678 | |
| 679 | lpfc_unreg_rpi(phba, new_ndlp); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 680 | new_ndlp->nlp_DID = ndlp->nlp_DID; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 681 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 682 | lpfc_nlp_set_state(phba, new_ndlp, ndlp->nlp_state); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 683 | |
| 684 | /* Move this back to NPR list */ |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 685 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) |
| 686 | lpfc_drop_node(phba, ndlp); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 687 | else { |
| 688 | lpfc_unreg_rpi(phba, ndlp); |
| 689 | ndlp->nlp_DID = 0; /* Two ndlps cannot have the same did */ |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 690 | lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 691 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 692 | return new_ndlp; |
| 693 | } |
| 694 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 695 | static void |
| 696 | lpfc_cmpl_els_plogi(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb, |
| 697 | struct lpfc_iocbq * rspiocb) |
| 698 | { |
| 699 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 700 | struct lpfc_nodelist *ndlp; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 701 | struct lpfc_dmabuf *prsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 702 | int disc, rc, did, type; |
| 703 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 704 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 705 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 706 | |
| 707 | irsp = &rspiocb->iocb; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame^] | 708 | ndlp = lpfc_findnode_did(phba, irsp->un.elsreq64.remoteID); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 709 | if (!ndlp) |
| 710 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 711 | |
| 712 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 713 | * is being used during discovery. |
| 714 | */ |
| 715 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 716 | spin_lock_irq(phba->host->host_lock); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 717 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 718 | spin_unlock_irq(phba->host->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 719 | rc = 0; |
| 720 | |
| 721 | /* PLOGI completes to NPort <nlp_DID> */ |
| 722 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 723 | "%d:0102 PLOGI completes to NPort x%x " |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 724 | "Data: x%x x%x x%x x%x x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 725 | phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus, |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 726 | irsp->un.ulpWord[4], irsp->ulpTimeout, disc, |
| 727 | phba->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 728 | |
| 729 | /* Check to see if link went down during discovery */ |
| 730 | if (lpfc_els_chk_latt(phba)) { |
| 731 | spin_lock_irq(phba->host->host_lock); |
| 732 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 733 | spin_unlock_irq(phba->host->host_lock); |
| 734 | goto out; |
| 735 | } |
| 736 | |
| 737 | /* ndlp could be freed in DSM, save these values now */ |
| 738 | type = ndlp->nlp_type; |
| 739 | did = ndlp->nlp_DID; |
| 740 | |
| 741 | if (irsp->ulpStatus) { |
| 742 | /* Check for retry */ |
| 743 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 744 | /* ELS command is being retried */ |
| 745 | if (disc) { |
| 746 | spin_lock_irq(phba->host->host_lock); |
| 747 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 748 | spin_unlock_irq(phba->host->host_lock); |
| 749 | } |
| 750 | goto out; |
| 751 | } |
| 752 | |
| 753 | /* PLOGI failed */ |
| 754 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
| 755 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
| 756 | ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) || |
James.Smart@Emulex.Com | 6281bfe | 2005-11-28 11:41:33 -0500 | [diff] [blame] | 757 | (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) || |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 758 | (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 759 | rc = NLP_STE_FREED_NODE; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 760 | } else { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 761 | rc = lpfc_disc_state_machine(phba, ndlp, cmdiocb, |
| 762 | NLP_EVT_CMPL_PLOGI); |
| 763 | } |
| 764 | } else { |
| 765 | /* Good status, call state machine */ |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 766 | prsp = list_entry(((struct lpfc_dmabuf *) |
| 767 | cmdiocb->context2)->list.next, |
| 768 | struct lpfc_dmabuf, list); |
| 769 | ndlp = lpfc_plogi_confirm_nport(phba, prsp, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 770 | rc = lpfc_disc_state_machine(phba, ndlp, cmdiocb, |
| 771 | NLP_EVT_CMPL_PLOGI); |
| 772 | } |
| 773 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 774 | if (disc && phba->num_disc_nodes) { |
| 775 | /* Check to see if there are more PLOGIs to be sent */ |
| 776 | lpfc_more_plogi(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 777 | |
James Smart | 10d4e95 | 2006-04-15 11:53:15 -0400 | [diff] [blame] | 778 | if (phba->num_disc_nodes == 0) { |
| 779 | spin_lock_irq(phba->host->host_lock); |
| 780 | phba->fc_flag &= ~FC_NDISC_ACTIVE; |
| 781 | spin_unlock_irq(phba->host->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 782 | |
James Smart | 10d4e95 | 2006-04-15 11:53:15 -0400 | [diff] [blame] | 783 | lpfc_can_disctmo(phba); |
| 784 | if (phba->fc_flag & FC_RSCN_MODE) { |
| 785 | /* |
| 786 | * Check to see if more RSCNs came in while |
| 787 | * we were processing this one. |
| 788 | */ |
| 789 | if ((phba->fc_rscn_id_cnt == 0) && |
| 790 | (!(phba->fc_flag & FC_RSCN_DISCOVERY))) { |
| 791 | spin_lock_irq(phba->host->host_lock); |
| 792 | phba->fc_flag &= ~FC_RSCN_MODE; |
| 793 | spin_unlock_irq(phba->host->host_lock); |
| 794 | } else { |
| 795 | lpfc_els_handle_rscn(phba); |
| 796 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 797 | } |
| 798 | } |
| 799 | } |
| 800 | |
| 801 | out: |
| 802 | lpfc_els_free_iocb(phba, cmdiocb); |
| 803 | return; |
| 804 | } |
| 805 | |
| 806 | int |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 807 | lpfc_issue_els_plogi(struct lpfc_hba * phba, uint32_t did, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 808 | { |
| 809 | struct serv_parm *sp; |
| 810 | IOCB_t *icmd; |
| 811 | struct lpfc_iocbq *elsiocb; |
| 812 | struct lpfc_sli_ring *pring; |
| 813 | struct lpfc_sli *psli; |
| 814 | uint8_t *pcmd; |
| 815 | uint16_t cmdsize; |
| 816 | |
| 817 | psli = &phba->sli; |
| 818 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 819 | |
| 820 | cmdsize = (sizeof (uint32_t) + sizeof (struct serv_parm)); |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 821 | elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, NULL, did, |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 822 | ELS_CMD_PLOGI); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 823 | if (!elsiocb) |
| 824 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 825 | |
| 826 | icmd = &elsiocb->iocb; |
| 827 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 828 | |
| 829 | /* For PLOGI request, remainder of payload is service parameters */ |
| 830 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; |
| 831 | pcmd += sizeof (uint32_t); |
| 832 | memcpy(pcmd, &phba->fc_sparam, sizeof (struct serv_parm)); |
| 833 | sp = (struct serv_parm *) pcmd; |
| 834 | |
| 835 | if (sp->cmn.fcphLow < FC_PH_4_3) |
| 836 | sp->cmn.fcphLow = FC_PH_4_3; |
| 837 | |
| 838 | if (sp->cmn.fcphHigh < FC_PH3) |
| 839 | sp->cmn.fcphHigh = FC_PH3; |
| 840 | |
| 841 | phba->fc_stat.elsXmitPLOGI++; |
| 842 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; |
| 843 | spin_lock_irq(phba->host->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 844 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 845 | spin_unlock_irq(phba->host->host_lock); |
| 846 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 847 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 848 | } |
| 849 | spin_unlock_irq(phba->host->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 850 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | static void |
| 854 | lpfc_cmpl_els_prli(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb, |
| 855 | struct lpfc_iocbq * rspiocb) |
| 856 | { |
| 857 | IOCB_t *irsp; |
| 858 | struct lpfc_sli *psli; |
| 859 | struct lpfc_nodelist *ndlp; |
| 860 | |
| 861 | psli = &phba->sli; |
| 862 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 863 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 864 | |
| 865 | irsp = &(rspiocb->iocb); |
| 866 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 867 | spin_lock_irq(phba->host->host_lock); |
| 868 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
| 869 | spin_unlock_irq(phba->host->host_lock); |
| 870 | |
| 871 | /* PRLI completes to NPort <nlp_DID> */ |
| 872 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 873 | "%d:0103 PRLI completes to NPort x%x " |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 874 | "Data: x%x x%x x%x x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 875 | phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus, |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 876 | irsp->un.ulpWord[4], irsp->ulpTimeout, |
| 877 | phba->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 878 | |
| 879 | phba->fc_prli_sent--; |
| 880 | /* Check to see if link went down during discovery */ |
| 881 | if (lpfc_els_chk_latt(phba)) |
| 882 | goto out; |
| 883 | |
| 884 | if (irsp->ulpStatus) { |
| 885 | /* Check for retry */ |
| 886 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 887 | /* ELS command is being retried */ |
| 888 | goto out; |
| 889 | } |
| 890 | /* PRLI failed */ |
| 891 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
| 892 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
| 893 | ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) || |
James.Smart@Emulex.Com | 6281bfe | 2005-11-28 11:41:33 -0500 | [diff] [blame] | 894 | (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) || |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 895 | (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) { |
| 896 | goto out; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 897 | } else { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 898 | lpfc_disc_state_machine(phba, ndlp, cmdiocb, |
| 899 | NLP_EVT_CMPL_PRLI); |
| 900 | } |
| 901 | } else { |
| 902 | /* Good status, call state machine */ |
| 903 | lpfc_disc_state_machine(phba, ndlp, cmdiocb, NLP_EVT_CMPL_PRLI); |
| 904 | } |
| 905 | |
| 906 | out: |
| 907 | lpfc_els_free_iocb(phba, cmdiocb); |
| 908 | return; |
| 909 | } |
| 910 | |
| 911 | int |
| 912 | lpfc_issue_els_prli(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, |
| 913 | uint8_t retry) |
| 914 | { |
| 915 | PRLI *npr; |
| 916 | IOCB_t *icmd; |
| 917 | struct lpfc_iocbq *elsiocb; |
| 918 | struct lpfc_sli_ring *pring; |
| 919 | struct lpfc_sli *psli; |
| 920 | uint8_t *pcmd; |
| 921 | uint16_t cmdsize; |
| 922 | |
| 923 | psli = &phba->sli; |
| 924 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 925 | |
| 926 | cmdsize = (sizeof (uint32_t) + sizeof (PRLI)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 927 | elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp, |
| 928 | ndlp->nlp_DID, ELS_CMD_PRLI); |
| 929 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 930 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 931 | |
| 932 | icmd = &elsiocb->iocb; |
| 933 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 934 | |
| 935 | /* For PRLI request, remainder of payload is service parameters */ |
| 936 | memset(pcmd, 0, (sizeof (PRLI) + sizeof (uint32_t))); |
| 937 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLI; |
| 938 | pcmd += sizeof (uint32_t); |
| 939 | |
| 940 | /* For PRLI, remainder of payload is PRLI parameter page */ |
| 941 | npr = (PRLI *) pcmd; |
| 942 | /* |
| 943 | * If our firmware version is 3.20 or later, |
| 944 | * set the following bits for FC-TAPE support. |
| 945 | */ |
| 946 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { |
| 947 | npr->ConfmComplAllowed = 1; |
| 948 | npr->Retry = 1; |
| 949 | npr->TaskRetryIdReq = 1; |
| 950 | } |
| 951 | npr->estabImagePair = 1; |
| 952 | npr->readXferRdyDis = 1; |
| 953 | |
| 954 | /* For FCP support */ |
| 955 | npr->prliType = PRLI_FCP_TYPE; |
| 956 | npr->initiatorFunc = 1; |
| 957 | |
| 958 | phba->fc_stat.elsXmitPRLI++; |
| 959 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; |
| 960 | spin_lock_irq(phba->host->host_lock); |
| 961 | ndlp->nlp_flag |= NLP_PRLI_SND; |
| 962 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
| 963 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
| 964 | spin_unlock_irq(phba->host->host_lock); |
| 965 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 966 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 967 | } |
| 968 | spin_unlock_irq(phba->host->host_lock); |
| 969 | phba->fc_prli_sent++; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 970 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | static void |
| 974 | lpfc_more_adisc(struct lpfc_hba * phba) |
| 975 | { |
| 976 | int sentadisc; |
| 977 | |
| 978 | if (phba->num_disc_nodes) |
| 979 | phba->num_disc_nodes--; |
| 980 | |
| 981 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
| 982 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
| 983 | "%d:0210 Continue discovery with %d ADISCs to go " |
| 984 | "Data: x%x x%x x%x\n", |
| 985 | phba->brd_no, phba->num_disc_nodes, phba->fc_adisc_cnt, |
| 986 | phba->fc_flag, phba->hba_state); |
| 987 | |
| 988 | /* Check to see if there are more ADISCs to be sent */ |
| 989 | if (phba->fc_flag & FC_NLP_MORE) { |
| 990 | lpfc_set_disctmo(phba); |
| 991 | |
| 992 | /* go thru NPR list and issue any remaining ELS ADISCs */ |
| 993 | sentadisc = lpfc_els_disc_adisc(phba); |
| 994 | } |
| 995 | return; |
| 996 | } |
| 997 | |
| 998 | static void |
| 999 | lpfc_rscn_disc(struct lpfc_hba * phba) |
| 1000 | { |
| 1001 | /* RSCN discovery */ |
| 1002 | /* go thru NPR list and issue ELS PLOGIs */ |
| 1003 | if (phba->fc_npr_cnt) { |
| 1004 | if (lpfc_els_disc_plogi(phba)) |
| 1005 | return; |
| 1006 | } |
| 1007 | if (phba->fc_flag & FC_RSCN_MODE) { |
| 1008 | /* Check to see if more RSCNs came in while we were |
| 1009 | * processing this one. |
| 1010 | */ |
| 1011 | if ((phba->fc_rscn_id_cnt == 0) && |
| 1012 | (!(phba->fc_flag & FC_RSCN_DISCOVERY))) { |
| 1013 | spin_lock_irq(phba->host->host_lock); |
| 1014 | phba->fc_flag &= ~FC_RSCN_MODE; |
| 1015 | spin_unlock_irq(phba->host->host_lock); |
| 1016 | } else { |
| 1017 | lpfc_els_handle_rscn(phba); |
| 1018 | } |
| 1019 | } |
| 1020 | } |
| 1021 | |
| 1022 | static void |
| 1023 | lpfc_cmpl_els_adisc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb, |
| 1024 | struct lpfc_iocbq * rspiocb) |
| 1025 | { |
| 1026 | IOCB_t *irsp; |
| 1027 | struct lpfc_sli *psli; |
| 1028 | struct lpfc_nodelist *ndlp; |
| 1029 | LPFC_MBOXQ_t *mbox; |
| 1030 | int disc, rc; |
| 1031 | |
| 1032 | psli = &phba->sli; |
| 1033 | |
| 1034 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1035 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1036 | |
| 1037 | irsp = &(rspiocb->iocb); |
| 1038 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1039 | |
| 1040 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1041 | * is being used during discovery. |
| 1042 | */ |
| 1043 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1044 | spin_lock_irq(phba->host->host_lock); |
| 1045 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
| 1046 | spin_unlock_irq(phba->host->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1047 | |
| 1048 | /* ADISC completes to NPort <nlp_DID> */ |
| 1049 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 1050 | "%d:0104 ADISC completes to NPort x%x " |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1051 | "Data: x%x x%x x%x x%x x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1052 | phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus, |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1053 | irsp->un.ulpWord[4], irsp->ulpTimeout, disc, |
| 1054 | phba->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1055 | |
| 1056 | /* Check to see if link went down during discovery */ |
| 1057 | if (lpfc_els_chk_latt(phba)) { |
| 1058 | spin_lock_irq(phba->host->host_lock); |
| 1059 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 1060 | spin_unlock_irq(phba->host->host_lock); |
| 1061 | goto out; |
| 1062 | } |
| 1063 | |
| 1064 | if (irsp->ulpStatus) { |
| 1065 | /* Check for retry */ |
| 1066 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1067 | /* ELS command is being retried */ |
| 1068 | if (disc) { |
| 1069 | spin_lock_irq(phba->host->host_lock); |
| 1070 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 1071 | spin_unlock_irq(phba->host->host_lock); |
| 1072 | lpfc_set_disctmo(phba); |
| 1073 | } |
| 1074 | goto out; |
| 1075 | } |
| 1076 | /* ADISC failed */ |
| 1077 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1078 | if ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 1079 | ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) && |
| 1080 | (irsp->un.ulpWord[4] != IOERR_LINK_DOWN) && |
| 1081 | (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1082 | lpfc_disc_state_machine(phba, ndlp, cmdiocb, |
| 1083 | NLP_EVT_CMPL_ADISC); |
| 1084 | } |
| 1085 | } else { |
| 1086 | /* Good status, call state machine */ |
| 1087 | lpfc_disc_state_machine(phba, ndlp, cmdiocb, |
| 1088 | NLP_EVT_CMPL_ADISC); |
| 1089 | } |
| 1090 | |
| 1091 | if (disc && phba->num_disc_nodes) { |
| 1092 | /* Check to see if there are more ADISCs to be sent */ |
| 1093 | lpfc_more_adisc(phba); |
| 1094 | |
| 1095 | /* Check to see if we are done with ADISC authentication */ |
| 1096 | if (phba->num_disc_nodes == 0) { |
| 1097 | lpfc_can_disctmo(phba); |
| 1098 | /* If we get here, there is nothing left to wait for */ |
| 1099 | if ((phba->hba_state < LPFC_HBA_READY) && |
| 1100 | (phba->hba_state != LPFC_CLEAR_LA)) { |
| 1101 | /* Link up discovery */ |
| 1102 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, |
| 1103 | GFP_KERNEL))) { |
| 1104 | phba->hba_state = LPFC_CLEAR_LA; |
| 1105 | lpfc_clear_la(phba, mbox); |
| 1106 | mbox->mbox_cmpl = |
| 1107 | lpfc_mbx_cmpl_clear_la; |
| 1108 | rc = lpfc_sli_issue_mbox |
| 1109 | (phba, mbox, |
| 1110 | (MBX_NOWAIT | MBX_STOP_IOCB)); |
| 1111 | if (rc == MBX_NOT_FINISHED) { |
| 1112 | mempool_free(mbox, |
| 1113 | phba->mbox_mem_pool); |
| 1114 | lpfc_disc_flush_list(phba); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 1115 | psli->ring[(psli->extra_ring)]. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1116 | flag &= |
| 1117 | ~LPFC_STOP_IOCB_EVENT; |
| 1118 | psli->ring[(psli->fcp_ring)]. |
| 1119 | flag &= |
| 1120 | ~LPFC_STOP_IOCB_EVENT; |
| 1121 | psli->ring[(psli->next_ring)]. |
| 1122 | flag &= |
| 1123 | ~LPFC_STOP_IOCB_EVENT; |
| 1124 | phba->hba_state = |
| 1125 | LPFC_HBA_READY; |
| 1126 | } |
| 1127 | } |
| 1128 | } else { |
| 1129 | lpfc_rscn_disc(phba); |
| 1130 | } |
| 1131 | } |
| 1132 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1133 | out: |
| 1134 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1135 | return; |
| 1136 | } |
| 1137 | |
| 1138 | int |
| 1139 | lpfc_issue_els_adisc(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, |
| 1140 | uint8_t retry) |
| 1141 | { |
| 1142 | ADISC *ap; |
| 1143 | IOCB_t *icmd; |
| 1144 | struct lpfc_iocbq *elsiocb; |
| 1145 | struct lpfc_sli_ring *pring; |
| 1146 | struct lpfc_sli *psli; |
| 1147 | uint8_t *pcmd; |
| 1148 | uint16_t cmdsize; |
| 1149 | |
| 1150 | psli = &phba->sli; |
| 1151 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 1152 | |
| 1153 | cmdsize = (sizeof (uint32_t) + sizeof (ADISC)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1154 | elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp, |
| 1155 | ndlp->nlp_DID, ELS_CMD_ADISC); |
| 1156 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1157 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1158 | |
| 1159 | icmd = &elsiocb->iocb; |
| 1160 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1161 | |
| 1162 | /* For ADISC request, remainder of payload is service parameters */ |
| 1163 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; |
| 1164 | pcmd += sizeof (uint32_t); |
| 1165 | |
| 1166 | /* Fill in ADISC payload */ |
| 1167 | ap = (ADISC *) pcmd; |
| 1168 | ap->hardAL_PA = phba->fc_pref_ALPA; |
| 1169 | memcpy(&ap->portName, &phba->fc_portname, sizeof (struct lpfc_name)); |
| 1170 | memcpy(&ap->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name)); |
| 1171 | ap->DID = be32_to_cpu(phba->fc_myDID); |
| 1172 | |
| 1173 | phba->fc_stat.elsXmitADISC++; |
| 1174 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; |
| 1175 | spin_lock_irq(phba->host->host_lock); |
| 1176 | ndlp->nlp_flag |= NLP_ADISC_SND; |
| 1177 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
| 1178 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
| 1179 | spin_unlock_irq(phba->host->host_lock); |
| 1180 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1181 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1182 | } |
| 1183 | spin_unlock_irq(phba->host->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1184 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1185 | } |
| 1186 | |
| 1187 | static void |
| 1188 | lpfc_cmpl_els_logo(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb, |
| 1189 | struct lpfc_iocbq * rspiocb) |
| 1190 | { |
| 1191 | IOCB_t *irsp; |
| 1192 | struct lpfc_sli *psli; |
| 1193 | struct lpfc_nodelist *ndlp; |
| 1194 | |
| 1195 | psli = &phba->sli; |
| 1196 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1197 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1198 | |
| 1199 | irsp = &(rspiocb->iocb); |
| 1200 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 1201 | spin_lock_irq(phba->host->host_lock); |
| 1202 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
| 1203 | spin_unlock_irq(phba->host->host_lock); |
| 1204 | |
| 1205 | /* LOGO completes to NPort <nlp_DID> */ |
| 1206 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 1207 | "%d:0105 LOGO completes to NPort x%x " |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1208 | "Data: x%x x%x x%x x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1209 | phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus, |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1210 | irsp->un.ulpWord[4], irsp->ulpTimeout, |
| 1211 | phba->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1212 | |
| 1213 | /* Check to see if link went down during discovery */ |
| 1214 | if (lpfc_els_chk_latt(phba)) |
| 1215 | goto out; |
| 1216 | |
| 1217 | if (irsp->ulpStatus) { |
| 1218 | /* Check for retry */ |
| 1219 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1220 | /* ELS command is being retried */ |
| 1221 | goto out; |
| 1222 | } |
| 1223 | /* LOGO failed */ |
| 1224 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
| 1225 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
| 1226 | ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) || |
James.Smart@Emulex.Com | 6281bfe | 2005-11-28 11:41:33 -0500 | [diff] [blame] | 1227 | (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) || |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1228 | (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) { |
| 1229 | goto out; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 1230 | } else { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1231 | lpfc_disc_state_machine(phba, ndlp, cmdiocb, |
| 1232 | NLP_EVT_CMPL_LOGO); |
| 1233 | } |
| 1234 | } else { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 1235 | /* Good status, call state machine. |
| 1236 | * This will unregister the rpi if needed. |
| 1237 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1238 | lpfc_disc_state_machine(phba, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1239 | } |
| 1240 | |
| 1241 | out: |
| 1242 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1243 | return; |
| 1244 | } |
| 1245 | |
| 1246 | int |
| 1247 | lpfc_issue_els_logo(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, |
| 1248 | uint8_t retry) |
| 1249 | { |
| 1250 | IOCB_t *icmd; |
| 1251 | struct lpfc_iocbq *elsiocb; |
| 1252 | struct lpfc_sli_ring *pring; |
| 1253 | struct lpfc_sli *psli; |
| 1254 | uint8_t *pcmd; |
| 1255 | uint16_t cmdsize; |
| 1256 | |
| 1257 | psli = &phba->sli; |
| 1258 | pring = &psli->ring[LPFC_ELS_RING]; |
| 1259 | |
James Smart | 10d4e95 | 2006-04-15 11:53:15 -0400 | [diff] [blame] | 1260 | cmdsize = (2 * sizeof (uint32_t)) + sizeof (struct lpfc_name); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1261 | elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp, |
| 1262 | ndlp->nlp_DID, ELS_CMD_LOGO); |
| 1263 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1264 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1265 | |
| 1266 | icmd = &elsiocb->iocb; |
| 1267 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1268 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
| 1269 | pcmd += sizeof (uint32_t); |
| 1270 | |
| 1271 | /* Fill in LOGO payload */ |
| 1272 | *((uint32_t *) (pcmd)) = be32_to_cpu(phba->fc_myDID); |
| 1273 | pcmd += sizeof (uint32_t); |
| 1274 | memcpy(pcmd, &phba->fc_portname, sizeof (struct lpfc_name)); |
| 1275 | |
| 1276 | phba->fc_stat.elsXmitLOGO++; |
| 1277 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; |
| 1278 | spin_lock_irq(phba->host->host_lock); |
| 1279 | ndlp->nlp_flag |= NLP_LOGO_SND; |
| 1280 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
| 1281 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
| 1282 | spin_unlock_irq(phba->host->host_lock); |
| 1283 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1284 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1285 | } |
| 1286 | spin_unlock_irq(phba->host->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1287 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1288 | } |
| 1289 | |
| 1290 | static void |
| 1291 | lpfc_cmpl_els_cmd(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb, |
| 1292 | struct lpfc_iocbq * rspiocb) |
| 1293 | { |
| 1294 | IOCB_t *irsp; |
| 1295 | |
| 1296 | irsp = &rspiocb->iocb; |
| 1297 | |
| 1298 | /* ELS cmd tag <ulpIoTag> completes */ |
| 1299 | lpfc_printf_log(phba, |
| 1300 | KERN_INFO, |
| 1301 | LOG_ELS, |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1302 | "%d:0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1303 | phba->brd_no, |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1304 | irsp->ulpIoTag, irsp->ulpStatus, |
| 1305 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1306 | |
| 1307 | /* Check to see if link went down during discovery */ |
| 1308 | lpfc_els_chk_latt(phba); |
| 1309 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1310 | return; |
| 1311 | } |
| 1312 | |
| 1313 | int |
| 1314 | lpfc_issue_els_scr(struct lpfc_hba * phba, uint32_t nportid, uint8_t retry) |
| 1315 | { |
| 1316 | IOCB_t *icmd; |
| 1317 | struct lpfc_iocbq *elsiocb; |
| 1318 | struct lpfc_sli_ring *pring; |
| 1319 | struct lpfc_sli *psli; |
| 1320 | uint8_t *pcmd; |
| 1321 | uint16_t cmdsize; |
| 1322 | struct lpfc_nodelist *ndlp; |
| 1323 | |
| 1324 | psli = &phba->sli; |
| 1325 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 1326 | cmdsize = (sizeof (uint32_t) + sizeof (SCR)); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1327 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1328 | if (!ndlp) |
| 1329 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1330 | |
| 1331 | lpfc_nlp_init(phba, ndlp, nportid); |
| 1332 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1333 | elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp, |
| 1334 | ndlp->nlp_DID, ELS_CMD_SCR); |
| 1335 | if (!elsiocb) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1336 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1337 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1338 | } |
| 1339 | |
| 1340 | icmd = &elsiocb->iocb; |
| 1341 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1342 | |
| 1343 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; |
| 1344 | pcmd += sizeof (uint32_t); |
| 1345 | |
| 1346 | /* For SCR, remainder of payload is SCR parameter page */ |
| 1347 | memset(pcmd, 0, sizeof (SCR)); |
| 1348 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
| 1349 | |
| 1350 | phba->fc_stat.elsXmitSCR++; |
| 1351 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
| 1352 | spin_lock_irq(phba->host->host_lock); |
| 1353 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
| 1354 | spin_unlock_irq(phba->host->host_lock); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1355 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1356 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1357 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1358 | } |
| 1359 | spin_unlock_irq(phba->host->host_lock); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1360 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1361 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1362 | } |
| 1363 | |
| 1364 | static int |
| 1365 | lpfc_issue_els_farpr(struct lpfc_hba * phba, uint32_t nportid, uint8_t retry) |
| 1366 | { |
| 1367 | IOCB_t *icmd; |
| 1368 | struct lpfc_iocbq *elsiocb; |
| 1369 | struct lpfc_sli_ring *pring; |
| 1370 | struct lpfc_sli *psli; |
| 1371 | FARP *fp; |
| 1372 | uint8_t *pcmd; |
| 1373 | uint32_t *lp; |
| 1374 | uint16_t cmdsize; |
| 1375 | struct lpfc_nodelist *ondlp; |
| 1376 | struct lpfc_nodelist *ndlp; |
| 1377 | |
| 1378 | psli = &phba->sli; |
| 1379 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 1380 | cmdsize = (sizeof (uint32_t) + sizeof (FARP)); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1381 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1382 | if (!ndlp) |
| 1383 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1384 | lpfc_nlp_init(phba, ndlp, nportid); |
| 1385 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1386 | elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp, |
| 1387 | ndlp->nlp_DID, ELS_CMD_RNID); |
| 1388 | if (!elsiocb) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1389 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1390 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1391 | } |
| 1392 | |
| 1393 | icmd = &elsiocb->iocb; |
| 1394 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1395 | |
| 1396 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; |
| 1397 | pcmd += sizeof (uint32_t); |
| 1398 | |
| 1399 | /* Fill in FARPR payload */ |
| 1400 | fp = (FARP *) (pcmd); |
| 1401 | memset(fp, 0, sizeof (FARP)); |
| 1402 | lp = (uint32_t *) pcmd; |
| 1403 | *lp++ = be32_to_cpu(nportid); |
| 1404 | *lp++ = be32_to_cpu(phba->fc_myDID); |
| 1405 | fp->Rflags = 0; |
| 1406 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); |
| 1407 | |
| 1408 | memcpy(&fp->RportName, &phba->fc_portname, sizeof (struct lpfc_name)); |
| 1409 | memcpy(&fp->RnodeName, &phba->fc_nodename, sizeof (struct lpfc_name)); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame^] | 1410 | if ((ondlp = lpfc_findnode_did(phba, nportid))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1411 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
| 1412 | sizeof (struct lpfc_name)); |
| 1413 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
| 1414 | sizeof (struct lpfc_name)); |
| 1415 | } |
| 1416 | |
| 1417 | phba->fc_stat.elsXmitFARPR++; |
| 1418 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
| 1419 | spin_lock_irq(phba->host->host_lock); |
| 1420 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
| 1421 | spin_unlock_irq(phba->host->host_lock); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1422 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1423 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1424 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1425 | } |
| 1426 | spin_unlock_irq(phba->host->host_lock); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1427 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1428 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1429 | } |
| 1430 | |
| 1431 | void |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 1432 | lpfc_cancel_retry_delay_tmo(struct lpfc_hba *phba, struct lpfc_nodelist * nlp) |
| 1433 | { |
| 1434 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
| 1435 | del_timer_sync(&nlp->nlp_delayfunc); |
| 1436 | nlp->nlp_last_elscmd = 0; |
| 1437 | |
| 1438 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) |
| 1439 | list_del_init(&nlp->els_retry_evt.evt_listp); |
| 1440 | |
| 1441 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
| 1442 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
| 1443 | if (phba->num_disc_nodes) { |
| 1444 | /* Check to see if there are more |
| 1445 | * PLOGIs to be sent |
| 1446 | */ |
| 1447 | lpfc_more_plogi(phba); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 1448 | |
James Smart | 10d4e95 | 2006-04-15 11:53:15 -0400 | [diff] [blame] | 1449 | if (phba->num_disc_nodes == 0) { |
| 1450 | phba->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1451 | lpfc_can_disctmo(phba); |
| 1452 | if (phba->fc_flag & FC_RSCN_MODE) { |
| 1453 | /* |
| 1454 | * Check to see if more RSCNs |
| 1455 | * came in while we were |
| 1456 | * processing this one. |
| 1457 | */ |
| 1458 | if((phba->fc_rscn_id_cnt==0) && |
| 1459 | !(phba->fc_flag & FC_RSCN_DISCOVERY)) { |
| 1460 | phba->fc_flag &= ~FC_RSCN_MODE; |
| 1461 | } |
| 1462 | else { |
| 1463 | lpfc_els_handle_rscn(phba); |
| 1464 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 1465 | } |
| 1466 | } |
| 1467 | } |
| 1468 | } |
| 1469 | return; |
| 1470 | } |
| 1471 | |
| 1472 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1473 | lpfc_els_retry_delay(unsigned long ptr) |
| 1474 | { |
| 1475 | struct lpfc_nodelist *ndlp; |
| 1476 | struct lpfc_hba *phba; |
| 1477 | unsigned long iflag; |
| 1478 | struct lpfc_work_evt *evtp; |
| 1479 | |
| 1480 | ndlp = (struct lpfc_nodelist *)ptr; |
| 1481 | phba = ndlp->nlp_phba; |
| 1482 | evtp = &ndlp->els_retry_evt; |
| 1483 | |
| 1484 | spin_lock_irqsave(phba->host->host_lock, iflag); |
| 1485 | if (!list_empty(&evtp->evt_listp)) { |
| 1486 | spin_unlock_irqrestore(phba->host->host_lock, iflag); |
| 1487 | return; |
| 1488 | } |
| 1489 | |
| 1490 | evtp->evt_arg1 = ndlp; |
| 1491 | evtp->evt = LPFC_EVT_ELS_RETRY; |
| 1492 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
| 1493 | if (phba->work_wait) |
| 1494 | wake_up(phba->work_wait); |
| 1495 | |
| 1496 | spin_unlock_irqrestore(phba->host->host_lock, iflag); |
| 1497 | return; |
| 1498 | } |
| 1499 | |
| 1500 | void |
| 1501 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) |
| 1502 | { |
| 1503 | struct lpfc_hba *phba; |
| 1504 | uint32_t cmd; |
| 1505 | uint32_t did; |
| 1506 | uint8_t retry; |
| 1507 | |
| 1508 | phba = ndlp->nlp_phba; |
| 1509 | spin_lock_irq(phba->host->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 1510 | did = ndlp->nlp_DID; |
| 1511 | cmd = ndlp->nlp_last_elscmd; |
| 1512 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1513 | |
| 1514 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { |
| 1515 | spin_unlock_irq(phba->host->host_lock); |
| 1516 | return; |
| 1517 | } |
| 1518 | |
| 1519 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
| 1520 | spin_unlock_irq(phba->host->host_lock); |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 1521 | /* |
| 1522 | * If a discovery event readded nlp_delayfunc after timer |
| 1523 | * firing and before processing the timer, cancel the |
| 1524 | * nlp_delayfunc. |
| 1525 | */ |
| 1526 | del_timer_sync(&ndlp->nlp_delayfunc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1527 | retry = ndlp->nlp_retry; |
| 1528 | |
| 1529 | switch (cmd) { |
| 1530 | case ELS_CMD_FLOGI: |
| 1531 | lpfc_issue_els_flogi(phba, ndlp, retry); |
| 1532 | break; |
| 1533 | case ELS_CMD_PLOGI: |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1534 | if(!lpfc_issue_els_plogi(phba, ndlp->nlp_DID, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 1535 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1536 | lpfc_nlp_set_state(phba, ndlp, NLP_STE_PLOGI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 1537 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1538 | break; |
| 1539 | case ELS_CMD_ADISC: |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 1540 | if (!lpfc_issue_els_adisc(phba, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 1541 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1542 | lpfc_nlp_set_state(phba, ndlp, NLP_STE_ADISC_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 1543 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1544 | break; |
| 1545 | case ELS_CMD_PRLI: |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 1546 | if (!lpfc_issue_els_prli(phba, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 1547 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1548 | lpfc_nlp_set_state(phba, ndlp, NLP_STE_PRLI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 1549 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1550 | break; |
| 1551 | case ELS_CMD_LOGO: |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 1552 | if (!lpfc_issue_els_logo(phba, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 1553 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1554 | lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 1555 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1556 | break; |
| 1557 | } |
| 1558 | return; |
| 1559 | } |
| 1560 | |
| 1561 | static int |
| 1562 | lpfc_els_retry(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb, |
| 1563 | struct lpfc_iocbq * rspiocb) |
| 1564 | { |
| 1565 | IOCB_t *irsp; |
| 1566 | struct lpfc_dmabuf *pcmd; |
| 1567 | struct lpfc_nodelist *ndlp; |
| 1568 | uint32_t *elscmd; |
| 1569 | struct ls_rjt stat; |
| 1570 | int retry, maxretry; |
| 1571 | int delay; |
| 1572 | uint32_t cmd; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1573 | uint32_t did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1574 | |
| 1575 | retry = 0; |
| 1576 | delay = 0; |
| 1577 | maxretry = lpfc_max_els_tries; |
| 1578 | irsp = &rspiocb->iocb; |
| 1579 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 1580 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 1581 | cmd = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1582 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1583 | /* Note: context2 may be 0 for internal driver abort |
| 1584 | * of delays ELS command. |
| 1585 | */ |
| 1586 | |
| 1587 | if (pcmd && pcmd->virt) { |
| 1588 | elscmd = (uint32_t *) (pcmd->virt); |
| 1589 | cmd = *elscmd++; |
| 1590 | } |
| 1591 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1592 | if (ndlp) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1593 | did = ndlp->nlp_DID; |
| 1594 | else { |
| 1595 | /* We should only hit this case for retrying PLOGI */ |
| 1596 | did = irsp->un.elsreq64.remoteID; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame^] | 1597 | ndlp = lpfc_findnode_did(phba, did); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1598 | if (!ndlp && (cmd != ELS_CMD_PLOGI)) |
| 1599 | return 1; |
| 1600 | } |
| 1601 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1602 | switch (irsp->ulpStatus) { |
| 1603 | case IOSTAT_FCP_RSP_ERROR: |
| 1604 | case IOSTAT_REMOTE_STOP: |
| 1605 | break; |
| 1606 | |
| 1607 | case IOSTAT_LOCAL_REJECT: |
| 1608 | switch ((irsp->un.ulpWord[4] & 0xff)) { |
| 1609 | case IOERR_LOOP_OPEN_FAILURE: |
| 1610 | if (cmd == ELS_CMD_PLOGI) { |
| 1611 | if (cmdiocb->retry == 0) { |
| 1612 | delay = 1; |
| 1613 | } |
| 1614 | } |
| 1615 | retry = 1; |
| 1616 | break; |
| 1617 | |
| 1618 | case IOERR_SEQUENCE_TIMEOUT: |
| 1619 | retry = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1620 | break; |
| 1621 | |
| 1622 | case IOERR_NO_RESOURCES: |
| 1623 | if (cmd == ELS_CMD_PLOGI) { |
| 1624 | delay = 1; |
| 1625 | } |
| 1626 | retry = 1; |
| 1627 | break; |
| 1628 | |
| 1629 | case IOERR_INVALID_RPI: |
| 1630 | retry = 1; |
| 1631 | break; |
| 1632 | } |
| 1633 | break; |
| 1634 | |
| 1635 | case IOSTAT_NPORT_RJT: |
| 1636 | case IOSTAT_FABRIC_RJT: |
| 1637 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 1638 | retry = 1; |
| 1639 | break; |
| 1640 | } |
| 1641 | break; |
| 1642 | |
| 1643 | case IOSTAT_NPORT_BSY: |
| 1644 | case IOSTAT_FABRIC_BSY: |
| 1645 | retry = 1; |
| 1646 | break; |
| 1647 | |
| 1648 | case IOSTAT_LS_RJT: |
| 1649 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); |
| 1650 | /* Added for Vendor specifc support |
| 1651 | * Just keep retrying for these Rsn / Exp codes |
| 1652 | */ |
| 1653 | switch (stat.un.b.lsRjtRsnCode) { |
| 1654 | case LSRJT_UNABLE_TPC: |
| 1655 | if (stat.un.b.lsRjtRsnCodeExp == |
| 1656 | LSEXP_CMD_IN_PROGRESS) { |
| 1657 | if (cmd == ELS_CMD_PLOGI) { |
| 1658 | delay = 1; |
| 1659 | maxretry = 48; |
| 1660 | } |
| 1661 | retry = 1; |
| 1662 | break; |
| 1663 | } |
| 1664 | if (cmd == ELS_CMD_PLOGI) { |
| 1665 | delay = 1; |
| 1666 | maxretry = lpfc_max_els_tries + 1; |
| 1667 | retry = 1; |
| 1668 | break; |
| 1669 | } |
| 1670 | break; |
| 1671 | |
| 1672 | case LSRJT_LOGICAL_BSY: |
| 1673 | if (cmd == ELS_CMD_PLOGI) { |
| 1674 | delay = 1; |
| 1675 | maxretry = 48; |
| 1676 | } |
| 1677 | retry = 1; |
| 1678 | break; |
| 1679 | } |
| 1680 | break; |
| 1681 | |
| 1682 | case IOSTAT_INTERMED_RSP: |
| 1683 | case IOSTAT_BA_RJT: |
| 1684 | break; |
| 1685 | |
| 1686 | default: |
| 1687 | break; |
| 1688 | } |
| 1689 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1690 | if (did == FDMI_DID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1691 | retry = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1692 | |
| 1693 | if ((++cmdiocb->retry) >= maxretry) { |
| 1694 | phba->fc_stat.elsRetryExceeded++; |
| 1695 | retry = 0; |
| 1696 | } |
| 1697 | |
| 1698 | if (retry) { |
| 1699 | |
| 1700 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ |
| 1701 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 1702 | "%d:0107 Retry ELS command x%x to remote " |
| 1703 | "NPORT x%x Data: x%x x%x\n", |
| 1704 | phba->brd_no, |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1705 | cmd, did, cmdiocb->retry, delay); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1706 | |
| 1707 | if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) { |
| 1708 | /* If discovery / RSCN timer is running, reset it */ |
| 1709 | if (timer_pending(&phba->fc_disctmo) || |
| 1710 | (phba->fc_flag & FC_RSCN_MODE)) { |
| 1711 | lpfc_set_disctmo(phba); |
| 1712 | } |
| 1713 | } |
| 1714 | |
| 1715 | phba->fc_stat.elsXmitRetry++; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1716 | if (ndlp && delay) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1717 | phba->fc_stat.elsDelayRetry++; |
| 1718 | ndlp->nlp_retry = cmdiocb->retry; |
| 1719 | |
| 1720 | mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ); |
| 1721 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 1722 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 1723 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1724 | lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1725 | ndlp->nlp_last_elscmd = cmd; |
| 1726 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1727 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1728 | } |
| 1729 | switch (cmd) { |
| 1730 | case ELS_CMD_FLOGI: |
| 1731 | lpfc_issue_els_flogi(phba, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1732 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1733 | case ELS_CMD_PLOGI: |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1734 | if (ndlp) { |
| 1735 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1736 | lpfc_nlp_set_state(phba, ndlp, |
| 1737 | NLP_STE_PLOGI_ISSUE); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1738 | } |
| 1739 | lpfc_issue_els_plogi(phba, did, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1740 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1741 | case ELS_CMD_ADISC: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 1742 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1743 | lpfc_nlp_set_state(phba, ndlp, NLP_STE_ADISC_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1744 | lpfc_issue_els_adisc(phba, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1745 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1746 | case ELS_CMD_PRLI: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 1747 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1748 | lpfc_nlp_set_state(phba, ndlp, NLP_STE_PRLI_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1749 | lpfc_issue_els_prli(phba, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1750 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1751 | case ELS_CMD_LOGO: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 1752 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1753 | lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1754 | lpfc_issue_els_logo(phba, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1755 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1756 | } |
| 1757 | } |
| 1758 | |
| 1759 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
| 1760 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 1761 | "%d:0108 No retry ELS command x%x to remote NPORT x%x " |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1762 | "Data: x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1763 | phba->brd_no, |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1764 | cmd, did, cmdiocb->retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1765 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1766 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1767 | } |
| 1768 | |
| 1769 | int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1770 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1771 | { |
| 1772 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; |
| 1773 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1774 | if (elsiocb->context1) { |
| 1775 | lpfc_nlp_put(elsiocb->context1); |
| 1776 | elsiocb->context1 = NULL; |
| 1777 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1778 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
| 1779 | if (elsiocb->context2) { |
| 1780 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; |
| 1781 | /* Free the response before processing the command. */ |
| 1782 | if (!list_empty(&buf_ptr1->list)) { |
| 1783 | list_remove_head(&buf_ptr1->list, buf_ptr, |
| 1784 | struct lpfc_dmabuf, |
| 1785 | list); |
| 1786 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 1787 | kfree(buf_ptr); |
| 1788 | } |
| 1789 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); |
| 1790 | kfree(buf_ptr1); |
| 1791 | } |
| 1792 | |
| 1793 | if (elsiocb->context3) { |
| 1794 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; |
| 1795 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 1796 | kfree(buf_ptr); |
| 1797 | } |
| 1798 | spin_lock_irq(phba->host->host_lock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1799 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1800 | spin_unlock_irq(phba->host->host_lock); |
| 1801 | return 0; |
| 1802 | } |
| 1803 | |
| 1804 | static void |
| 1805 | lpfc_cmpl_els_logo_acc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb, |
| 1806 | struct lpfc_iocbq * rspiocb) |
| 1807 | { |
| 1808 | struct lpfc_nodelist *ndlp; |
| 1809 | |
| 1810 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 1811 | |
| 1812 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
| 1813 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 1814 | "%d:0109 ACC to LOGO completes to NPort x%x " |
| 1815 | "Data: x%x x%x x%x\n", |
| 1816 | phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag, |
| 1817 | ndlp->nlp_state, ndlp->nlp_rpi); |
| 1818 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1819 | switch (ndlp->nlp_state) { |
| 1820 | case NLP_STE_UNUSED_NODE: /* node is just allocated */ |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1821 | lpfc_drop_node(phba, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1822 | break; |
| 1823 | case NLP_STE_NPR_NODE: /* NPort Recovery mode */ |
| 1824 | lpfc_unreg_rpi(phba, ndlp); |
| 1825 | break; |
| 1826 | default: |
| 1827 | break; |
| 1828 | } |
| 1829 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1830 | return; |
| 1831 | } |
| 1832 | |
| 1833 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1834 | lpfc_cmpl_els_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1835 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1836 | { |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 1837 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1838 | struct lpfc_nodelist *ndlp; |
| 1839 | LPFC_MBOXQ_t *mbox = NULL; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1840 | struct lpfc_dmabuf *mp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1841 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 1842 | irsp = &rspiocb->iocb; |
| 1843 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1844 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 1845 | if (cmdiocb->context_un.mbox) |
| 1846 | mbox = cmdiocb->context_un.mbox; |
| 1847 | |
| 1848 | |
| 1849 | /* Check to see if link went down during discovery */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1850 | if (lpfc_els_chk_latt(phba) || !ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1851 | if (mbox) { |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1852 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 1853 | if (mp) { |
| 1854 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 1855 | kfree(mp); |
| 1856 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1857 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1858 | } |
| 1859 | goto out; |
| 1860 | } |
| 1861 | |
| 1862 | /* ELS response tag <ulpIoTag> completes */ |
| 1863 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 1864 | "%d:0110 ELS response tag x%x completes " |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1865 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1866 | phba->brd_no, |
| 1867 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1868 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, |
| 1869 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 1870 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1871 | |
| 1872 | if (mbox) { |
| 1873 | if ((rspiocb->iocb.ulpStatus == 0) |
| 1874 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1875 | lpfc_unreg_rpi(phba, ndlp); |
| 1876 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1877 | mbox->context2 = lpfc_nlp_get(ndlp); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 1878 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1879 | lpfc_nlp_set_state(phba, ndlp, NLP_STE_REG_LOGIN_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1880 | if (lpfc_sli_issue_mbox(phba, mbox, |
| 1881 | (MBX_NOWAIT | MBX_STOP_IOCB)) |
| 1882 | != MBX_NOT_FINISHED) { |
| 1883 | goto out; |
| 1884 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1885 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1886 | /* NOTE: we should have messages for unsuccessful |
| 1887 | reglogin */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1888 | } else { |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 1889 | /* Do not call NO_LIST for lpfc_els_abort'ed ELS cmds */ |
| 1890 | if (!((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
| 1891 | ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) || |
| 1892 | (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) || |
| 1893 | (irsp->un.ulpWord[4] == IOERR_SLI_DOWN)))) { |
| 1894 | if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) { |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 1895 | lpfc_drop_node(phba, ndlp); |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 1896 | ndlp = NULL; |
| 1897 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1898 | } |
| 1899 | } |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1900 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 1901 | if (mp) { |
| 1902 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 1903 | kfree(mp); |
| 1904 | } |
| 1905 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1906 | } |
| 1907 | out: |
| 1908 | if (ndlp) { |
| 1909 | spin_lock_irq(phba->host->host_lock); |
| 1910 | ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN; |
| 1911 | spin_unlock_irq(phba->host->host_lock); |
| 1912 | } |
| 1913 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1914 | return; |
| 1915 | } |
| 1916 | |
| 1917 | int |
| 1918 | lpfc_els_rsp_acc(struct lpfc_hba * phba, uint32_t flag, |
| 1919 | struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp, |
| 1920 | LPFC_MBOXQ_t * mbox, uint8_t newnode) |
| 1921 | { |
| 1922 | IOCB_t *icmd; |
| 1923 | IOCB_t *oldcmd; |
| 1924 | struct lpfc_iocbq *elsiocb; |
| 1925 | struct lpfc_sli_ring *pring; |
| 1926 | struct lpfc_sli *psli; |
| 1927 | uint8_t *pcmd; |
| 1928 | uint16_t cmdsize; |
| 1929 | int rc; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 1930 | ELS_PKT *els_pkt_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1931 | |
| 1932 | psli = &phba->sli; |
| 1933 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 1934 | oldcmd = &oldiocb->iocb; |
| 1935 | |
| 1936 | switch (flag) { |
| 1937 | case ELS_CMD_ACC: |
| 1938 | cmdsize = sizeof (uint32_t); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1939 | elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry, |
| 1940 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
| 1941 | if (!elsiocb) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 1942 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1943 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1944 | } |
| 1945 | icmd = &elsiocb->iocb; |
| 1946 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 1947 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1948 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 1949 | pcmd += sizeof (uint32_t); |
| 1950 | break; |
| 1951 | case ELS_CMD_PLOGI: |
| 1952 | cmdsize = (sizeof (struct serv_parm) + sizeof (uint32_t)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1953 | elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry, |
| 1954 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
| 1955 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1956 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1957 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1958 | icmd = &elsiocb->iocb; |
| 1959 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 1960 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1961 | |
| 1962 | if (mbox) |
| 1963 | elsiocb->context_un.mbox = mbox; |
| 1964 | |
| 1965 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 1966 | pcmd += sizeof (uint32_t); |
| 1967 | memcpy(pcmd, &phba->fc_sparam, sizeof (struct serv_parm)); |
| 1968 | break; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 1969 | case ELS_CMD_PRLO: |
| 1970 | cmdsize = sizeof (uint32_t) + sizeof (PRLO); |
| 1971 | elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry, |
| 1972 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
| 1973 | if (!elsiocb) |
| 1974 | return 1; |
| 1975 | |
| 1976 | icmd = &elsiocb->iocb; |
| 1977 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 1978 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1979 | |
| 1980 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, |
| 1981 | sizeof (uint32_t) + sizeof (PRLO)); |
| 1982 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
| 1983 | els_pkt_ptr = (ELS_PKT *) pcmd; |
| 1984 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; |
| 1985 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1986 | default: |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1987 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1988 | } |
| 1989 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1990 | if (newnode) { |
| 1991 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1992 | elsiocb->context1 = NULL; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1993 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1994 | |
| 1995 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
| 1996 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 1997 | "%d:0128 Xmit ELS ACC response tag x%x, XRI: x%x, " |
| 1998 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n", |
| 1999 | phba->brd_no, elsiocb->iotag, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2000 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 2001 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
| 2002 | |
| 2003 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2004 | spin_lock_irq(phba->host->host_lock); |
| 2005 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
| 2006 | spin_unlock_irq(phba->host->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2007 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
| 2008 | } else { |
| 2009 | elsiocb->iocb_cmpl = lpfc_cmpl_els_acc; |
| 2010 | } |
| 2011 | |
| 2012 | phba->fc_stat.elsXmitACC++; |
| 2013 | spin_lock_irq(phba->host->host_lock); |
| 2014 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| 2015 | spin_unlock_irq(phba->host->host_lock); |
| 2016 | if (rc == IOCB_ERROR) { |
| 2017 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2018 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2019 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2020 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2021 | } |
| 2022 | |
| 2023 | int |
| 2024 | lpfc_els_rsp_reject(struct lpfc_hba * phba, uint32_t rejectError, |
| 2025 | struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp) |
| 2026 | { |
| 2027 | IOCB_t *icmd; |
| 2028 | IOCB_t *oldcmd; |
| 2029 | struct lpfc_iocbq *elsiocb; |
| 2030 | struct lpfc_sli_ring *pring; |
| 2031 | struct lpfc_sli *psli; |
| 2032 | uint8_t *pcmd; |
| 2033 | uint16_t cmdsize; |
| 2034 | int rc; |
| 2035 | |
| 2036 | psli = &phba->sli; |
| 2037 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 2038 | |
| 2039 | cmdsize = 2 * sizeof (uint32_t); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2040 | elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry, |
| 2041 | ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT); |
| 2042 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2043 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2044 | |
| 2045 | icmd = &elsiocb->iocb; |
| 2046 | oldcmd = &oldiocb->iocb; |
| 2047 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 2048 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2049 | |
| 2050 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
| 2051 | pcmd += sizeof (uint32_t); |
| 2052 | *((uint32_t *) (pcmd)) = rejectError; |
| 2053 | |
| 2054 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
| 2055 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 2056 | "%d:0129 Xmit ELS RJT x%x response tag x%x xri x%x, " |
| 2057 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 2058 | phba->brd_no, rejectError, elsiocb->iotag, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2059 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 2060 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
| 2061 | |
| 2062 | phba->fc_stat.elsXmitLSRJT++; |
| 2063 | elsiocb->iocb_cmpl = lpfc_cmpl_els_acc; |
| 2064 | spin_lock_irq(phba->host->host_lock); |
| 2065 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| 2066 | spin_unlock_irq(phba->host->host_lock); |
| 2067 | if (rc == IOCB_ERROR) { |
| 2068 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2069 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2070 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2071 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2072 | } |
| 2073 | |
| 2074 | int |
| 2075 | lpfc_els_rsp_adisc_acc(struct lpfc_hba * phba, |
| 2076 | struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp) |
| 2077 | { |
| 2078 | ADISC *ap; |
| 2079 | IOCB_t *icmd; |
| 2080 | IOCB_t *oldcmd; |
| 2081 | struct lpfc_iocbq *elsiocb; |
| 2082 | struct lpfc_sli_ring *pring; |
| 2083 | struct lpfc_sli *psli; |
| 2084 | uint8_t *pcmd; |
| 2085 | uint16_t cmdsize; |
| 2086 | int rc; |
| 2087 | |
| 2088 | psli = &phba->sli; |
| 2089 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 2090 | |
| 2091 | cmdsize = sizeof (uint32_t) + sizeof (ADISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2092 | elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry, |
| 2093 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
| 2094 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2095 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2096 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2097 | icmd = &elsiocb->iocb; |
| 2098 | oldcmd = &oldiocb->iocb; |
| 2099 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 2100 | |
| 2101 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
| 2102 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 2103 | "%d:0130 Xmit ADISC ACC response iotag x%x xri: " |
| 2104 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", |
| 2105 | phba->brd_no, elsiocb->iotag, |
| 2106 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 2107 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
| 2108 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2109 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2110 | |
| 2111 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 2112 | pcmd += sizeof (uint32_t); |
| 2113 | |
| 2114 | ap = (ADISC *) (pcmd); |
| 2115 | ap->hardAL_PA = phba->fc_pref_ALPA; |
| 2116 | memcpy(&ap->portName, &phba->fc_portname, sizeof (struct lpfc_name)); |
| 2117 | memcpy(&ap->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name)); |
| 2118 | ap->DID = be32_to_cpu(phba->fc_myDID); |
| 2119 | |
| 2120 | phba->fc_stat.elsXmitACC++; |
| 2121 | elsiocb->iocb_cmpl = lpfc_cmpl_els_acc; |
| 2122 | spin_lock_irq(phba->host->host_lock); |
| 2123 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| 2124 | spin_unlock_irq(phba->host->host_lock); |
| 2125 | if (rc == IOCB_ERROR) { |
| 2126 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2127 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2128 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2129 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2130 | } |
| 2131 | |
| 2132 | int |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 2133 | lpfc_els_rsp_prli_acc(struct lpfc_hba *phba, struct lpfc_iocbq *oldiocb, |
| 2134 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2135 | { |
| 2136 | PRLI *npr; |
| 2137 | lpfc_vpd_t *vpd; |
| 2138 | IOCB_t *icmd; |
| 2139 | IOCB_t *oldcmd; |
| 2140 | struct lpfc_iocbq *elsiocb; |
| 2141 | struct lpfc_sli_ring *pring; |
| 2142 | struct lpfc_sli *psli; |
| 2143 | uint8_t *pcmd; |
| 2144 | uint16_t cmdsize; |
| 2145 | int rc; |
| 2146 | |
| 2147 | psli = &phba->sli; |
| 2148 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 2149 | |
| 2150 | cmdsize = sizeof (uint32_t) + sizeof (PRLI); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2151 | elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry, ndlp, |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2152 | ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK))); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2153 | if (!elsiocb) |
| 2154 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2155 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2156 | icmd = &elsiocb->iocb; |
| 2157 | oldcmd = &oldiocb->iocb; |
| 2158 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 2159 | |
| 2160 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
| 2161 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 2162 | "%d:0131 Xmit PRLI ACC response tag x%x xri x%x, " |
| 2163 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 2164 | phba->brd_no, elsiocb->iotag, |
| 2165 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 2166 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
| 2167 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2168 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2169 | |
| 2170 | *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); |
| 2171 | pcmd += sizeof (uint32_t); |
| 2172 | |
| 2173 | /* For PRLI, remainder of payload is PRLI parameter page */ |
| 2174 | memset(pcmd, 0, sizeof (PRLI)); |
| 2175 | |
| 2176 | npr = (PRLI *) pcmd; |
| 2177 | vpd = &phba->vpd; |
| 2178 | /* |
| 2179 | * If our firmware version is 3.20 or later, |
| 2180 | * set the following bits for FC-TAPE support. |
| 2181 | */ |
| 2182 | if (vpd->rev.feaLevelHigh >= 0x02) { |
| 2183 | npr->ConfmComplAllowed = 1; |
| 2184 | npr->Retry = 1; |
| 2185 | npr->TaskRetryIdReq = 1; |
| 2186 | } |
| 2187 | |
| 2188 | npr->acceptRspCode = PRLI_REQ_EXECUTED; |
| 2189 | npr->estabImagePair = 1; |
| 2190 | npr->readXferRdyDis = 1; |
| 2191 | npr->ConfmComplAllowed = 1; |
| 2192 | |
| 2193 | npr->prliType = PRLI_FCP_TYPE; |
| 2194 | npr->initiatorFunc = 1; |
| 2195 | |
| 2196 | phba->fc_stat.elsXmitACC++; |
| 2197 | elsiocb->iocb_cmpl = lpfc_cmpl_els_acc; |
| 2198 | |
| 2199 | spin_lock_irq(phba->host->host_lock); |
| 2200 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| 2201 | spin_unlock_irq(phba->host->host_lock); |
| 2202 | if (rc == IOCB_ERROR) { |
| 2203 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2204 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2205 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2206 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2207 | } |
| 2208 | |
| 2209 | static int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2210 | lpfc_els_rsp_rnid_acc(struct lpfc_hba *phba, uint8_t format, |
| 2211 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2212 | { |
| 2213 | RNID *rn; |
| 2214 | IOCB_t *icmd; |
| 2215 | IOCB_t *oldcmd; |
| 2216 | struct lpfc_iocbq *elsiocb; |
| 2217 | struct lpfc_sli_ring *pring; |
| 2218 | struct lpfc_sli *psli; |
| 2219 | uint8_t *pcmd; |
| 2220 | uint16_t cmdsize; |
| 2221 | int rc; |
| 2222 | |
| 2223 | psli = &phba->sli; |
| 2224 | pring = &psli->ring[LPFC_ELS_RING]; |
| 2225 | |
| 2226 | cmdsize = sizeof (uint32_t) + sizeof (uint32_t) |
| 2227 | + (2 * sizeof (struct lpfc_name)); |
| 2228 | if (format) |
| 2229 | cmdsize += sizeof (RNID_TOP_DISC); |
| 2230 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2231 | elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry, |
| 2232 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
| 2233 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2234 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2235 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2236 | icmd = &elsiocb->iocb; |
| 2237 | oldcmd = &oldiocb->iocb; |
| 2238 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 2239 | |
| 2240 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
| 2241 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 2242 | "%d:0132 Xmit RNID ACC response tag x%x " |
| 2243 | "xri x%x\n", |
| 2244 | phba->brd_no, elsiocb->iotag, |
| 2245 | elsiocb->iocb.ulpContext); |
| 2246 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2247 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2248 | |
| 2249 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 2250 | pcmd += sizeof (uint32_t); |
| 2251 | |
| 2252 | memset(pcmd, 0, sizeof (RNID)); |
| 2253 | rn = (RNID *) (pcmd); |
| 2254 | rn->Format = format; |
| 2255 | rn->CommonLen = (2 * sizeof (struct lpfc_name)); |
| 2256 | memcpy(&rn->portName, &phba->fc_portname, sizeof (struct lpfc_name)); |
| 2257 | memcpy(&rn->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name)); |
| 2258 | switch (format) { |
| 2259 | case 0: |
| 2260 | rn->SpecificLen = 0; |
| 2261 | break; |
| 2262 | case RNID_TOPOLOGY_DISC: |
| 2263 | rn->SpecificLen = sizeof (RNID_TOP_DISC); |
| 2264 | memcpy(&rn->un.topologyDisc.portName, |
| 2265 | &phba->fc_portname, sizeof (struct lpfc_name)); |
| 2266 | rn->un.topologyDisc.unitType = RNID_HBA; |
| 2267 | rn->un.topologyDisc.physPort = 0; |
| 2268 | rn->un.topologyDisc.attachedNodes = 0; |
| 2269 | break; |
| 2270 | default: |
| 2271 | rn->CommonLen = 0; |
| 2272 | rn->SpecificLen = 0; |
| 2273 | break; |
| 2274 | } |
| 2275 | |
| 2276 | phba->fc_stat.elsXmitACC++; |
| 2277 | elsiocb->iocb_cmpl = lpfc_cmpl_els_acc; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2278 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2279 | elsiocb->context1 = NULL; /* Don't need ndlp for cmpl, |
| 2280 | * it could be freed */ |
| 2281 | |
| 2282 | spin_lock_irq(phba->host->host_lock); |
| 2283 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| 2284 | spin_unlock_irq(phba->host->host_lock); |
| 2285 | if (rc == IOCB_ERROR) { |
| 2286 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2287 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2288 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2289 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2290 | } |
| 2291 | |
| 2292 | int |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame^] | 2293 | lpfc_els_disc_adisc(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2294 | { |
| 2295 | int sentadisc; |
| 2296 | struct lpfc_nodelist *ndlp, *next_ndlp; |
| 2297 | |
| 2298 | sentadisc = 0; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame^] | 2299 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
| 2300 | list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nodes, nlp_listp) { |
| 2301 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 2302 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 2303 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { |
| 2304 | spin_lock_irq(phba->host->host_lock); |
| 2305 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
| 2306 | spin_unlock_irq(phba->host->host_lock); |
| 2307 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 2308 | lpfc_nlp_set_state(phba, ndlp, NLP_STE_ADISC_ISSUE); |
| 2309 | lpfc_issue_els_adisc(phba, ndlp, 0); |
| 2310 | sentadisc++; |
| 2311 | phba->num_disc_nodes++; |
| 2312 | if (phba->num_disc_nodes >= |
| 2313 | phba->cfg_discovery_threads) { |
| 2314 | spin_lock_irq(phba->host->host_lock); |
| 2315 | phba->fc_flag |= FC_NLP_MORE; |
| 2316 | spin_unlock_irq(phba->host->host_lock); |
| 2317 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2318 | } |
| 2319 | } |
| 2320 | } |
| 2321 | if (sentadisc == 0) { |
| 2322 | spin_lock_irq(phba->host->host_lock); |
| 2323 | phba->fc_flag &= ~FC_NLP_MORE; |
| 2324 | spin_unlock_irq(phba->host->host_lock); |
| 2325 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2326 | return sentadisc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2327 | } |
| 2328 | |
| 2329 | int |
| 2330 | lpfc_els_disc_plogi(struct lpfc_hba * phba) |
| 2331 | { |
| 2332 | int sentplogi; |
| 2333 | struct lpfc_nodelist *ndlp, *next_ndlp; |
| 2334 | |
| 2335 | sentplogi = 0; |
| 2336 | /* go thru NPR list and issue any remaining ELS PLOGIs */ |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame^] | 2337 | list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nodes, nlp_listp) { |
| 2338 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 2339 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 2340 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && |
| 2341 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { |
| 2342 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 2343 | lpfc_nlp_set_state(phba, ndlp, NLP_STE_PLOGI_ISSUE); |
| 2344 | lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0); |
| 2345 | sentplogi++; |
| 2346 | phba->num_disc_nodes++; |
| 2347 | if (phba->num_disc_nodes >= |
| 2348 | phba->cfg_discovery_threads) { |
| 2349 | spin_lock_irq(phba->host->host_lock); |
| 2350 | phba->fc_flag |= FC_NLP_MORE; |
| 2351 | spin_unlock_irq(phba->host->host_lock); |
| 2352 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2353 | } |
| 2354 | } |
| 2355 | } |
| 2356 | if (sentplogi == 0) { |
| 2357 | spin_lock_irq(phba->host->host_lock); |
| 2358 | phba->fc_flag &= ~FC_NLP_MORE; |
| 2359 | spin_unlock_irq(phba->host->host_lock); |
| 2360 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2361 | return sentplogi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2362 | } |
| 2363 | |
| 2364 | int |
| 2365 | lpfc_els_flush_rscn(struct lpfc_hba * phba) |
| 2366 | { |
| 2367 | struct lpfc_dmabuf *mp; |
| 2368 | int i; |
| 2369 | |
| 2370 | for (i = 0; i < phba->fc_rscn_id_cnt; i++) { |
| 2371 | mp = phba->fc_rscn_id_list[i]; |
| 2372 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2373 | kfree(mp); |
| 2374 | phba->fc_rscn_id_list[i] = NULL; |
| 2375 | } |
| 2376 | phba->fc_rscn_id_cnt = 0; |
| 2377 | spin_lock_irq(phba->host->host_lock); |
| 2378 | phba->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); |
| 2379 | spin_unlock_irq(phba->host->host_lock); |
| 2380 | lpfc_can_disctmo(phba); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2381 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2382 | } |
| 2383 | |
| 2384 | int |
| 2385 | lpfc_rscn_payload_check(struct lpfc_hba * phba, uint32_t did) |
| 2386 | { |
| 2387 | D_ID ns_did; |
| 2388 | D_ID rscn_did; |
| 2389 | struct lpfc_dmabuf *mp; |
| 2390 | uint32_t *lp; |
| 2391 | uint32_t payload_len, cmd, i, match; |
| 2392 | |
| 2393 | ns_did.un.word = did; |
| 2394 | match = 0; |
| 2395 | |
| 2396 | /* Never match fabric nodes for RSCNs */ |
| 2397 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| 2398 | return(0); |
| 2399 | |
| 2400 | /* If we are doing a FULL RSCN rediscovery, match everything */ |
| 2401 | if (phba->fc_flag & FC_RSCN_DISCOVERY) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2402 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2403 | } |
| 2404 | |
| 2405 | for (i = 0; i < phba->fc_rscn_id_cnt; i++) { |
| 2406 | mp = phba->fc_rscn_id_list[i]; |
| 2407 | lp = (uint32_t *) mp->virt; |
| 2408 | cmd = *lp++; |
| 2409 | payload_len = be32_to_cpu(cmd) & 0xffff; /* payload length */ |
| 2410 | payload_len -= sizeof (uint32_t); /* take off word 0 */ |
| 2411 | while (payload_len) { |
| 2412 | rscn_did.un.word = *lp++; |
| 2413 | rscn_did.un.word = be32_to_cpu(rscn_did.un.word); |
| 2414 | payload_len -= sizeof (uint32_t); |
| 2415 | switch (rscn_did.un.b.resv) { |
| 2416 | case 0: /* Single N_Port ID effected */ |
| 2417 | if (ns_did.un.word == rscn_did.un.word) { |
| 2418 | match = did; |
| 2419 | } |
| 2420 | break; |
| 2421 | case 1: /* Whole N_Port Area effected */ |
| 2422 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 2423 | && (ns_did.un.b.area == rscn_did.un.b.area)) |
| 2424 | { |
| 2425 | match = did; |
| 2426 | } |
| 2427 | break; |
| 2428 | case 2: /* Whole N_Port Domain effected */ |
| 2429 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
| 2430 | { |
| 2431 | match = did; |
| 2432 | } |
| 2433 | break; |
| 2434 | case 3: /* Whole Fabric effected */ |
| 2435 | match = did; |
| 2436 | break; |
| 2437 | default: |
| 2438 | /* Unknown Identifier in RSCN list */ |
| 2439 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
| 2440 | "%d:0217 Unknown Identifier in " |
| 2441 | "RSCN payload Data: x%x\n", |
| 2442 | phba->brd_no, rscn_did.un.word); |
| 2443 | break; |
| 2444 | } |
| 2445 | if (match) { |
| 2446 | break; |
| 2447 | } |
| 2448 | } |
| 2449 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2450 | return match; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2451 | } |
| 2452 | |
| 2453 | static int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2454 | lpfc_rscn_recovery_check(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2455 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame^] | 2456 | struct lpfc_nodelist *ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2457 | |
| 2458 | /* Look at all nodes effected by pending RSCNs and move |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame^] | 2459 | * them to NPR state. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2460 | */ |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame^] | 2461 | |
| 2462 | list_for_each_entry(ndlp, &phba->fc_nodes, nlp_listp) { |
| 2463 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE || |
| 2464 | lpfc_rscn_payload_check(phba, ndlp->nlp_DID) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2465 | continue; |
| 2466 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame^] | 2467 | lpfc_disc_state_machine(phba, ndlp, NULL, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2468 | NLP_EVT_DEVICE_RECOVERY); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2469 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame^] | 2470 | /* |
| 2471 | * Make sure NLP_DELAY_TMO is NOT running after a device |
| 2472 | * recovery event. |
| 2473 | */ |
| 2474 | if (ndlp->nlp_flag & NLP_DELAY_TMO) |
| 2475 | lpfc_cancel_retry_delay_tmo(phba, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2476 | } |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame^] | 2477 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2478 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2479 | } |
| 2480 | |
| 2481 | static int |
| 2482 | lpfc_els_rcv_rscn(struct lpfc_hba * phba, |
| 2483 | struct lpfc_iocbq * cmdiocb, |
| 2484 | struct lpfc_nodelist * ndlp, uint8_t newnode) |
| 2485 | { |
| 2486 | struct lpfc_dmabuf *pcmd; |
| 2487 | uint32_t *lp; |
| 2488 | IOCB_t *icmd; |
| 2489 | uint32_t payload_len, cmd; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 2490 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2491 | |
| 2492 | icmd = &cmdiocb->iocb; |
| 2493 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 2494 | lp = (uint32_t *) pcmd->virt; |
| 2495 | |
| 2496 | cmd = *lp++; |
| 2497 | payload_len = be32_to_cpu(cmd) & 0xffff; /* payload length */ |
| 2498 | payload_len -= sizeof (uint32_t); /* take off word 0 */ |
| 2499 | cmd &= ELS_CMD_MASK; |
| 2500 | |
| 2501 | /* RSCN received */ |
| 2502 | lpfc_printf_log(phba, |
| 2503 | KERN_INFO, |
| 2504 | LOG_DISCOVERY, |
| 2505 | "%d:0214 RSCN received Data: x%x x%x x%x x%x\n", |
| 2506 | phba->brd_no, |
| 2507 | phba->fc_flag, payload_len, *lp, phba->fc_rscn_id_cnt); |
| 2508 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 2509 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
| 2510 | fc_host_post_event(phba->host, fc_get_event_number(), |
| 2511 | FCH_EVT_RSCN, lp[i]); |
| 2512 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2513 | /* If we are about to begin discovery, just ACC the RSCN. |
| 2514 | * Discovery processing will satisfy it. |
| 2515 | */ |
James Smart | 071fbd3d | 2006-04-15 11:53:20 -0400 | [diff] [blame] | 2516 | if (phba->hba_state <= LPFC_NS_QRY) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2517 | lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, |
| 2518 | newnode); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2519 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2520 | } |
| 2521 | |
| 2522 | /* If we are already processing an RSCN, save the received |
| 2523 | * RSCN payload buffer, cmdiocb->context2 to process later. |
| 2524 | */ |
| 2525 | if (phba->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
| 2526 | if ((phba->fc_rscn_id_cnt < FC_MAX_HOLD_RSCN) && |
| 2527 | !(phba->fc_flag & FC_RSCN_DISCOVERY)) { |
| 2528 | spin_lock_irq(phba->host->host_lock); |
| 2529 | phba->fc_flag |= FC_RSCN_MODE; |
| 2530 | spin_unlock_irq(phba->host->host_lock); |
| 2531 | phba->fc_rscn_id_list[phba->fc_rscn_id_cnt++] = pcmd; |
| 2532 | |
| 2533 | /* If we zero, cmdiocb->context2, the calling |
| 2534 | * routine will not try to free it. |
| 2535 | */ |
| 2536 | cmdiocb->context2 = NULL; |
| 2537 | |
| 2538 | /* Deferred RSCN */ |
| 2539 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
| 2540 | "%d:0235 Deferred RSCN " |
| 2541 | "Data: x%x x%x x%x\n", |
| 2542 | phba->brd_no, phba->fc_rscn_id_cnt, |
| 2543 | phba->fc_flag, phba->hba_state); |
| 2544 | } else { |
| 2545 | spin_lock_irq(phba->host->host_lock); |
| 2546 | phba->fc_flag |= FC_RSCN_DISCOVERY; |
| 2547 | spin_unlock_irq(phba->host->host_lock); |
| 2548 | /* ReDiscovery RSCN */ |
| 2549 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
| 2550 | "%d:0234 ReDiscovery RSCN " |
| 2551 | "Data: x%x x%x x%x\n", |
| 2552 | phba->brd_no, phba->fc_rscn_id_cnt, |
| 2553 | phba->fc_flag, phba->hba_state); |
| 2554 | } |
| 2555 | /* Send back ACC */ |
| 2556 | lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, |
| 2557 | newnode); |
| 2558 | |
| 2559 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
| 2560 | lpfc_rscn_recovery_check(phba); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2561 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2562 | } |
| 2563 | |
| 2564 | phba->fc_flag |= FC_RSCN_MODE; |
| 2565 | phba->fc_rscn_id_list[phba->fc_rscn_id_cnt++] = pcmd; |
| 2566 | /* |
| 2567 | * If we zero, cmdiocb->context2, the calling routine will |
| 2568 | * not try to free it. |
| 2569 | */ |
| 2570 | cmdiocb->context2 = NULL; |
| 2571 | |
| 2572 | lpfc_set_disctmo(phba); |
| 2573 | |
| 2574 | /* Send back ACC */ |
| 2575 | lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, newnode); |
| 2576 | |
| 2577 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
| 2578 | lpfc_rscn_recovery_check(phba); |
| 2579 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2580 | return lpfc_els_handle_rscn(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2581 | } |
| 2582 | |
| 2583 | int |
| 2584 | lpfc_els_handle_rscn(struct lpfc_hba * phba) |
| 2585 | { |
| 2586 | struct lpfc_nodelist *ndlp; |
| 2587 | |
| 2588 | /* Start timer for RSCN processing */ |
| 2589 | lpfc_set_disctmo(phba); |
| 2590 | |
| 2591 | /* RSCN processed */ |
| 2592 | lpfc_printf_log(phba, |
| 2593 | KERN_INFO, |
| 2594 | LOG_DISCOVERY, |
| 2595 | "%d:0215 RSCN processed Data: x%x x%x x%x x%x\n", |
| 2596 | phba->brd_no, |
| 2597 | phba->fc_flag, 0, phba->fc_rscn_id_cnt, |
| 2598 | phba->hba_state); |
| 2599 | |
| 2600 | /* To process RSCN, first compare RSCN data with NameServer */ |
| 2601 | phba->fc_ns_retry = 0; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame^] | 2602 | ndlp = lpfc_findnode_did(phba, NameServer_DID); |
| 2603 | if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2604 | /* Good ndlp, issue CT Request to NameServer */ |
| 2605 | if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT) == 0) { |
| 2606 | /* Wait for NameServer query cmpl before we can |
| 2607 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2608 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2609 | } |
| 2610 | } else { |
| 2611 | /* If login to NameServer does not exist, issue one */ |
| 2612 | /* Good status, issue PLOGI to NameServer */ |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame^] | 2613 | ndlp = lpfc_findnode_did(phba, NameServer_DID); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2614 | if (ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2615 | /* Wait for NameServer login cmpl before we can |
| 2616 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2617 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2618 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2619 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 2620 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2621 | lpfc_els_flush_rscn(phba); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2622 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2623 | } else { |
| 2624 | lpfc_nlp_init(phba, ndlp, NameServer_DID); |
| 2625 | ndlp->nlp_type |= NLP_FABRIC; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2626 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2627 | lpfc_nlp_set_state(phba, ndlp, NLP_STE_PLOGI_ISSUE); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2628 | lpfc_issue_els_plogi(phba, NameServer_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2629 | /* Wait for NameServer login cmpl before we can |
| 2630 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2631 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2632 | } |
| 2633 | } |
| 2634 | |
| 2635 | lpfc_els_flush_rscn(phba); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2636 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2637 | } |
| 2638 | |
| 2639 | static int |
| 2640 | lpfc_els_rcv_flogi(struct lpfc_hba * phba, |
| 2641 | struct lpfc_iocbq * cmdiocb, |
| 2642 | struct lpfc_nodelist * ndlp, uint8_t newnode) |
| 2643 | { |
| 2644 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 2645 | uint32_t *lp = (uint32_t *) pcmd->virt; |
| 2646 | IOCB_t *icmd = &cmdiocb->iocb; |
| 2647 | struct serv_parm *sp; |
| 2648 | LPFC_MBOXQ_t *mbox; |
| 2649 | struct ls_rjt stat; |
| 2650 | uint32_t cmd, did; |
| 2651 | int rc; |
| 2652 | |
| 2653 | cmd = *lp++; |
| 2654 | sp = (struct serv_parm *) lp; |
| 2655 | |
| 2656 | /* FLOGI received */ |
| 2657 | |
| 2658 | lpfc_set_disctmo(phba); |
| 2659 | |
| 2660 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 2661 | /* We should never receive a FLOGI in loop mode, ignore it */ |
| 2662 | did = icmd->un.elsreq64.remoteID; |
| 2663 | |
| 2664 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in |
| 2665 | Loop Mode */ |
| 2666 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, |
| 2667 | "%d:0113 An FLOGI ELS command x%x was received " |
| 2668 | "from DID x%x in Loop Mode\n", |
| 2669 | phba->brd_no, cmd, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2670 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2671 | } |
| 2672 | |
| 2673 | did = Fabric_DID; |
| 2674 | |
| 2675 | if ((lpfc_check_sparm(phba, ndlp, sp, CLASS3))) { |
| 2676 | /* For a FLOGI we accept, then if our portname is greater |
| 2677 | * then the remote portname we initiate Nport login. |
| 2678 | */ |
| 2679 | |
| 2680 | rc = memcmp(&phba->fc_portname, &sp->portName, |
| 2681 | sizeof (struct lpfc_name)); |
| 2682 | |
| 2683 | if (!rc) { |
| 2684 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, |
| 2685 | GFP_KERNEL)) == 0) { |
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 | } |
| 2688 | lpfc_linkdown(phba); |
| 2689 | lpfc_init_link(phba, mbox, |
| 2690 | phba->cfg_topology, |
| 2691 | phba->cfg_link_speed); |
| 2692 | mbox->mb.un.varInitLnk.lipsr_AL_PA = 0; |
| 2693 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 2694 | rc = lpfc_sli_issue_mbox |
| 2695 | (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB)); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 2696 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2697 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2698 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2699 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2700 | return 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2701 | } else if (rc > 0) { /* greater than */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2702 | spin_lock_irq(phba->host->host_lock); |
| 2703 | phba->fc_flag |= FC_PT2PT_PLOGI; |
| 2704 | spin_unlock_irq(phba->host->host_lock); |
| 2705 | } |
| 2706 | phba->fc_flag |= FC_PT2PT; |
| 2707 | phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 2708 | } else { |
| 2709 | /* Reject this request because invalid parameters */ |
| 2710 | stat.un.b.lsRjtRsvd0 = 0; |
| 2711 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 2712 | stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; |
| 2713 | stat.un.b.vendorUnique = 0; |
| 2714 | lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2715 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2716 | } |
| 2717 | |
| 2718 | /* Send back ACC */ |
| 2719 | lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL, newnode); |
| 2720 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2721 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2722 | } |
| 2723 | |
| 2724 | static int |
| 2725 | lpfc_els_rcv_rnid(struct lpfc_hba * phba, |
| 2726 | struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp) |
| 2727 | { |
| 2728 | struct lpfc_dmabuf *pcmd; |
| 2729 | uint32_t *lp; |
| 2730 | IOCB_t *icmd; |
| 2731 | RNID *rn; |
| 2732 | struct ls_rjt stat; |
| 2733 | uint32_t cmd, did; |
| 2734 | |
| 2735 | icmd = &cmdiocb->iocb; |
| 2736 | did = icmd->un.elsreq64.remoteID; |
| 2737 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 2738 | lp = (uint32_t *) pcmd->virt; |
| 2739 | |
| 2740 | cmd = *lp++; |
| 2741 | rn = (RNID *) lp; |
| 2742 | |
| 2743 | /* RNID received */ |
| 2744 | |
| 2745 | switch (rn->Format) { |
| 2746 | case 0: |
| 2747 | case RNID_TOPOLOGY_DISC: |
| 2748 | /* Send back ACC */ |
| 2749 | lpfc_els_rsp_rnid_acc(phba, rn->Format, cmdiocb, ndlp); |
| 2750 | break; |
| 2751 | default: |
| 2752 | /* Reject this request because format not supported */ |
| 2753 | stat.un.b.lsRjtRsvd0 = 0; |
| 2754 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 2755 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 2756 | stat.un.b.vendorUnique = 0; |
| 2757 | lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp); |
| 2758 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2759 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2760 | } |
| 2761 | |
| 2762 | static int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2763 | lpfc_els_rcv_lirr(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2764 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 2765 | { |
| 2766 | struct ls_rjt stat; |
| 2767 | |
| 2768 | /* For now, unconditionally reject this command */ |
| 2769 | stat.un.b.lsRjtRsvd0 = 0; |
| 2770 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 2771 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 2772 | stat.un.b.vendorUnique = 0; |
| 2773 | lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp); |
| 2774 | return 0; |
| 2775 | } |
| 2776 | |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 2777 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2778 | 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] | 2779 | { |
| 2780 | struct lpfc_sli *psli; |
| 2781 | struct lpfc_sli_ring *pring; |
| 2782 | MAILBOX_t *mb; |
| 2783 | IOCB_t *icmd; |
| 2784 | RPS_RSP *rps_rsp; |
| 2785 | uint8_t *pcmd; |
| 2786 | struct lpfc_iocbq *elsiocb; |
| 2787 | struct lpfc_nodelist *ndlp; |
| 2788 | uint16_t xri, status; |
| 2789 | uint32_t cmdsize; |
| 2790 | |
| 2791 | psli = &phba->sli; |
| 2792 | pring = &psli->ring[LPFC_ELS_RING]; |
| 2793 | mb = &pmb->mb; |
| 2794 | |
| 2795 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 2796 | xri = (uint16_t) ((unsigned long)(pmb->context1)); |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 2797 | pmb->context1 = NULL; |
| 2798 | pmb->context2 = NULL; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 2799 | |
| 2800 | if (mb->mbxStatus) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2801 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 2802 | return; |
| 2803 | } |
| 2804 | |
| 2805 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2806 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2807 | elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, lpfc_max_els_tries, ndlp, |
| 2808 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2809 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2810 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 2811 | return; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 2812 | |
| 2813 | icmd = &elsiocb->iocb; |
| 2814 | icmd->ulpContext = xri; |
| 2815 | |
| 2816 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2817 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 2818 | pcmd += sizeof (uint32_t); /* Skip past command */ |
| 2819 | rps_rsp = (RPS_RSP *)pcmd; |
| 2820 | |
| 2821 | if (phba->fc_topology != TOPOLOGY_LOOP) |
| 2822 | status = 0x10; |
| 2823 | else |
| 2824 | status = 0x8; |
| 2825 | if (phba->fc_flag & FC_FABRIC) |
| 2826 | status |= 0x4; |
| 2827 | |
| 2828 | rps_rsp->rsvd1 = 0; |
| 2829 | rps_rsp->portStatus = be16_to_cpu(status); |
| 2830 | rps_rsp->linkFailureCnt = be32_to_cpu(mb->un.varRdLnk.linkFailureCnt); |
| 2831 | rps_rsp->lossSyncCnt = be32_to_cpu(mb->un.varRdLnk.lossSyncCnt); |
| 2832 | rps_rsp->lossSignalCnt = be32_to_cpu(mb->un.varRdLnk.lossSignalCnt); |
| 2833 | rps_rsp->primSeqErrCnt = be32_to_cpu(mb->un.varRdLnk.primSeqErrCnt); |
| 2834 | rps_rsp->invalidXmitWord = be32_to_cpu(mb->un.varRdLnk.invalidXmitWord); |
| 2835 | rps_rsp->crcCnt = be32_to_cpu(mb->un.varRdLnk.crcCnt); |
| 2836 | |
| 2837 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ |
| 2838 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 2839 | "%d:0118 Xmit ELS RPS ACC response tag x%x xri x%x, " |
| 2840 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 2841 | phba->brd_no, elsiocb->iotag, |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 2842 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 2843 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
| 2844 | |
| 2845 | elsiocb->iocb_cmpl = lpfc_cmpl_els_acc; |
| 2846 | phba->fc_stat.elsXmitACC++; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame^] | 2847 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 2848 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
| 2849 | lpfc_els_free_iocb(phba, elsiocb); |
| 2850 | } |
| 2851 | return; |
| 2852 | } |
| 2853 | |
| 2854 | static int |
| 2855 | lpfc_els_rcv_rps(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb, |
| 2856 | struct lpfc_nodelist * ndlp) |
| 2857 | { |
| 2858 | uint32_t *lp; |
| 2859 | uint8_t flag; |
| 2860 | LPFC_MBOXQ_t *mbox; |
| 2861 | struct lpfc_dmabuf *pcmd; |
| 2862 | RPS *rps; |
| 2863 | struct ls_rjt stat; |
| 2864 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2865 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 2866 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 2867 | stat.un.b.lsRjtRsvd0 = 0; |
| 2868 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 2869 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 2870 | stat.un.b.vendorUnique = 0; |
| 2871 | lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp); |
| 2872 | } |
| 2873 | |
| 2874 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 2875 | lp = (uint32_t *) pcmd->virt; |
| 2876 | flag = (be32_to_cpu(*lp++) & 0xf); |
| 2877 | rps = (RPS *) lp; |
| 2878 | |
| 2879 | if ((flag == 0) || |
| 2880 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || |
| 2881 | ((flag == 2) && (memcmp(&rps->un.portName, &phba->fc_portname, |
| 2882 | sizeof (struct lpfc_name)) == 0))) { |
| 2883 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC))) { |
| 2884 | lpfc_read_lnk_stat(phba, mbox); |
| 2885 | mbox->context1 = |
| 2886 | (void *)((unsigned long)cmdiocb->iocb.ulpContext); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2887 | mbox->context2 = lpfc_nlp_get(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 2888 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; |
| 2889 | if (lpfc_sli_issue_mbox (phba, mbox, |
| 2890 | (MBX_NOWAIT | MBX_STOP_IOCB)) != MBX_NOT_FINISHED) { |
| 2891 | /* Mbox completion will send ELS Response */ |
| 2892 | return 0; |
| 2893 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2894 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 2895 | mempool_free(mbox, phba->mbox_mem_pool); |
| 2896 | } |
| 2897 | } |
| 2898 | stat.un.b.lsRjtRsvd0 = 0; |
| 2899 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 2900 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 2901 | stat.un.b.vendorUnique = 0; |
| 2902 | lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp); |
| 2903 | return 0; |
| 2904 | } |
| 2905 | |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 2906 | static int |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 2907 | lpfc_els_rsp_rpl_acc(struct lpfc_hba * phba, uint16_t cmdsize, |
| 2908 | struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp) |
| 2909 | { |
| 2910 | IOCB_t *icmd; |
| 2911 | IOCB_t *oldcmd; |
| 2912 | RPL_RSP rpl_rsp; |
| 2913 | struct lpfc_iocbq *elsiocb; |
| 2914 | struct lpfc_sli_ring *pring; |
| 2915 | struct lpfc_sli *psli; |
| 2916 | uint8_t *pcmd; |
| 2917 | |
| 2918 | psli = &phba->sli; |
| 2919 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 2920 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2921 | elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry, |
| 2922 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
| 2923 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 2924 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2925 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 2926 | icmd = &elsiocb->iocb; |
| 2927 | oldcmd = &oldiocb->iocb; |
| 2928 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 2929 | |
| 2930 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2931 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
| 2932 | pcmd += sizeof (uint16_t); |
| 2933 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
| 2934 | pcmd += sizeof(uint16_t); |
| 2935 | |
| 2936 | /* Setup the RPL ACC payload */ |
| 2937 | rpl_rsp.listLen = be32_to_cpu(1); |
| 2938 | rpl_rsp.index = 0; |
| 2939 | rpl_rsp.port_num_blk.portNum = 0; |
| 2940 | rpl_rsp.port_num_blk.portID = be32_to_cpu(phba->fc_myDID); |
| 2941 | memcpy(&rpl_rsp.port_num_blk.portName, &phba->fc_portname, |
| 2942 | sizeof(struct lpfc_name)); |
| 2943 | |
| 2944 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
| 2945 | |
| 2946 | |
| 2947 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
| 2948 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 2949 | "%d:0120 Xmit ELS RPL ACC response tag x%x xri x%x, " |
| 2950 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 2951 | phba->brd_no, elsiocb->iotag, |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 2952 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 2953 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
| 2954 | |
| 2955 | elsiocb->iocb_cmpl = lpfc_cmpl_els_acc; |
| 2956 | |
| 2957 | phba->fc_stat.elsXmitACC++; |
| 2958 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
| 2959 | lpfc_els_free_iocb(phba, elsiocb); |
| 2960 | return 1; |
| 2961 | } |
| 2962 | return 0; |
| 2963 | } |
| 2964 | |
| 2965 | static int |
| 2966 | lpfc_els_rcv_rpl(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2967 | struct lpfc_nodelist * ndlp) |
| 2968 | { |
| 2969 | struct lpfc_dmabuf *pcmd; |
| 2970 | uint32_t *lp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 2971 | uint32_t maxsize; |
| 2972 | uint16_t cmdsize; |
| 2973 | RPL *rpl; |
| 2974 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2975 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2976 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 2977 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 2978 | stat.un.b.lsRjtRsvd0 = 0; |
| 2979 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 2980 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 2981 | stat.un.b.vendorUnique = 0; |
| 2982 | lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2983 | } |
| 2984 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 2985 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 2986 | lp = (uint32_t *) pcmd->virt; |
| 2987 | rpl = (RPL *) (lp + 1); |
| 2988 | |
| 2989 | maxsize = be32_to_cpu(rpl->maxsize); |
| 2990 | |
| 2991 | /* We support only one port */ |
| 2992 | if ((rpl->index == 0) && |
| 2993 | ((maxsize == 0) || |
| 2994 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { |
| 2995 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2996 | } else { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 2997 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
| 2998 | } |
| 2999 | lpfc_els_rsp_rpl_acc(phba, cmdsize, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3000 | |
| 3001 | return 0; |
| 3002 | } |
| 3003 | |
| 3004 | static int |
| 3005 | lpfc_els_rcv_farp(struct lpfc_hba * phba, |
| 3006 | struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp) |
| 3007 | { |
| 3008 | struct lpfc_dmabuf *pcmd; |
| 3009 | uint32_t *lp; |
| 3010 | IOCB_t *icmd; |
| 3011 | FARP *fp; |
| 3012 | uint32_t cmd, cnt, did; |
| 3013 | |
| 3014 | icmd = &cmdiocb->iocb; |
| 3015 | did = icmd->un.elsreq64.remoteID; |
| 3016 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 3017 | lp = (uint32_t *) pcmd->virt; |
| 3018 | |
| 3019 | cmd = *lp++; |
| 3020 | fp = (FARP *) lp; |
| 3021 | |
| 3022 | /* FARP-REQ received from DID <did> */ |
| 3023 | lpfc_printf_log(phba, |
| 3024 | KERN_INFO, |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3025 | LOG_ELS, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3026 | "%d:0601 FARP-REQ received from DID x%x\n", |
| 3027 | phba->brd_no, did); |
| 3028 | |
| 3029 | /* We will only support match on WWPN or WWNN */ |
| 3030 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3031 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3032 | } |
| 3033 | |
| 3034 | cnt = 0; |
| 3035 | /* If this FARP command is searching for my portname */ |
| 3036 | if (fp->Mflags & FARP_MATCH_PORT) { |
| 3037 | if (memcmp(&fp->RportName, &phba->fc_portname, |
| 3038 | sizeof (struct lpfc_name)) == 0) |
| 3039 | cnt = 1; |
| 3040 | } |
| 3041 | |
| 3042 | /* If this FARP command is searching for my nodename */ |
| 3043 | if (fp->Mflags & FARP_MATCH_NODE) { |
| 3044 | if (memcmp(&fp->RnodeName, &phba->fc_nodename, |
| 3045 | sizeof (struct lpfc_name)) == 0) |
| 3046 | cnt = 1; |
| 3047 | } |
| 3048 | |
| 3049 | if (cnt) { |
| 3050 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 3051 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { |
| 3052 | /* Log back into the node before sending the FARP. */ |
| 3053 | if (fp->Rflags & FARP_REQUEST_PLOGI) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3054 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3055 | lpfc_nlp_set_state(phba, ndlp, |
| 3056 | NLP_STE_PLOGI_ISSUE); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3057 | lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3058 | } |
| 3059 | |
| 3060 | /* Send a FARP response to that node */ |
| 3061 | if (fp->Rflags & FARP_REQUEST_FARPR) { |
| 3062 | lpfc_issue_els_farpr(phba, did, 0); |
| 3063 | } |
| 3064 | } |
| 3065 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3066 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3067 | } |
| 3068 | |
| 3069 | static int |
| 3070 | lpfc_els_rcv_farpr(struct lpfc_hba * phba, |
| 3071 | struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp) |
| 3072 | { |
| 3073 | struct lpfc_dmabuf *pcmd; |
| 3074 | uint32_t *lp; |
| 3075 | IOCB_t *icmd; |
| 3076 | uint32_t cmd, did; |
| 3077 | |
| 3078 | icmd = &cmdiocb->iocb; |
| 3079 | did = icmd->un.elsreq64.remoteID; |
| 3080 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 3081 | lp = (uint32_t *) pcmd->virt; |
| 3082 | |
| 3083 | cmd = *lp++; |
| 3084 | /* FARP-RSP received from DID <did> */ |
| 3085 | lpfc_printf_log(phba, |
| 3086 | KERN_INFO, |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3087 | LOG_ELS, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3088 | "%d:0600 FARP-RSP received from DID x%x\n", |
| 3089 | phba->brd_no, did); |
| 3090 | |
| 3091 | /* ACCEPT the Farp resp request */ |
| 3092 | lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0); |
| 3093 | |
| 3094 | return 0; |
| 3095 | } |
| 3096 | |
| 3097 | static int |
| 3098 | lpfc_els_rcv_fan(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb, |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3099 | struct lpfc_nodelist * fan_ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3100 | { |
| 3101 | struct lpfc_dmabuf *pcmd; |
| 3102 | uint32_t *lp; |
| 3103 | IOCB_t *icmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3104 | uint32_t cmd, did; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3105 | FAN *fp; |
| 3106 | struct lpfc_nodelist *ndlp, *next_ndlp; |
| 3107 | |
| 3108 | /* FAN received */ |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3109 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, "%d:0265 FAN received\n", |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3110 | phba->brd_no); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3111 | |
| 3112 | icmd = &cmdiocb->iocb; |
| 3113 | did = icmd->un.elsreq64.remoteID; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3114 | pcmd = (struct lpfc_dmabuf *)cmdiocb->context2; |
| 3115 | lp = (uint32_t *)pcmd->virt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3116 | |
| 3117 | cmd = *lp++; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3118 | fp = (FAN *)lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3119 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3120 | /* FAN received; Fan does not have a reply sequence */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3121 | |
| 3122 | if (phba->hba_state == LPFC_LOCAL_CFG_LINK) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3123 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
| 3124 | sizeof(struct lpfc_name)) != 0) || |
| 3125 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
| 3126 | sizeof(struct lpfc_name)) != 0)) { |
| 3127 | /* |
| 3128 | * This node has switched fabrics. FLOGI is required |
| 3129 | * Clean up the old rpi's |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3130 | */ |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3131 | |
| 3132 | list_for_each_entry_safe(ndlp, next_ndlp, |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame^] | 3133 | &phba->fc_nodes, nlp_listp) { |
| 3134 | if (ndlp->nlp_state != NLP_STE_NPR_NODE) |
| 3135 | continue; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3136 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 3137 | /* |
| 3138 | * Clean up old Fabric, Nameserver and |
| 3139 | * other NLP_FABRIC logins |
| 3140 | */ |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3141 | lpfc_drop_node(phba, ndlp); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3142 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3143 | /* Fail outstanding I/O now since this |
| 3144 | * device is marked for PLOGI |
| 3145 | */ |
| 3146 | lpfc_unreg_rpi(phba, ndlp); |
| 3147 | } |
| 3148 | } |
| 3149 | |
| 3150 | phba->hba_state = LPFC_FLOGI; |
| 3151 | lpfc_set_disctmo(phba); |
| 3152 | lpfc_initial_flogi(phba); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3153 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3154 | } |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3155 | /* Discovery not needed, |
| 3156 | * move the nodes to their original state. |
| 3157 | */ |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame^] | 3158 | list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nodes, |
| 3159 | nlp_listp) { |
| 3160 | if (ndlp->nlp_state != NLP_STE_NPR_NODE) |
| 3161 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3162 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3163 | switch (ndlp->nlp_prev_state) { |
| 3164 | case NLP_STE_UNMAPPED_NODE: |
| 3165 | ndlp->nlp_prev_state = NLP_STE_NPR_NODE; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3166 | lpfc_nlp_set_state(phba, ndlp, |
| 3167 | NLP_STE_UNMAPPED_NODE); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3168 | break; |
| 3169 | |
| 3170 | case NLP_STE_MAPPED_NODE: |
| 3171 | ndlp->nlp_prev_state = NLP_STE_NPR_NODE; |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3172 | lpfc_nlp_set_state(phba, ndlp, |
| 3173 | NLP_STE_MAPPED_NODE); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3174 | break; |
| 3175 | |
| 3176 | default: |
| 3177 | break; |
| 3178 | } |
| 3179 | } |
| 3180 | |
| 3181 | /* Start discovery - this should just do CLEAR_LA */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3182 | lpfc_disc_start(phba); |
| 3183 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3184 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3185 | } |
| 3186 | |
| 3187 | void |
| 3188 | lpfc_els_timeout(unsigned long ptr) |
| 3189 | { |
| 3190 | struct lpfc_hba *phba; |
| 3191 | unsigned long iflag; |
| 3192 | |
| 3193 | phba = (struct lpfc_hba *)ptr; |
| 3194 | if (phba == 0) |
| 3195 | return; |
| 3196 | spin_lock_irqsave(phba->host->host_lock, iflag); |
| 3197 | if (!(phba->work_hba_events & WORKER_ELS_TMO)) { |
| 3198 | phba->work_hba_events |= WORKER_ELS_TMO; |
| 3199 | if (phba->work_wait) |
| 3200 | wake_up(phba->work_wait); |
| 3201 | } |
| 3202 | spin_unlock_irqrestore(phba->host->host_lock, iflag); |
| 3203 | return; |
| 3204 | } |
| 3205 | |
| 3206 | void |
| 3207 | lpfc_els_timeout_handler(struct lpfc_hba *phba) |
| 3208 | { |
| 3209 | struct lpfc_sli_ring *pring; |
| 3210 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 3211 | IOCB_t *cmd = NULL; |
| 3212 | struct lpfc_dmabuf *pcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3213 | uint32_t *elscmd; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3214 | uint32_t els_command=0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3215 | uint32_t timeout; |
| 3216 | uint32_t remote_ID; |
| 3217 | |
| 3218 | if (phba == 0) |
| 3219 | return; |
| 3220 | spin_lock_irq(phba->host->host_lock); |
| 3221 | /* If the timer is already canceled do nothing */ |
| 3222 | if (!(phba->work_hba_events & WORKER_ELS_TMO)) { |
| 3223 | spin_unlock_irq(phba->host->host_lock); |
| 3224 | return; |
| 3225 | } |
| 3226 | timeout = (uint32_t)(phba->fc_ratov << 1); |
| 3227 | |
| 3228 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3229 | |
| 3230 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 3231 | cmd = &piocb->iocb; |
| 3232 | |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3233 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) || |
| 3234 | (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN) || |
| 3235 | (piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3236 | continue; |
| 3237 | } |
| 3238 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3239 | if (pcmd) { |
| 3240 | elscmd = (uint32_t *) (pcmd->virt); |
| 3241 | els_command = *elscmd; |
| 3242 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3243 | |
| 3244 | if ((els_command == ELS_CMD_FARP) |
| 3245 | || (els_command == ELS_CMD_FARPR)) { |
| 3246 | continue; |
| 3247 | } |
| 3248 | |
| 3249 | if (piocb->drvrTimeout > 0) { |
| 3250 | if (piocb->drvrTimeout >= timeout) { |
| 3251 | piocb->drvrTimeout -= timeout; |
| 3252 | } else { |
| 3253 | piocb->drvrTimeout = 0; |
| 3254 | } |
| 3255 | continue; |
| 3256 | } |
| 3257 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3258 | if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR) { |
| 3259 | struct lpfc_nodelist *ndlp; |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3260 | ndlp = __lpfc_findnode_rpi(phba, cmd->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3261 | remote_ID = ndlp->nlp_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3262 | } else { |
| 3263 | remote_ID = cmd->un.elsreq64.remoteID; |
| 3264 | } |
| 3265 | |
| 3266 | lpfc_printf_log(phba, |
| 3267 | KERN_ERR, |
| 3268 | LOG_ELS, |
| 3269 | "%d:0127 ELS timeout Data: x%x x%x x%x x%x\n", |
| 3270 | phba->brd_no, els_command, |
| 3271 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); |
| 3272 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3273 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3274 | } |
James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 3275 | if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) |
| 3276 | mod_timer(&phba->els_tmofunc, jiffies + HZ * timeout); |
| 3277 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3278 | spin_unlock_irq(phba->host->host_lock); |
| 3279 | } |
| 3280 | |
| 3281 | void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3282 | lpfc_els_flush_cmd(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3283 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3284 | LIST_HEAD(completions); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3285 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3286 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 3287 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3288 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3289 | spin_lock_irq(phba->host->host_lock); |
| 3290 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 3291 | cmd = &piocb->iocb; |
| 3292 | |
| 3293 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 3294 | continue; |
| 3295 | } |
| 3296 | |
| 3297 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3298 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 3299 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 3300 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 3301 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3302 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3303 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3304 | list_move_tail(&piocb->list, &completions); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3305 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3306 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3307 | } |
| 3308 | |
| 3309 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 3310 | cmd = &piocb->iocb; |
| 3311 | |
| 3312 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 3313 | continue; |
| 3314 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3315 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3316 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3317 | } |
| 3318 | spin_unlock_irq(phba->host->host_lock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3319 | |
| 3320 | while(!list_empty(&completions)) { |
| 3321 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| 3322 | cmd = &piocb->iocb; |
| 3323 | list_del(&piocb->list); |
| 3324 | |
| 3325 | if (piocb->iocb_cmpl) { |
| 3326 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 3327 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 3328 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 3329 | } else |
| 3330 | lpfc_sli_release_iocbq(phba, piocb); |
| 3331 | } |
| 3332 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3333 | return; |
| 3334 | } |
| 3335 | |
| 3336 | void |
| 3337 | lpfc_els_unsol_event(struct lpfc_hba * phba, |
| 3338 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * elsiocb) |
| 3339 | { |
| 3340 | struct lpfc_sli *psli; |
| 3341 | struct lpfc_nodelist *ndlp; |
| 3342 | struct lpfc_dmabuf *mp; |
| 3343 | uint32_t *lp; |
| 3344 | IOCB_t *icmd; |
| 3345 | struct ls_rjt stat; |
| 3346 | uint32_t cmd; |
| 3347 | uint32_t did; |
| 3348 | uint32_t newnode; |
| 3349 | uint32_t drop_cmd = 0; /* by default do NOT drop received cmd */ |
| 3350 | uint32_t rjt_err = 0; |
| 3351 | |
| 3352 | psli = &phba->sli; |
| 3353 | icmd = &elsiocb->iocb; |
| 3354 | |
| 3355 | if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) && |
| 3356 | ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) { |
| 3357 | /* Not enough posted buffers; Try posting more buffers */ |
| 3358 | phba->fc_stat.NoRcvBuf++; |
| 3359 | lpfc_post_buffer(phba, pring, 0, 1); |
| 3360 | return; |
| 3361 | } |
| 3362 | |
| 3363 | /* If there are no BDEs associated with this IOCB, |
| 3364 | * there is nothing to do. |
| 3365 | */ |
| 3366 | if (icmd->ulpBdeCount == 0) |
| 3367 | return; |
| 3368 | |
| 3369 | /* type of ELS cmd is first 32bit word in packet */ |
| 3370 | mp = lpfc_sli_ringpostbuf_get(phba, pring, getPaddr(icmd->un. |
| 3371 | cont64[0]. |
| 3372 | addrHigh, |
| 3373 | icmd->un. |
| 3374 | cont64[0].addrLow)); |
| 3375 | if (mp == 0) { |
| 3376 | drop_cmd = 1; |
| 3377 | goto dropit; |
| 3378 | } |
| 3379 | |
| 3380 | newnode = 0; |
| 3381 | lp = (uint32_t *) mp->virt; |
| 3382 | cmd = *lp++; |
| 3383 | lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], 1, 1); |
| 3384 | |
| 3385 | if (icmd->ulpStatus) { |
| 3386 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3387 | kfree(mp); |
| 3388 | drop_cmd = 1; |
| 3389 | goto dropit; |
| 3390 | } |
| 3391 | |
| 3392 | /* Check to see if link went down during discovery */ |
| 3393 | if (lpfc_els_chk_latt(phba)) { |
| 3394 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3395 | kfree(mp); |
| 3396 | drop_cmd = 1; |
| 3397 | goto dropit; |
| 3398 | } |
| 3399 | |
| 3400 | did = icmd->un.rcvels.remoteID; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame^] | 3401 | ndlp = lpfc_findnode_did(phba, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3402 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3403 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3404 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 3405 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3406 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3407 | kfree(mp); |
| 3408 | drop_cmd = 1; |
| 3409 | goto dropit; |
| 3410 | } |
| 3411 | |
| 3412 | lpfc_nlp_init(phba, ndlp, did); |
| 3413 | newnode = 1; |
| 3414 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) { |
| 3415 | ndlp->nlp_type |= NLP_FABRIC; |
| 3416 | } |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3417 | lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNUSED_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3418 | } |
| 3419 | |
| 3420 | phba->fc_stat.elsRcvFrame++; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3421 | if (elsiocb->context1) |
| 3422 | lpfc_nlp_put(elsiocb->context1); |
| 3423 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3424 | elsiocb->context2 = mp; |
| 3425 | |
| 3426 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { |
| 3427 | cmd &= ELS_CMD_MASK; |
| 3428 | } |
| 3429 | /* ELS command <elsCmd> received from NPORT <did> */ |
| 3430 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 3431 | "%d:0112 ELS command x%x received from NPORT x%x " |
| 3432 | "Data: x%x\n", phba->brd_no, cmd, did, phba->hba_state); |
| 3433 | |
| 3434 | switch (cmd) { |
| 3435 | case ELS_CMD_PLOGI: |
| 3436 | phba->fc_stat.elsRcvPLOGI++; |
| 3437 | if (phba->hba_state < LPFC_DISC_AUTH) { |
James.Smart@Emulex.Com | 1f679ca | 2005-06-25 10:34:27 -0400 | [diff] [blame] | 3438 | rjt_err = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3439 | break; |
| 3440 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 3441 | ndlp = lpfc_plogi_confirm_nport(phba, mp, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3442 | lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PLOGI); |
| 3443 | break; |
| 3444 | case ELS_CMD_FLOGI: |
| 3445 | phba->fc_stat.elsRcvFLOGI++; |
| 3446 | lpfc_els_rcv_flogi(phba, elsiocb, ndlp, newnode); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3447 | if (newnode) |
| 3448 | lpfc_drop_node(phba, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3449 | break; |
| 3450 | case ELS_CMD_LOGO: |
| 3451 | phba->fc_stat.elsRcvLOGO++; |
| 3452 | if (phba->hba_state < LPFC_DISC_AUTH) { |
James.Smart@Emulex.Com | 1f679ca | 2005-06-25 10:34:27 -0400 | [diff] [blame] | 3453 | rjt_err = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3454 | break; |
| 3455 | } |
| 3456 | lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
| 3457 | break; |
| 3458 | case ELS_CMD_PRLO: |
| 3459 | phba->fc_stat.elsRcvPRLO++; |
| 3460 | if (phba->hba_state < LPFC_DISC_AUTH) { |
James.Smart@Emulex.Com | 1f679ca | 2005-06-25 10:34:27 -0400 | [diff] [blame] | 3461 | rjt_err = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3462 | break; |
| 3463 | } |
| 3464 | lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
| 3465 | break; |
| 3466 | case ELS_CMD_RSCN: |
| 3467 | phba->fc_stat.elsRcvRSCN++; |
| 3468 | lpfc_els_rcv_rscn(phba, elsiocb, ndlp, newnode); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3469 | if (newnode) |
| 3470 | lpfc_drop_node(phba, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3471 | break; |
| 3472 | case ELS_CMD_ADISC: |
| 3473 | phba->fc_stat.elsRcvADISC++; |
| 3474 | if (phba->hba_state < LPFC_DISC_AUTH) { |
James.Smart@Emulex.Com | 1f679ca | 2005-06-25 10:34:27 -0400 | [diff] [blame] | 3475 | rjt_err = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3476 | break; |
| 3477 | } |
| 3478 | lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_ADISC); |
| 3479 | break; |
| 3480 | case ELS_CMD_PDISC: |
| 3481 | phba->fc_stat.elsRcvPDISC++; |
| 3482 | if (phba->hba_state < LPFC_DISC_AUTH) { |
James.Smart@Emulex.Com | 1f679ca | 2005-06-25 10:34:27 -0400 | [diff] [blame] | 3483 | rjt_err = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3484 | break; |
| 3485 | } |
| 3486 | lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PDISC); |
| 3487 | break; |
| 3488 | case ELS_CMD_FARPR: |
| 3489 | phba->fc_stat.elsRcvFARPR++; |
| 3490 | lpfc_els_rcv_farpr(phba, elsiocb, ndlp); |
| 3491 | break; |
| 3492 | case ELS_CMD_FARP: |
| 3493 | phba->fc_stat.elsRcvFARP++; |
| 3494 | lpfc_els_rcv_farp(phba, elsiocb, ndlp); |
| 3495 | break; |
| 3496 | case ELS_CMD_FAN: |
| 3497 | phba->fc_stat.elsRcvFAN++; |
| 3498 | lpfc_els_rcv_fan(phba, elsiocb, ndlp); |
| 3499 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3500 | case ELS_CMD_PRLI: |
| 3501 | phba->fc_stat.elsRcvPRLI++; |
| 3502 | if (phba->hba_state < LPFC_DISC_AUTH) { |
James.Smart@Emulex.Com | 1f679ca | 2005-06-25 10:34:27 -0400 | [diff] [blame] | 3503 | rjt_err = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3504 | break; |
| 3505 | } |
| 3506 | lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
| 3507 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3508 | case ELS_CMD_LIRR: |
| 3509 | phba->fc_stat.elsRcvLIRR++; |
| 3510 | lpfc_els_rcv_lirr(phba, elsiocb, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3511 | if (newnode) |
| 3512 | lpfc_drop_node(phba, ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3513 | break; |
| 3514 | case ELS_CMD_RPS: |
| 3515 | phba->fc_stat.elsRcvRPS++; |
| 3516 | lpfc_els_rcv_rps(phba, elsiocb, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3517 | if (newnode) |
| 3518 | lpfc_drop_node(phba, ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3519 | break; |
| 3520 | case ELS_CMD_RPL: |
| 3521 | phba->fc_stat.elsRcvRPL++; |
| 3522 | lpfc_els_rcv_rpl(phba, elsiocb, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3523 | if (newnode) |
| 3524 | lpfc_drop_node(phba, ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3525 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3526 | case ELS_CMD_RNID: |
| 3527 | phba->fc_stat.elsRcvRNID++; |
| 3528 | lpfc_els_rcv_rnid(phba, elsiocb, ndlp); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3529 | if (newnode) |
| 3530 | lpfc_drop_node(phba, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3531 | break; |
| 3532 | default: |
| 3533 | /* Unsupported ELS command, reject */ |
James.Smart@Emulex.Com | 1f679ca | 2005-06-25 10:34:27 -0400 | [diff] [blame] | 3534 | rjt_err = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3535 | |
| 3536 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ |
| 3537 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, |
| 3538 | "%d:0115 Unknown ELS command x%x received from " |
| 3539 | "NPORT x%x\n", phba->brd_no, cmd, did); |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3540 | if (newnode) |
| 3541 | lpfc_drop_node(phba, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3542 | break; |
| 3543 | } |
| 3544 | |
| 3545 | /* check if need to LS_RJT received ELS cmd */ |
| 3546 | if (rjt_err) { |
| 3547 | stat.un.b.lsRjtRsvd0 = 0; |
| 3548 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
James.Smart@Emulex.Com | 1f679ca | 2005-06-25 10:34:27 -0400 | [diff] [blame] | 3549 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3550 | stat.un.b.vendorUnique = 0; |
| 3551 | lpfc_els_rsp_reject(phba, stat.un.lsRjtError, elsiocb, ndlp); |
| 3552 | } |
| 3553 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3554 | lpfc_nlp_put(elsiocb->context1); |
| 3555 | elsiocb->context1 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3556 | if (elsiocb->context2) { |
| 3557 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 3558 | kfree(mp); |
| 3559 | } |
| 3560 | dropit: |
| 3561 | /* check if need to drop received ELS cmd */ |
| 3562 | if (drop_cmd == 1) { |
| 3563 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, |
| 3564 | "%d:0111 Dropping received ELS cmd " |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3565 | "Data: x%x x%x x%x\n", phba->brd_no, |
| 3566 | icmd->ulpStatus, icmd->un.ulpWord[4], |
| 3567 | icmd->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3568 | phba->fc_stat.elsRcvDrop++; |
| 3569 | } |
| 3570 | return; |
| 3571 | } |