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