| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1 | /******************************************************************* |
| 2 | * This file is part of the Emulex Linux Device Driver for * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 3 | * Fibre Channel Host Bus Adapters. * |
James Smart | 9413aff | 2007-04-25 09:53:35 -0400 | [diff] [blame] | 4 | * Copyright (C) 2004-2007 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" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 38 | #include "lpfc_vport.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 39 | #include "lpfc_debugfs.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 40 | |
| 41 | static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *, |
| 42 | struct lpfc_iocbq *); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 43 | static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *, |
| 44 | struct lpfc_iocbq *); |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 45 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport); |
| 46 | static int lpfc_issue_els_fdisc(struct lpfc_vport *vport, |
| 47 | struct lpfc_nodelist *ndlp, uint8_t retry); |
| 48 | static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba, |
| 49 | struct lpfc_iocbq *iocb); |
| 50 | static void lpfc_register_new_vport(struct lpfc_hba *phba, |
| 51 | struct lpfc_vport *vport, |
| 52 | struct lpfc_nodelist *ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 53 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 54 | static int lpfc_max_els_tries = 3; |
| 55 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 56 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 57 | lpfc_els_chk_latt(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 58 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 59 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 60 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 61 | uint32_t ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 62 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 63 | if (vport->port_state >= LPFC_VPORT_READY || |
| 64 | phba->link_state == LPFC_LINK_DOWN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 65 | return 0; |
| 66 | |
| 67 | /* Read the HBA Host Attention Register */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 68 | ha_copy = readl(phba->HAregaddr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 69 | |
| 70 | if (!(ha_copy & HA_LATT)) |
| 71 | return 0; |
| 72 | |
| 73 | /* Pending Link Event during Discovery */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 74 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 75 | "0237 Pending Link Event during " |
| 76 | "Discovery: State x%x\n", |
| 77 | phba->pport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 78 | |
| 79 | /* CLEAR_LA should re-enable link attention events and |
| 80 | * we should then imediately take a LATT event. The |
| 81 | * LATT processing should call lpfc_linkdown() which |
| 82 | * will cleanup any left over in-progress discovery |
| 83 | * events. |
| 84 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 85 | spin_lock_irq(shost->host_lock); |
| 86 | vport->fc_flag |= FC_ABORT_DISCOVERY; |
| 87 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 88 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 89 | if (phba->link_state != LPFC_CLEAR_LA) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 90 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 91 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 92 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 96 | lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp, |
| 97 | uint16_t cmdSize, uint8_t retry, |
| 98 | struct lpfc_nodelist *ndlp, uint32_t did, |
| 99 | uint32_t elscmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 100 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 101 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 102 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 103 | struct lpfc_dmabuf *pcmd, *prsp, *pbuflist; |
| 104 | struct ulp_bde64 *bpl; |
| 105 | IOCB_t *icmd; |
| 106 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 107 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 108 | if (!lpfc_is_link_up(phba)) |
| 109 | return NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 110 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 111 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 112 | elsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 113 | |
| 114 | if (elsiocb == NULL) |
| 115 | return NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 116 | icmd = &elsiocb->iocb; |
| 117 | |
| 118 | /* fill in BDEs for command */ |
| 119 | /* Allocate buffer for command payload */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 120 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 121 | if (pcmd) |
| 122 | pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys); |
| 123 | if (!pcmd || !pcmd->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 124 | kfree(pcmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 125 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 126 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 127 | return NULL; |
| 128 | } |
| 129 | |
| 130 | INIT_LIST_HEAD(&pcmd->list); |
| 131 | |
| 132 | /* Allocate buffer for response payload */ |
| 133 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 134 | prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 135 | if (prsp) |
| 136 | prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 137 | &prsp->phys); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 138 | if (!prsp || !prsp->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 139 | kfree(prsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 140 | lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); |
| 141 | kfree(pcmd); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 142 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 143 | return NULL; |
| 144 | } |
| 145 | INIT_LIST_HEAD(&prsp->list); |
| 146 | } else { |
| 147 | prsp = NULL; |
| 148 | } |
| 149 | |
| 150 | /* Allocate buffer for Buffer ptr list */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 151 | pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 152 | if (pbuflist) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 153 | pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 154 | &pbuflist->phys); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 155 | if (!pbuflist || !pbuflist->virt) { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 156 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 157 | lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); |
| 158 | lpfc_mbuf_free(phba, prsp->virt, prsp->phys); |
| 159 | kfree(pcmd); |
| 160 | kfree(prsp); |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 161 | kfree(pbuflist); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 162 | return NULL; |
| 163 | } |
| 164 | |
| 165 | INIT_LIST_HEAD(&pbuflist->list); |
| 166 | |
| 167 | icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); |
| 168 | icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys); |
| 169 | icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BDL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 170 | icmd->un.elsreq64.remoteID = did; /* DID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 171 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 172 | icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 173 | icmd->ulpCommand = CMD_ELS_REQUEST64_CR; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 174 | icmd->ulpTimeout = phba->fc_ratov * 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 175 | } else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 176 | icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 177 | icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX; |
| 178 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 179 | icmd->ulpBdeCount = 1; |
| 180 | icmd->ulpLe = 1; |
| 181 | icmd->ulpClass = CLASS3; |
| 182 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 183 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 184 | icmd->un.elsreq64.myID = vport->fc_myDID; |
| 185 | |
| 186 | /* For ELS_REQUEST64_CR, use the VPI by default */ |
| 187 | icmd->ulpContext = vport->vpi; |
| 188 | icmd->ulpCt_h = 0; |
| 189 | icmd->ulpCt_l = 1; |
| 190 | } |
| 191 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 192 | bpl = (struct ulp_bde64 *) pbuflist->virt; |
| 193 | bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys)); |
| 194 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys)); |
| 195 | bpl->tus.f.bdeSize = cmdSize; |
| 196 | bpl->tus.f.bdeFlags = 0; |
| 197 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 198 | |
| 199 | if (expectRsp) { |
| 200 | bpl++; |
| 201 | bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys)); |
| 202 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys)); |
| 203 | bpl->tus.f.bdeSize = FCELSSIZE; |
| 204 | bpl->tus.f.bdeFlags = BUFF_USE_RCV; |
| 205 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 206 | } |
| 207 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 208 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 209 | elsiocb->context2 = pcmd; |
| 210 | elsiocb->context3 = pbuflist; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 211 | elsiocb->retry = retry; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 212 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 213 | elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT; |
| 214 | |
| 215 | if (prsp) { |
| 216 | list_add(&prsp->list, &pcmd->list); |
| 217 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 218 | if (expectRsp) { |
| 219 | /* Xmit ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 220 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 221 | "0116 Xmit ELS command x%x to remote " |
| 222 | "NPORT x%x I/O tag: x%x, port state: x%x\n", |
| 223 | elscmd, did, elsiocb->iotag, |
| 224 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 225 | } else { |
| 226 | /* Xmit ELS response <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 227 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 228 | "0117 Xmit ELS response x%x to remote " |
| 229 | "NPORT x%x I/O tag: x%x, size: x%x\n", |
| 230 | elscmd, ndlp->nlp_DID, elsiocb->iotag, |
| 231 | cmdSize); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 232 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 233 | return elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | |
| 237 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 238 | lpfc_issue_fabric_reglogin(struct lpfc_vport *vport) |
| 239 | { |
| 240 | struct lpfc_hba *phba = vport->phba; |
| 241 | LPFC_MBOXQ_t *mbox; |
| 242 | struct lpfc_dmabuf *mp; |
| 243 | struct lpfc_nodelist *ndlp; |
| 244 | struct serv_parm *sp; |
| 245 | int rc; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 246 | int err = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 247 | |
| 248 | sp = &phba->fc_fabparam; |
| 249 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 250 | if (!ndlp) { |
| 251 | err = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 252 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 253 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 254 | |
| 255 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 256 | if (!mbox) { |
| 257 | err = 2; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 258 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 259 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 260 | |
| 261 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 262 | lpfc_config_link(phba, mbox); |
| 263 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 264 | mbox->vport = vport; |
| 265 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 266 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 267 | if (rc == MBX_NOT_FINISHED) { |
| 268 | err = 3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 269 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 270 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 271 | |
| 272 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 273 | if (!mbox) { |
| 274 | err = 4; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 275 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 276 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 277 | rc = lpfc_reg_login(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, |
| 278 | 0); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 279 | if (rc) { |
| 280 | err = 5; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 281 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 282 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 283 | |
| 284 | mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login; |
| 285 | mbox->vport = vport; |
| 286 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 287 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 288 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 289 | if (rc == MBX_NOT_FINISHED) { |
| 290 | err = 6; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 291 | goto fail_issue_reg_login; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 292 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 293 | |
| 294 | return 0; |
| 295 | |
| 296 | fail_issue_reg_login: |
| 297 | lpfc_nlp_put(ndlp); |
| 298 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 299 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 300 | kfree(mp); |
| 301 | fail_free_mbox: |
| 302 | mempool_free(mbox, phba->mbox_mem_pool); |
| 303 | |
| 304 | fail: |
| 305 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 306 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 307 | "0249 Cannot issue Register Fabric login: Err %d\n", err); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 308 | return -ENXIO; |
| 309 | } |
| 310 | |
| 311 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 312 | lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 313 | struct serv_parm *sp, IOCB_t *irsp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 314 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 315 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 316 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 317 | struct lpfc_nodelist *np; |
| 318 | struct lpfc_nodelist *next_np; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 319 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 320 | spin_lock_irq(shost->host_lock); |
| 321 | vport->fc_flag |= FC_FABRIC; |
| 322 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 323 | |
| 324 | phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov); |
| 325 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ |
| 326 | phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000; |
| 327 | |
| 328 | phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; |
| 329 | |
| 330 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 331 | spin_lock_irq(shost->host_lock); |
| 332 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 333 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 334 | } else { |
| 335 | /* |
| 336 | * If we are a N-port connected to a Fabric, fixup sparam's so |
| 337 | * logins to devices on remote loops work. |
| 338 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 339 | vport->fc_sparam.cmn.altBbCredit = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 340 | } |
| 341 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 342 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 343 | memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 344 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 345 | ndlp->nlp_class_sup = 0; |
| 346 | if (sp->cls1.classValid) |
| 347 | ndlp->nlp_class_sup |= FC_COS_CLASS1; |
| 348 | if (sp->cls2.classValid) |
| 349 | ndlp->nlp_class_sup |= FC_COS_CLASS2; |
| 350 | if (sp->cls3.classValid) |
| 351 | ndlp->nlp_class_sup |= FC_COS_CLASS3; |
| 352 | if (sp->cls4.classValid) |
| 353 | ndlp->nlp_class_sup |= FC_COS_CLASS4; |
| 354 | ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 355 | sp->cmn.bbRcvSizeLsb; |
| 356 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
| 357 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 358 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 359 | if (sp->cmn.response_multiple_NPort) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 360 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 361 | LOG_ELS | LOG_VPORT, |
| 362 | "1816 FLOGI NPIV supported, " |
| 363 | "response data 0x%x\n", |
| 364 | sp->cmn.response_multiple_NPort); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 365 | phba->link_flag |= LS_NPIV_FAB_SUPPORTED; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 366 | } else { |
| 367 | /* Because we asked f/w for NPIV it still expects us |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 368 | to call reg_vnpid atleast for the physcial host */ |
| 369 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 370 | LOG_ELS | LOG_VPORT, |
| 371 | "1817 Fabric does not support NPIV " |
| 372 | "- configuring single port mode.\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 373 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 378 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 379 | |
| 380 | /* If our NportID changed, we need to ensure all |
| 381 | * remaining NPORTs get unreg_login'ed. |
| 382 | */ |
| 383 | list_for_each_entry_safe(np, next_np, |
| 384 | &vport->fc_nodes, nlp_listp) { |
| 385 | if ((np->nlp_state != NLP_STE_NPR_NODE) || |
| 386 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 387 | continue; |
| 388 | spin_lock_irq(shost->host_lock); |
| 389 | np->nlp_flag &= ~NLP_NPR_ADISC; |
| 390 | spin_unlock_irq(shost->host_lock); |
| 391 | lpfc_unreg_rpi(vport, np); |
| 392 | } |
| 393 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 394 | lpfc_mbx_unreg_vpi(vport); |
| 395 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 396 | } |
| 397 | } |
| 398 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 399 | ndlp->nlp_sid = irsp->un.ulpWord[4] & Mask_DID; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 400 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 401 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 402 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED && |
| 403 | vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) { |
| 404 | lpfc_register_new_vport(phba, vport, ndlp); |
| 405 | return 0; |
| 406 | } |
| 407 | lpfc_issue_fabric_reglogin(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 408 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | /* |
| 412 | * We FLOGIed into an NPort, initiate pt2pt protocol |
| 413 | */ |
| 414 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 415 | lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 416 | struct serv_parm *sp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 417 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 418 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 419 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 420 | LPFC_MBOXQ_t *mbox; |
| 421 | int rc; |
| 422 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 423 | spin_lock_irq(shost->host_lock); |
| 424 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 425 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 426 | |
| 427 | phba->fc_edtov = FF_DEF_EDTOV; |
| 428 | phba->fc_ratov = FF_DEF_RATOV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 429 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 430 | sizeof(vport->fc_portname)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 431 | if (rc >= 0) { |
| 432 | /* This side will initiate the PLOGI */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 433 | spin_lock_irq(shost->host_lock); |
| 434 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 435 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 436 | |
| 437 | /* |
| 438 | * N_Port ID cannot be 0, set our to LocalID the other |
| 439 | * side will be RemoteID. |
| 440 | */ |
| 441 | |
| 442 | /* not equal */ |
| 443 | if (rc) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 444 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 445 | |
| 446 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 447 | if (!mbox) |
| 448 | goto fail; |
| 449 | |
| 450 | lpfc_config_link(phba, mbox); |
| 451 | |
| 452 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 453 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 454 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 455 | if (rc == MBX_NOT_FINISHED) { |
| 456 | mempool_free(mbox, phba->mbox_mem_pool); |
| 457 | goto fail; |
| 458 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 459 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 460 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 461 | ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 462 | if (!ndlp) { |
| 463 | /* |
| 464 | * Cannot find existing Fabric ndlp, so allocate a |
| 465 | * new one |
| 466 | */ |
| 467 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 468 | if (!ndlp) |
| 469 | goto fail; |
| 470 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 471 | lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | memcpy(&ndlp->nlp_portname, &sp->portName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 475 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 476 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 477 | sizeof(struct lpfc_name)); |
| 478 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 479 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 480 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 481 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 482 | } else { |
| 483 | /* This side will wait for the PLOGI */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 484 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 485 | } |
| 486 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 487 | spin_lock_irq(shost->host_lock); |
| 488 | vport->fc_flag |= FC_PT2PT; |
| 489 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 490 | |
| 491 | /* Start discovery - this should just do CLEAR_LA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 492 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 493 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 494 | fail: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 495 | return -ENXIO; |
| 496 | } |
| 497 | |
| 498 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 499 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 500 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 501 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 502 | struct lpfc_vport *vport = cmdiocb->vport; |
| 503 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 504 | IOCB_t *irsp = &rspiocb->iocb; |
| 505 | struct lpfc_nodelist *ndlp = cmdiocb->context1; |
| 506 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 507 | struct serv_parm *sp; |
| 508 | int rc; |
| 509 | |
| 510 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 511 | if (lpfc_els_chk_latt(vport)) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 512 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 513 | goto out; |
| 514 | } |
| 515 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 516 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 517 | "FLOGI cmpl: status:x%x/x%x state:x%x", |
| 518 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 519 | vport->port_state); |
| 520 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 521 | if (irsp->ulpStatus) { |
| 522 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 523 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 524 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 525 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 526 | /* FLOGI failed, so there is no fabric */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 527 | spin_lock_irq(shost->host_lock); |
| 528 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 529 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 530 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 531 | /* If private loop, then allow max outstanding els to be |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 532 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no |
| 533 | * alpa map would take too long otherwise. |
| 534 | */ |
| 535 | if (phba->alpa_map[0] == 0) { |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 536 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | /* FLOGI failure */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 540 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 541 | "0100 FLOGI failure Data: x%x x%x " |
| 542 | "x%x\n", |
| 543 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 544 | irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 545 | goto flogifail; |
| 546 | } |
| 547 | |
| 548 | /* |
| 549 | * The FLogI succeeded. Sync the data for the CPU before |
| 550 | * accessing it. |
| 551 | */ |
| 552 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
| 553 | |
| 554 | sp = prsp->virt + sizeof(uint32_t); |
| 555 | |
| 556 | /* FLOGI completes successfully */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 557 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 558 | "0101 FLOGI completes sucessfully " |
| 559 | "Data: x%x x%x x%x x%x\n", |
| 560 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, |
| 561 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 562 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 563 | if (vport->port_state == LPFC_FLOGI) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 564 | /* |
| 565 | * If Common Service Parameters indicate Nport |
| 566 | * we are point to point, if Fport we are Fabric. |
| 567 | */ |
| 568 | if (sp->cmn.fPort) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 569 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 570 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 571 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 572 | |
| 573 | if (!rc) |
| 574 | goto out; |
| 575 | } |
| 576 | |
| 577 | flogifail: |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 578 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 579 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 580 | if (!lpfc_error_lost_link(irsp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 581 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 582 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 583 | |
| 584 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 585 | lpfc_disc_start(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 586 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 587 | ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) && |
| 588 | (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) && |
| 589 | (phba->link_state != LPFC_CLEAR_LA)) { |
| 590 | /* If FLOGI failed enable link interrupt. */ |
| 591 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 592 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 593 | out: |
| 594 | lpfc_els_free_iocb(phba, cmdiocb); |
| 595 | } |
| 596 | |
| 597 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 598 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 599 | uint8_t retry) |
| 600 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 601 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 602 | struct serv_parm *sp; |
| 603 | IOCB_t *icmd; |
| 604 | struct lpfc_iocbq *elsiocb; |
| 605 | struct lpfc_sli_ring *pring; |
| 606 | uint8_t *pcmd; |
| 607 | uint16_t cmdsize; |
| 608 | uint32_t tmo; |
| 609 | int rc; |
| 610 | |
| 611 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 612 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 613 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 614 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 615 | ndlp->nlp_DID, ELS_CMD_FLOGI); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 616 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 617 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 618 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 619 | |
| 620 | icmd = &elsiocb->iocb; |
| 621 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 622 | |
| 623 | /* For FLOGI request, remainder of payload is service parameters */ |
| 624 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 625 | pcmd += sizeof(uint32_t); |
| 626 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 627 | sp = (struct serv_parm *) pcmd; |
| 628 | |
| 629 | /* Setup CSPs accordingly for Fabric */ |
| 630 | sp->cmn.e_d_tov = 0; |
| 631 | sp->cmn.w2.r_a_tov = 0; |
| 632 | sp->cls1.classValid = 0; |
| 633 | sp->cls2.seqDelivery = 1; |
| 634 | sp->cls3.seqDelivery = 1; |
| 635 | if (sp->cmn.fcphLow < FC_PH3) |
| 636 | sp->cmn.fcphLow = FC_PH3; |
| 637 | if (sp->cmn.fcphHigh < FC_PH3) |
| 638 | sp->cmn.fcphHigh = FC_PH3; |
| 639 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 640 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 641 | sp->cmn.request_multiple_Nport = 1; |
| 642 | |
| 643 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ |
| 644 | icmd->ulpCt_h = 1; |
| 645 | icmd->ulpCt_l = 0; |
| 646 | } |
| 647 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 648 | if (phba->fc_topology != TOPOLOGY_LOOP) { |
| 649 | icmd->un.elsreq64.myID = 0; |
| 650 | icmd->un.elsreq64.fl = 1; |
| 651 | } |
| 652 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 653 | tmo = phba->fc_ratov; |
| 654 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 655 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 656 | phba->fc_ratov = tmo; |
| 657 | |
| 658 | phba->fc_stat.elsXmitFLOGI++; |
| 659 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 660 | |
| 661 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 662 | "Issue FLOGI: opt:x%x", |
| 663 | phba->sli3_options, 0, 0); |
| 664 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 665 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 666 | if (rc == IOCB_ERROR) { |
| 667 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 668 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 669 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 670 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 674 | lpfc_els_abort_flogi(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 675 | { |
| 676 | struct lpfc_sli_ring *pring; |
| 677 | struct lpfc_iocbq *iocb, *next_iocb; |
| 678 | struct lpfc_nodelist *ndlp; |
| 679 | IOCB_t *icmd; |
| 680 | |
| 681 | /* Abort outstanding I/O on NPort <nlp_DID> */ |
| 682 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 683 | "0201 Abort outstanding I/O on NPort x%x\n", |
| 684 | Fabric_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 685 | |
| 686 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 687 | |
| 688 | /* |
| 689 | * Check the txcmplq for an iocb that matches the nport the driver is |
| 690 | * searching for. |
| 691 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 692 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 693 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 694 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 695 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR && |
| 696 | icmd->un.elsreq64.bdl.ulpIoTag32) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 697 | ndlp = (struct lpfc_nodelist *)(iocb->context1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 698 | if (ndlp && (ndlp->nlp_DID == Fabric_DID)) { |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 699 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 700 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 701 | } |
| 702 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 703 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 704 | |
| 705 | return 0; |
| 706 | } |
| 707 | |
| 708 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 709 | lpfc_initial_flogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 710 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 711 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 712 | struct lpfc_nodelist *ndlp; |
| 713 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 714 | vport->port_state = LPFC_FLOGI; |
| 715 | lpfc_set_disctmo(vport); |
| 716 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 717 | /* First look for the Fabric ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 718 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 719 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 720 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 721 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 722 | if (!ndlp) |
| 723 | return 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 724 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 725 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 726 | lpfc_dequeue_node(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 727 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 728 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 729 | if (lpfc_issue_els_flogi(vport, ndlp, 0)) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 730 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 731 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 732 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 733 | } |
| 734 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 735 | int |
| 736 | lpfc_initial_fdisc(struct lpfc_vport *vport) |
| 737 | { |
| 738 | struct lpfc_hba *phba = vport->phba; |
| 739 | struct lpfc_nodelist *ndlp; |
| 740 | |
| 741 | /* First look for the Fabric ndlp */ |
| 742 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 743 | if (!ndlp) { |
| 744 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
| 745 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 746 | if (!ndlp) |
| 747 | return 0; |
| 748 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
| 749 | } else { |
| 750 | lpfc_dequeue_node(vport, ndlp); |
| 751 | } |
| 752 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { |
| 753 | lpfc_nlp_put(ndlp); |
| 754 | } |
| 755 | return 1; |
| 756 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 757 | |
| 758 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 759 | lpfc_more_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 760 | { |
| 761 | int sentplogi; |
| 762 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 763 | if (vport->num_disc_nodes) |
| 764 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 765 | |
| 766 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 767 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 768 | "0232 Continue discovery with %d PLOGIs to go " |
| 769 | "Data: x%x x%x x%x\n", |
| 770 | vport->num_disc_nodes, vport->fc_plogi_cnt, |
| 771 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 772 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 773 | if (vport->fc_flag & FC_NLP_MORE) |
| 774 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 775 | sentplogi = lpfc_els_disc_plogi(vport); |
| 776 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 777 | return; |
| 778 | } |
| 779 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 780 | static struct lpfc_nodelist * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 781 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 782 | struct lpfc_nodelist *ndlp) |
| 783 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 784 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 785 | struct lpfc_nodelist *new_ndlp; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame^] | 786 | struct lpfc_rport_data *rdata; |
| 787 | struct fc_rport *rport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 788 | struct serv_parm *sp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 789 | uint8_t name[sizeof(struct lpfc_name)]; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 790 | uint32_t rc; |
| 791 | |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 792 | /* Fabric nodes can have the same WWPN so we don't bother searching |
| 793 | * by WWPN. Just return the ndlp that was given to us. |
| 794 | */ |
| 795 | if (ndlp->nlp_type & NLP_FABRIC) |
| 796 | return ndlp; |
| 797 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 798 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 799 | memset(name, 0, sizeof(struct lpfc_name)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 800 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 801 | /* Now we find out if the NPort we are logging into, matches the WWPN |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 802 | * we have for that ndlp. If not, we have some work to do. |
| 803 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 804 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 805 | |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 806 | if (new_ndlp == ndlp) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 807 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 808 | |
| 809 | if (!new_ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 810 | rc = memcmp(&ndlp->nlp_portname, name, |
| 811 | sizeof(struct lpfc_name)); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 812 | if (!rc) |
| 813 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 814 | new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC); |
| 815 | if (!new_ndlp) |
| 816 | return ndlp; |
| 817 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 818 | lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 819 | } |
| 820 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 821 | lpfc_unreg_rpi(vport, new_ndlp); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 822 | new_ndlp->nlp_DID = ndlp->nlp_DID; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 823 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame^] | 824 | |
| 825 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) |
| 826 | new_ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 827 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
| 828 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 829 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 830 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 831 | /* Move this back to NPR state */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 832 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { |
| 833 | /* The new_ndlp is replacing ndlp totally, so we need |
| 834 | * to put ndlp on UNUSED list and try to free it. |
| 835 | */ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame^] | 836 | |
| 837 | /* Fix up the rport accordingly */ |
| 838 | rport = ndlp->rport; |
| 839 | if (rport) { |
| 840 | rdata = rport->dd_data; |
| 841 | if (rdata->pnode == ndlp) { |
| 842 | lpfc_nlp_put(ndlp); |
| 843 | ndlp->rport = NULL; |
| 844 | rdata->pnode = lpfc_nlp_get(new_ndlp); |
| 845 | new_ndlp->rport = rport; |
| 846 | } |
| 847 | new_ndlp->nlp_type = ndlp->nlp_type; |
| 848 | } |
| 849 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 850 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 851 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 852 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 853 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 854 | ndlp->nlp_DID = 0; /* Two ndlps cannot have the same did */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 855 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 856 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 857 | return new_ndlp; |
| 858 | } |
| 859 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 860 | void |
| 861 | lpfc_end_rscn(struct lpfc_vport *vport) |
| 862 | { |
| 863 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 864 | |
| 865 | if (vport->fc_flag & FC_RSCN_MODE) { |
| 866 | /* |
| 867 | * Check to see if more RSCNs came in while we were |
| 868 | * processing this one. |
| 869 | */ |
| 870 | if (vport->fc_rscn_id_cnt || |
| 871 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) |
| 872 | lpfc_els_handle_rscn(vport); |
| 873 | else { |
| 874 | spin_lock_irq(shost->host_lock); |
| 875 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 876 | spin_unlock_irq(shost->host_lock); |
| 877 | } |
| 878 | } |
| 879 | } |
| 880 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 881 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 882 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 883 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 884 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 885 | struct lpfc_vport *vport = cmdiocb->vport; |
| 886 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 887 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 888 | struct lpfc_nodelist *ndlp; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 889 | struct lpfc_dmabuf *prsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 890 | int disc, rc, did, type; |
| 891 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 892 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 893 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 894 | |
| 895 | irsp = &rspiocb->iocb; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 896 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 897 | "PLOGI cmpl: status:x%x/x%x did:x%x", |
| 898 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 899 | irsp->un.elsreq64.remoteID); |
| 900 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 901 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 902 | if (!ndlp) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 903 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 904 | "0136 PLOGI completes to NPort x%x " |
| 905 | "with no ndlp. Data: x%x x%x x%x\n", |
| 906 | irsp->un.elsreq64.remoteID, |
| 907 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 908 | irsp->ulpIoTag); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 909 | goto out; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 910 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 911 | |
| 912 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 913 | * is being used during discovery. |
| 914 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 915 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 916 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 917 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 918 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 919 | rc = 0; |
| 920 | |
| 921 | /* PLOGI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 922 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 923 | "0102 PLOGI completes to NPort x%x " |
| 924 | "Data: x%x x%x x%x x%x x%x\n", |
| 925 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 926 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 927 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 928 | if (lpfc_els_chk_latt(vport)) { |
| 929 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 930 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 931 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 932 | goto out; |
| 933 | } |
| 934 | |
| 935 | /* ndlp could be freed in DSM, save these values now */ |
| 936 | type = ndlp->nlp_type; |
| 937 | did = ndlp->nlp_DID; |
| 938 | |
| 939 | if (irsp->ulpStatus) { |
| 940 | /* Check for retry */ |
| 941 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 942 | /* ELS command is being retried */ |
| 943 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 944 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 945 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 946 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 947 | } |
| 948 | goto out; |
| 949 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 950 | /* PLOGI failed */ |
| 951 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 952 | if (lpfc_error_lost_link(irsp)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 953 | rc = NLP_STE_FREED_NODE; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 954 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 955 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 956 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 957 | } |
| 958 | } else { |
| 959 | /* Good status, call state machine */ |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 960 | prsp = list_entry(((struct lpfc_dmabuf *) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 961 | cmdiocb->context2)->list.next, |
| 962 | struct lpfc_dmabuf, list); |
| 963 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 964 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 965 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 966 | } |
| 967 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 968 | if (disc && vport->num_disc_nodes) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 969 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 970 | lpfc_more_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 971 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 972 | if (vport->num_disc_nodes == 0) { |
| 973 | spin_lock_irq(shost->host_lock); |
| 974 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 975 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 976 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 977 | lpfc_can_disctmo(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 978 | lpfc_end_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 979 | } |
| 980 | } |
| 981 | |
| 982 | out: |
| 983 | lpfc_els_free_iocb(phba, cmdiocb); |
| 984 | return; |
| 985 | } |
| 986 | |
| 987 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 988 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 989 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 990 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 991 | struct serv_parm *sp; |
| 992 | IOCB_t *icmd; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 993 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 994 | struct lpfc_iocbq *elsiocb; |
| 995 | struct lpfc_sli_ring *pring; |
| 996 | struct lpfc_sli *psli; |
| 997 | uint8_t *pcmd; |
| 998 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 999 | int ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1000 | |
| 1001 | psli = &phba->sli; |
| 1002 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 1003 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1004 | ndlp = lpfc_findnode_did(vport, did); |
| 1005 | /* If ndlp if not NULL, we will bump the reference count on it */ |
| 1006 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1007 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1008 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1009 | ELS_CMD_PLOGI); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1010 | if (!elsiocb) |
| 1011 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1012 | |
| 1013 | icmd = &elsiocb->iocb; |
| 1014 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1015 | |
| 1016 | /* For PLOGI request, remainder of payload is service parameters */ |
| 1017 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1018 | pcmd += sizeof(uint32_t); |
| 1019 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1020 | sp = (struct serv_parm *) pcmd; |
| 1021 | |
| 1022 | if (sp->cmn.fcphLow < FC_PH_4_3) |
| 1023 | sp->cmn.fcphLow = FC_PH_4_3; |
| 1024 | |
| 1025 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1026 | sp->cmn.fcphHigh = FC_PH3; |
| 1027 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1028 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1029 | "Issue PLOGI: did:x%x", |
| 1030 | did, 0, 0); |
| 1031 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1032 | phba->fc_stat.elsXmitPLOGI++; |
| 1033 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1034 | ret = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| 1035 | |
| 1036 | if (ret == IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1037 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1038 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1039 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1040 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1044 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1045 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1046 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1047 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1048 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1049 | IOCB_t *irsp; |
| 1050 | struct lpfc_sli *psli; |
| 1051 | struct lpfc_nodelist *ndlp; |
| 1052 | |
| 1053 | psli = &phba->sli; |
| 1054 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1055 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1056 | |
| 1057 | irsp = &(rspiocb->iocb); |
| 1058 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1059 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1060 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1061 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1062 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1063 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1064 | "PRLI cmpl: status:x%x/x%x did:x%x", |
| 1065 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1066 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1067 | /* PRLI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1068 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1069 | "0103 PRLI completes to NPort x%x " |
| 1070 | "Data: x%x x%x x%x x%x\n", |
| 1071 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1072 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1073 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1074 | vport->fc_prli_sent--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1075 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1076 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1077 | goto out; |
| 1078 | |
| 1079 | if (irsp->ulpStatus) { |
| 1080 | /* Check for retry */ |
| 1081 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1082 | /* ELS command is being retried */ |
| 1083 | goto out; |
| 1084 | } |
| 1085 | /* PRLI failed */ |
| 1086 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1087 | if (lpfc_error_lost_link(irsp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1088 | goto out; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 1089 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1090 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1091 | NLP_EVT_CMPL_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1092 | } |
| 1093 | } else { |
| 1094 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1095 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1096 | NLP_EVT_CMPL_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | out: |
| 1100 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1101 | return; |
| 1102 | } |
| 1103 | |
| 1104 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1105 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1106 | uint8_t retry) |
| 1107 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1108 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1109 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1110 | PRLI *npr; |
| 1111 | IOCB_t *icmd; |
| 1112 | struct lpfc_iocbq *elsiocb; |
| 1113 | struct lpfc_sli_ring *pring; |
| 1114 | struct lpfc_sli *psli; |
| 1115 | uint8_t *pcmd; |
| 1116 | uint16_t cmdsize; |
| 1117 | |
| 1118 | psli = &phba->sli; |
| 1119 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 1120 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1121 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1122 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1123 | ndlp->nlp_DID, ELS_CMD_PRLI); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1124 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1125 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1126 | |
| 1127 | icmd = &elsiocb->iocb; |
| 1128 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1129 | |
| 1130 | /* For PRLI request, remainder of payload is service parameters */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1131 | memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1132 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1133 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1134 | |
| 1135 | /* For PRLI, remainder of payload is PRLI parameter page */ |
| 1136 | npr = (PRLI *) pcmd; |
| 1137 | /* |
| 1138 | * If our firmware version is 3.20 or later, |
| 1139 | * set the following bits for FC-TAPE support. |
| 1140 | */ |
| 1141 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { |
| 1142 | npr->ConfmComplAllowed = 1; |
| 1143 | npr->Retry = 1; |
| 1144 | npr->TaskRetryIdReq = 1; |
| 1145 | } |
| 1146 | npr->estabImagePair = 1; |
| 1147 | npr->readXferRdyDis = 1; |
| 1148 | |
| 1149 | /* For FCP support */ |
| 1150 | npr->prliType = PRLI_FCP_TYPE; |
| 1151 | npr->initiatorFunc = 1; |
| 1152 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1153 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1154 | "Issue PRLI: did:x%x", |
| 1155 | ndlp->nlp_DID, 0, 0); |
| 1156 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1157 | phba->fc_stat.elsXmitPRLI++; |
| 1158 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1159 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1160 | ndlp->nlp_flag |= NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1161 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1162 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1163 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1164 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1165 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1166 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1167 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1168 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1169 | vport->fc_prli_sent++; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1170 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1171 | } |
| 1172 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame^] | 1173 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1174 | lpfc_more_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1175 | { |
| 1176 | int sentadisc; |
| 1177 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1178 | if (vport->num_disc_nodes) |
| 1179 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1180 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1181 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1182 | "0210 Continue discovery with %d ADISCs to go " |
| 1183 | "Data: x%x x%x x%x\n", |
| 1184 | vport->num_disc_nodes, vport->fc_adisc_cnt, |
| 1185 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1186 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1187 | if (vport->fc_flag & FC_NLP_MORE) { |
| 1188 | lpfc_set_disctmo(vport); |
| 1189 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
| 1190 | sentadisc = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1191 | } |
| 1192 | return; |
| 1193 | } |
| 1194 | |
| 1195 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1196 | lpfc_rscn_disc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1197 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1198 | lpfc_can_disctmo(vport); |
| 1199 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1200 | /* RSCN discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1201 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 1202 | if (vport->fc_npr_cnt) |
| 1203 | if (lpfc_els_disc_plogi(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1204 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1205 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1206 | lpfc_end_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1207 | } |
| 1208 | |
| 1209 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1210 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1211 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1212 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1213 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1214 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1215 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1216 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1217 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1218 | |
| 1219 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1220 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1221 | |
| 1222 | irsp = &(rspiocb->iocb); |
| 1223 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1224 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1225 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1226 | "ADISC cmpl: status:x%x/x%x did:x%x", |
| 1227 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1228 | ndlp->nlp_DID); |
| 1229 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1230 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1231 | * is being used during discovery. |
| 1232 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1233 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1234 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1235 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1236 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1237 | /* ADISC completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1238 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1239 | "0104 ADISC completes to NPort x%x " |
| 1240 | "Data: x%x x%x x%x x%x x%x\n", |
| 1241 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1242 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1243 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1244 | if (lpfc_els_chk_latt(vport)) { |
| 1245 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1246 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1247 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1248 | goto out; |
| 1249 | } |
| 1250 | |
| 1251 | if (irsp->ulpStatus) { |
| 1252 | /* Check for retry */ |
| 1253 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1254 | /* ELS command is being retried */ |
| 1255 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1256 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1257 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1258 | spin_unlock_irq(shost->host_lock); |
| 1259 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1260 | } |
| 1261 | goto out; |
| 1262 | } |
| 1263 | /* ADISC failed */ |
| 1264 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1265 | if (!lpfc_error_lost_link(irsp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1266 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1267 | NLP_EVT_CMPL_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1268 | } |
| 1269 | } else { |
| 1270 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1271 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1272 | NLP_EVT_CMPL_ADISC); |
| 1273 | } |
| 1274 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1275 | if (disc && vport->num_disc_nodes) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1276 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1277 | lpfc_more_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1278 | |
| 1279 | /* Check to see if we are done with ADISC authentication */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1280 | if (vport->num_disc_nodes == 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1281 | /* If we get here, there is nothing left to ADISC */ |
| 1282 | /* |
| 1283 | * For NPIV, cmpl_reg_vpi will set port_state to READY, |
| 1284 | * and continue discovery. |
| 1285 | */ |
| 1286 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 1287 | !(vport->fc_flag & FC_RSCN_MODE)) { |
| 1288 | lpfc_issue_reg_vpi(phba, vport); |
| 1289 | goto out; |
| 1290 | } |
| 1291 | /* |
| 1292 | * For SLI2, we need to set port_state to READY |
| 1293 | * and continue discovery. |
| 1294 | */ |
| 1295 | if (vport->port_state < LPFC_VPORT_READY) { |
| 1296 | /* If we get here, there is nothing to ADISC */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1297 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1298 | lpfc_issue_clear_la(phba, vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1299 | |
| 1300 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
| 1301 | vport->num_disc_nodes = 0; |
| 1302 | /* go thru NPR list, issue ELS PLOGIs */ |
| 1303 | if (vport->fc_npr_cnt) |
| 1304 | lpfc_els_disc_plogi(vport); |
| 1305 | |
| 1306 | if (!vport->num_disc_nodes) { |
| 1307 | spin_lock_irq(shost->host_lock); |
| 1308 | vport->fc_flag &= |
| 1309 | ~FC_NDISC_ACTIVE; |
| 1310 | spin_unlock_irq( |
| 1311 | shost->host_lock); |
| 1312 | lpfc_can_disctmo(vport); |
| 1313 | } |
| 1314 | } |
| 1315 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1316 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1317 | lpfc_rscn_disc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1318 | } |
| 1319 | } |
| 1320 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1321 | out: |
| 1322 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1323 | return; |
| 1324 | } |
| 1325 | |
| 1326 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1327 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1328 | uint8_t retry) |
| 1329 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1330 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1331 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1332 | ADISC *ap; |
| 1333 | IOCB_t *icmd; |
| 1334 | struct lpfc_iocbq *elsiocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1335 | struct lpfc_sli *psli = &phba->sli; |
| 1336 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1337 | uint8_t *pcmd; |
| 1338 | uint16_t cmdsize; |
| 1339 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1340 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1341 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1342 | ndlp->nlp_DID, ELS_CMD_ADISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1343 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1344 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1345 | |
| 1346 | icmd = &elsiocb->iocb; |
| 1347 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1348 | |
| 1349 | /* For ADISC request, remainder of payload is service parameters */ |
| 1350 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1351 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1352 | |
| 1353 | /* Fill in ADISC payload */ |
| 1354 | ap = (ADISC *) pcmd; |
| 1355 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1356 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 1357 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1358 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1359 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1360 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1361 | "Issue ADISC: did:x%x", |
| 1362 | ndlp->nlp_DID, 0, 0); |
| 1363 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1364 | phba->fc_stat.elsXmitADISC++; |
| 1365 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1366 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1367 | ndlp->nlp_flag |= NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1368 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1369 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1370 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1371 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1372 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1373 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1374 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1375 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1376 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1377 | } |
| 1378 | |
| 1379 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1380 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1381 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1382 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1383 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 1384 | struct lpfc_vport *vport = ndlp->vport; |
| 1385 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1386 | IOCB_t *irsp; |
| 1387 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1388 | |
| 1389 | psli = &phba->sli; |
| 1390 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1391 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1392 | |
| 1393 | irsp = &(rspiocb->iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1394 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1395 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1396 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1397 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1398 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1399 | "LOGO cmpl: status:x%x/x%x did:x%x", |
| 1400 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1401 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1402 | /* LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1403 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1404 | "0105 LOGO completes to NPort x%x " |
| 1405 | "Data: x%x x%x x%x x%x\n", |
| 1406 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1407 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1408 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1409 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1410 | goto out; |
| 1411 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1412 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
| 1413 | /* NLP_EVT_DEVICE_RM should unregister the RPI |
| 1414 | * which should abort all outstanding IOs. |
| 1415 | */ |
| 1416 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 1417 | NLP_EVT_DEVICE_RM); |
| 1418 | goto out; |
| 1419 | } |
| 1420 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1421 | if (irsp->ulpStatus) { |
| 1422 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1423 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1424 | /* ELS command is being retried */ |
| 1425 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1426 | /* LOGO failed */ |
| 1427 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1428 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1429 | goto out; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1430 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1431 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1432 | NLP_EVT_CMPL_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1433 | } else { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 1434 | /* Good status, call state machine. |
| 1435 | * This will unregister the rpi if needed. |
| 1436 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1437 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1438 | NLP_EVT_CMPL_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1439 | } |
| 1440 | |
| 1441 | out: |
| 1442 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1443 | return; |
| 1444 | } |
| 1445 | |
| 1446 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1447 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1448 | uint8_t retry) |
| 1449 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1450 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1451 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1452 | IOCB_t *icmd; |
| 1453 | struct lpfc_iocbq *elsiocb; |
| 1454 | struct lpfc_sli_ring *pring; |
| 1455 | struct lpfc_sli *psli; |
| 1456 | uint8_t *pcmd; |
| 1457 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1458 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1459 | |
| 1460 | psli = &phba->sli; |
| 1461 | pring = &psli->ring[LPFC_ELS_RING]; |
| 1462 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1463 | spin_lock_irq(shost->host_lock); |
| 1464 | if (ndlp->nlp_flag & NLP_LOGO_SND) { |
| 1465 | spin_unlock_irq(shost->host_lock); |
| 1466 | return 0; |
| 1467 | } |
| 1468 | spin_unlock_irq(shost->host_lock); |
| 1469 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1470 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1471 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1472 | ndlp->nlp_DID, ELS_CMD_LOGO); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1473 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1474 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1475 | |
| 1476 | icmd = &elsiocb->iocb; |
| 1477 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1478 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1479 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1480 | |
| 1481 | /* Fill in LOGO payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1482 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1483 | pcmd += sizeof(uint32_t); |
| 1484 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1485 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1486 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1487 | "Issue LOGO: did:x%x", |
| 1488 | ndlp->nlp_DID, 0, 0); |
| 1489 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1490 | phba->fc_stat.elsXmitLOGO++; |
| 1491 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1492 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1493 | ndlp->nlp_flag |= NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1494 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1495 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| 1496 | |
| 1497 | if (rc == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1498 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1499 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1500 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1501 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1502 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1503 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1504 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1505 | } |
| 1506 | |
| 1507 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1508 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1509 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1510 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1511 | struct lpfc_vport *vport = cmdiocb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1512 | IOCB_t *irsp; |
| 1513 | |
| 1514 | irsp = &rspiocb->iocb; |
| 1515 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1516 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1517 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 1518 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1519 | irsp->un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1520 | /* ELS cmd tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1521 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1522 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", |
| 1523 | irsp->ulpIoTag, irsp->ulpStatus, |
| 1524 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1525 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1526 | lpfc_els_chk_latt(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1527 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1528 | return; |
| 1529 | } |
| 1530 | |
| 1531 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1532 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1533 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1534 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1535 | IOCB_t *icmd; |
| 1536 | struct lpfc_iocbq *elsiocb; |
| 1537 | struct lpfc_sli_ring *pring; |
| 1538 | struct lpfc_sli *psli; |
| 1539 | uint8_t *pcmd; |
| 1540 | uint16_t cmdsize; |
| 1541 | struct lpfc_nodelist *ndlp; |
| 1542 | |
| 1543 | psli = &phba->sli; |
| 1544 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1545 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1546 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1547 | if (!ndlp) |
| 1548 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1549 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1550 | lpfc_nlp_init(vport, ndlp, nportid); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1551 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1552 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1553 | ndlp->nlp_DID, ELS_CMD_SCR); |
| 1554 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1555 | if (!elsiocb) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1556 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1557 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1558 | } |
| 1559 | |
| 1560 | icmd = &elsiocb->iocb; |
| 1561 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1562 | |
| 1563 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1564 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1565 | |
| 1566 | /* For SCR, remainder of payload is SCR parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1567 | memset(pcmd, 0, sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1568 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
| 1569 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1570 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1571 | "Issue SCR: did:x%x", |
| 1572 | ndlp->nlp_DID, 0, 0); |
| 1573 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1574 | phba->fc_stat.elsXmitSCR++; |
| 1575 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1576 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1577 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1578 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1579 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1580 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1581 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1582 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1583 | } |
| 1584 | |
| 1585 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1586 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1587 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1588 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1589 | IOCB_t *icmd; |
| 1590 | struct lpfc_iocbq *elsiocb; |
| 1591 | struct lpfc_sli_ring *pring; |
| 1592 | struct lpfc_sli *psli; |
| 1593 | FARP *fp; |
| 1594 | uint8_t *pcmd; |
| 1595 | uint32_t *lp; |
| 1596 | uint16_t cmdsize; |
| 1597 | struct lpfc_nodelist *ondlp; |
| 1598 | struct lpfc_nodelist *ndlp; |
| 1599 | |
| 1600 | psli = &phba->sli; |
| 1601 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1602 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1603 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1604 | if (!ndlp) |
| 1605 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1606 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1607 | lpfc_nlp_init(vport, ndlp, nportid); |
| 1608 | |
| 1609 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1610 | ndlp->nlp_DID, ELS_CMD_RNID); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1611 | if (!elsiocb) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1612 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1613 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1614 | } |
| 1615 | |
| 1616 | icmd = &elsiocb->iocb; |
| 1617 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1618 | |
| 1619 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1620 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1621 | |
| 1622 | /* Fill in FARPR payload */ |
| 1623 | fp = (FARP *) (pcmd); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1624 | memset(fp, 0, sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1625 | lp = (uint32_t *) pcmd; |
| 1626 | *lp++ = be32_to_cpu(nportid); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1627 | *lp++ = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1628 | fp->Rflags = 0; |
| 1629 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); |
| 1630 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1631 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 1632 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1633 | ondlp = lpfc_findnode_did(vport, nportid); |
| 1634 | if (ondlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1635 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1636 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1637 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1638 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1639 | } |
| 1640 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1641 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1642 | "Issue FARPR: did:x%x", |
| 1643 | ndlp->nlp_DID, 0, 0); |
| 1644 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1645 | phba->fc_stat.elsXmitFARPR++; |
| 1646 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1647 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1648 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1649 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1650 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1651 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1652 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1653 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1654 | } |
| 1655 | |
| 1656 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1657 | lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp) |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 1658 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1659 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1660 | |
| 1661 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 1662 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1663 | spin_unlock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 1664 | del_timer_sync(&nlp->nlp_delayfunc); |
| 1665 | nlp->nlp_last_elscmd = 0; |
| 1666 | |
| 1667 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) |
| 1668 | list_del_init(&nlp->els_retry_evt.evt_listp); |
| 1669 | |
| 1670 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1671 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 1672 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1673 | spin_unlock_irq(shost->host_lock); |
| 1674 | if (vport->num_disc_nodes) { |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 1675 | /* Check to see if there are more |
| 1676 | * PLOGIs to be sent |
| 1677 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1678 | lpfc_more_plogi(vport); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 1679 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1680 | if (vport->num_disc_nodes == 0) { |
| 1681 | spin_lock_irq(shost->host_lock); |
| 1682 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1683 | spin_unlock_irq(shost->host_lock); |
| 1684 | lpfc_can_disctmo(vport); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1685 | lpfc_end_rscn(vport); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 1686 | } |
| 1687 | } |
| 1688 | } |
| 1689 | return; |
| 1690 | } |
| 1691 | |
| 1692 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1693 | lpfc_els_retry_delay(unsigned long ptr) |
| 1694 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1695 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr; |
| 1696 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1697 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1698 | unsigned long flags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1699 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1700 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1701 | ndlp = (struct lpfc_nodelist *) ptr; |
| 1702 | phba = ndlp->vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1703 | evtp = &ndlp->els_retry_evt; |
| 1704 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1705 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1706 | if (!list_empty(&evtp->evt_listp)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1707 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1708 | return; |
| 1709 | } |
| 1710 | |
| 1711 | evtp->evt_arg1 = ndlp; |
| 1712 | evtp->evt = LPFC_EVT_ELS_RETRY; |
| 1713 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
| 1714 | if (phba->work_wait) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1715 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1716 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1717 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1718 | return; |
| 1719 | } |
| 1720 | |
| 1721 | void |
| 1722 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) |
| 1723 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1724 | struct lpfc_vport *vport = ndlp->vport; |
| 1725 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1726 | uint32_t cmd, did, retry; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1727 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1728 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 1729 | did = ndlp->nlp_DID; |
| 1730 | cmd = ndlp->nlp_last_elscmd; |
| 1731 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1732 | |
| 1733 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1734 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1735 | return; |
| 1736 | } |
| 1737 | |
| 1738 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1739 | spin_unlock_irq(shost->host_lock); |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 1740 | /* |
| 1741 | * If a discovery event readded nlp_delayfunc after timer |
| 1742 | * firing and before processing the timer, cancel the |
| 1743 | * nlp_delayfunc. |
| 1744 | */ |
| 1745 | del_timer_sync(&ndlp->nlp_delayfunc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1746 | retry = ndlp->nlp_retry; |
| 1747 | |
| 1748 | switch (cmd) { |
| 1749 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1750 | lpfc_issue_els_flogi(vport, ndlp, retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1751 | break; |
| 1752 | case ELS_CMD_PLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1753 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 1754 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1755 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 1756 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1757 | break; |
| 1758 | case ELS_CMD_ADISC: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1759 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 1760 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1761 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 1762 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1763 | break; |
| 1764 | case ELS_CMD_PRLI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1765 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 1766 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1767 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 1768 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1769 | break; |
| 1770 | case ELS_CMD_LOGO: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1771 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 1772 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1773 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 1774 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1775 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1776 | case ELS_CMD_FDISC: |
| 1777 | lpfc_issue_els_fdisc(vport, ndlp, retry); |
| 1778 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1779 | } |
| 1780 | return; |
| 1781 | } |
| 1782 | |
| 1783 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1784 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1785 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1786 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1787 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1788 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1789 | IOCB_t *irsp = &rspiocb->iocb; |
| 1790 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 1791 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1792 | uint32_t *elscmd; |
| 1793 | struct ls_rjt stat; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1794 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1795 | int logerr = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1796 | uint32_t cmd = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1797 | uint32_t did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1798 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1799 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1800 | /* Note: context2 may be 0 for internal driver abort |
| 1801 | * of delays ELS command. |
| 1802 | */ |
| 1803 | |
| 1804 | if (pcmd && pcmd->virt) { |
| 1805 | elscmd = (uint32_t *) (pcmd->virt); |
| 1806 | cmd = *elscmd++; |
| 1807 | } |
| 1808 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1809 | if (ndlp) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1810 | did = ndlp->nlp_DID; |
| 1811 | else { |
| 1812 | /* We should only hit this case for retrying PLOGI */ |
| 1813 | did = irsp->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1814 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1815 | if (!ndlp && (cmd != ELS_CMD_PLOGI)) |
| 1816 | return 1; |
| 1817 | } |
| 1818 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1819 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1820 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", |
| 1821 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); |
| 1822 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1823 | switch (irsp->ulpStatus) { |
| 1824 | case IOSTAT_FCP_RSP_ERROR: |
| 1825 | case IOSTAT_REMOTE_STOP: |
| 1826 | break; |
| 1827 | |
| 1828 | case IOSTAT_LOCAL_REJECT: |
| 1829 | switch ((irsp->un.ulpWord[4] & 0xff)) { |
| 1830 | case IOERR_LOOP_OPEN_FAILURE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1831 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1832 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1833 | retry = 1; |
| 1834 | break; |
| 1835 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1836 | case IOERR_ILLEGAL_COMMAND: |
| 1837 | if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) && |
| 1838 | (cmd == ELS_CMD_FDISC)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1839 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1840 | "0124 FDISC failed (3/6) " |
| 1841 | "retrying...\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1842 | lpfc_mbx_unreg_vpi(vport); |
| 1843 | retry = 1; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1844 | /* FDISC retry policy */ |
| 1845 | maxretry = 48; |
| 1846 | if (cmdiocb->retry >= 32) |
| 1847 | delay = 1000; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1848 | } |
| 1849 | break; |
| 1850 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1851 | case IOERR_NO_RESOURCES: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1852 | logerr = 1; /* HBA out of resources */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1853 | retry = 1; |
| 1854 | if (cmdiocb->retry > 100) |
| 1855 | delay = 100; |
| 1856 | maxretry = 250; |
| 1857 | break; |
| 1858 | |
| 1859 | case IOERR_ILLEGAL_FRAME: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1860 | delay = 100; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1861 | retry = 1; |
| 1862 | break; |
| 1863 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1864 | case IOERR_SEQUENCE_TIMEOUT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1865 | case IOERR_INVALID_RPI: |
| 1866 | retry = 1; |
| 1867 | break; |
| 1868 | } |
| 1869 | break; |
| 1870 | |
| 1871 | case IOSTAT_NPORT_RJT: |
| 1872 | case IOSTAT_FABRIC_RJT: |
| 1873 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 1874 | retry = 1; |
| 1875 | break; |
| 1876 | } |
| 1877 | break; |
| 1878 | |
| 1879 | case IOSTAT_NPORT_BSY: |
| 1880 | case IOSTAT_FABRIC_BSY: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1881 | logerr = 1; /* Fabric / Remote NPort out of resources */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1882 | retry = 1; |
| 1883 | break; |
| 1884 | |
| 1885 | case IOSTAT_LS_RJT: |
| 1886 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); |
| 1887 | /* Added for Vendor specifc support |
| 1888 | * Just keep retrying for these Rsn / Exp codes |
| 1889 | */ |
| 1890 | switch (stat.un.b.lsRjtRsnCode) { |
| 1891 | case LSRJT_UNABLE_TPC: |
| 1892 | if (stat.un.b.lsRjtRsnCodeExp == |
| 1893 | LSEXP_CMD_IN_PROGRESS) { |
| 1894 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1895 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1896 | maxretry = 48; |
| 1897 | } |
| 1898 | retry = 1; |
| 1899 | break; |
| 1900 | } |
| 1901 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1902 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1903 | maxretry = lpfc_max_els_tries + 1; |
| 1904 | retry = 1; |
| 1905 | break; |
| 1906 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1907 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 1908 | (cmd == ELS_CMD_FDISC) && |
| 1909 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1910 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1911 | "0125 FDISC Failed (x%x). " |
| 1912 | "Fabric out of resources\n", |
| 1913 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1914 | lpfc_vport_set_state(vport, |
| 1915 | FC_VPORT_NO_FABRIC_RSCS); |
| 1916 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1917 | break; |
| 1918 | |
| 1919 | case LSRJT_LOGICAL_BSY: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1920 | if ((cmd == ELS_CMD_PLOGI) || |
| 1921 | (cmd == ELS_CMD_PRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1922 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1923 | maxretry = 48; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1924 | } else if (cmd == ELS_CMD_FDISC) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1925 | /* FDISC retry policy */ |
| 1926 | maxretry = 48; |
| 1927 | if (cmdiocb->retry >= 32) |
| 1928 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1929 | } |
| 1930 | retry = 1; |
| 1931 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1932 | |
| 1933 | case LSRJT_LOGICAL_ERR: |
| 1934 | case LSRJT_PROTOCOL_ERR: |
| 1935 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 1936 | (cmd == ELS_CMD_FDISC) && |
| 1937 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || |
| 1938 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) |
| 1939 | ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1940 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1941 | "0123 FDISC Failed (x%x). " |
| 1942 | "Fabric Detected Bad WWN\n", |
| 1943 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1944 | lpfc_vport_set_state(vport, |
| 1945 | FC_VPORT_FABRIC_REJ_WWN); |
| 1946 | } |
| 1947 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1948 | } |
| 1949 | break; |
| 1950 | |
| 1951 | case IOSTAT_INTERMED_RSP: |
| 1952 | case IOSTAT_BA_RJT: |
| 1953 | break; |
| 1954 | |
| 1955 | default: |
| 1956 | break; |
| 1957 | } |
| 1958 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1959 | if (did == FDMI_DID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1960 | retry = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1961 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1962 | if ((cmd == ELS_CMD_FLOGI) && |
| 1963 | (phba->fc_topology != TOPOLOGY_LOOP)) { |
| 1964 | /* FLOGI retry policy */ |
| 1965 | retry = 1; |
| 1966 | maxretry = 48; |
| 1967 | if (cmdiocb->retry >= 32) |
| 1968 | delay = 1000; |
| 1969 | } |
| 1970 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1971 | if ((++cmdiocb->retry) >= maxretry) { |
| 1972 | phba->fc_stat.elsRetryExceeded++; |
| 1973 | retry = 0; |
| 1974 | } |
| 1975 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1976 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 1977 | retry = 0; |
| 1978 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1979 | if (retry) { |
| 1980 | |
| 1981 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1982 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1983 | "0107 Retry ELS command x%x to remote " |
| 1984 | "NPORT x%x Data: x%x x%x\n", |
| 1985 | cmd, did, cmdiocb->retry, delay); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1986 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1987 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && |
| 1988 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 1989 | ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) { |
| 1990 | /* Don't reset timer for no resources */ |
| 1991 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1992 | /* If discovery / RSCN timer is running, reset it */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1993 | if (timer_pending(&vport->fc_disctmo) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1994 | (vport->fc_flag & FC_RSCN_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1995 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1996 | } |
| 1997 | |
| 1998 | phba->fc_stat.elsXmitRetry++; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1999 | if (ndlp && delay) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2000 | phba->fc_stat.elsDelayRetry++; |
| 2001 | ndlp->nlp_retry = cmdiocb->retry; |
| 2002 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2003 | /* delay is specified in milliseconds */ |
| 2004 | mod_timer(&ndlp->nlp_delayfunc, |
| 2005 | jiffies + msecs_to_jiffies(delay)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2006 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2007 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2008 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2009 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2010 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2011 | if (cmd == ELS_CMD_PRLI) |
| 2012 | lpfc_nlp_set_state(vport, ndlp, |
| 2013 | NLP_STE_REG_LOGIN_ISSUE); |
| 2014 | else |
| 2015 | lpfc_nlp_set_state(vport, ndlp, |
| 2016 | NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2017 | ndlp->nlp_last_elscmd = cmd; |
| 2018 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2019 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2020 | } |
| 2021 | switch (cmd) { |
| 2022 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2023 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2024 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2025 | case ELS_CMD_FDISC: |
| 2026 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); |
| 2027 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2028 | case ELS_CMD_PLOGI: |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2029 | if (ndlp) { |
| 2030 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2031 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2032 | NLP_STE_PLOGI_ISSUE); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2033 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2034 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2035 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2036 | case ELS_CMD_ADISC: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2037 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2038 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 2039 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2040 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2041 | case ELS_CMD_PRLI: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2042 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2043 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
| 2044 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2045 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2046 | case ELS_CMD_LOGO: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2047 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2048 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 2049 | lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2050 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2051 | } |
| 2052 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2053 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2054 | if (logerr) { |
| 2055 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2056 | "0137 No retry ELS command x%x to remote " |
| 2057 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", |
| 2058 | cmd, did, irsp->ulpStatus, |
| 2059 | irsp->un.ulpWord[4]); |
| 2060 | } |
| 2061 | else { |
| 2062 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 2063 | "0108 No retry ELS command x%x to remote " |
| 2064 | "NPORT x%x Retried:%d Error:x%x/%x\n", |
| 2065 | cmd, did, cmdiocb->retry, irsp->ulpStatus, |
| 2066 | irsp->un.ulpWord[4]); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2067 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2068 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2069 | } |
| 2070 | |
| 2071 | int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2072 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) |
| 2073 | { |
| 2074 | struct lpfc_dmabuf *buf_ptr; |
| 2075 | |
| 2076 | /* Free the response before processing the command. */ |
| 2077 | if (!list_empty(&buf_ptr1->list)) { |
| 2078 | list_remove_head(&buf_ptr1->list, buf_ptr, |
| 2079 | struct lpfc_dmabuf, |
| 2080 | list); |
| 2081 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 2082 | kfree(buf_ptr); |
| 2083 | } |
| 2084 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); |
| 2085 | kfree(buf_ptr1); |
| 2086 | return 0; |
| 2087 | } |
| 2088 | |
| 2089 | int |
| 2090 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) |
| 2091 | { |
| 2092 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 2093 | kfree(buf_ptr); |
| 2094 | return 0; |
| 2095 | } |
| 2096 | |
| 2097 | int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2098 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2099 | { |
| 2100 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2101 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2102 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2103 | ndlp = (struct lpfc_nodelist *)elsiocb->context1; |
| 2104 | if (ndlp) { |
| 2105 | if (ndlp->nlp_flag & NLP_DEFER_RM) { |
| 2106 | lpfc_nlp_put(ndlp); |
| 2107 | |
| 2108 | /* If the ndlp is not being used by another discovery |
| 2109 | * thread, free it. |
| 2110 | */ |
| 2111 | if (!lpfc_nlp_not_used(ndlp)) { |
| 2112 | /* If ndlp is being used by another discovery |
| 2113 | * thread, just clear NLP_DEFER_RM |
| 2114 | */ |
| 2115 | ndlp->nlp_flag &= ~NLP_DEFER_RM; |
| 2116 | } |
| 2117 | } |
| 2118 | else |
| 2119 | lpfc_nlp_put(ndlp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2120 | elsiocb->context1 = NULL; |
| 2121 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2122 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
| 2123 | if (elsiocb->context2) { |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame^] | 2124 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { |
| 2125 | /* Firmware could still be in progress of DMAing |
| 2126 | * payload, so don't free data buffer till after |
| 2127 | * a hbeat. |
| 2128 | */ |
| 2129 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; |
| 2130 | buf_ptr = elsiocb->context2; |
| 2131 | elsiocb->context2 = NULL; |
| 2132 | if (buf_ptr) { |
| 2133 | buf_ptr1 = NULL; |
| 2134 | spin_lock_irq(&phba->hbalock); |
| 2135 | if (!list_empty(&buf_ptr->list)) { |
| 2136 | list_remove_head(&buf_ptr->list, |
| 2137 | buf_ptr1, struct lpfc_dmabuf, |
| 2138 | list); |
| 2139 | INIT_LIST_HEAD(&buf_ptr1->list); |
| 2140 | list_add_tail(&buf_ptr1->list, |
| 2141 | &phba->elsbuf); |
| 2142 | phba->elsbuf_cnt++; |
| 2143 | } |
| 2144 | INIT_LIST_HEAD(&buf_ptr->list); |
| 2145 | list_add_tail(&buf_ptr->list, &phba->elsbuf); |
| 2146 | phba->elsbuf_cnt++; |
| 2147 | spin_unlock_irq(&phba->hbalock); |
| 2148 | } |
| 2149 | } else { |
| 2150 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; |
| 2151 | lpfc_els_free_data(phba, buf_ptr1); |
| 2152 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2153 | } |
| 2154 | |
| 2155 | if (elsiocb->context3) { |
| 2156 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2157 | lpfc_els_free_bpl(phba, buf_ptr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2158 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2159 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2160 | return 0; |
| 2161 | } |
| 2162 | |
| 2163 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2164 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2165 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2166 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2167 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2168 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2169 | IOCB_t *irsp; |
| 2170 | |
| 2171 | irsp = &rspiocb->iocb; |
| 2172 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 2173 | "ACC LOGO cmpl: status:x%x/x%x did:x%x", |
| 2174 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2175 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2176 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2177 | "0109 ACC to LOGO completes to NPort x%x " |
| 2178 | "Data: x%x x%x x%x\n", |
| 2179 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 2180 | ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2181 | |
| 2182 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { |
| 2183 | /* NPort Recovery mode or node is just allocated */ |
| 2184 | if (!lpfc_nlp_not_used(ndlp)) { |
| 2185 | /* If the ndlp is being used by another discovery |
| 2186 | * thread, just unregister the RPI. |
| 2187 | */ |
| 2188 | lpfc_unreg_rpi(vport, ndlp); |
| 2189 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2190 | } |
| 2191 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2192 | return; |
| 2193 | } |
| 2194 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2195 | void |
| 2196 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 2197 | { |
| 2198 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 2199 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 2200 | |
| 2201 | pmb->context1 = NULL; |
| 2202 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2203 | kfree(mp); |
| 2204 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2205 | if (ndlp) { |
| 2206 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2207 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2208 | /* This is the end of the default RPI cleanup logic for this |
| 2209 | * ndlp. If no other discovery threads are using this ndlp. |
| 2210 | * we should free all resources associated with it. |
| 2211 | */ |
| 2212 | lpfc_nlp_not_used(ndlp); |
| 2213 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2214 | return; |
| 2215 | } |
| 2216 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2217 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2218 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2219 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2220 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2221 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2222 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; |
| 2223 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2224 | IOCB_t *irsp; |
| 2225 | uint8_t *pcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2226 | LPFC_MBOXQ_t *mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2227 | struct lpfc_dmabuf *mp = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2228 | uint32_t ls_rjt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2229 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 2230 | irsp = &rspiocb->iocb; |
| 2231 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2232 | if (cmdiocb->context_un.mbox) |
| 2233 | mbox = cmdiocb->context_un.mbox; |
| 2234 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2235 | /* First determine if this is a LS_RJT cmpl */ |
| 2236 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
| 2237 | if (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT) { |
| 2238 | /* A LS_RJT associated with Default RPI cleanup |
| 2239 | * has its own seperate code path. |
| 2240 | */ |
| 2241 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
| 2242 | ls_rjt = 1; |
| 2243 | } |
| 2244 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2245 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2246 | if (!ndlp || lpfc_els_chk_latt(vport)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2247 | if (mbox) { |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2248 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 2249 | if (mp) { |
| 2250 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2251 | kfree(mp); |
| 2252 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2253 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2254 | } |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2255 | if (ndlp && (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
| 2256 | if (lpfc_nlp_not_used(ndlp)) |
| 2257 | ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2258 | goto out; |
| 2259 | } |
| 2260 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2261 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2262 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2263 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2264 | cmdiocb->iocb.un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2265 | /* ELS response tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2266 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2267 | "0110 ELS response tag x%x completes " |
| 2268 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", |
| 2269 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, |
| 2270 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, |
| 2271 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 2272 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2273 | if (mbox) { |
| 2274 | if ((rspiocb->iocb.ulpStatus == 0) |
| 2275 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2276 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2277 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2278 | mbox->vport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2279 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
| 2280 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 2281 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 2282 | } |
| 2283 | else { |
| 2284 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
| 2285 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 2286 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2287 | NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2288 | } |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 2289 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2290 | != MBX_NOT_FINISHED) { |
| 2291 | goto out; |
| 2292 | } |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2293 | |
| 2294 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ |
| 2295 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2296 | "0138 ELS rsp: Cannot issue reg_login for x%x " |
| 2297 | "Data: x%x x%x x%x\n", |
| 2298 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 2299 | ndlp->nlp_rpi); |
| 2300 | |
| 2301 | if (lpfc_nlp_not_used(ndlp)) |
| 2302 | ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2303 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2304 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
| 2305 | if (!lpfc_error_lost_link(irsp) && |
| 2306 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2307 | if (lpfc_nlp_not_used(ndlp)) |
| 2308 | ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2309 | } |
| 2310 | } |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2311 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 2312 | if (mp) { |
| 2313 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2314 | kfree(mp); |
| 2315 | } |
| 2316 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2317 | } |
| 2318 | out: |
| 2319 | if (ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2320 | spin_lock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2321 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2322 | spin_unlock_irq(shost->host_lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2323 | |
| 2324 | /* If the node is not being used by another discovery thread, |
| 2325 | * and we are sending a reject, we are done with it. |
| 2326 | * Release driver reference count here and free associated |
| 2327 | * resources. |
| 2328 | */ |
| 2329 | if (ls_rjt) |
| 2330 | lpfc_nlp_not_used(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2331 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2332 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2333 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2334 | return; |
| 2335 | } |
| 2336 | |
| 2337 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2338 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
| 2339 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2340 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2341 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2342 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2343 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2344 | IOCB_t *icmd; |
| 2345 | IOCB_t *oldcmd; |
| 2346 | struct lpfc_iocbq *elsiocb; |
| 2347 | struct lpfc_sli_ring *pring; |
| 2348 | struct lpfc_sli *psli; |
| 2349 | uint8_t *pcmd; |
| 2350 | uint16_t cmdsize; |
| 2351 | int rc; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 2352 | ELS_PKT *els_pkt_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2353 | |
| 2354 | psli = &phba->sli; |
| 2355 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 2356 | oldcmd = &oldiocb->iocb; |
| 2357 | |
| 2358 | switch (flag) { |
| 2359 | case ELS_CMD_ACC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2360 | cmdsize = sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2361 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 2362 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2363 | if (!elsiocb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2364 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2365 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2366 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2367 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2368 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2369 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2370 | icmd = &elsiocb->iocb; |
| 2371 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 2372 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2373 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2374 | pcmd += sizeof(uint32_t); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2375 | |
| 2376 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 2377 | "Issue ACC: did:x%x flg:x%x", |
| 2378 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2379 | break; |
| 2380 | case ELS_CMD_PLOGI: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2381 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2382 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 2383 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2384 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2385 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2386 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2387 | icmd = &elsiocb->iocb; |
| 2388 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 2389 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2390 | |
| 2391 | if (mbox) |
| 2392 | elsiocb->context_un.mbox = mbox; |
| 2393 | |
| 2394 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2395 | pcmd += sizeof(uint32_t); |
| 2396 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2397 | |
| 2398 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 2399 | "Issue ACC PLOGI: did:x%x flg:x%x", |
| 2400 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2401 | break; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 2402 | case ELS_CMD_PRLO: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2403 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2404 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 2405 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
| 2406 | if (!elsiocb) |
| 2407 | return 1; |
| 2408 | |
| 2409 | icmd = &elsiocb->iocb; |
| 2410 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 2411 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2412 | |
| 2413 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2414 | sizeof(uint32_t) + sizeof(PRLO)); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 2415 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
| 2416 | els_pkt_ptr = (ELS_PKT *) pcmd; |
| 2417 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2418 | |
| 2419 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 2420 | "Issue ACC PRLO: did:x%x flg:x%x", |
| 2421 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 2422 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2423 | default: |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2424 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2425 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2426 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2427 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2428 | "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " |
| 2429 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n", |
| 2430 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 2431 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 2432 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2433 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2434 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2435 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2436 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2437 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
| 2438 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2439 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2440 | } |
| 2441 | |
| 2442 | phba->fc_stat.elsXmitACC++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2443 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2444 | if (rc == IOCB_ERROR) { |
| 2445 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2446 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2447 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2448 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2449 | } |
| 2450 | |
| 2451 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2452 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2453 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
| 2454 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2455 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2456 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2457 | IOCB_t *icmd; |
| 2458 | IOCB_t *oldcmd; |
| 2459 | struct lpfc_iocbq *elsiocb; |
| 2460 | struct lpfc_sli_ring *pring; |
| 2461 | struct lpfc_sli *psli; |
| 2462 | uint8_t *pcmd; |
| 2463 | uint16_t cmdsize; |
| 2464 | int rc; |
| 2465 | |
| 2466 | psli = &phba->sli; |
| 2467 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 2468 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2469 | cmdsize = 2 * sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2470 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 2471 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2472 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2473 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2474 | |
| 2475 | icmd = &elsiocb->iocb; |
| 2476 | oldcmd = &oldiocb->iocb; |
| 2477 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 2478 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2479 | |
| 2480 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2481 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2482 | *((uint32_t *) (pcmd)) = rejectError; |
| 2483 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2484 | if (mbox) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2485 | elsiocb->context_un.mbox = mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2486 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2487 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2488 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2489 | "0129 Xmit ELS RJT x%x response tag x%x " |
| 2490 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 2491 | "rpi x%x\n", |
| 2492 | rejectError, elsiocb->iotag, |
| 2493 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 2494 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2495 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 2496 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", |
| 2497 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); |
| 2498 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2499 | phba->fc_stat.elsXmitLSRJT++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2500 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2501 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2502 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2503 | if (rc == IOCB_ERROR) { |
| 2504 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2505 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2506 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2507 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2508 | } |
| 2509 | |
| 2510 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2511 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
| 2512 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2513 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2514 | struct lpfc_hba *phba = vport->phba; |
| 2515 | struct lpfc_sli *psli = &phba->sli; |
| 2516 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2517 | ADISC *ap; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2518 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2519 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2520 | uint8_t *pcmd; |
| 2521 | uint16_t cmdsize; |
| 2522 | int rc; |
| 2523 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2524 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2525 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 2526 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2527 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2528 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2529 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2530 | icmd = &elsiocb->iocb; |
| 2531 | oldcmd = &oldiocb->iocb; |
| 2532 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 2533 | |
| 2534 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2535 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2536 | "0130 Xmit ADISC ACC response iotag x%x xri: " |
| 2537 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", |
| 2538 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 2539 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 2540 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2541 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2542 | |
| 2543 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2544 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2545 | |
| 2546 | ap = (ADISC *) (pcmd); |
| 2547 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2548 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2549 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2550 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2551 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2552 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 2553 | "Issue ACC ADISC: did:x%x flg:x%x", |
| 2554 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 2555 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2556 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2557 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2558 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2559 | if (rc == IOCB_ERROR) { |
| 2560 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2561 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2562 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2563 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2564 | } |
| 2565 | |
| 2566 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2567 | lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 2568 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2569 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2570 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2571 | PRLI *npr; |
| 2572 | lpfc_vpd_t *vpd; |
| 2573 | IOCB_t *icmd; |
| 2574 | IOCB_t *oldcmd; |
| 2575 | struct lpfc_iocbq *elsiocb; |
| 2576 | struct lpfc_sli_ring *pring; |
| 2577 | struct lpfc_sli *psli; |
| 2578 | uint8_t *pcmd; |
| 2579 | uint16_t cmdsize; |
| 2580 | int rc; |
| 2581 | |
| 2582 | psli = &phba->sli; |
| 2583 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 2584 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2585 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2586 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2587 | ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK))); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2588 | if (!elsiocb) |
| 2589 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2590 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2591 | icmd = &elsiocb->iocb; |
| 2592 | oldcmd = &oldiocb->iocb; |
| 2593 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 2594 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2595 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2596 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " |
| 2597 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 2598 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 2599 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 2600 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2601 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2602 | |
| 2603 | *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2604 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2605 | |
| 2606 | /* For PRLI, remainder of payload is PRLI parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2607 | memset(pcmd, 0, sizeof(PRLI)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2608 | |
| 2609 | npr = (PRLI *) pcmd; |
| 2610 | vpd = &phba->vpd; |
| 2611 | /* |
| 2612 | * If our firmware version is 3.20 or later, |
| 2613 | * set the following bits for FC-TAPE support. |
| 2614 | */ |
| 2615 | if (vpd->rev.feaLevelHigh >= 0x02) { |
| 2616 | npr->ConfmComplAllowed = 1; |
| 2617 | npr->Retry = 1; |
| 2618 | npr->TaskRetryIdReq = 1; |
| 2619 | } |
| 2620 | |
| 2621 | npr->acceptRspCode = PRLI_REQ_EXECUTED; |
| 2622 | npr->estabImagePair = 1; |
| 2623 | npr->readXferRdyDis = 1; |
| 2624 | npr->ConfmComplAllowed = 1; |
| 2625 | |
| 2626 | npr->prliType = PRLI_FCP_TYPE; |
| 2627 | npr->initiatorFunc = 1; |
| 2628 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2629 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 2630 | "Issue ACC PRLI: did:x%x flg:x%x", |
| 2631 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 2632 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2633 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2634 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2635 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2636 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2637 | if (rc == IOCB_ERROR) { |
| 2638 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2639 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2640 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2641 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2642 | } |
| 2643 | |
| 2644 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2645 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2646 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2647 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2648 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2649 | RNID *rn; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2650 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2651 | struct lpfc_iocbq *elsiocb; |
| 2652 | struct lpfc_sli_ring *pring; |
| 2653 | struct lpfc_sli *psli; |
| 2654 | uint8_t *pcmd; |
| 2655 | uint16_t cmdsize; |
| 2656 | int rc; |
| 2657 | |
| 2658 | psli = &phba->sli; |
| 2659 | pring = &psli->ring[LPFC_ELS_RING]; |
| 2660 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2661 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
| 2662 | + (2 * sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2663 | if (format) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2664 | cmdsize += sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2665 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2666 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 2667 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2668 | if (!elsiocb) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2669 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2670 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2671 | icmd = &elsiocb->iocb; |
| 2672 | oldcmd = &oldiocb->iocb; |
| 2673 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 2674 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2675 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2676 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", |
| 2677 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2678 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2679 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2680 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2681 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2682 | memset(pcmd, 0, sizeof(RNID)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2683 | rn = (RNID *) (pcmd); |
| 2684 | rn->Format = format; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2685 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
| 2686 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2687 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2688 | switch (format) { |
| 2689 | case 0: |
| 2690 | rn->SpecificLen = 0; |
| 2691 | break; |
| 2692 | case RNID_TOPOLOGY_DISC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2693 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2694 | memcpy(&rn->un.topologyDisc.portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2695 | &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2696 | rn->un.topologyDisc.unitType = RNID_HBA; |
| 2697 | rn->un.topologyDisc.physPort = 0; |
| 2698 | rn->un.topologyDisc.attachedNodes = 0; |
| 2699 | break; |
| 2700 | default: |
| 2701 | rn->CommonLen = 0; |
| 2702 | rn->SpecificLen = 0; |
| 2703 | break; |
| 2704 | } |
| 2705 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2706 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 2707 | "Issue ACC RNID: did:x%x flg:x%x", |
| 2708 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 2709 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2710 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2711 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2712 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2713 | elsiocb->context1 = NULL; /* Don't need ndlp for cmpl, |
| 2714 | * it could be freed */ |
| 2715 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2716 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2717 | if (rc == IOCB_ERROR) { |
| 2718 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2719 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2720 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2721 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2722 | } |
| 2723 | |
| 2724 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2725 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2726 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2727 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2728 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2729 | int sentadisc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2730 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2731 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2732 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2733 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 2734 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 2735 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2736 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2737 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2738 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2739 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2740 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 2741 | lpfc_issue_els_adisc(vport, ndlp, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2742 | sentadisc++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2743 | vport->num_disc_nodes++; |
| 2744 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2745 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2746 | spin_lock_irq(shost->host_lock); |
| 2747 | vport->fc_flag |= FC_NLP_MORE; |
| 2748 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2749 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2750 | } |
| 2751 | } |
| 2752 | } |
| 2753 | if (sentadisc == 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2754 | spin_lock_irq(shost->host_lock); |
| 2755 | vport->fc_flag &= ~FC_NLP_MORE; |
| 2756 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2757 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2758 | return sentadisc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2759 | } |
| 2760 | |
| 2761 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2762 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2763 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2764 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2765 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2766 | int sentplogi = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2767 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2768 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 2769 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2770 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 2771 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 2772 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && |
| 2773 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { |
| 2774 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2775 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 2776 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2777 | sentplogi++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2778 | vport->num_disc_nodes++; |
| 2779 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2780 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2781 | spin_lock_irq(shost->host_lock); |
| 2782 | vport->fc_flag |= FC_NLP_MORE; |
| 2783 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2784 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2785 | } |
| 2786 | } |
| 2787 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2788 | if (sentplogi) { |
| 2789 | lpfc_set_disctmo(vport); |
| 2790 | } |
| 2791 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2792 | spin_lock_irq(shost->host_lock); |
| 2793 | vport->fc_flag &= ~FC_NLP_MORE; |
| 2794 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2795 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2796 | return sentplogi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2797 | } |
| 2798 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2799 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2800 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2801 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2802 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2803 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2804 | int i; |
| 2805 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2806 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2807 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2808 | vport->fc_rscn_id_list[i] = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2809 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2810 | spin_lock_irq(shost->host_lock); |
| 2811 | vport->fc_rscn_id_cnt = 0; |
| 2812 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); |
| 2813 | spin_unlock_irq(shost->host_lock); |
| 2814 | lpfc_can_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2815 | } |
| 2816 | |
| 2817 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2818 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2819 | { |
| 2820 | D_ID ns_did; |
| 2821 | D_ID rscn_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2822 | uint32_t *lp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2823 | uint32_t payload_len, i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2824 | |
| 2825 | ns_did.un.word = did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2826 | |
| 2827 | /* Never match fabric nodes for RSCNs */ |
| 2828 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2829 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2830 | |
| 2831 | /* If we are doing a FULL RSCN rediscovery, match everything */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2832 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2833 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2834 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2835 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2836 | lp = vport->fc_rscn_id_list[i]->virt; |
| 2837 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 2838 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2839 | while (payload_len) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2840 | rscn_did.un.word = be32_to_cpu(*lp++); |
| 2841 | payload_len -= sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2842 | switch (rscn_did.un.b.resv) { |
| 2843 | case 0: /* Single N_Port ID effected */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2844 | if (ns_did.un.word == rscn_did.un.word) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2845 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2846 | break; |
| 2847 | case 1: /* Whole N_Port Area effected */ |
| 2848 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 2849 | && (ns_did.un.b.area == rscn_did.un.b.area)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2850 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2851 | break; |
| 2852 | case 2: /* Whole N_Port Domain effected */ |
| 2853 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2854 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2855 | break; |
| 2856 | default: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2857 | /* Unknown Identifier in RSCN node */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2858 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 2859 | "0217 Unknown Identifier in " |
| 2860 | "RSCN payload Data: x%x\n", |
| 2861 | rscn_did.un.word); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2862 | case 3: /* Whole Fabric effected */ |
| 2863 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2864 | } |
| 2865 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2866 | } |
| 2867 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2868 | } |
| 2869 | |
| 2870 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2871 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2872 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2873 | struct lpfc_nodelist *ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2874 | |
| 2875 | /* Look at all nodes effected by pending RSCNs and move |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2876 | * them to NPR state. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2877 | */ |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2878 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2879 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2880 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2881 | lpfc_rscn_payload_check(vport, ndlp->nlp_DID) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2882 | continue; |
| 2883 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2884 | lpfc_disc_state_machine(vport, ndlp, NULL, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2885 | NLP_EVT_DEVICE_RECOVERY); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2886 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2887 | /* |
| 2888 | * Make sure NLP_DELAY_TMO is NOT running after a device |
| 2889 | * recovery event. |
| 2890 | */ |
| 2891 | if (ndlp->nlp_flag & NLP_DELAY_TMO) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2892 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2893 | } |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2894 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2895 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2896 | } |
| 2897 | |
| 2898 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2899 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2900 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2901 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2902 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2903 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2904 | struct lpfc_dmabuf *pcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2905 | uint32_t *lp, *datap; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2906 | IOCB_t *icmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2907 | uint32_t payload_len, length, nportid, *cmd; |
| 2908 | int rscn_cnt = vport->fc_rscn_id_cnt; |
| 2909 | int rscn_id = 0, hba_id = 0; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 2910 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2911 | |
| 2912 | icmd = &cmdiocb->iocb; |
| 2913 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 2914 | lp = (uint32_t *) pcmd->virt; |
| 2915 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2916 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 2917 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2918 | /* RSCN received */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2919 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 2920 | "0214 RSCN received Data: x%x x%x x%x x%x\n", |
| 2921 | vport->fc_flag, payload_len, *lp, rscn_cnt); |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 2922 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2923 | fc_host_post_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 2924 | FCH_EVT_RSCN, lp[i]); |
| 2925 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2926 | /* If we are about to begin discovery, just ACC the RSCN. |
| 2927 | * Discovery processing will satisfy it. |
| 2928 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2929 | if (vport->port_state <= LPFC_NS_QRY) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2930 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 2931 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", |
| 2932 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 2933 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2934 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2935 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2936 | } |
| 2937 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2938 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
| 2939 | * just ACC and ignore it. |
| 2940 | */ |
| 2941 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2942 | !(vport->cfg_peer_port_login)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2943 | i = payload_len; |
| 2944 | datap = lp; |
| 2945 | while (i > 0) { |
| 2946 | nportid = *datap++; |
| 2947 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); |
| 2948 | i -= sizeof(uint32_t); |
| 2949 | rscn_id++; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2950 | if (lpfc_find_vport_by_did(phba, nportid)) |
| 2951 | hba_id++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2952 | } |
| 2953 | if (rscn_id == hba_id) { |
| 2954 | /* ALL NPortIDs in RSCN are on HBA */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2955 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 2956 | "0214 Ignore RSCN " |
| 2957 | "Data: x%x x%x x%x x%x\n", |
| 2958 | vport->fc_flag, payload_len, |
| 2959 | *lp, rscn_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2960 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 2961 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", |
| 2962 | ndlp->nlp_DID, vport->port_state, |
| 2963 | ndlp->nlp_flag); |
| 2964 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2965 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2966 | ndlp, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2967 | return 0; |
| 2968 | } |
| 2969 | } |
| 2970 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2971 | /* If we are already processing an RSCN, save the received |
| 2972 | * RSCN payload buffer, cmdiocb->context2 to process later. |
| 2973 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2974 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2975 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 2976 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", |
| 2977 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 2978 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2979 | vport->fc_flag |= FC_RSCN_DEFERRED; |
| 2980 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2981 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
| 2982 | spin_lock_irq(shost->host_lock); |
| 2983 | vport->fc_flag |= FC_RSCN_MODE; |
| 2984 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2985 | if (rscn_cnt) { |
| 2986 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; |
| 2987 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); |
| 2988 | } |
| 2989 | if ((rscn_cnt) && |
| 2990 | (payload_len + length <= LPFC_BPL_SIZE)) { |
| 2991 | *cmd &= ELS_CMD_MASK; |
| 2992 | *cmd |= be32_to_cpu(payload_len + length); |
| 2993 | memcpy(((uint8_t *)cmd) + length, lp, |
| 2994 | payload_len); |
| 2995 | } else { |
| 2996 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; |
| 2997 | vport->fc_rscn_id_cnt++; |
| 2998 | /* If we zero, cmdiocb->context2, the calling |
| 2999 | * routine will not try to free it. |
| 3000 | */ |
| 3001 | cmdiocb->context2 = NULL; |
| 3002 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3003 | |
| 3004 | /* Deferred RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3005 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 3006 | "0235 Deferred RSCN " |
| 3007 | "Data: x%x x%x x%x\n", |
| 3008 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 3009 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3010 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3011 | spin_lock_irq(shost->host_lock); |
| 3012 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
| 3013 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3014 | /* ReDiscovery RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3015 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 3016 | "0234 ReDiscovery RSCN " |
| 3017 | "Data: x%x x%x x%x\n", |
| 3018 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 3019 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3020 | } |
| 3021 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3022 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3023 | |
| 3024 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3025 | lpfc_rscn_recovery_check(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3026 | vport->fc_flag &= ~FC_RSCN_DEFERRED; |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3027 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3028 | } |
| 3029 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3030 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 3031 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", |
| 3032 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 3033 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3034 | spin_lock_irq(shost->host_lock); |
| 3035 | vport->fc_flag |= FC_RSCN_MODE; |
| 3036 | spin_unlock_irq(shost->host_lock); |
| 3037 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3038 | /* |
| 3039 | * If we zero, cmdiocb->context2, the calling routine will |
| 3040 | * not try to free it. |
| 3041 | */ |
| 3042 | cmdiocb->context2 = NULL; |
| 3043 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3044 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3045 | |
| 3046 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3047 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3048 | |
| 3049 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3050 | lpfc_rscn_recovery_check(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3051 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3052 | return lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3053 | } |
| 3054 | |
| 3055 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3056 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3057 | { |
| 3058 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3059 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3060 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3061 | /* Ignore RSCN if the port is being torn down. */ |
| 3062 | if (vport->load_flag & FC_UNLOADING) { |
| 3063 | lpfc_els_flush_rscn(vport); |
| 3064 | return 0; |
| 3065 | } |
| 3066 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3067 | /* Start timer for RSCN processing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3068 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3069 | |
| 3070 | /* RSCN processed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3071 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 3072 | "0215 RSCN processed Data: x%x x%x x%x x%x\n", |
| 3073 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, |
| 3074 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3075 | |
| 3076 | /* To process RSCN, first compare RSCN data with NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3077 | vport->fc_ns_retry = 0; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame^] | 3078 | vport->num_disc_nodes = 0; |
| 3079 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3080 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3081 | if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3082 | /* Good ndlp, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3083 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3084 | /* Wait for NameServer query cmpl before we can |
| 3085 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3086 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3087 | } else { |
| 3088 | /* If login to NameServer does not exist, issue one */ |
| 3089 | /* Good status, issue PLOGI to NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3090 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 3091 | if (ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3092 | /* Wait for NameServer login cmpl before we can |
| 3093 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3094 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3095 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3096 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 3097 | if (!ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3098 | lpfc_els_flush_rscn(vport); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3099 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3100 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3101 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3102 | ndlp->nlp_type |= NLP_FABRIC; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3103 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3104 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 3105 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3106 | /* Wait for NameServer login cmpl before we can |
| 3107 | continue */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3108 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3109 | } |
| 3110 | } |
| 3111 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3112 | lpfc_els_flush_rscn(vport); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3113 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3114 | } |
| 3115 | |
| 3116 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3117 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3118 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3119 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3120 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3121 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3122 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 3123 | uint32_t *lp = (uint32_t *) pcmd->virt; |
| 3124 | IOCB_t *icmd = &cmdiocb->iocb; |
| 3125 | struct serv_parm *sp; |
| 3126 | LPFC_MBOXQ_t *mbox; |
| 3127 | struct ls_rjt stat; |
| 3128 | uint32_t cmd, did; |
| 3129 | int rc; |
| 3130 | |
| 3131 | cmd = *lp++; |
| 3132 | sp = (struct serv_parm *) lp; |
| 3133 | |
| 3134 | /* FLOGI received */ |
| 3135 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3136 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3137 | |
| 3138 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 3139 | /* We should never receive a FLOGI in loop mode, ignore it */ |
| 3140 | did = icmd->un.elsreq64.remoteID; |
| 3141 | |
| 3142 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in |
| 3143 | Loop Mode */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3144 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3145 | "0113 An FLOGI ELS command x%x was " |
| 3146 | "received from DID x%x in Loop Mode\n", |
| 3147 | cmd, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3148 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3149 | } |
| 3150 | |
| 3151 | did = Fabric_DID; |
| 3152 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3153 | if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3154 | /* For a FLOGI we accept, then if our portname is greater |
| 3155 | * then the remote portname we initiate Nport login. |
| 3156 | */ |
| 3157 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3158 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3159 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3160 | |
| 3161 | if (!rc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3162 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3163 | if (!mbox) |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3164 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3165 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3166 | lpfc_linkdown(phba); |
| 3167 | lpfc_init_link(phba, mbox, |
| 3168 | phba->cfg_topology, |
| 3169 | phba->cfg_link_speed); |
| 3170 | mbox->mb.un.varInitLnk.lipsr_AL_PA = 0; |
| 3171 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3172 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3173 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3174 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3175 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3176 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3177 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3178 | return 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3179 | } else if (rc > 0) { /* greater than */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3180 | spin_lock_irq(shost->host_lock); |
| 3181 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 3182 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3183 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3184 | spin_lock_irq(shost->host_lock); |
| 3185 | vport->fc_flag |= FC_PT2PT; |
| 3186 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 3187 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3188 | } else { |
| 3189 | /* Reject this request because invalid parameters */ |
| 3190 | stat.un.b.lsRjtRsvd0 = 0; |
| 3191 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 3192 | stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; |
| 3193 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3194 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 3195 | NULL); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3196 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3197 | } |
| 3198 | |
| 3199 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3200 | lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3201 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3202 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3203 | } |
| 3204 | |
| 3205 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3206 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 3207 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3208 | { |
| 3209 | struct lpfc_dmabuf *pcmd; |
| 3210 | uint32_t *lp; |
| 3211 | IOCB_t *icmd; |
| 3212 | RNID *rn; |
| 3213 | struct ls_rjt stat; |
| 3214 | uint32_t cmd, did; |
| 3215 | |
| 3216 | icmd = &cmdiocb->iocb; |
| 3217 | did = icmd->un.elsreq64.remoteID; |
| 3218 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 3219 | lp = (uint32_t *) pcmd->virt; |
| 3220 | |
| 3221 | cmd = *lp++; |
| 3222 | rn = (RNID *) lp; |
| 3223 | |
| 3224 | /* RNID received */ |
| 3225 | |
| 3226 | switch (rn->Format) { |
| 3227 | case 0: |
| 3228 | case RNID_TOPOLOGY_DISC: |
| 3229 | /* Send back ACC */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3230 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3231 | break; |
| 3232 | default: |
| 3233 | /* Reject this request because format not supported */ |
| 3234 | stat.un.b.lsRjtRsvd0 = 0; |
| 3235 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 3236 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 3237 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3238 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 3239 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3240 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3241 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3242 | } |
| 3243 | |
| 3244 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3245 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 3246 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3247 | { |
| 3248 | struct ls_rjt stat; |
| 3249 | |
| 3250 | /* For now, unconditionally reject this command */ |
| 3251 | stat.un.b.lsRjtRsvd0 = 0; |
| 3252 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 3253 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 3254 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3255 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3256 | return 0; |
| 3257 | } |
| 3258 | |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 3259 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3260 | lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3261 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3262 | struct lpfc_sli *psli = &phba->sli; |
| 3263 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3264 | MAILBOX_t *mb; |
| 3265 | IOCB_t *icmd; |
| 3266 | RPS_RSP *rps_rsp; |
| 3267 | uint8_t *pcmd; |
| 3268 | struct lpfc_iocbq *elsiocb; |
| 3269 | struct lpfc_nodelist *ndlp; |
| 3270 | uint16_t xri, status; |
| 3271 | uint32_t cmdsize; |
| 3272 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3273 | mb = &pmb->mb; |
| 3274 | |
| 3275 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3276 | xri = (uint16_t) ((unsigned long)(pmb->context1)); |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 3277 | pmb->context1 = NULL; |
| 3278 | pmb->context2 = NULL; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3279 | |
| 3280 | if (mb->mbxStatus) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3281 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3282 | return; |
| 3283 | } |
| 3284 | |
| 3285 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3286 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3287 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 3288 | lpfc_max_els_tries, ndlp, |
| 3289 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3290 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3291 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3292 | return; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3293 | |
| 3294 | icmd = &elsiocb->iocb; |
| 3295 | icmd->ulpContext = xri; |
| 3296 | |
| 3297 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3298 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3299 | pcmd += sizeof(uint32_t); /* Skip past command */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3300 | rps_rsp = (RPS_RSP *)pcmd; |
| 3301 | |
| 3302 | if (phba->fc_topology != TOPOLOGY_LOOP) |
| 3303 | status = 0x10; |
| 3304 | else |
| 3305 | status = 0x8; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3306 | if (phba->pport->fc_flag & FC_FABRIC) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3307 | status |= 0x4; |
| 3308 | |
| 3309 | rps_rsp->rsvd1 = 0; |
| 3310 | rps_rsp->portStatus = be16_to_cpu(status); |
| 3311 | rps_rsp->linkFailureCnt = be32_to_cpu(mb->un.varRdLnk.linkFailureCnt); |
| 3312 | rps_rsp->lossSyncCnt = be32_to_cpu(mb->un.varRdLnk.lossSyncCnt); |
| 3313 | rps_rsp->lossSignalCnt = be32_to_cpu(mb->un.varRdLnk.lossSignalCnt); |
| 3314 | rps_rsp->primSeqErrCnt = be32_to_cpu(mb->un.varRdLnk.primSeqErrCnt); |
| 3315 | rps_rsp->invalidXmitWord = be32_to_cpu(mb->un.varRdLnk.invalidXmitWord); |
| 3316 | rps_rsp->crcCnt = be32_to_cpu(mb->un.varRdLnk.crcCnt); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3317 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3318 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 3319 | "0118 Xmit ELS RPS ACC response tag x%x xri x%x, " |
| 3320 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 3321 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3322 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3323 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3324 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3325 | phba->fc_stat.elsXmitACC++; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3326 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3327 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3328 | return; |
| 3329 | } |
| 3330 | |
| 3331 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3332 | lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 3333 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3334 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3335 | struct lpfc_hba *phba = vport->phba; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3336 | uint32_t *lp; |
| 3337 | uint8_t flag; |
| 3338 | LPFC_MBOXQ_t *mbox; |
| 3339 | struct lpfc_dmabuf *pcmd; |
| 3340 | RPS *rps; |
| 3341 | struct ls_rjt stat; |
| 3342 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3343 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 3344 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3345 | stat.un.b.lsRjtRsvd0 = 0; |
| 3346 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 3347 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 3348 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3349 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 3350 | NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3351 | } |
| 3352 | |
| 3353 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 3354 | lp = (uint32_t *) pcmd->virt; |
| 3355 | flag = (be32_to_cpu(*lp++) & 0xf); |
| 3356 | rps = (RPS *) lp; |
| 3357 | |
| 3358 | if ((flag == 0) || |
| 3359 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3360 | ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3361 | sizeof(struct lpfc_name)) == 0))) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3362 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3363 | printk("Fix me....\n"); |
| 3364 | dump_stack(); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3365 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 3366 | if (mbox) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3367 | lpfc_read_lnk_stat(phba, mbox); |
| 3368 | mbox->context1 = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3369 | (void *)((unsigned long) cmdiocb->iocb.ulpContext); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3370 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3371 | mbox->vport = vport; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3372 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3373 | if (lpfc_sli_issue_mbox (phba, mbox, MBX_NOWAIT) |
| 3374 | != MBX_NOT_FINISHED) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3375 | /* Mbox completion will send ELS Response */ |
| 3376 | return 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3377 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3378 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3379 | mempool_free(mbox, phba->mbox_mem_pool); |
| 3380 | } |
| 3381 | } |
| 3382 | stat.un.b.lsRjtRsvd0 = 0; |
| 3383 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 3384 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 3385 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3386 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3387 | return 0; |
| 3388 | } |
| 3389 | |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 3390 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3391 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
| 3392 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3393 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3394 | struct lpfc_hba *phba = vport->phba; |
| 3395 | IOCB_t *icmd, *oldcmd; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3396 | RPL_RSP rpl_rsp; |
| 3397 | struct lpfc_iocbq *elsiocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3398 | struct lpfc_sli *psli = &phba->sli; |
| 3399 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3400 | uint8_t *pcmd; |
| 3401 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3402 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3403 | ndlp->nlp_DID, ELS_CMD_ACC); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3404 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3405 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3406 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3407 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3408 | icmd = &elsiocb->iocb; |
| 3409 | oldcmd = &oldiocb->iocb; |
| 3410 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3411 | |
| 3412 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3413 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3414 | pcmd += sizeof(uint16_t); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3415 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
| 3416 | pcmd += sizeof(uint16_t); |
| 3417 | |
| 3418 | /* Setup the RPL ACC payload */ |
| 3419 | rpl_rsp.listLen = be32_to_cpu(1); |
| 3420 | rpl_rsp.index = 0; |
| 3421 | rpl_rsp.port_num_blk.portNum = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3422 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
| 3423 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3424 | sizeof(struct lpfc_name)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3425 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3426 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3427 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3428 | "0120 Xmit ELS RPL ACC response tag x%x " |
| 3429 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 3430 | "rpi x%x\n", |
| 3431 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3432 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3433 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3434 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3435 | phba->fc_stat.elsXmitACC++; |
| 3436 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
| 3437 | lpfc_els_free_iocb(phba, elsiocb); |
| 3438 | return 1; |
| 3439 | } |
| 3440 | return 0; |
| 3441 | } |
| 3442 | |
| 3443 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3444 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 3445 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3446 | { |
| 3447 | struct lpfc_dmabuf *pcmd; |
| 3448 | uint32_t *lp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3449 | uint32_t maxsize; |
| 3450 | uint16_t cmdsize; |
| 3451 | RPL *rpl; |
| 3452 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3453 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3454 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 3455 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3456 | stat.un.b.lsRjtRsvd0 = 0; |
| 3457 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 3458 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 3459 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3460 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 3461 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3462 | } |
| 3463 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3464 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 3465 | lp = (uint32_t *) pcmd->virt; |
| 3466 | rpl = (RPL *) (lp + 1); |
| 3467 | |
| 3468 | maxsize = be32_to_cpu(rpl->maxsize); |
| 3469 | |
| 3470 | /* We support only one port */ |
| 3471 | if ((rpl->index == 0) && |
| 3472 | ((maxsize == 0) || |
| 3473 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { |
| 3474 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3475 | } else { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3476 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
| 3477 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3478 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3479 | |
| 3480 | return 0; |
| 3481 | } |
| 3482 | |
| 3483 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3484 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 3485 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3486 | { |
| 3487 | struct lpfc_dmabuf *pcmd; |
| 3488 | uint32_t *lp; |
| 3489 | IOCB_t *icmd; |
| 3490 | FARP *fp; |
| 3491 | uint32_t cmd, cnt, did; |
| 3492 | |
| 3493 | icmd = &cmdiocb->iocb; |
| 3494 | did = icmd->un.elsreq64.remoteID; |
| 3495 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 3496 | lp = (uint32_t *) pcmd->virt; |
| 3497 | |
| 3498 | cmd = *lp++; |
| 3499 | fp = (FARP *) lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3500 | /* FARP-REQ received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3501 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3502 | "0601 FARP-REQ received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3503 | /* We will only support match on WWPN or WWNN */ |
| 3504 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3505 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3506 | } |
| 3507 | |
| 3508 | cnt = 0; |
| 3509 | /* If this FARP command is searching for my portname */ |
| 3510 | if (fp->Mflags & FARP_MATCH_PORT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3511 | if (memcmp(&fp->RportName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3512 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3513 | cnt = 1; |
| 3514 | } |
| 3515 | |
| 3516 | /* If this FARP command is searching for my nodename */ |
| 3517 | if (fp->Mflags & FARP_MATCH_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3518 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3519 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3520 | cnt = 1; |
| 3521 | } |
| 3522 | |
| 3523 | if (cnt) { |
| 3524 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 3525 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { |
| 3526 | /* Log back into the node before sending the FARP. */ |
| 3527 | if (fp->Rflags & FARP_REQUEST_PLOGI) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3528 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3529 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3530 | NLP_STE_PLOGI_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3531 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3532 | } |
| 3533 | |
| 3534 | /* Send a FARP response to that node */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3535 | if (fp->Rflags & FARP_REQUEST_FARPR) |
| 3536 | lpfc_issue_els_farpr(vport, did, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3537 | } |
| 3538 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3539 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3540 | } |
| 3541 | |
| 3542 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3543 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 3544 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3545 | { |
| 3546 | struct lpfc_dmabuf *pcmd; |
| 3547 | uint32_t *lp; |
| 3548 | IOCB_t *icmd; |
| 3549 | uint32_t cmd, did; |
| 3550 | |
| 3551 | icmd = &cmdiocb->iocb; |
| 3552 | did = icmd->un.elsreq64.remoteID; |
| 3553 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 3554 | lp = (uint32_t *) pcmd->virt; |
| 3555 | |
| 3556 | cmd = *lp++; |
| 3557 | /* FARP-RSP received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3558 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3559 | "0600 FARP-RSP received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3560 | /* ACCEPT the Farp resp request */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3561 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3562 | |
| 3563 | return 0; |
| 3564 | } |
| 3565 | |
| 3566 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3567 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 3568 | struct lpfc_nodelist *fan_ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3569 | { |
| 3570 | struct lpfc_dmabuf *pcmd; |
| 3571 | uint32_t *lp; |
| 3572 | IOCB_t *icmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3573 | uint32_t cmd, did; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3574 | FAN *fp; |
| 3575 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3576 | struct lpfc_hba *phba = vport->phba; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3577 | |
| 3578 | /* FAN received */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3579 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3580 | "0265 FAN received\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3581 | icmd = &cmdiocb->iocb; |
| 3582 | did = icmd->un.elsreq64.remoteID; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3583 | pcmd = (struct lpfc_dmabuf *)cmdiocb->context2; |
| 3584 | lp = (uint32_t *)pcmd->virt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3585 | |
| 3586 | cmd = *lp++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3587 | fp = (FAN *) lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3588 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3589 | /* FAN received; Fan does not have a reply sequence */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3590 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3591 | if (phba->pport->port_state == LPFC_LOCAL_CFG_LINK) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3592 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
| 3593 | sizeof(struct lpfc_name)) != 0) || |
| 3594 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
| 3595 | sizeof(struct lpfc_name)) != 0)) { |
| 3596 | /* |
| 3597 | * This node has switched fabrics. FLOGI is required |
| 3598 | * Clean up the old rpi's |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3599 | */ |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3600 | |
| 3601 | list_for_each_entry_safe(ndlp, next_ndlp, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3602 | &vport->fc_nodes, nlp_listp) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3603 | if (ndlp->nlp_state != NLP_STE_NPR_NODE) |
| 3604 | continue; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3605 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 3606 | /* |
| 3607 | * Clean up old Fabric, Nameserver and |
| 3608 | * other NLP_FABRIC logins |
| 3609 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3610 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3611 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3612 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3613 | /* Fail outstanding I/O now since this |
| 3614 | * device is marked for PLOGI |
| 3615 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3616 | lpfc_unreg_rpi(vport, ndlp); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3617 | } |
| 3618 | } |
| 3619 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3620 | lpfc_initial_flogi(vport); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3621 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3622 | } |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3623 | /* Discovery not needed, |
| 3624 | * move the nodes to their original state. |
| 3625 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3626 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3627 | nlp_listp) { |
| 3628 | if (ndlp->nlp_state != NLP_STE_NPR_NODE) |
| 3629 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3630 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3631 | switch (ndlp->nlp_prev_state) { |
| 3632 | case NLP_STE_UNMAPPED_NODE: |
| 3633 | ndlp->nlp_prev_state = NLP_STE_NPR_NODE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3634 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3635 | NLP_STE_UNMAPPED_NODE); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3636 | break; |
| 3637 | |
| 3638 | case NLP_STE_MAPPED_NODE: |
| 3639 | ndlp->nlp_prev_state = NLP_STE_NPR_NODE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3640 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3641 | NLP_STE_MAPPED_NODE); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3642 | break; |
| 3643 | |
| 3644 | default: |
| 3645 | break; |
| 3646 | } |
| 3647 | } |
| 3648 | |
| 3649 | /* Start discovery - this should just do CLEAR_LA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3650 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3651 | } |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3652 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3653 | } |
| 3654 | |
| 3655 | void |
| 3656 | lpfc_els_timeout(unsigned long ptr) |
| 3657 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3658 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 3659 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3660 | unsigned long iflag; |
| 3661 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3662 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
| 3663 | if ((vport->work_port_events & WORKER_ELS_TMO) == 0) { |
| 3664 | vport->work_port_events |= WORKER_ELS_TMO; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3665 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
| 3666 | |
| 3667 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3668 | if (phba->work_wait) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3669 | lpfc_worker_wake_up(phba); |
| 3670 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3671 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3672 | else |
| 3673 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3674 | return; |
| 3675 | } |
| 3676 | |
| 3677 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3678 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3679 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3680 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3681 | struct lpfc_sli_ring *pring; |
| 3682 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 3683 | IOCB_t *cmd = NULL; |
| 3684 | struct lpfc_dmabuf *pcmd; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3685 | uint32_t els_command = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3686 | uint32_t timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3687 | uint32_t remote_ID = 0xffffffff; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3688 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3689 | /* If the timer is already canceled do nothing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3690 | if ((vport->work_port_events & WORKER_ELS_TMO) == 0) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3691 | return; |
| 3692 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3693 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3694 | timeout = (uint32_t)(phba->fc_ratov << 1); |
| 3695 | |
| 3696 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3697 | |
| 3698 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 3699 | cmd = &piocb->iocb; |
| 3700 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3701 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
| 3702 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 3703 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3704 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3705 | |
| 3706 | if (piocb->vport != vport) |
| 3707 | continue; |
| 3708 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3709 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3710 | if (pcmd) |
| 3711 | els_command = *(uint32_t *) (pcmd->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3712 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3713 | if (els_command == ELS_CMD_FARP || |
| 3714 | els_command == ELS_CMD_FARPR || |
| 3715 | els_command == ELS_CMD_FDISC) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3716 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3717 | |
| 3718 | if (vport != piocb->vport) |
| 3719 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3720 | |
| 3721 | if (piocb->drvrTimeout > 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3722 | if (piocb->drvrTimeout >= timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3723 | piocb->drvrTimeout -= timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3724 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3725 | piocb->drvrTimeout = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3726 | continue; |
| 3727 | } |
| 3728 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3729 | remote_ID = 0xffffffff; |
| 3730 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3731 | remote_ID = cmd->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3732 | else { |
| 3733 | struct lpfc_nodelist *ndlp; |
| 3734 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); |
| 3735 | if (ndlp) |
| 3736 | remote_ID = ndlp->nlp_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3737 | } |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3738 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3739 | "0127 ELS timeout Data: x%x x%x x%x " |
| 3740 | "x%x\n", els_command, |
| 3741 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3742 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3743 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3744 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 3745 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3746 | if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) |
| 3747 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3748 | } |
| 3749 | |
| 3750 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3751 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3752 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3753 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3754 | struct lpfc_hba *phba = vport->phba; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3755 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3756 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 3757 | IOCB_t *cmd = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3758 | |
| 3759 | lpfc_fabric_abort_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3760 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3761 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3762 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 3763 | cmd = &piocb->iocb; |
| 3764 | |
| 3765 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 3766 | continue; |
| 3767 | } |
| 3768 | |
| 3769 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3770 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 3771 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 3772 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 3773 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3774 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3775 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3776 | if (piocb->vport != vport) |
| 3777 | continue; |
| 3778 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3779 | list_move_tail(&piocb->list, &completions); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3780 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3781 | } |
| 3782 | |
| 3783 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3784 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 3785 | continue; |
| 3786 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3787 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3788 | if (piocb->vport != vport) |
| 3789 | continue; |
| 3790 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3791 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3792 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3793 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3794 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3795 | while (!list_empty(&completions)) { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3796 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| 3797 | cmd = &piocb->iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3798 | list_del_init(&piocb->list); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3799 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3800 | if (!piocb->iocb_cmpl) |
| 3801 | lpfc_sli_release_iocbq(phba, piocb); |
| 3802 | else { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3803 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 3804 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 3805 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3806 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3807 | } |
| 3808 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3809 | return; |
| 3810 | } |
| 3811 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3812 | void |
| 3813 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) |
| 3814 | { |
| 3815 | LIST_HEAD(completions); |
| 3816 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 3817 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 3818 | IOCB_t *cmd = NULL; |
| 3819 | |
| 3820 | lpfc_fabric_abort_hba(phba); |
| 3821 | spin_lock_irq(&phba->hbalock); |
| 3822 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 3823 | cmd = &piocb->iocb; |
| 3824 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 3825 | continue; |
| 3826 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
| 3827 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 3828 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 3829 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 3830 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| 3831 | continue; |
| 3832 | list_move_tail(&piocb->list, &completions); |
| 3833 | pring->txq_cnt--; |
| 3834 | } |
| 3835 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 3836 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 3837 | continue; |
| 3838 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 3839 | } |
| 3840 | spin_unlock_irq(&phba->hbalock); |
| 3841 | while (!list_empty(&completions)) { |
| 3842 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| 3843 | cmd = &piocb->iocb; |
| 3844 | list_del_init(&piocb->list); |
| 3845 | if (!piocb->iocb_cmpl) |
| 3846 | lpfc_sli_release_iocbq(phba, piocb); |
| 3847 | else { |
| 3848 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 3849 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 3850 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 3851 | } |
| 3852 | } |
| 3853 | return; |
| 3854 | } |
| 3855 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3856 | static void |
| 3857 | lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3858 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3859 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3860 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3861 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3862 | struct ls_rjt stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3863 | uint32_t *payload; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3864 | uint32_t cmd, did, newnode, rjt_err = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3865 | IOCB_t *icmd = &elsiocb->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3866 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3867 | if (vport == NULL || elsiocb->context2 == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3868 | goto dropit; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3869 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3870 | newnode = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3871 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
| 3872 | cmd = *payload; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3873 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
| 3874 | lpfc_post_buffer(phba, pring, 1, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3875 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3876 | did = icmd->un.rcvels.remoteID; |
| 3877 | if (icmd->ulpStatus) { |
| 3878 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 3879 | "RCV Unsol ELS: status:x%x/x%x did:x%x", |
| 3880 | icmd->ulpStatus, icmd->un.ulpWord[4], did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3881 | goto dropit; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3882 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3883 | |
| 3884 | /* Check to see if link went down during discovery */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3885 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3886 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3887 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3888 | /* Ignore traffic recevied during vport shutdown. */ |
| 3889 | if (vport->load_flag & FC_UNLOADING) |
| 3890 | goto dropit; |
| 3891 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3892 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3893 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3894 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3895 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3896 | if (!ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3897 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3898 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3899 | lpfc_nlp_init(vport, ndlp, did); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3900 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3901 | newnode = 1; |
| 3902 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) { |
| 3903 | ndlp->nlp_type |= NLP_FABRIC; |
| 3904 | } |
| 3905 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3906 | else { |
| 3907 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 3908 | /* This is simular to the new node path */ |
| 3909 | lpfc_nlp_get(ndlp); |
| 3910 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 3911 | newnode = 1; |
| 3912 | } |
| 3913 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3914 | |
| 3915 | phba->fc_stat.elsRcvFrame++; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3916 | if (elsiocb->context1) |
| 3917 | lpfc_nlp_put(elsiocb->context1); |
| 3918 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3919 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3920 | |
| 3921 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { |
| 3922 | cmd &= ELS_CMD_MASK; |
| 3923 | } |
| 3924 | /* ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3925 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3926 | "0112 ELS command x%x received from NPORT x%x " |
| 3927 | "Data: x%x\n", cmd, did, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3928 | switch (cmd) { |
| 3929 | case ELS_CMD_PLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3930 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 3931 | "RCV PLOGI: did:x%x/ste:x%x flg:x%x", |
| 3932 | did, vport->port_state, ndlp->nlp_flag); |
| 3933 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3934 | phba->fc_stat.elsRcvPLOGI++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3935 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
| 3936 | |
| 3937 | if (vport->port_state < LPFC_DISC_AUTH) { |
| 3938 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3939 | break; |
| 3940 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3941 | |
| 3942 | shost = lpfc_shost_from_vport(vport); |
| 3943 | spin_lock_irq(shost->host_lock); |
| 3944 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; |
| 3945 | spin_unlock_irq(shost->host_lock); |
| 3946 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3947 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 3948 | NLP_EVT_RCV_PLOGI); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3949 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3950 | break; |
| 3951 | case ELS_CMD_FLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3952 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 3953 | "RCV FLOGI: did:x%x/ste:x%x flg:x%x", |
| 3954 | did, vport->port_state, ndlp->nlp_flag); |
| 3955 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3956 | phba->fc_stat.elsRcvFLOGI++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3957 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3958 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3959 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3960 | break; |
| 3961 | case ELS_CMD_LOGO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3962 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 3963 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", |
| 3964 | did, vport->port_state, ndlp->nlp_flag); |
| 3965 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3966 | phba->fc_stat.elsRcvLOGO++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3967 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3968 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3969 | break; |
| 3970 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3971 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3972 | break; |
| 3973 | case ELS_CMD_PRLO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3974 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 3975 | "RCV PRLO: did:x%x/ste:x%x flg:x%x", |
| 3976 | did, vport->port_state, ndlp->nlp_flag); |
| 3977 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3978 | phba->fc_stat.elsRcvPRLO++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3979 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3980 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3981 | break; |
| 3982 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3983 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3984 | break; |
| 3985 | case ELS_CMD_RSCN: |
| 3986 | phba->fc_stat.elsRcvRSCN++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3987 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3988 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3989 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3990 | break; |
| 3991 | case ELS_CMD_ADISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3992 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 3993 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", |
| 3994 | did, vport->port_state, ndlp->nlp_flag); |
| 3995 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3996 | phba->fc_stat.elsRcvADISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3997 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3998 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3999 | break; |
| 4000 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4001 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 4002 | NLP_EVT_RCV_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4003 | break; |
| 4004 | case ELS_CMD_PDISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4005 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4006 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", |
| 4007 | did, vport->port_state, ndlp->nlp_flag); |
| 4008 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4009 | phba->fc_stat.elsRcvPDISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4010 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4011 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4012 | break; |
| 4013 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4014 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 4015 | NLP_EVT_RCV_PDISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4016 | break; |
| 4017 | case ELS_CMD_FARPR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4018 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4019 | "RCV FARPR: did:x%x/ste:x%x flg:x%x", |
| 4020 | did, vport->port_state, ndlp->nlp_flag); |
| 4021 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4022 | phba->fc_stat.elsRcvFARPR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4023 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4024 | break; |
| 4025 | case ELS_CMD_FARP: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4026 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4027 | "RCV FARP: did:x%x/ste:x%x flg:x%x", |
| 4028 | did, vport->port_state, ndlp->nlp_flag); |
| 4029 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4030 | phba->fc_stat.elsRcvFARP++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4031 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4032 | break; |
| 4033 | case ELS_CMD_FAN: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4034 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4035 | "RCV FAN: did:x%x/ste:x%x flg:x%x", |
| 4036 | did, vport->port_state, ndlp->nlp_flag); |
| 4037 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4038 | phba->fc_stat.elsRcvFAN++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4039 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4040 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4041 | case ELS_CMD_PRLI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4042 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4043 | "RCV PRLI: did:x%x/ste:x%x flg:x%x", |
| 4044 | did, vport->port_state, ndlp->nlp_flag); |
| 4045 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4046 | phba->fc_stat.elsRcvPRLI++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4047 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4048 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4049 | break; |
| 4050 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4051 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4052 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4053 | case ELS_CMD_LIRR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4054 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4055 | "RCV LIRR: did:x%x/ste:x%x flg:x%x", |
| 4056 | did, vport->port_state, ndlp->nlp_flag); |
| 4057 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4058 | phba->fc_stat.elsRcvLIRR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4059 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4060 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4061 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4062 | break; |
| 4063 | case ELS_CMD_RPS: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4064 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4065 | "RCV RPS: did:x%x/ste:x%x flg:x%x", |
| 4066 | did, vport->port_state, ndlp->nlp_flag); |
| 4067 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4068 | phba->fc_stat.elsRcvRPS++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4069 | lpfc_els_rcv_rps(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4070 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4071 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4072 | break; |
| 4073 | case ELS_CMD_RPL: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4074 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4075 | "RCV RPL: did:x%x/ste:x%x flg:x%x", |
| 4076 | did, vport->port_state, ndlp->nlp_flag); |
| 4077 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4078 | phba->fc_stat.elsRcvRPL++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4079 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4080 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4081 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4082 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4083 | case ELS_CMD_RNID: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4084 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4085 | "RCV RNID: did:x%x/ste:x%x flg:x%x", |
| 4086 | did, vport->port_state, ndlp->nlp_flag); |
| 4087 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4088 | phba->fc_stat.elsRcvRNID++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4089 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4090 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4091 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4092 | break; |
| 4093 | default: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4094 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4095 | "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", |
| 4096 | cmd, did, vport->port_state); |
| 4097 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4098 | /* Unsupported ELS command, reject */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4099 | rjt_err = LSRJT_INVALID_CMD; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4100 | |
| 4101 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4102 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4103 | "0115 Unknown ELS command x%x " |
| 4104 | "received from NPORT x%x\n", cmd, did); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4105 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4106 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4107 | break; |
| 4108 | } |
| 4109 | |
| 4110 | /* check if need to LS_RJT received ELS cmd */ |
| 4111 | if (rjt_err) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4112 | memset(&stat, 0, sizeof(stat)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4113 | stat.un.b.lsRjtRsnCode = rjt_err; |
James.Smart@Emulex.Com | 1f679ca | 2005-06-25 10:34:27 -0400 | [diff] [blame] | 4114 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4115 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
| 4116 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4117 | } |
| 4118 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4119 | return; |
| 4120 | |
| 4121 | dropit: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4122 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
| 4123 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4124 | "(%d):0111 Dropping received ELS cmd " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4125 | "Data: x%x x%x x%x\n", |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4126 | vport->vpi, icmd->ulpStatus, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4127 | icmd->un.ulpWord[4], icmd->ulpTimeout); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4128 | phba->fc_stat.elsRcvDrop++; |
| 4129 | } |
| 4130 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4131 | static struct lpfc_vport * |
| 4132 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) |
| 4133 | { |
| 4134 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 4135 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4136 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 4137 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4138 | list_for_each_entry(vport, &phba->port_list, listentry) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 4139 | if (vport->vpi == vpi) { |
| 4140 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4141 | return vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 4142 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4143 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 4144 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4145 | return NULL; |
| 4146 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4147 | |
| 4148 | void |
| 4149 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 4150 | struct lpfc_iocbq *elsiocb) |
| 4151 | { |
| 4152 | struct lpfc_vport *vport = phba->pport; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4153 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4154 | dma_addr_t paddr; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4155 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
| 4156 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4157 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4158 | elsiocb->context2 = NULL; |
| 4159 | elsiocb->context3 = NULL; |
| 4160 | |
| 4161 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
| 4162 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 4163 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 4164 | (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4165 | phba->fc_stat.NoRcvBuf++; |
| 4166 | /* Not enough posted buffers; Try posting more buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4167 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4168 | lpfc_post_buffer(phba, pring, 0, 1); |
| 4169 | return; |
| 4170 | } |
| 4171 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4172 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 4173 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || |
| 4174 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 4175 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) |
| 4176 | vport = phba->pport; |
| 4177 | else { |
| 4178 | uint16_t vpi = icmd->unsli3.rcvsli3.vpi; |
| 4179 | vport = lpfc_find_vport_by_vpid(phba, vpi); |
| 4180 | } |
| 4181 | } |
| 4182 | /* If there are no BDEs associated |
| 4183 | * with this IOCB, there is nothing to do. |
| 4184 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4185 | if (icmd->ulpBdeCount == 0) |
| 4186 | return; |
| 4187 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4188 | /* type of ELS cmd is first 32bit word |
| 4189 | * in packet |
| 4190 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4191 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4192 | elsiocb->context2 = bdeBuf1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4193 | } else { |
| 4194 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, |
| 4195 | icmd->un.cont64[0].addrLow); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4196 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
| 4197 | paddr); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4198 | } |
| 4199 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4200 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
| 4201 | /* |
| 4202 | * The different unsolicited event handlers would tell us |
| 4203 | * if they are done with "mp" by setting context2 to NULL. |
| 4204 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4205 | lpfc_nlp_put(elsiocb->context1); |
| 4206 | elsiocb->context1 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4207 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4208 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
| 4209 | elsiocb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4210 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4211 | |
| 4212 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4213 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4214 | icmd->ulpBdeCount == 2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4215 | elsiocb->context2 = bdeBuf2; |
| 4216 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4217 | /* free mp if we are done with it */ |
| 4218 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4219 | lpfc_in_buf_free(phba, elsiocb->context2); |
| 4220 | elsiocb->context2 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4221 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4222 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4223 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4224 | |
| 4225 | void |
| 4226 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 4227 | { |
| 4228 | struct lpfc_nodelist *ndlp, *ndlp_fdmi; |
| 4229 | |
| 4230 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 4231 | if (!ndlp) { |
| 4232 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 4233 | if (!ndlp) { |
| 4234 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 4235 | lpfc_disc_start(vport); |
| 4236 | return; |
| 4237 | } |
| 4238 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4239 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4240 | "0251 NameServer login: no memory\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4241 | return; |
| 4242 | } |
| 4243 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
| 4244 | ndlp->nlp_type |= NLP_FABRIC; |
| 4245 | } |
| 4246 | |
| 4247 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 4248 | |
| 4249 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { |
| 4250 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4251 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4252 | "0252 Cannot issue NameServer login\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4253 | return; |
| 4254 | } |
| 4255 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4256 | if (vport->cfg_fdmi_on) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4257 | ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool, |
| 4258 | GFP_KERNEL); |
| 4259 | if (ndlp_fdmi) { |
| 4260 | lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID); |
| 4261 | ndlp_fdmi->nlp_type |= NLP_FABRIC; |
| 4262 | ndlp_fdmi->nlp_state = |
| 4263 | NLP_STE_PLOGI_ISSUE; |
| 4264 | lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, |
| 4265 | 0); |
| 4266 | } |
| 4267 | } |
| 4268 | return; |
| 4269 | } |
| 4270 | |
| 4271 | static void |
| 4272 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 4273 | { |
| 4274 | struct lpfc_vport *vport = pmb->vport; |
| 4275 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4276 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 4277 | MAILBOX_t *mb = &pmb->mb; |
| 4278 | |
| 4279 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 4280 | lpfc_nlp_put(ndlp); |
| 4281 | |
| 4282 | if (mb->mbxStatus) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4283 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 4284 | "0915 Register VPI failed: 0x%x\n", |
| 4285 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4286 | |
| 4287 | switch (mb->mbxStatus) { |
| 4288 | case 0x11: /* unsupported feature */ |
| 4289 | case 0x9603: /* max_vpi exceeded */ |
| 4290 | /* giving up on vport registration */ |
| 4291 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 4292 | spin_lock_irq(shost->host_lock); |
| 4293 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 4294 | spin_unlock_irq(shost->host_lock); |
| 4295 | lpfc_can_disctmo(vport); |
| 4296 | break; |
| 4297 | default: |
| 4298 | /* Try to recover from this error */ |
| 4299 | lpfc_mbx_unreg_vpi(vport); |
| 4300 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 4301 | lpfc_initial_fdisc(vport); |
| 4302 | break; |
| 4303 | } |
| 4304 | |
| 4305 | } else { |
| 4306 | if (vport == phba->pport) |
| 4307 | lpfc_issue_fabric_reglogin(vport); |
| 4308 | else |
| 4309 | lpfc_do_scr_ns_plogi(phba, vport); |
| 4310 | } |
| 4311 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4312 | return; |
| 4313 | } |
| 4314 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 4315 | static void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4316 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 4317 | struct lpfc_nodelist *ndlp) |
| 4318 | { |
| 4319 | LPFC_MBOXQ_t *mbox; |
| 4320 | |
| 4321 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4322 | if (mbox) { |
| 4323 | lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, mbox); |
| 4324 | mbox->vport = vport; |
| 4325 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 4326 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4327 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4328 | == MBX_NOT_FINISHED) { |
| 4329 | mempool_free(mbox, phba->mbox_mem_pool); |
| 4330 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 4331 | |
| 4332 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4333 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 4334 | "0253 Register VPI: Can't send mbox\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4335 | } |
| 4336 | } else { |
| 4337 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 4338 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4339 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 4340 | "0254 Register VPI: no memory\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4341 | |
| 4342 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 4343 | lpfc_nlp_put(ndlp); |
| 4344 | } |
| 4345 | } |
| 4346 | |
| 4347 | static void |
| 4348 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 4349 | struct lpfc_iocbq *rspiocb) |
| 4350 | { |
| 4351 | struct lpfc_vport *vport = cmdiocb->vport; |
| 4352 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4353 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 4354 | struct lpfc_nodelist *np; |
| 4355 | struct lpfc_nodelist *next_np; |
| 4356 | IOCB_t *irsp = &rspiocb->iocb; |
| 4357 | struct lpfc_iocbq *piocb; |
| 4358 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4359 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4360 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", |
| 4361 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 4362 | vport->fc_prevDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4363 | /* Since all FDISCs are being single threaded, we |
| 4364 | * must reset the discovery timer for ALL vports |
| 4365 | * waiting to send FDISC when one completes. |
| 4366 | */ |
| 4367 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { |
| 4368 | lpfc_set_disctmo(piocb->vport); |
| 4369 | } |
| 4370 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4371 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 4372 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", |
| 4373 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); |
| 4374 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4375 | if (irsp->ulpStatus) { |
| 4376 | /* Check for retry */ |
| 4377 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| 4378 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4379 | /* FDISC failed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4380 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4381 | "0124 FDISC failed. (%d/%d)\n", |
| 4382 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4383 | if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING) |
| 4384 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 4385 | |
| 4386 | lpfc_nlp_put(ndlp); |
| 4387 | /* giving up on FDISC. Cancel discovery timer */ |
| 4388 | lpfc_can_disctmo(vport); |
| 4389 | } else { |
| 4390 | spin_lock_irq(shost->host_lock); |
| 4391 | vport->fc_flag |= FC_FABRIC; |
| 4392 | if (vport->phba->fc_topology == TOPOLOGY_LOOP) |
| 4393 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 4394 | spin_unlock_irq(shost->host_lock); |
| 4395 | |
| 4396 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| 4397 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); |
| 4398 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 4399 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 4400 | /* If our NportID changed, we need to ensure all |
| 4401 | * remaining NPORTs get unreg_login'ed so we can |
| 4402 | * issue unreg_vpi. |
| 4403 | */ |
| 4404 | list_for_each_entry_safe(np, next_np, |
| 4405 | &vport->fc_nodes, nlp_listp) { |
| 4406 | if (np->nlp_state != NLP_STE_NPR_NODE |
| 4407 | || !(np->nlp_flag & NLP_NPR_ADISC)) |
| 4408 | continue; |
| 4409 | spin_lock_irq(shost->host_lock); |
| 4410 | np->nlp_flag &= ~NLP_NPR_ADISC; |
| 4411 | spin_unlock_irq(shost->host_lock); |
| 4412 | lpfc_unreg_rpi(vport, np); |
| 4413 | } |
| 4414 | lpfc_mbx_unreg_vpi(vport); |
| 4415 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 4416 | } |
| 4417 | |
| 4418 | if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
| 4419 | lpfc_register_new_vport(phba, vport, ndlp); |
| 4420 | else |
| 4421 | lpfc_do_scr_ns_plogi(phba, vport); |
| 4422 | |
| 4423 | lpfc_nlp_put(ndlp); /* Free Fabric ndlp for vports */ |
| 4424 | } |
| 4425 | |
| 4426 | out: |
| 4427 | lpfc_els_free_iocb(phba, cmdiocb); |
| 4428 | } |
| 4429 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 4430 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4431 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4432 | uint8_t retry) |
| 4433 | { |
| 4434 | struct lpfc_hba *phba = vport->phba; |
| 4435 | IOCB_t *icmd; |
| 4436 | struct lpfc_iocbq *elsiocb; |
| 4437 | struct serv_parm *sp; |
| 4438 | uint8_t *pcmd; |
| 4439 | uint16_t cmdsize; |
| 4440 | int did = ndlp->nlp_DID; |
| 4441 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4442 | |
| 4443 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
| 4444 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
| 4445 | ELS_CMD_FDISC); |
| 4446 | if (!elsiocb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4447 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4448 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4449 | "0255 Issue FDISC: no IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4450 | return 1; |
| 4451 | } |
| 4452 | |
| 4453 | icmd = &elsiocb->iocb; |
| 4454 | icmd->un.elsreq64.myID = 0; |
| 4455 | icmd->un.elsreq64.fl = 1; |
| 4456 | |
| 4457 | /* For FDISC, Let FDISC rsp set the NPortID for this VPI */ |
| 4458 | icmd->ulpCt_h = 1; |
| 4459 | icmd->ulpCt_l = 0; |
| 4460 | |
| 4461 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4462 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; |
| 4463 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ |
| 4464 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); |
| 4465 | sp = (struct serv_parm *) pcmd; |
| 4466 | /* Setup CSPs accordingly for Fabric */ |
| 4467 | sp->cmn.e_d_tov = 0; |
| 4468 | sp->cmn.w2.r_a_tov = 0; |
| 4469 | sp->cls1.classValid = 0; |
| 4470 | sp->cls2.seqDelivery = 1; |
| 4471 | sp->cls3.seqDelivery = 1; |
| 4472 | |
| 4473 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ |
| 4474 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ |
| 4475 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ |
| 4476 | pcmd += sizeof(uint32_t); /* Port Name */ |
| 4477 | memcpy(pcmd, &vport->fc_portname, 8); |
| 4478 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 4479 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 4480 | memcpy(pcmd, &vport->fc_nodename, 8); |
| 4481 | |
| 4482 | lpfc_set_disctmo(vport); |
| 4483 | |
| 4484 | phba->fc_stat.elsXmitFDISC++; |
| 4485 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; |
| 4486 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4487 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 4488 | "Issue FDISC: did:x%x", |
| 4489 | did, 0, 0); |
| 4490 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4491 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| 4492 | if (rc == IOCB_ERROR) { |
| 4493 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4494 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4495 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4496 | "0256 Issue FDISC: Cannot send IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4497 | return 1; |
| 4498 | } |
| 4499 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); |
| 4500 | vport->port_state = LPFC_FDISC; |
| 4501 | return 0; |
| 4502 | } |
| 4503 | |
| 4504 | static void |
| 4505 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 4506 | struct lpfc_iocbq *rspiocb) |
| 4507 | { |
| 4508 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4509 | IOCB_t *irsp; |
| 4510 | |
| 4511 | irsp = &rspiocb->iocb; |
| 4512 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 4513 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", |
| 4514 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4515 | |
| 4516 | lpfc_els_free_iocb(phba, cmdiocb); |
| 4517 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
| 4518 | } |
| 4519 | |
| 4520 | int |
| 4521 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 4522 | { |
| 4523 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4524 | struct lpfc_hba *phba = vport->phba; |
| 4525 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 4526 | IOCB_t *icmd; |
| 4527 | struct lpfc_iocbq *elsiocb; |
| 4528 | uint8_t *pcmd; |
| 4529 | uint16_t cmdsize; |
| 4530 | |
| 4531 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); |
| 4532 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, |
| 4533 | ELS_CMD_LOGO); |
| 4534 | if (!elsiocb) |
| 4535 | return 1; |
| 4536 | |
| 4537 | icmd = &elsiocb->iocb; |
| 4538 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4539 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
| 4540 | pcmd += sizeof(uint32_t); |
| 4541 | |
| 4542 | /* Fill in LOGO payload */ |
| 4543 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
| 4544 | pcmd += sizeof(uint32_t); |
| 4545 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 4546 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4547 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 4548 | "Issue LOGO npiv did:x%x flg:x%x", |
| 4549 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4550 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4551 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
| 4552 | spin_lock_irq(shost->host_lock); |
| 4553 | ndlp->nlp_flag |= NLP_LOGO_SND; |
| 4554 | spin_unlock_irq(shost->host_lock); |
| 4555 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
| 4556 | spin_lock_irq(shost->host_lock); |
| 4557 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
| 4558 | spin_unlock_irq(shost->host_lock); |
| 4559 | lpfc_els_free_iocb(phba, elsiocb); |
| 4560 | return 1; |
| 4561 | } |
| 4562 | return 0; |
| 4563 | } |
| 4564 | |
| 4565 | void |
| 4566 | lpfc_fabric_block_timeout(unsigned long ptr) |
| 4567 | { |
| 4568 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| 4569 | unsigned long iflags; |
| 4570 | uint32_t tmo_posted; |
| 4571 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 4572 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; |
| 4573 | if (!tmo_posted) |
| 4574 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; |
| 4575 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 4576 | |
| 4577 | if (!tmo_posted) { |
| 4578 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 4579 | if (phba->work_wait) |
| 4580 | lpfc_worker_wake_up(phba); |
| 4581 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 4582 | } |
| 4583 | } |
| 4584 | |
| 4585 | static void |
| 4586 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) |
| 4587 | { |
| 4588 | struct lpfc_iocbq *iocb; |
| 4589 | unsigned long iflags; |
| 4590 | int ret; |
| 4591 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 4592 | IOCB_t *cmd; |
| 4593 | |
| 4594 | repeat: |
| 4595 | iocb = NULL; |
| 4596 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 4597 | /* Post any pending iocb to the SLI layer */ |
| 4598 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
| 4599 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), |
| 4600 | list); |
| 4601 | if (iocb) |
| 4602 | atomic_inc(&phba->fabric_iocb_count); |
| 4603 | } |
| 4604 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 4605 | if (iocb) { |
| 4606 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 4607 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 4608 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 4609 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4610 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 4611 | "Fabric sched1: ste:x%x", |
| 4612 | iocb->vport->port_state, 0, 0); |
| 4613 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4614 | ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0); |
| 4615 | |
| 4616 | if (ret == IOCB_ERROR) { |
| 4617 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 4618 | iocb->fabric_iocb_cmpl = NULL; |
| 4619 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 4620 | cmd = &iocb->iocb; |
| 4621 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 4622 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 4623 | iocb->iocb_cmpl(phba, iocb, iocb); |
| 4624 | |
| 4625 | atomic_dec(&phba->fabric_iocb_count); |
| 4626 | goto repeat; |
| 4627 | } |
| 4628 | } |
| 4629 | |
| 4630 | return; |
| 4631 | } |
| 4632 | |
| 4633 | void |
| 4634 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) |
| 4635 | { |
| 4636 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 4637 | |
| 4638 | lpfc_resume_fabric_iocbs(phba); |
| 4639 | return; |
| 4640 | } |
| 4641 | |
| 4642 | static void |
| 4643 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) |
| 4644 | { |
| 4645 | int blocked; |
| 4646 | |
| 4647 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 4648 | /* Start a timer to unblock fabric |
| 4649 | * iocbs after 100ms |
| 4650 | */ |
| 4651 | if (!blocked) |
| 4652 | mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 ); |
| 4653 | |
| 4654 | return; |
| 4655 | } |
| 4656 | |
| 4657 | static void |
| 4658 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 4659 | struct lpfc_iocbq *rspiocb) |
| 4660 | { |
| 4661 | struct ls_rjt stat; |
| 4662 | |
| 4663 | if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC) |
| 4664 | BUG(); |
| 4665 | |
| 4666 | switch (rspiocb->iocb.ulpStatus) { |
| 4667 | case IOSTAT_NPORT_RJT: |
| 4668 | case IOSTAT_FABRIC_RJT: |
| 4669 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 4670 | lpfc_block_fabric_iocbs(phba); |
| 4671 | } |
| 4672 | break; |
| 4673 | |
| 4674 | case IOSTAT_NPORT_BSY: |
| 4675 | case IOSTAT_FABRIC_BSY: |
| 4676 | lpfc_block_fabric_iocbs(phba); |
| 4677 | break; |
| 4678 | |
| 4679 | case IOSTAT_LS_RJT: |
| 4680 | stat.un.lsRjtError = |
| 4681 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); |
| 4682 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || |
| 4683 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) |
| 4684 | lpfc_block_fabric_iocbs(phba); |
| 4685 | break; |
| 4686 | } |
| 4687 | |
| 4688 | if (atomic_read(&phba->fabric_iocb_count) == 0) |
| 4689 | BUG(); |
| 4690 | |
| 4691 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; |
| 4692 | cmdiocb->fabric_iocb_cmpl = NULL; |
| 4693 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 4694 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); |
| 4695 | |
| 4696 | atomic_dec(&phba->fabric_iocb_count); |
| 4697 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { |
| 4698 | /* Post any pending iocbs to HBA */ |
| 4699 | lpfc_resume_fabric_iocbs(phba); |
| 4700 | } |
| 4701 | } |
| 4702 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 4703 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4704 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
| 4705 | { |
| 4706 | unsigned long iflags; |
| 4707 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 4708 | int ready; |
| 4709 | int ret; |
| 4710 | |
| 4711 | if (atomic_read(&phba->fabric_iocb_count) > 1) |
| 4712 | BUG(); |
| 4713 | |
| 4714 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 4715 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && |
| 4716 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 4717 | |
| 4718 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 4719 | if (ready) { |
| 4720 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 4721 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 4722 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 4723 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4724 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 4725 | "Fabric sched2: ste:x%x", |
| 4726 | iocb->vport->port_state, 0, 0); |
| 4727 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4728 | atomic_inc(&phba->fabric_iocb_count); |
| 4729 | ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0); |
| 4730 | |
| 4731 | if (ret == IOCB_ERROR) { |
| 4732 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 4733 | iocb->fabric_iocb_cmpl = NULL; |
| 4734 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 4735 | atomic_dec(&phba->fabric_iocb_count); |
| 4736 | } |
| 4737 | } else { |
| 4738 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 4739 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); |
| 4740 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 4741 | ret = IOCB_SUCCESS; |
| 4742 | } |
| 4743 | return ret; |
| 4744 | } |
| 4745 | |
| 4746 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 4747 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4748 | { |
| 4749 | LIST_HEAD(completions); |
| 4750 | struct lpfc_hba *phba = vport->phba; |
| 4751 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 4752 | IOCB_t *cmd; |
| 4753 | |
| 4754 | spin_lock_irq(&phba->hbalock); |
| 4755 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 4756 | list) { |
| 4757 | |
| 4758 | if (piocb->vport != vport) |
| 4759 | continue; |
| 4760 | |
| 4761 | list_move_tail(&piocb->list, &completions); |
| 4762 | } |
| 4763 | spin_unlock_irq(&phba->hbalock); |
| 4764 | |
| 4765 | while (!list_empty(&completions)) { |
| 4766 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| 4767 | list_del_init(&piocb->list); |
| 4768 | |
| 4769 | cmd = &piocb->iocb; |
| 4770 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 4771 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 4772 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 4773 | } |
| 4774 | } |
| 4775 | |
| 4776 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) |
| 4777 | { |
| 4778 | LIST_HEAD(completions); |
| 4779 | struct lpfc_hba *phba = ndlp->vport->phba; |
| 4780 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 4781 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 4782 | IOCB_t *cmd; |
| 4783 | |
| 4784 | spin_lock_irq(&phba->hbalock); |
| 4785 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 4786 | list) { |
| 4787 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { |
| 4788 | |
| 4789 | list_move_tail(&piocb->list, &completions); |
| 4790 | } |
| 4791 | } |
| 4792 | spin_unlock_irq(&phba->hbalock); |
| 4793 | |
| 4794 | while (!list_empty(&completions)) { |
| 4795 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| 4796 | list_del_init(&piocb->list); |
| 4797 | |
| 4798 | cmd = &piocb->iocb; |
| 4799 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 4800 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 4801 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 4802 | } |
| 4803 | } |
| 4804 | |
| 4805 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) |
| 4806 | { |
| 4807 | LIST_HEAD(completions); |
| 4808 | struct lpfc_iocbq *piocb; |
| 4809 | IOCB_t *cmd; |
| 4810 | |
| 4811 | spin_lock_irq(&phba->hbalock); |
| 4812 | list_splice_init(&phba->fabric_iocb_list, &completions); |
| 4813 | spin_unlock_irq(&phba->hbalock); |
| 4814 | |
| 4815 | while (!list_empty(&completions)) { |
| 4816 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| 4817 | list_del_init(&piocb->list); |
| 4818 | |
| 4819 | cmd = &piocb->iocb; |
| 4820 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 4821 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 4822 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 4823 | } |
| 4824 | } |
| 4825 | |
| 4826 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 4827 | #if 0 |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4828 | void lpfc_fabric_abort_flogi(struct lpfc_hba *phba) |
| 4829 | { |
| 4830 | LIST_HEAD(completions); |
| 4831 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 4832 | IOCB_t *cmd; |
| 4833 | struct lpfc_nodelist *ndlp; |
| 4834 | |
| 4835 | spin_lock_irq(&phba->hbalock); |
| 4836 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 4837 | list) { |
| 4838 | |
| 4839 | cmd = &piocb->iocb; |
| 4840 | ndlp = (struct lpfc_nodelist *) piocb->context1; |
| 4841 | if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR && |
| 4842 | ndlp != NULL && |
| 4843 | ndlp->nlp_DID == Fabric_DID) |
| 4844 | list_move_tail(&piocb->list, &completions); |
| 4845 | } |
| 4846 | spin_unlock_irq(&phba->hbalock); |
| 4847 | |
| 4848 | while (!list_empty(&completions)) { |
| 4849 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| 4850 | list_del_init(&piocb->list); |
| 4851 | |
| 4852 | cmd = &piocb->iocb; |
| 4853 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 4854 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 4855 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 4856 | } |
| 4857 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 4858 | #endif /* 0 */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4859 | |
| 4860 | |